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

@@ -181,13 +181,22 @@ b4_syncline([@oline@], [@ofile@])],
]/* Line __line__ of lalr1.cc. */
b4_syncline([@oline@], [@ofile@])[
/* 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) \
do { \
((Current).begin = (Rhs)[1].begin); \
((Current).end = (Rhs)[N].end); \
# define YYLLOC_DEFAULT(Current, Rhs, N) \
do { \
if (N) \
{ \
(Current).begin = (Rhs)[1].begin; \
(Current).end = (Rhs)[N].end; \
} \
else \
{ \
(Current).begin = (Current).end = (Rhs)[0].end; \
} \
} while (0)
#endif
@@ -583,21 +592,14 @@ yyreduce:
This behavior is undocumented and Bison
users should not rely upon it. */
if (len_)
{
yyval = semantic_stack_[len_ - 1];
yyloc = location_stack_[len_ - 1];
}
yyval = semantic_stack_[len_ - 1];
else
{
yyval = semantic_stack_[0];
yyloc = location_stack_[0];
}
yyval = semantic_stack_[0];
if (len_)
{
Slice<LocationType, LocationStack> slice (location_stack_, len_);
YYLLOC_DEFAULT (yyloc, slice, len_);
}
{
Slice<LocationType, LocationStack> slice (location_stack_, len_);
YYLLOC_DEFAULT (yyloc, slice, len_);
}
YY_REDUCE_PRINT (n_);
switch (n_)
{