* data/glr.c (struct yyGLRStack): If pure, add yyval and yyloc members.

(yylval, yylloc): If pure, #define to yystackp->yyval and
yystackp->yyloc similar to yychar and yynerrs.
(yyparse): If pure, remove local yylval and yylloc. Add local
yystackp to accommodate pure definitions of yylval and yylloc.
(b4_lex_param, b4_lyyerror_args, b4_lpure_args): If pure, change
yylvalp and yyllocp to &yylval and &yylloc.
(nerrs, char, lval, lloc): If pure, add #define's for b4_prefix[]
namespace. Previously, nerrs and char were missing, but lval and lloc
weren't necessary.
(yyprocessOneStack, yyreportSyntaxError, yyrecoverSyntaxError): Remove
yylvalp and yyllocp parameters since, if pure, these are now always
accessible through yystackp.  If not pure, they are still accessible
globally.
* data/glr.c, data/yacc.c (YYLLOC_DEFAULT): Change `if (N)' to
`if (YYID (N))' to pacify lint.
This commit is contained in:
Akim Demaille
2005-12-21 15:33:13 +00:00
parent a85284cfbd
commit d6cff4dc6f
3 changed files with 73 additions and 60 deletions

View File

@@ -1,3 +1,22 @@
2005-12-21 Joel E. Denny <address@hidden>
* data/glr.c (struct yyGLRStack): If pure, add yyval and yyloc members.
(yylval, yylloc): If pure, #define to yystackp->yyval and
yystackp->yyloc similar to yychar and yynerrs.
(yyparse): If pure, remove local yylval and yylloc. Add local
yystackp to accommodate pure definitions of yylval and yylloc.
(b4_lex_param, b4_lyyerror_args, b4_lpure_args): If pure, change
yylvalp and yyllocp to &yylval and &yylloc.
(nerrs, char, lval, lloc): If pure, add #define's for b4_prefix[]
namespace. Previously, nerrs and char were missing, but lval and lloc
weren't necessary.
(yyprocessOneStack, yyreportSyntaxError, yyrecoverSyntaxError): Remove
yylvalp and yyllocp parameters since, if pure, these are now always
accessible through yystackp. If not pure, they are still accessible
globally.
* data/glr.c, data/yacc.c (YYLLOC_DEFAULT): Change `if (N)' to
`if (YYID (N))' to pacify lint.
2005-12-21 Akim Demaille <akim@epita.fr> 2005-12-21 Akim Demaille <akim@epita.fr>
YYACCEPT, YYERROR, and YYABORT, as user actions, should not YYACCEPT, YYERROR, and YYABORT, as user actions, should not

View File

