mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-13 22:33:03 +00:00
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:
37
data/glr.c
37
data/glr.c
@@ -420,17 +420,31 @@ static const ]b4_int_type_for([b4_stos])[ yystos[] =
|
||||
/* Error token number */
|
||||
#define YYTERROR 1
|
||||
|
||||
/* 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). */
|
||||
|
||||
]b4_location_if([[
|
||||
#define YYRHSLOC(yyRhs,YYK) ((yyRhs)[YYK].yystate.yyloc)
|
||||
|
||||
#ifndef YYLLOC_DEFAULT
|
||||
# define YYLLOC_DEFAULT(yyCurrent, yyRhs, YYN) \
|
||||
((yyCurrent).first_line = YYRHSLOC(yyRhs, 1).first_line, \
|
||||
(yyCurrent).first_column = YYRHSLOC(yyRhs, 1).first_column, \
|
||||
(yyCurrent).last_line = YYRHSLOC(yyRhs, YYN).last_line, \
|
||||
(yyCurrent).last_column = YYRHSLOC(yyRhs, YYN).last_column)
|
||||
# define YYLLOC_DEFAULT(yyCurrent, yyRhs, YYN) \
|
||||
do { \
|
||||
if (YYN) \
|
||||
{ \
|
||||
(yyCurrent).first_line = YYRHSLOC(yyRhs, 1).first_line; \
|
||||
(yyCurrent).first_column = YYRHSLOC(yyRhs, 1).first_column; \
|
||||
(yyCurrent).last_line = YYRHSLOC(yyRhs, YYN).last_line; \
|
||||
(yyCurrent).last_column = YYRHSLOC(yyRhs, YYN).last_column; \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
(yyCurrent).first_line = YYRHSLOC(yyRhs, 0).last_line; \
|
||||
(yyCurrent).first_column = YYRHSLOC(yyRhs, 0).last_column; \
|
||||
(yyCurrent).last_line = YYRHSLOC(yyRhs, 0).last_line; \
|
||||
(yyCurrent).last_column = YYRHSLOC(yyRhs, 0).last_column; \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
/* YY_LOCATION_PRINT -- Print the location on the stream.
|
||||
This macro was not mandated originally: define only if we know
|
||||
@@ -718,15 +732,10 @@ yyuserAction (yyRuleNum yyn, int yyrhslen, yyGLRStackItem* yyvsp,
|
||||
|
||||
yylow = 1;
|
||||
if (yyrhslen == 0)
|
||||
{
|
||||
*yyvalp = yyval_default;
|
||||
*yylocp = yyvsp[0].yystate.yyloc;
|
||||
}
|
||||
*yyvalp = yyval_default;
|
||||
else
|
||||
{
|
||||
*yyvalp = yyvsp[YYFILL (1-yyrhslen)].yystate.yysemantics.yysval;
|
||||
YYLLOC_DEFAULT (*yylocp, yyvsp - yyrhslen, yyrhslen);
|
||||
}
|
||||
*yyvalp = yyvsp[YYFILL (1-yyrhslen)].yystate.yysemantics.yysval;
|
||||
YYLLOC_DEFAULT (*yylocp, yyvsp - yyrhslen, yyrhslen);
|
||||
|
||||
]
|
||||
switch (yyn)
|
||||
|
||||
Reference in New Issue
Block a user