Skip to content

Commit 4cbffd8

Browse files
akimdkocsismate
authored andcommitted
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
1 parent 2127a37 commit 4cbffd8

File tree

8 files changed

+29
-36
lines changed

8 files changed

+29
-36
lines changed

Diff for: Zend/Makefile.frag

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ $(srcdir)/zend_language_parser.c: $(srcdir)/zend_language_parser.y
1313
# Tweak zendparse to be exported through ZEND_API. This has to be revisited once
1414
# bison supports foreign skeletons and that bison version is used. Read
1515
# https://git.savannah.gnu.org/cgit/bison.git/tree/data/README.md for more.
16-
@$(YACC) $(YFLAGS) -p zend -v -d $(srcdir)/zend_language_parser.y -o $@
16+
@$(YACC) $(YFLAGS) -v -d $(srcdir)/zend_language_parser.y -o $@
1717
@$(SED) -e 's,^int zendparse\(.*\),ZEND_API int zendparse\1,g' < $@ \
1818
> $@.tmp && \
1919
mv $@.tmp $@
@@ -27,7 +27,7 @@ $(srcdir)/zend_language_parser.c: $(srcdir)/zend_language_parser.y
2727

2828
$(srcdir)/zend_ini_parser.h: $(srcdir)/zend_ini_parser.c
2929
$(srcdir)/zend_ini_parser.c: $(srcdir)/zend_ini_parser.y
30-
@$(YACC) $(YFLAGS) -p ini_ -v -d $(srcdir)/zend_ini_parser.y -o $@
30+
$(YACC) $(YFLAGS) -v -d $(srcdir)/zend_ini_parser.y -o $@
3131

3232
$(srcdir)/zend_ini_scanner.c: $(srcdir)/zend_ini_scanner.l
3333
@(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 for: Zend/zend_ini_parser.y

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@
3232
#include "win32/syslog.h"
3333
#endif
3434

35-
#define YYSTYPE zval
36-
3735
int ini_parse(void);
3836

3937
#define ZEND_INI_PARSER_CB (CG(ini_parser_param))->ini_parser_cb
@@ -289,7 +287,9 @@ static void zval_ini_dtor(zval *zv)
289287
%}
290288

291289
%expect 0
290+
%define api.prefix {ini_}
292291
%define api.pure full
292+
%define api.value.type {zval}
293293
%define parse.error verbose
294294

295295
%token TC_SECTION

Diff for: Zend/zend_language_parser.y

+7-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
%require "3.0"
2-
%{
32
/*
43
+----------------------------------------------------------------------+
54
| Zend Engine |
@@ -20,7 +19,7 @@
2019
+----------------------------------------------------------------------+
2120
*/
2221

23-
#include "zend_compile.h"
22+
%code top {
2423
#include "zend.h"
2524
#include "zend_list.h"
2625
#include "zend_globals.h"
@@ -33,22 +32,22 @@
3332
#define yytnamerr zend_yytnamerr
3433
static YYSIZE_T zend_yytnamerr(char*, const char*);
3534

36-
#define YYSTYPE zend_parser_stack_elem
37-
3835
#ifdef _MSC_VER
3936
#define YYMALLOC malloc
4037
#define YYFREE free
4138
#endif
39+
}
4240

43-
%}
41+
%code requires {
42+
#include "zend_compile.h"
43+
}
4444

45+
%define api.prefix {zend}
4546
%define api.pure full
47+
%define api.value.type {zend_parser_stack_elem}
4648
%define parse.error verbose
4749
%expect 0
4850

49-
%code requires {
50-
}
51-
5251
%destructor { zend_ast_destroy($$); } <ast>
5352
%destructor { if ($$) zend_string_release_ex($$, 0); } <str>
5453

Diff for: ext/json/json_parser.y

+2-3
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,9 @@ int json_yydebug = 1;
4141

4242
}
4343

44-
%define api.pure full
4544
%define api.prefix {php_json_yy}
46-
%lex-param { php_json_parser *parser }
47-
%parse-param { php_json_parser *parser }
45+
%define api.pure full
46+
%param { php_json_parser *parser }
4847

