X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-psi;a=blobdiff_plain;f=src%2Fmodule.c;h=33e3ae2de8d1231655dc560bfad6d9b3994042af;hp=c3728a71b961137540d7d51ae747da5824588333;hb=5359ad5c181e5772f350fe1cba060cbed3a05b91;hpb=52815a5aac85e8c69ffba76c25a51de3b6ae1365 diff --git a/src/module.c b/src/module.c index c3728a7..33e3ae2 100644 --- a/src/module.c +++ b/src/module.c @@ -1,4 +1,3 @@ - #ifdef HAVE_CONFIG_H # include "config.h" #endif @@ -10,6 +9,8 @@ #include "zend_operators.h" #include "php_psi.h" +#include "token.h" +#include "parser.h" #if HAVE_LIBJIT # include "libjit.h" @@ -37,12 +38,18 @@ zend_class_entry *psi_object_get_class_entry() return psi_class_entry; } -void psi_error_wrapper(PSI_Token *t, int type, const char *msg, ...) +void psi_error_wrapper(void *context, struct psi_token *t, int type, const char *msg, ...) { va_list argv; const char *fn = NULL; unsigned ln = 0; + if (context) { + if (PSI_DATA(context)->flags & PSI_PARSER_SILENT) { + return; + } + } + if (t) { fn = t->file; ln = t->line; @@ -50,7 +57,7 @@ void psi_error_wrapper(PSI_Token *t, int type, const char *msg, ...) fn = zend_get_executed_filename(); ln = zend_get_executed_lineno(); } else if (zend_is_compiling()) { - fn = zend_get_compiled_filename(); + fn = zend_get_compiled_filename()->val; ln = zend_get_compiled_lineno(); } @@ -113,7 +120,7 @@ static PHP_FUNCTION(psi_dump) { RETURN_FALSE; } } - PSI_ContextDump(&PSI_G(context), fd); + psi_context_dump(&PSI_G(context), fd); } ZEND_BEGIN_ARG_INFO_EX(ai_psi_validate, 0, 0, 1) @@ -121,36 +128,38 @@ ZEND_BEGIN_ARG_INFO_EX(ai_psi_validate, 0, 0, 1) ZEND_END_ARG_INFO(); static PHP_FUNCTION(psi_validate) { zend_string *file; - PSI_Parser P; + struct psi_parser P; if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "P", &file)) { return; } - if (!PSI_ParserInit(&P, file->val, psi_error_wrapper, 0)) { + if (!psi_parser_init(&P, file->val, psi_error_wrapper, 0)) { RETURN_FALSE; } - while (0 < PSI_ParserScan(&P)) { - PSI_ParserParse(&P, PSI_TokenAlloc(&P)); + while (0 < psi_parser_scan(&P)) { + psi_parser_parse(&P, psi_token_alloc(&P)); if (P.num == PSI_T_EOF) { break; } } - PSI_ParserParse(&P, NULL); + psi_parser_parse(&P, NULL); - if (0 == PSI_ContextValidateData(NULL, PSI_DATA(&P)) && !P.errors) { + if (0 == psi_context_validate_data(NULL, PSI_DATA(&P)) && !P.errors) { RETVAL_TRUE; } else { RETVAL_FALSE; } - PSI_ParserDtor(&P); + psi_parser_dtor(&P); } static PHP_MINIT_FUNCTION(psi) { - PSI_ContextOps *ops = NULL; + struct psi_context_ops *ops = NULL; zend_class_entry ce = {0}; + unsigned flags = psi_check_env("PSI_DEBUG") ? PSI_PARSER_DEBUG : ( + psi_check_env("PSI_SILENT") ? PSI_PARSER_SILENT : 0); REGISTER_INI_ENTRIES(); @@ -165,11 +174,11 @@ static PHP_MINIT_FUNCTION(psi) #ifdef HAVE_LIBJIT if (!strcasecmp(PSI_G(engine), "jit")) { - ops = PSI_Libjit(); + ops = psi_libjit_ops(); } else #endif #ifdef HAVE_LIBFFI - ops = PSI_Libffi(); + ops = psi_libffi_ops(); #endif if (!ops) { @@ -177,11 +186,11 @@ static PHP_MINIT_FUNCTION(psi) return FAILURE; } - PSI_ContextInit(&PSI_G(context), ops, psi_error_wrapper); - PSI_ContextBuild(&PSI_G(context), PSI_G(directory)); + psi_context_init(&PSI_G(context), ops, psi_error_wrapper, flags); + psi_context_build(&PSI_G(context), PSI_G(directory)); if (psi_check_env("PSI_DUMP")) { - PSI_ContextDump(&PSI_G(context), STDOUT_FILENO); + psi_context_dump(&PSI_G(context), STDOUT_FILENO); } return SUCCESS; @@ -189,7 +198,7 @@ static PHP_MINIT_FUNCTION(psi) static PHP_MSHUTDOWN_FUNCTION(psi) { - PSI_ContextDtor(&PSI_G(context)); + psi_context_dtor(&PSI_G(context)); UNREGISTER_INI_ENTRIES();