data/glr.c (yyfill): Adjust comment.

(yyresolveAction): Initialize default location properly for empty right-hand
 sides.
 (yydoAction): Ditto.  Add comment explaining apparently dead code.
* tests/glr-regression.at
 (Incorrectly initialized location for empty right-hand side in GLR): New test.
This commit is contained in:
Paul Hilfinger
2005-10-31 01:16:32 +00:00
parent e10a80eeac
commit 44e7ead165
3 changed files with 123 additions and 6 deletions

View File

@@ -1,3 +1,14 @@
2005-10-30 Paul Hilfinger <hilfingr@tully.CS.Berkeley.EDU>
* data/glr.c (yyfill): Adjust comment.
(yyresolveAction): Initialize default location properly
for empty right-hand sides.
(yydoAction): Ditto.
Add comment explaining apparently dead code.
* tests/glr-regression.at
(Incorrectly initialized location for empty right-hand side in GLR):
New test.
2005-10-30 Paul Eggert <eggert@cs.ucla.edu> 2005-10-30 Paul Eggert <eggert@cs.ucla.edu>
* bootstrap (cleanup_gnulib): New function. Use it to clean up * bootstrap (cleanup_gnulib): New function. Use it to clean up

View File

@@ -782,8 +782,7 @@ yytokenName (yySymbol yytoken)
/** Fill in YYVSP[YYLOW1 .. YYLOW0-1] from the chain of states starting /** Fill in YYVSP[YYLOW1 .. YYLOW0-1] from the chain of states starting
* at YYVSP[YYLOW0].yystate.yypred. Leaves YYVSP[YYLOW1].yystate.yypred * at YYVSP[YYLOW0].yystate.yypred. Leaves YYVSP[YYLOW1].yystate.yypred
* containing the pointer to the next state in the chain. Assumes * containing the pointer to the next state in the chain. */
* YYLOW1 < YYLOW0. */
static void yyfillin (yyGLRStackItem *, int, int) __attribute__ ((__unused__)); static void yyfillin (yyGLRStackItem *, int, int) __attribute__ ((__unused__));
static void static void
yyfillin (yyGLRStackItem *yyvsp, int yylow0, int yylow1) yyfillin (yyGLRStackItem *yyvsp, int yylow0, int yylow1)
@@ -802,8 +801,8 @@ yyfillin (yyGLRStackItem *yyvsp, int yylow0, int yylow1)
} }
/* Do nothing if YYNORMAL or if *YYLOW <= YYLOW1. Otherwise, fill in /* Do nothing if YYNORMAL or if *YYLOW <= YYLOW1. Otherwise, fill in
YYVSP[YYLOW1 .. *YYLOW-1] as in yyfillin and set *YYLOW = YYLOW1. * YYVSP[YYLOW1 .. *YYLOW-1] as in yyfillin and set *YYLOW = YYLOW1.
For convenience, always return YYLOW1. */ * For convenience, always return YYLOW1. */
static inline int yyfill (yyGLRStackItem *, int *, int, yybool) static inline int yyfill (yyGLRStackItem *, int *, int, yybool)
__attribute__ ((__unused__)); __attribute__ ((__unused__));
static inline int static inline int
@@ -1286,11 +1285,18 @@ yydoAction (yyGLRStack* yystack, size_t yyk, yyRuleNum yyrule,
} }
else else
{ {
/* At present, doAction is never called in nondeterministic
* mode, so this branch is never taken. It is here in
* anticipation of a future feature that will allow immediate
* evaluation of selected actions in nondeterministic mode. */
int yyi; int yyi;
yyGLRState* yys; yyGLRState* yys;
yyGLRStackItem yyrhsVals[YYMAXRHS + YYMAXLEFT + 1]; yyGLRStackItem yyrhsVals[YYMAXRHS + YYMAXLEFT + 1];
yys = yyrhsVals[YYMAXRHS + YYMAXLEFT].yystate.yypred yys = yyrhsVals[YYMAXRHS + YYMAXLEFT].yystate.yypred
= yystack->yytops.yystates[yyk]; = yystack->yytops.yystates[yyk];]b4_location_if([[
if (yynrhs == 0)
/* Set default location. */
yyrhsVals[YYMAXRHS + YYMAXLEFT - 1].yystate.yyloc = yys->yyloc;]])[
for (yyi = 0; yyi < yynrhs; yyi += 1) for (yyi = 0; yyi < yynrhs; yyi += 1)
{ {
yys = yys->yypred; yys = yys->yypred;
@@ -1564,7 +1570,10 @@ yyresolveAction (yySemanticOption* yyopt, yyGLRStack* yystack,
yynrhs = yyrhsLength (yyopt->yyrule); yynrhs = yyrhsLength (yyopt->yyrule);
YYCHK (yyresolveStates (yyopt->yystate, yynrhs, yystack]b4_user_args[)); YYCHK (yyresolveStates (yyopt->yystate, yynrhs, yystack]b4_user_args[));
yyrhsVals[YYMAXRHS + YYMAXLEFT].yystate.yypred = yyopt->yystate; yyrhsVals[YYMAXRHS + YYMAXLEFT].yystate.yypred = yyopt->yystate;]b4_location_if([[
if (yynrhs == 0)
/* Set default location. */
yyrhsVals[YYMAXRHS + YYMAXLEFT - 1].yystate.yyloc = yyopt->yystate->yyloc;]])[
return yyuserAction (yyopt->yyrule, yynrhs, return yyuserAction (yyopt->yyrule, yynrhs,
yyrhsVals + YYMAXRHS + YYMAXLEFT - 1, yyrhsVals + YYMAXRHS + YYMAXLEFT - 1,
yyvalp, yylocp, yystack]b4_user_args[); yyvalp, yylocp, yystack]b4_user_args[);

View File

@@ -636,3 +636,100 @@ AT_CHECK([[./glr-regr7]], 2, [],
AT_XFAIL_IF(:) AT_XFAIL_IF(:)
AT_CLEANUP AT_CLEANUP
## ------------------------------------------------------------------------- ##
## Incorrect default location for empty right-hand sides. Adapted from bug ##
## report by Claudia Hermann. ##
## See http://lists.gnu.org/archive/html/bug-bison/2005-10/msg00069.html and ##
## http://lists.gnu.org/archive/html/bug-bison/2005-10/msg00072.html ##
## ------------------------------------------------------------------------- ##
AT_SETUP([Incorrectly initialized location for empty right-hand side in GLR])
AT_DATA_GRAMMAR([glr-regr8.y],
[[
%{
#include <stdio.h>
#include <stdlib.h>
static void yyerror (char const *);
static int yylex (void);
static void yyerror(const char *msg);
%}
%token T_CONSTANT
%token T_PORT
%token T_SIGNAL
%glr-parser
%%
PortClause : T_PORT InterfaceDeclaration T_PORT
{ printf("%d/%d - %d/%d - %d/%d\n",
@1.first_column, @1.last_column,
@2.first_column, @2.last_column,
@3.first_column, @3.last_column); }
;
InterfaceDeclaration : OptConstantWord %dprec 1
| OptSignalWord %dprec 2
;
OptConstantWord : /* empty */
| T_CONSTANT
;
OptSignalWord : /* empty */
{ printf("empty: %d/%d\n", @$.first_column, @$.last_column); }
| T_SIGNAL
;
%%
void yyerror(const char *msg)
{
fprintf (stderr, "error\n");
}
static int lexIndex;
int yylex()
{
lexIndex += 1;
switch (lexIndex)
{
case 1:
yylloc.first_column = 1;
yylloc.last_column = 9;
return T_PORT;
case 2:
yylloc.first_column = 13;
yylloc.last_column = 17;
return T_PORT;
default:
return 0;
}
}
int
main (void)
{
yyparse();
return 0;
}
]])
AT_CHECK([[bison -o glr-regr8.c glr-regr8.y]], 0, [],
[glr-regr8.y: conflicts: 1 reduce/reduce
])
AT_COMPILE([glr-regr8])
AT_CHECK([[./glr-regr8]], 0,
[empty: 9/9
1/9 - 9/9 - 13/17
],
[])
AT_CLEANUP