4948
%union {
5049
zval value;

Diff for: sapi/phpdbg/Makefile.frag

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ $(srcdir)/phpdbg_lexer.c: $(srcdir)/phpdbg_lexer.l
1818

1919
$(srcdir)/phpdbg_parser.h: $(srcdir)/phpdbg_parser.c
2020
$(srcdir)/phpdbg_parser.c: $(srcdir)/phpdbg_parser.y
21-
@$(YACC) $(YFLAGS) -p phpdbg_ -v -d $(srcdir)/phpdbg_parser.y -o $@
21+
@$(YACC) $(YFLAGS) -v -d $(srcdir)/phpdbg_parser.y -o $@
2222

2323
install-phpdbg: $(BUILD_BINARY)
2424
@echo "Installing phpdbg binary: $(INSTALL_ROOT)$(bindir)/"

Diff for: sapi/phpdbg/phpdbg_cmd.h

-4
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,6 @@ struct _phpdbg_param {
8181
(v)->top = NULL; \
8282
} while(0)
8383

84-
#ifndef YYSTYPE
85-
#define YYSTYPE phpdbg_param_t
86-
#endif
87-
8884
#define PHPDBG_ASYNC_SAFE 1
8985

9086
typedef int (*phpdbg_command_handler_t)(const phpdbg_param_t*);

Diff for: sapi/phpdbg/phpdbg_parser.y

+12-13
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11
%require "3.0"
2-
%{
3-
42
/*
53
* phpdbg_parser.y
64
* (from php-src root)
75
*/
86

7+
%code requires {
98
#include "phpdbg.h"
9+
#ifndef YY_TYPEDEF_YY_SCANNER_T
10+
#define YY_TYPEDEF_YY_SCANNER_T
11+
typedef void* yyscan_t;
12+
#endif
13+
}
14+
15+
%code {
16+
1017
#include "phpdbg_cmd.h"
1118
#include "phpdbg_utils.h"
1219
#include "phpdbg_cmd.h"
1320
#include "phpdbg_prompt.h"
1421

15-
#define YYSTYPE phpdbg_param_t
16-
1722
#include "phpdbg_parser.h"
1823
#include "phpdbg_lexer.h"
1924

@@ -27,19 +32,13 @@ ZEND_EXTERN_MODULE_GLOBALS(phpdbg)
2732
#define YYFREE free
2833
#endif
2934

30-
%}
35+
}
3136

37+
%define api.prefix {phpdbg_}
3238
%define api.pure full
39+
%define api.value.type {phpdbg_param_t}
3340
%define parse.error verbose
3441

35-
%code requires {
36-
#include "phpdbg.h"
37-
#ifndef YY_TYPEDEF_YY_SCANNER_T
38-
#define YY_TYPEDEF_YY_SCANNER_T
39-
typedef void* yyscan_t;
40-
#endif
41-
}
42-
4342
%token T_EVAL "eval"
4443
%token T_RUN "run"
4544
%token T_SHELL "shell"

Diff for: win32/build/Makefile

+3-3
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,16 @@ $(BUILD_DIR)\$(PHPDLL).def: $(PHP_DLL_DEF_SOURCES)
7575
type $(PHP_DLL_DEF_SOURCES) > $(BUILD_DIR)\$(PHPDLL).def
7676

7777
Zend\zend_ini_parser.c Zend\zend_ini_parser.h: Zend\zend_ini_parser.y
78-
$(BISON) --output=Zend/zend_ini_parser.c -v -d -p ini_ Zend/zend_ini_parser.y
78+
$(BISON) --output=Zend/zend_ini_parser.c -v -d Zend/zend_ini_parser.y
7979

8080
Zend\zend_language_parser.c Zend\zend_language_parser.h: Zend\zend_language_parser.y
81-
$(BISON) --output=Zend/zend_language_parser.c -v -d -p zend Zend/zend_language_parser.y
81+
$(BISON) --output=Zend/zend_language_parser.c -v -d Zend/zend_language_parser.y
8282
@if "$(SED)" neq "" $(SED) -i "s,^int zendparse\(.*\),ZEND_API int zendparse\1,g" Zend/zend_language_parser.c
8383
@if "$(SED)" neq "" $(SED) -i "s,^int zendparse\(.*\),ZEND_API int zendparse\1,g" Zend/zend_language_parser.h
8484
@if "$(SED)" neq "" $(SED) -i "s,^#ifndef YYTOKENTYPE,#include \"zend.h\"\n#ifndef YYTOKENTYPE,g" Zend/zend_language_parser.h
8585

8686
sapi\phpdbg\phpdbg_parser.c sapi\phpdbg\phpdbg_parser.h: sapi\phpdbg\phpdbg_parser.y
87-
$(BISON) --output=sapi/phpdbg/phpdbg_parser.c -v -d -p phpdbg_ sapi/phpdbg/phpdbg_parser.y
87+
$(BISON) --output=sapi/phpdbg/phpdbg_parser.c -v -d sapi/phpdbg/phpdbg_parser.y
8888

8989
!if $(RE2C) != ""
9090
Zend\zend_ini_scanner.c: Zend\zend_ini_scanner.l

0 commit comments

Comments
 (0)