From: Akim Demaille Date: Sat, 1 Feb 2020 06:07:28 +0000 (+0100) Subject: Clean up the generation of the parsers X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4cbffd89d9e82d81a26746aadca27ad061cab43a;p=php Clean up the generation of the parsers Prefer '%define api.value.type' to '#define YYSTYPE', so that Bison know the type. Use '%code requires' to declare what is needed to define the api.value.type (that code is output in the generated header before the generated definition of YYSTYPE). Prefer '%define api.prefix' inside the grammar file to '-p' outside, as anyway the functions defined in the file actually use this prefix. Prefer `%param` to both `%parse-param` and `%lex-param`. Closes GH-5138 --- diff --git a/Zend/Makefile.frag b/Zend/Makefile.frag index 2f3c2d948d..4160fe2b5e 100644 --- a/Zend/Makefile.frag +++ b/Zend/Makefile.frag @@ -13,7 +13,7 @@ $(srcdir)/zend_language_parser.c: $(srcdir)/zend_language_parser.y # Tweak zendparse to be exported through ZEND_API. This has to be revisited once # bison supports foreign skeletons and that bison version is used. Read # https://git.savannah.gnu.org/cgit/bison.git/tree/data/README.md for more. - @$(YACC) $(YFLAGS) -p zend -v -d $(srcdir)/zend_language_parser.y -o $@ + @$(YACC) $(YFLAGS) -v -d $(srcdir)/zend_language_parser.y -o $@ @$(SED) -e 's,^int zendparse\(.*\),ZEND_API int zendparse\1,g' < $@ \ > $@.tmp && \ mv $@.tmp $@ @@ -27,7 +27,7 @@ $(srcdir)/zend_language_parser.c: $(srcdir)/zend_language_parser.y $(srcdir)/zend_ini_parser.h: $(srcdir)/zend_ini_parser.c $(srcdir)/zend_ini_parser.c: $(srcdir)/zend_ini_parser.y - @$(YACC) $(YFLAGS) -p ini_ -v -d $(srcdir)/zend_ini_parser.y -o $@ + $(YACC) $(YFLAGS) -v -d $(srcdir)/zend_ini_parser.y -o $@ $(srcdir)/zend_ini_scanner.c: $(srcdir)/zend_ini_scanner.l @(cd $(top_srcdir); $(RE2C) $(RE2C_FLAGS) --no-generation-date --case-inverted -cbdFt Zend/zend_ini_scanner_defs.h -oZend/zend_ini_scanner.c Zend/zend_ini_scanner.l) diff --git a/Zend/zend_ini_parser.y b/Zend/zend_ini_parser.y index 6b69aec7d9..a204496a35 100644 --- a/Zend/zend_ini_parser.y +++ b/Zend/zend_ini_parser.y @@ -32,8 +32,6 @@ #include "win32/syslog.h" #endif -#define YYSTYPE zval - int ini_parse(void); #define ZEND_INI_PARSER_CB (CG(ini_parser_param))->ini_parser_cb @@ -289,7 +287,9 @@ static void zval_ini_dtor(zval *zv) %} %expect 0 +%define api.prefix {ini_} %define api.pure full +%define api.value.type {zval} %define parse.error verbose %token TC_SECTION diff --git a/Zend/zend_language_parser.y b/Zend/zend_language_parser.y index 2f7b772c8b..078c863c4e 100644 --- a/Zend/zend_language_parser.y +++ b/Zend/zend_language_parser.y @@ -1,5 +1,4 @@ %require "3.0" -%{ /* +----------------------------------------------------------------------+ | Zend Engine | @@ -20,7 +19,7 @@ +----------------------------------------------------------------------+ */ -#include "zend_compile.h" +%code top { #include "zend.h" #include "zend_list.h" #include "zend_globals.h" @@ -33,22 +32,22 @@ #define yytnamerr zend_yytnamerr static YYSIZE_T zend_yytnamerr(char*, const char*); -#define YYSTYPE zend_parser_stack_elem - #ifdef _MSC_VER #define YYMALLOC malloc #define YYFREE free #endif +} -%} +%code requires { +#include "zend_compile.h" +} +%define api.prefix {zend} %define api.pure full +%define api.value.type {zend_parser_stack_elem} %define parse.error verbose %expect 0 -%code requires { -} - %destructor { zend_ast_destroy($$); } %destructor { if ($$) zend_string_release_ex($$, 0); } diff --git a/ext/json/json_parser.y b/ext/json/json_parser.y index 833a772807..4705e498a6 100644 --- a/ext/json/json_parser.y +++ b/ext/json/json_parser.y @@ -41,10 +41,9 @@ int json_yydebug = 1; } -%define api.pure full %define api.prefix {php_json_yy} -%lex-param { php_json_parser *parser } -%parse-param { php_json_parser *parser } +%define api.pure full +%param { php_json_parser *parser } %union { zval value; diff --git a/sapi/phpdbg/Makefile.frag b/sapi/phpdbg/Makefile.frag index 448cc3676b..1572bfd9f0 100644 --- a/sapi/phpdbg/Makefile.frag +++ b/sapi/phpdbg/Makefile.frag @@ -18,7 +18,7 @@ $(srcdir)/phpdbg_lexer.c: $(srcdir)/phpdbg_lexer.l $(srcdir)/phpdbg_parser.h: $(srcdir)/phpdbg_parser.c $(srcdir)/phpdbg_parser.c: $(srcdir)/phpdbg_parser.y - @$(YACC) $(YFLAGS) -p phpdbg_ -v -d $(srcdir)/phpdbg_parser.y -o $@ + @$(YACC) $(YFLAGS) -v -d $(srcdir)/phpdbg_parser.y -o $@ install-phpdbg: $(BUILD_BINARY) @echo "Installing phpdbg binary: $(INSTALL_ROOT)$(bindir)/" diff --git a/sapi/phpdbg/phpdbg_cmd.h b/sapi/phpdbg/phpdbg_cmd.h index 56c8681c59..dd80e61db3 100644 --- a/sapi/phpdbg/phpdbg_cmd.h +++ b/sapi/phpdbg/phpdbg_cmd.h @@ -81,10 +81,6 @@ struct _phpdbg_param { (v)->top = NULL; \ } while(0) -#ifndef YYSTYPE -#define YYSTYPE phpdbg_param_t -#endif - #define PHPDBG_ASYNC_SAFE 1 typedef int (*phpdbg_command_handler_t)(const phpdbg_param_t*); diff --git a/sapi/phpdbg/phpdbg_parser.y b/sapi/phpdbg/phpdbg_parser.y index 1384abe6fb..f776586810 100644 --- a/sapi/phpdbg/phpdbg_parser.y +++ b/sapi/phpdbg/phpdbg_parser.y @@ -1,19 +1,24 @@ %require "3.0" -%{ - /* * phpdbg_parser.y * (from php-src root) */ +%code requires { #include "phpdbg.h" +#ifndef YY_TYPEDEF_YY_SCANNER_T +#define YY_TYPEDEF_YY_SCANNER_T +typedef void* yyscan_t; +#endif +} + +%code { + #include "phpdbg_cmd.h" #include "phpdbg_utils.h" #include "phpdbg_cmd.h" #include "phpdbg_prompt.h" -#define YYSTYPE phpdbg_param_t - #include "phpdbg_parser.h" #include "phpdbg_lexer.h" @@ -27,19 +32,13 @@ ZEND_EXTERN_MODULE_GLOBALS(phpdbg) #define YYFREE free #endif -%} +} +%define api.prefix {phpdbg_} %define api.pure full +%define api.value.type {phpdbg_param_t} %define parse.error verbose -%code requires { -#include "phpdbg.h" -#ifndef YY_TYPEDEF_YY_SCANNER_T -#define YY_TYPEDEF_YY_SCANNER_T -typedef void* yyscan_t; -#endif -} - %token T_EVAL "eval" %token T_RUN "run" %token T_SHELL "shell" diff --git a/win32/build/Makefile b/win32/build/Makefile index a6b54c07ff..d0315f41c4 100644 --- a/win32/build/Makefile +++ b/win32/build/Makefile @@ -75,16 +75,16 @@ $(BUILD_DIR)\$(PHPDLL).def: $(PHP_DLL_DEF_SOURCES) type $(PHP_DLL_DEF_SOURCES) > $(BUILD_DIR)\$(PHPDLL).def Zend\zend_ini_parser.c Zend\zend_ini_parser.h: Zend\zend_ini_parser.y - $(BISON) --output=Zend/zend_ini_parser.c -v -d -p ini_ Zend/zend_ini_parser.y + $(BISON) --output=Zend/zend_ini_parser.c -v -d Zend/zend_ini_parser.y Zend\zend_language_parser.c Zend\zend_language_parser.h: Zend\zend_language_parser.y - $(BISON) --output=Zend/zend_language_parser.c -v -d -p zend Zend/zend_language_parser.y + $(BISON) --output=Zend/zend_language_parser.c -v -d Zend/zend_language_parser.y @if "$(SED)" neq "" $(SED) -i "s,^int zendparse\(.*\),ZEND_API int zendparse\1,g" Zend/zend_language_parser.c @if "$(SED)" neq "" $(SED) -i "s,^int zendparse\(.*\),ZEND_API int zendparse\1,g" Zend/zend_language_parser.h @if "$(SED)" neq "" $(SED) -i "s,^#ifndef YYTOKENTYPE,#include \"zend.h\"\n#ifndef YYTOKENTYPE,g" Zend/zend_language_parser.h sapi\phpdbg\phpdbg_parser.c sapi\phpdbg\phpdbg_parser.h: sapi\phpdbg\phpdbg_parser.y - $(BISON) --output=sapi/phpdbg/phpdbg_parser.c -v -d -p phpdbg_ sapi/phpdbg/phpdbg_parser.y + $(BISON) --output=sapi/phpdbg/phpdbg_parser.c -v -d sapi/phpdbg/phpdbg_parser.y !if $(RE2C) != "" Zend\zend_ini_scanner.c: Zend\zend_ini_scanner.l