mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-13 14:23:04 +00:00
glr.cc, yacc.c: initialize yylloc properly
There are several issues to address here. One is that yylloc should be initialized when possible. Another is that the push parser needs to update yypushed_loc when the user modified it. And if the parser starts by a reduction of an empty, it uses the first location on the stack, which, therefore, must also be initialized to this initial location. This is getting complex, especially since because initializing a global (impure interface) is different from initializing a local variable. To simplify, the local yylloc is not initialized during its definition. * data/c.m4 (b4_yyloc_default_define): Replace by... (b4_yyloc_default): this. Adjust dependencies. * data/glr.cc: Initialize yylloc. * data/yacc.c (b4_declare_scanner_communication_variables): Initialize yylloc during its definition. Don't define yyloc_default. (yypush_parse): The location formal is not const, as we might initialize it. (yyparse): Define yyloc_default. Use it before running the user initial action. Possibly update the first location on the stack, and the pushed location after the user initial action. * tests/actions.at (Initial locations): Check that the initial location is correct.
This commit is contained in:
14
data/c.m4
14
data/c.m4
@@ -673,12 +673,11 @@ m4_define([b4_yy_location_print_define],
|
||||
#endif]])
|
||||
])
|
||||
|
||||
# b4_yyloc_default_define
|
||||
# -----------------------
|
||||
# Define yyloc_default, which can be used to initialize location
|
||||
# variables.
|
||||
m4_define([b4_yyloc_default_define],
|
||||
[[static YYLTYPE yyloc_default
|
||||
# b4_yyloc_default
|
||||
# ----------------
|
||||
# Expand to a possible default value for yylloc.
|
||||
m4_define([b4_yyloc_default],
|
||||
[[
|
||||
# if defined ]b4_api_PREFIX[LTYPE_IS_TRIVIAL && ]b4_api_PREFIX[LTYPE_IS_TRIVIAL
|
||||
= { ]m4_join([, ],
|
||||
m4_defn([b4_location_initial_line]),
|
||||
@@ -686,5 +685,4 @@ m4_define([b4_yyloc_default_define],
|
||||
m4_defn([b4_location_initial_line]),
|
||||
m4_defn([b4_location_initial_column]))[ }
|
||||
# endif
|
||||
;]dnl
|
||||
])
|
||||
]])
|
||||
|
||||
Reference in New Issue
Block a user