In Bison 1.875's yacc.c, YYLLOC_DEFAULT was called regardless

whether the reducion was empty or not.  This leaves room to
improve the use of YYLLOC_DEFAULT in such a case.
lalr1.cc is still experimental, so changing this is acceptable.
And finally, there are probably not many users who changed the
handling of locations in GLR, so changing is admissible too.
* data/glr.c, data/lalr1.cc, data/yacc.c (YYLLOC_DEFAULT): On an
empty reduction, set @$ to an empty location ending the previously
stacked symbol.
Adjust uses to make sure the code is triggered on empty
reductions.
* tests/actions.at (_AT_CHECK_PRINTER_AND_DESTRUCTOR): Adjust the
expected output: empty reductions have empty locations.
This commit is contained in:
Akim Demaille
2004-10-05 08:39:17 +00:00
parent f85a5e6f4b
commit b4a2033855
5 changed files with 85 additions and 48 deletions

View File

@@ -506,14 +506,26 @@ while (0)
#define YYERRCODE 256
/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N]. */
/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
If N is 0, then set CURRENT to the empty location which ends
the previous symbol: RHS[0] (always defined). */
#ifndef YYLLOC_DEFAULT
# define YYLLOC_DEFAULT(Current, Rhs, N) \
((Current).first_line = (Rhs)[1].first_line, \
(Current).first_column = (Rhs)[1].first_column, \
(Current).last_line = (Rhs)[N].last_line, \
(Current).last_column = (Rhs)[N].last_column)
# define YYLLOC_DEFAULT(Current, Rhs, N) \
do { \
if (N) \
{ \
(Current).first_line = (Rhs)[1].first_line; \
(Current).first_column = (Rhs)[1].first_column; \
(Current).last_line = (Rhs)[N].last_line; \
(Current).last_column = (Rhs)[N].last_column; \
} \
else \
{ \
(Current).first_line = (Current).last_line = (Rhs)[0].last_line; \
(Current).first_column = (Current).last_column = (Rhs)[0].last_column; \
} \
} while(0)
#endif
@@ -1021,10 +1033,7 @@ yyreduce:
]b4_location_if(
[[ /* Default location. */
if (yylen)
YYLLOC_DEFAULT (yyloc, yylsp - yylen, yylen);
else
yyloc = yylsp[0];]])[
YYLLOC_DEFAULT (yyloc, yylsp - yylen, yylen);]])[
YY_REDUCE_PRINT (yyn);
switch (yyn)
]{