X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=src%2Fcontext.c;h=9b5730ed64736fe121866a0f04c2d807f34c233a;hb=5f4abb70454abc62e885f4119339aaad2e5eeb1c;hp=1d5e23086be1e56a2a4d626fe14c7829c7d1b5b0;hpb=216e7ac3b97aed5a5d65c511dc061c78be90e79d;p=m6w6%2Fext-psi diff --git a/src/context.c b/src/context.c index 1d5e230..9b5730e 100644 --- a/src/context.c +++ b/src/context.c @@ -98,7 +98,9 @@ PHP_MINIT_FUNCTION(psi_context) PHP_MSHUTDOWN_FUNCTION(psi_context) { if (psi_check_env("PSI_DUMP")) { - psi_context_dump(PSI_G(context), STDOUT_FILENO); + struct psi_dump dump = {{.hn = stdout}, (psi_dump_cb) fprintf}; + + psi_context_dump(&dump, PSI_G(context)); } psi_context_free(&PSI_G(context)); @@ -148,7 +150,7 @@ static bool psi_context_add(struct psi_context *C, struct psi_parser *P) D = psi_data_exchange(&C->data[C->count++], PSI_DATA(P)); psi_validate_scope_ctor(&scope); - scope.defs = &P->preproc->defs; + scope.cpp = P->preproc; valid = psi_validate(&scope, PSI_DATA(C), D); psi_validate_scope_dtor(&scope); @@ -209,13 +211,35 @@ void psi_context_build(struct psi_context *C, const char *paths) } while (sep); - if (psi_context_compile(C) && SUCCESS != zend_register_functions(NULL, C->closures, NULL, MODULE_PERSISTENT)) { - C->error(PSI_DATA(C), NULL, PSI_WARNING, "Failed to register functions!"); + if (psi_context_compile(C)) { + /* zend_register_functions depends on EG(current_module) pointing into module */ + EG(current_module) = zend_hash_str_find_ptr(&module_registry, "psi", sizeof("psi") - 1); + if (SUCCESS != zend_register_functions(NULL, C->closures, NULL, MODULE_PERSISTENT)) { + C->error(PSI_DATA(C), NULL, PSI_WARNING, "Failed to register functions!"); + } + EG(current_module) = NULL; } free(cpy); } +#include +static inline bool prefix_match(zend_string *a, zend_string *b) +{ + size_t i; + + for (i = 0; i < a->len && i < b->len; ++i) { + if (tolower(a->val[i]) != tolower(b->val[i])) { + return false; + } + if (i && a->val[i] == '_') { + break; + } + } + + return true; +} + zend_function_entry *psi_context_compile(struct psi_context *C) { zend_constant zc; @@ -233,29 +257,7 @@ zend_function_entry *psi_context_compile(struct psi_context *C) } zc.name = zend_string_copy(c->name); - - switch (c->type->type) { - case PSI_T_BOOL: - ZVAL_BOOL(&zc.value, c->val->ival.zend.bval); - break; - case PSI_T_INT: - ZVAL_LONG(&zc.value, c->val->ival.zend.lval); - break; - case PSI_T_FLOAT: - case PSI_T_DOUBLE: - ZVAL_DOUBLE(&zc.value, c->val->ival.dval); - break; - case PSI_T_STRING: - case PSI_T_QUOTED_STRING: - ZVAL_NEW_STR(&zc.value, zend_string_copy(c->val->ival.zend.str)); - if (ZSTR_IS_INTERNED(Z_STR(zc.value))) { - Z_TYPE_FLAGS(zc.value) = 0; - } - break; - default: - assert(0); - break; - } + psi_impl_def_val_get_zval(c->val, c->type ? c->type->type : PSI_T_MIXED, &zc.value); zend_register_constant(&zc); } @@ -272,9 +274,11 @@ zend_function_entry *psi_context_compile(struct psi_context *C) while (psi_plist_get(e->items, j++, &item)) { zend_string *name; - if (psi_decl_type_is_anon(e->name, "enum")) { + if (psi_decl_type_is_anon(e->name, "enum") + || prefix_match(e->name, item->name)) { name = strpprintf(0, "psi\\%s", item->name->val); } else { + name = strpprintf(0, "psi\\%s\\%s", e->name->val, item->name->val); } @@ -376,15 +380,21 @@ void psi_context_free(struct psi_context **C) } } -void psi_context_dump(struct psi_context *C, int fd) +void psi_context_dump(struct psi_dump *dump, struct psi_context *C) { - size_t i; - - dprintf(fd, "// psi.engine=%s\n// %lu files\n", + PSI_DUMP(dump, "// psi.engine=%s\n// %lu files\n", (char *) C->ops->query(C, PSI_CONTEXT_QUERY_SELF, NULL), C->count); - for (i = 0; i < C->count; ++i) { - psi_data_dump(fd, &C->data[i]); + psi_data_dump(dump, PSI_DATA(C)); + +#if 0 + if (C->flags & PSI_DEBUG) { + size_t i; + + for (i = 0; i < C->count; ++i) { + psi_data_dump(dump, &C->data[i]); + } } +#endif }