@@ -49,8 +49,8 @@ m4_define([b4_user_formals],
# Accumule in b4_lex_param all the yylex arguments. # Accumule in b4_lex_param all the yylex arguments.
# Yes, this is quite ugly... # Yes, this is quite ugly...
m4_define([b4_lex_param], m4_define([b4_lex_param],
m4_dquote(b4_pure_if([[[[YYSTYPE *]], [[yylvalp]]][]dnl m4_dquote(b4_pure_if([[[[YYSTYPE *]], [[&yylval]]][]dnl
b4_location_if([, [[YYLTYPE *], [yyllocp]]])])dnl b4_location_if([, [[YYLTYPE *], [&yylloc]]])])dnl
m4_ifdef([b4_lex_param], [, ]b4_lex_param))) m4_ifdef([b4_lex_param], [, ]b4_lex_param)))
@@ -65,9 +65,9 @@ m4_ifset([b4_parse_param], [b4_c_args(b4_parse_param), ])])
# b4_lyyerror_args # b4_lyyerror_args
# ---------------- # ----------------
# Same as above, but on the look-ahead, hence yyllocp instead of yylocp. # Same as above, but on the look-ahead, hence &yylloc instead of yylocp.
m4_define([b4_lyyerror_args], m4_define([b4_lyyerror_args],
[b4_pure_if([b4_location_if([yyllocp, ])])dnl [b4_pure_if([b4_location_if([&yylloc, ])])dnl
m4_ifset([b4_parse_param], [b4_c_args(b4_parse_param), ])]) m4_ifset([b4_parse_param], [b4_c_args(b4_parse_param), ])])
@@ -80,14 +80,14 @@ m4_define([b4_pure_args],
# b4_lpure_args # b4_lpure_args
# ------------- # -------------
# Same as above, but on the look-ahead, hence yyllocp instead of yylocp. # Same as above, but on the look-ahead, hence &yylloc instead of yylocp.
m4_define([b4_lpure_args], m4_define([b4_lpure_args],
[b4_pure_if([b4_location_if([, yyllocp])])[]b4_user_args]) [b4_pure_if([b4_location_if([, &yylloc])])[]b4_user_args])
# b4_pure_formals # b4_pure_formals
# --------------- # ---------------
# Arguments passed to yyerror: user formals plus yyllocp. # Arguments passed to yyerror: user formals plus yylocp.
m4_define([b4_pure_formals], m4_define([b4_pure_formals],
[b4_pure_if([b4_location_if([, YYLTYPE *yylocp])])[]b4_user_formals]) [b4_pure_if([b4_location_if([, YYLTYPE *yylocp])])[]b4_user_formals])
@@ -495,7 +495,7 @@ static const ]b4_int_type_for([b4_stos])[ yystos[] =
#ifndef YYLLOC_DEFAULT #ifndef YYLLOC_DEFAULT
# define YYLLOC_DEFAULT(Current, Rhs, N) \ # define YYLLOC_DEFAULT(Current, Rhs, N) \
do \ do \
if (N) \ if (YYID (N)) \
{ \ { \
(Current).first_line = YYRHSLOC (Rhs, 1).first_line; \ (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
(Current).first_column = YYRHSLOC (Rhs, 1).first_column; \ (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
@@ -539,7 +539,16 @@ static const ]b4_int_type_for([b4_stos])[ yystos[] =
#undef yynerrs #undef yynerrs
#define yynerrs (yystackp->yyerrcnt) #define yynerrs (yystackp->yyerrcnt)
#undef yychar #undef yychar
#define yychar (yystackp->yyrawchar)], #define yychar (yystackp->yyrawchar)
#undef yylval
#define yylval (yystackp->yyval)
#undef yylloc
#define yylloc (yystackp->yyloc)
m4_if(b4_prefix[], [yy], [],
[#define b4_prefix[]nerrs yynerrs
#define b4_prefix[]char yychar
#define b4_prefix[]lval yylval
#define b4_prefix[]lloc yylloc])],
[YYSTYPE yylval; [YYSTYPE yylval;
YYLTYPE yylloc; YYLTYPE yylloc;
@@ -786,6 +795,8 @@ struct yyGLRStack {
[ [
int yyerrcnt; int yyerrcnt;
int yyrawchar; int yyrawchar;
YYSTYPE yyval;
YYLTYPE yyloc;
])[ ])[
yySymbol* yytokenp; yySymbol* yytokenp;
YYJMP_BUF yyexception_buffer; YYJMP_BUF yyexception_buffer;
@@ -1840,8 +1851,7 @@ yycompressStack (yyGLRStack* yystackp)
static YYRESULTTAG static YYRESULTTAG
yyprocessOneStack (yyGLRStack* yystackp, size_t yyk, yyprocessOneStack (yyGLRStack* yystackp, size_t yyk,
size_t yyposn, YYSTYPE* yylvalp, YYLTYPE* yyllocp size_t yyposn]b4_pure_formals[)
]b4_pure_formals[)
{ {
int yyaction; int yyaction;
const short int* yyconflicts; const short int* yyconflicts;
@@ -1875,7 +1885,7 @@ yyprocessOneStack (yyGLRStack* yystackp, size_t yyk,
YYDPRINTF ((stderr, "Reading a token: ")); YYDPRINTF ((stderr, "Reading a token: "));
yychar = YYLEX; yychar = YYLEX;
*yytokenp = YYTRANSLATE (yychar); *yytokenp = YYTRANSLATE (yychar);
YY_SYMBOL_PRINT ("Next token is", *yytokenp, yylvalp, yyllocp); YY_SYMBOL_PRINT ("Next token is", *yytokenp, &yylval, &yylloc);
} }
yygetLRActions (yystate, *yytokenp, &yyaction, &yyconflicts); yygetLRActions (yystate, *yytokenp, &yyaction, &yyconflicts);
@@ -1887,8 +1897,8 @@ yyprocessOneStack (yyGLRStack* yystackp, size_t yyk,
(unsigned long int) yyk)); (unsigned long int) yyk));
YYCHK (yyglrReduce (yystackp, yynewStack, YYCHK (yyglrReduce (yystackp, yynewStack,
*yyconflicts, yyfalse]b4_user_args[)); *yyconflicts, yyfalse]b4_user_args[));
YYCHK (yyprocessOneStack (yystackp, yynewStack, yyposn, YYCHK (yyprocessOneStack (yystackp, yynewStack,
yylvalp, yyllocp]b4_pure_args[)); yyposn]b4_pure_args[));
yyconflicts += 1; yyconflicts += 1;
} }
@@ -1902,19 +1912,16 @@ yyprocessOneStack (yyGLRStack* yystackp, size_t yyk,
break; break;
} }
else else
YYCHK (yyglrReduce (yystackp, yyk, -yyaction, yyfalse]b4_user_args[)); YYCHK (yyglrReduce (yystackp, yyk, -yyaction,
yyfalse]b4_user_args[));
} }
} }
return yyok; return yyok;
} }
/*ARGSUSED*/ static void /*ARGSUSED*/ static void
yyreportSyntaxError (yyGLRStack* yystackp, yyreportSyntaxError (yyGLRStack* yystackp]b4_user_formals[)
YYSTYPE* yylvalp, YYLTYPE* yyllocp]b4_user_formals[)
{ {
YYUSE (yylvalp);
YYUSE (yyllocp);
if (yystackp->yyerrState == 0) if (yystackp->yyerrState == 0)
{ {
#if YYERROR_VERBOSE #if YYERROR_VERBOSE
@@ -2013,14 +2020,11 @@ yyreportSyntaxError (yyGLRStack* yystackp,
} }
} }
/* Recover from a syntax error on YYSTACK, assuming that YYTOKENP, /* Recover from a syntax error on *YYSTACKP, assuming that *YYSTACKP->YYTOKENP,
YYLVALP, and YYLLOCP point to the syntactic category, semantic yylval, and yylloc are the syntactic category, semantic value, and location
value, and location of the look-ahead. */ of the look-ahead. */
/*ARGSUSED*/ static void /*ARGSUSED*/ static void
yyrecoverSyntaxError (yyGLRStack* yystackp, yyrecoverSyntaxError (yyGLRStack* yystackp]b4_user_formals[)
YYSTYPE* yylvalp,
YYLTYPE* YYOPTIONAL_LOC (yyllocp)
]b4_user_formals[)
{ {
yySymbol* const yytokenp = yystackp->yytokenp; yySymbol* const yytokenp = yystackp->yytokenp;
size_t yyk; size_t yyk;
@@ -2040,15 +2044,15 @@ yyrecoverSyntaxError (yyGLRStack* yystackp,
yyGLRState *yys = yystackp->yytops.yystates[0]; yyGLRState *yys = yystackp->yytops.yystates[0];
yyGLRStackItem yyerror_range[3]; yyGLRStackItem yyerror_range[3];
yyerror_range[1].yystate.yyloc = yys->yyloc; yyerror_range[1].yystate.yyloc = yys->yyloc;
yyerror_range[2].yystate.yyloc = *yyllocp; yyerror_range[2].yystate.yyloc = yylloc;
YYLLOC_DEFAULT (yys->yyloc, yyerror_range, 2);]])[ YYLLOC_DEFAULT (yys->yyloc, yyerror_range, 2);]])[
yydestruct ("Error: discarding", yydestruct ("Error: discarding",
*yytokenp, yylvalp]b4_location_if([, yyllocp])[]b4_user_args[); *yytokenp, &yylval]b4_location_if([, &yylloc])[]b4_user_args[);
} }
YYDPRINTF ((stderr, "Reading a token: ")); YYDPRINTF ((stderr, "Reading a token: "));
yychar = YYLEX; yychar = YYLEX;
*yytokenp = YYTRANSLATE (yychar); *yytokenp = YYTRANSLATE (yychar);
YY_SYMBOL_PRINT ("Next token is", *yytokenp, yylvalp, yyllocp); YY_SYMBOL_PRINT ("Next token is", *yytokenp, &yylval, &yylloc);
yyj = yypact[yystackp->yytops.yystates[0]->yylrState]; yyj = yypact[yystackp->yytops.yystates[0]->yylrState];
if (yyis_pact_ninf (yyj)) if (yyis_pact_ninf (yyj))
return; return;
@@ -2087,12 +2091,12 @@ yyrecoverSyntaxError (yyGLRStack* yystackp,
{ {
/* Shift the error token having adjusted its location. */ /* Shift the error token having adjusted its location. */
YYLTYPE yyerrloc;]b4_location_if([[ YYLTYPE yyerrloc;]b4_location_if([[
yystackp->yyerror_range[2].yystate.yyloc = *yyllocp; yystackp->yyerror_range[2].yystate.yyloc = yylloc;
YYLLOC_DEFAULT (yyerrloc, yystackp->yyerror_range, 2);]])[ YYLLOC_DEFAULT (yyerrloc, yystackp->yyerror_range, 2);]])[
YY_SYMBOL_PRINT ("Shifting", yystos[yytable[yyj]], YY_SYMBOL_PRINT ("Shifting", yystos[yytable[yyj]],
yylvalp, &yyerrloc); &yylval, &yyerrloc);
yyglrShift (yystackp, 0, yytable[yyj], yyglrShift (yystackp, 0, yytable[yyj],
yys->yyposn, yylvalp, &yyerrloc); yys->yyposn, &yylval, &yyerrloc);
yys = yystackp->yytops.yystates[0]; yys = yystackp->yytops.yystates[0];
break; break;
} }
@@ -2133,17 +2137,8 @@ yyrecoverSyntaxError (yyGLRStack* yystackp,
int yyresult; int yyresult;
yySymbol yytoken; yySymbol yytoken;
yyGLRStack yystack; yyGLRStack yystack;
yyGLRStack* const yystackp = &yystack;
size_t yyposn; size_t yyposn;
]b4_pure_if(
[
YYSTYPE yylval;
YYLTYPE yylloc;
#undef yychar
#define yychar (yystack.yyrawchar)
])[
YYSTYPE* const yylvalp = &yylval;
YYLTYPE* const yyllocp = &yylloc;
YYDPRINTF ((stderr, "Starting parse\n")); YYDPRINTF ((stderr, "Starting parse\n"));
@@ -2165,7 +2160,7 @@ m4_popdef([b4_at_dollar])dnl
/* Line __line__ of glr.c. */ /* Line __line__ of glr.c. */
b4_syncline([@oline@], [@ofile@])])dnl b4_syncline([@oline@], [@ofile@])])dnl
[ [
if (! yyinitGLRStack (&yystack, YYINITDEPTH)) if (! yyinitGLRStack (yystackp, YYINITDEPTH))
goto yyexhaustedlab; goto yyexhaustedlab;
switch (YYSETJMP (yystack.yyexception_buffer)) switch (YYSETJMP (yystack.yyexception_buffer))
{ {
@@ -2199,8 +2194,8 @@ b4_syncline([@oline@], [@ofile@])])dnl
yyrule = yydefaultAction (yystate); yyrule = yydefaultAction (yystate);
if (yyrule == 0) if (yyrule == 0)
{ {
]b4_location_if([[ yystack.yyerror_range[1].yystate.yyloc = *yyllocp;]])[ ]b4_location_if([[ yystack.yyerror_range[1].yystate.yyloc = yylloc;]])[
yyreportSyntaxError (&yystack, yylvalp, yyllocp]b4_user_args[); yyreportSyntaxError (&yystack]b4_user_args[);
goto yyuser_error; goto yyuser_error;
} }
YYCHK1 (yyglrReduce (&yystack, 0, yyrule, yytrue]b4_user_args[)); YYCHK1 (yyglrReduce (&yystack, 0, yyrule, yytrue]b4_user_args[));
@@ -2212,25 +2207,25 @@ b4_syncline([@oline@], [@ofile@])])dnl
YYDPRINTF ((stderr, "Reading a token: ")); YYDPRINTF ((stderr, "Reading a token: "));
yychar = YYLEX; yychar = YYLEX;
yytoken = YYTRANSLATE (yychar); yytoken = YYTRANSLATE (yychar);
YY_SYMBOL_PRINT ("Next token is", yytoken, yylvalp, yyllocp); YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
} }
yygetLRActions (yystate, yytoken, &yyaction, &yyconflicts); yygetLRActions (yystate, yytoken, &yyaction, &yyconflicts);
if (*yyconflicts != 0) if (*yyconflicts != 0)
break; break;
if (yyisShiftAction (yyaction)) if (yyisShiftAction (yyaction))
{ {
YY_SYMBOL_PRINT ("Shifting", yytoken, yylvalp, yyllocp); YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
if (yytoken != YYEOF) if (yytoken != YYEOF)
yytoken = YYEMPTY; yytoken = YYEMPTY;
yyposn += 1; yyposn += 1;
yyglrShift (&yystack, 0, yyaction, yyposn, yylvalp, yyllocp); yyglrShift (&yystack, 0, yyaction, yyposn, &yylval, &yylloc);
if (0 < yystack.yyerrState) if (0 < yystack.yyerrState)
yystack.yyerrState -= 1; yystack.yyerrState -= 1;
} }
else if (yyisErrorAction (yyaction)) else if (yyisErrorAction (yyaction))
{ {
]b4_location_if([[ yystack.yyerror_range[1].yystate.yyloc = *yyllocp;]])[ ]b4_location_if([[ yystack.yyerror_range[1].yystate.yyloc = yylloc;]])[
yyreportSyntaxError (&yystack, yylvalp, yyllocp]b4_user_args[); yyreportSyntaxError (&yystack]b4_user_args[);
goto yyuser_error; goto yyuser_error;
} }
else else
@@ -2264,8 +2259,7 @@ b4_syncline([@oline@], [@ofile@])])dnl
on yylval in the event of memory exhaustion. */ on yylval in the event of memory exhaustion. */
for (yys = 0; yys < yyn; yys += 1) for (yys = 0; yys < yyn; yys += 1)
YYCHK1 (yyprocessOneStack (&yystack, yys, yyposn, YYCHK1 (yyprocessOneStack (&yystack, yys, yyposn]b4_lpure_args[));
yylvalp, yyllocp]b4_lpure_args[));
yyremoveDeletes (&yystack); yyremoveDeletes (&yystack);
yyn = yystack.yytops.yysize; yyn = yystack.yytops.yysize;
@@ -2286,9 +2280,9 @@ b4_syncline([@oline@], [@ofile@])])dnl
&yyconflicts); &yyconflicts);
/* Note that yyconflicts were handled by yyprocessOneStack. */ /* Note that yyconflicts were handled by yyprocessOneStack. */
YYDPRINTF ((stderr, "On stack %lu, ", (unsigned long int) yys)); YYDPRINTF ((stderr, "On stack %lu, ", (unsigned long int) yys));
YY_SYMBOL_PRINT ("shifting", yytoken_to_shift, yylvalp, yyllocp); YY_SYMBOL_PRINT ("shifting", yytoken_to_shift, &yylval, &yylloc);
yyglrShift (&yystack, yys, yyaction, yyposn, yyglrShift (&yystack, yys, yyaction, yyposn,
yylvalp, yyllocp); &yylval, &yylloc);
YYDPRINTF ((stderr, "Stack %lu now in state #%d\n", YYDPRINTF ((stderr, "Stack %lu now in state #%d\n",
(unsigned long int) yys, (unsigned long int) yys,
yystack.yytops.yystates[yys]->yylrState)); yystack.yytops.yystates[yys]->yylrState));
@@ -2300,8 +2294,8 @@ b4_syncline([@oline@], [@ofile@])])dnl
yyFail (&yystack][]b4_lpure_args[, YY_("syntax error")); yyFail (&yystack][]b4_lpure_args[, YY_("syntax error"));
YYCHK1 (yyresolveStack (&yystack]b4_user_args[)); YYCHK1 (yyresolveStack (&yystack]b4_user_args[));
YYDPRINTF ((stderr, "Returning to deterministic operation.\n")); YYDPRINTF ((stderr, "Returning to deterministic operation.\n"));
]b4_location_if([[ yystack.yyerror_range[1].yystate.yyloc = *yyllocp;]])[ ]b4_location_if([[ yystack.yyerror_range[1].yystate.yyloc = yylloc;]])[
yyreportSyntaxError (&yystack, yylvalp, yyllocp]b4_user_args[); yyreportSyntaxError (&yystack]b4_user_args[);
goto yyuser_error; goto yyuser_error;
} }
else if (yystack.yytops.yysize == 1) else if (yystack.yytops.yysize == 1)
@@ -2314,7 +2308,7 @@ b4_syncline([@oline@], [@ofile@])])dnl
} }
continue; continue;
yyuser_error: yyuser_error:
yyrecoverSyntaxError (&yystack, yylvalp, yyllocp]b4_user_args[); yyrecoverSyntaxError (&yystack]b4_user_args[);
yyposn = yystack.yytops.yystates[0]->yyposn; yyposn = yystack.yytops.yystates[0]->yyposn;
} }
@@ -2338,7 +2332,7 @@ b4_syncline([@oline@], [@ofile@])])dnl
yyreturn: yyreturn:
if (yytoken != YYEOF && yytoken != YYEMPTY) if (yytoken != YYEOF && yytoken != YYEMPTY)
yydestruct ("Cleanup: discarding lookahead", yydestruct ("Cleanup: discarding lookahead",
yytoken, yylvalp]b4_location_if([, yyllocp])[]b4_user_args[); yytoken, &yylval]b4_location_if([, &yylloc])[]b4_user_args[);
/* If the stack is well-formed, pop the stack until it is empty, /* If the stack is well-formed, pop the stack until it is empty,
destroying its entries as we go. But free the stack regardless destroying its entries as we go. But free the stack regardless

View File

@@ -587,7 +587,7 @@ while (YYID (0))
#ifndef YYLLOC_DEFAULT #ifndef YYLLOC_DEFAULT
# define YYLLOC_DEFAULT(Current, Rhs, N) \ # define YYLLOC_DEFAULT(Current, Rhs, N) \
do \ do \
if (N) \ if (YYID (N)) \
{ \ { \
(Current).first_line = YYRHSLOC (Rhs, 1).first_line; \ (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
(Current).first_column = YYRHSLOC (Rhs, 1).first_column; \ (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \