#include "php_psi.h"
+HashTable psi_cpp_defaults;
+
+PHP_MINIT_FUNCTION(psi_cpp)
+{
+ struct psi_parser parser;
+ struct psi_parser_input *predef;
+
+ if (!psi_parser_init(&parser, NULL, 0)) {
+ return FAILURE;
+ }
+
+ if (!(predef = psi_parser_open_string(&parser, psi_cpp_predef, sizeof(psi_cpp_predef) - 1))) {
+ psi_parser_dtor(&parser);
+ return FAILURE;
+ }
+
+ if (!psi_parser_parse(&parser, predef)) {
+ psi_parser_input_free(&predef);
+ psi_parser_dtor(&parser);
+ return FAILURE;
+ }
+ psi_parser_input_free(&predef);
+
+ zend_hash_init(&psi_cpp_defaults, 0, NULL, NULL, 1);
+ zend_hash_copy(&psi_cpp_defaults, &parser.preproc->defs, NULL);
+
+ psi_parser_dtor(&parser);
+
+ return SUCCESS;
+}
+
+PHP_MSHUTDOWN_FUNCTION(psi_cpp)
+{
+ struct psi_cpp_macro_decl *macro;
+
+ ZEND_HASH_FOREACH_PTR(&psi_cpp_defaults, macro)
+ {
+ psi_cpp_macro_decl_free(¯o);
+ }
+ ZEND_HASH_FOREACH_END();
+
+ zend_hash_destroy(&psi_cpp_defaults);
+
+ return SUCCESS;
+}
+
static void free_cpp_def(zval *p)
{
if (Z_TYPE_P(p) == IS_PTR) {
- psi_cpp_macro_decl_free((void *) &Z_PTR_P(p));
+ struct psi_cpp_macro_decl *macro = Z_PTR_P(p);
+
+ if (!zend_hash_exists(&psi_cpp_defaults, macro->token->text)) {
+ psi_cpp_macro_decl_free(¯o);
+ }
}
}
struct psi_cpp *cpp = calloc(1, sizeof(*cpp));
cpp->parser = P;
- zend_hash_init(&cpp->defs, 0, NULL, free_cpp_def, 1);
zend_hash_init(&cpp->once, 0, NULL, NULL, 1);
+ zend_hash_init(&cpp->defs, 0, NULL, free_cpp_def, 1);
+ zend_hash_copy(&cpp->defs, &psi_cpp_defaults, NULL);
return cpp;
}
-bool psi_cpp_load_defaults(struct psi_cpp *cpp)
-{
- struct psi_parser_input *predef;
-
- if ((predef = psi_parser_open_string(cpp->parser, psi_cpp_predef, sizeof(psi_cpp_predef) - 1))) {
- bool parsed = psi_parser_parse(cpp->parser, predef);
- psi_parser_input_free(&predef);
- return parsed;
- }
-
- return false;
-}
-
#if PSI_CPP_DEBUG
static int dump_def(zval *p)
{
#include "php_psi.h"
#include "token.h"
#include "parser.h"
+#include "cpp.h"
#define PSI_CPP_SEARCH
#include "php_psi_cpp.h"
return SUCCESS;
}
+PHP_MINIT_FUNCTION(psi_cpp);
static PHP_MINIT_FUNCTION(psi)
{
zend_class_entry ce = {0};
psi_object_handlers.free_obj = psi_object_free;
psi_object_handlers.clone_obj = NULL;
+ if (SUCCESS != PHP_MINIT(psi_cpp)(type, module_number)) {
+ return FAILURE;
+ }
+
if (SUCCESS != psi_ops_load()) {
return FAILURE;
}
return SUCCESS;
}
+PHP_MSHUTDOWN_FUNCTION(psi_cpp);
static PHP_MSHUTDOWN_FUNCTION(psi)
{
if (psi_check_env("PSI_DUMP")) {
PSI_G(ops)->free();
}
+ PHP_MSHUTDOWN(psi_cpp)(type, module_number);
+
UNREGISTER_INI_ENTRIES();
return SUCCESS;
-/* Generated by re2c 1.1.1 on Fri Nov 2 07:35:40 2018 */
+/* Generated by re2c 1.1.1 on Fri Nov 2 08:39:44 2018 */
#line 1 "src/parser.re"
/*******************************************************************************
Copyright (c) 2016, Michael Wallner <mike@php.net>.
P->preproc = psi_cpp_init(P);
- psi_cpp_load_defaults(P->preproc);
-
return P;
}
}
+
+
struct psi_plist *psi_parser_scan(struct psi_parser *P, struct psi_parser_input *I)
{
struct psi_plist *tokens;