X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/1bd0dedaaa08858f4ad13a11a75d814fd7ceb5ce..44e7ead165c56bb55b2fdafd4aff2f511baa8e68:/data/glr.c diff --git a/data/glr.c b/data/glr.c index 6d3ec6cc..c04372ee 100644 --- a/data/glr.c +++ b/data/glr.c @@ -34,6 +34,14 @@ m4_define_default([b4_stack_depth_init], [200]) ## ------------------------ ## +# b4_user_formals +# --------------- +# This is specific to GLR because it relies on ISO C formal argument +# declarations. +m4_define([b4_user_formals], +[m4_ifset([b4_parse_param], [, b4_c_ansi_formals(b4_parse_param)])]) + + # b4_lex_param # ------------ # Accumule in b4_lex_param all the yylex arguments. @@ -44,12 +52,6 @@ b4_location_if([, [[YYLTYPE *], [yyllocp]]])])dnl m4_ifdef([b4_lex_param], [, ]b4_lex_param))) -# b4_user_formals -# --------------- -m4_define([b4_user_formals], -[m4_ifset([b4_parse_param], [, b4_c_ansi_formals(b4_parse_param)])]) - - # b4_yyerror_args # --------------- # Arguments passed to yyerror: user args plus yylloc. @@ -154,7 +156,7 @@ m4_if(b4_prefix[], [yy], [], #define yynerrs b4_prefix[]nerrs #define yylloc b4_prefix[]lloc]) -b4_token_enums_defines(b4_tokens) +b4_token_enums(b4_tokens) /* Copy the first part of user declarations. */ b4_pre_prologue[ @@ -234,6 +236,9 @@ b4_syncline([@oline@], [@ofile@]) # endif #endif +/* Suppress unused-variable warnings by "using" E. */ +#define YYUSE(e) do {;} while (/*CONSTCOND*/ yyfalse && (e)) + #ifndef YYFREE # define YYFREE free #endif @@ -470,7 +475,7 @@ static const ]b4_int_type_for([b4_stos])[ yystos[] = (Current).first_column = (Current).last_column = \ YYRHSLOC (Rhs, 0).last_column; \ } \ - while (0) + while (/*CONSTCOND*/ 0) /* YY_LOCATION_PRINT -- Print the location on the stream. This macro was not mandated originally: define only if we know @@ -515,7 +520,7 @@ typedef enum { yyok, yyaccept, yyabort, yyerr } YYRESULTTAG; #define YYCHK(YYE) \ do { YYRESULTTAG yyflag = YYE; if (yyflag != yyok) return yyflag; } \ - while (0) + while (/*CONSTCOND*/ 0) #if YYDEBUG @@ -527,20 +532,20 @@ typedef enum { yyok, yyaccept, yyabort, yyerr } YYRESULTTAG; do { \ if (yydebug) \ YYFPRINTF Args; \ -} while (0) +} while (/*CONSTCOND*/ 0) ]b4_yysymprint_generate([b4_c_ansi_function_def])[ -# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \ -do { \ - if (yydebug) \ - { \ - YYFPRINTF (stderr, "%s ", Title); \ - yysymprint (stderr, \ - Type, Value]b4_location_if([, Location])[); \ - YYFPRINTF (stderr, "\n"); \ - } \ -} while (0) +# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \ +do { \ + if (yydebug) \ + { \ + YYFPRINTF (stderr, "%s ", Title); \ + yysymprint (stderr, \ + Type, Value]b4_location_if([, Location])[]b4_user_args[); \ + YYFPRINTF (stderr, "\n"); \ + } \ +} while (/*CONSTCOND*/ 0) /* Nonzero means print parse trace. It is left uninitialized so that multiple parsers can coexist. */ @@ -777,8 +782,7 @@ yytokenName (yySymbol yytoken) /** Fill in YYVSP[YYLOW1 .. YYLOW0-1] from the chain of states starting * at YYVSP[YYLOW0].yystate.yypred. Leaves YYVSP[YYLOW1].yystate.yypred - * containing the pointer to the next state in the chain. Assumes - * YYLOW1 < YYLOW0. */ + * containing the pointer to the next state in the chain. */ static void yyfillin (yyGLRStackItem *, int, int) __attribute__ ((__unused__)); static void yyfillin (yyGLRStackItem *yyvsp, int yylow0, int yylow1) @@ -797,8 +801,8 @@ yyfillin (yyGLRStackItem *yyvsp, int yylow0, int yylow1) } /* Do nothing if YYNORMAL or if *YYLOW <= YYLOW1. Otherwise, fill in - YYVSP[YYLOW1 .. *YYLOW-1] as in yyfillin and set *YYLOW = YYLOW1. - For convenience, always return YYLOW1. */ + * YYVSP[YYLOW1 .. *YYLOW-1] as in yyfillin and set *YYLOW = YYLOW1. + * For convenience, always return YYLOW1. */ static inline int yyfill (yyGLRStackItem *, int *, int, yybool) __attribute__ ((__unused__)); static inline int @@ -877,9 +881,8 @@ b4_syncline([@oline@], [@ofile@]) static void yyuserMerge (int yyn, YYSTYPE* yy0, YYSTYPE* yy1) { - /* `Use' the arguments. */ - (void) yy0; - (void) yy1; + YYUSE (yy0); + YYUSE (yy1); switch (yyn) { @@ -900,11 +903,11 @@ yyrhsLength (yyRuleNum yyrule) } static void -yydestroyGLRState (char const *yymsg, yyGLRState *yys) +yydestroyGLRState (char const *yymsg, yyGLRState *yys]b4_user_formals[) { if (yys->yyresolved) yydestruct (yymsg, yystos[yys->yylrState], - &yys->yysemantics.yysval]b4_location_if([, &yys->yyloc])[); + &yys->yysemantics.yysval]b4_location_if([, &yys->yyloc])[]b4_user_args[); else { #if YYDEBUG @@ -912,7 +915,7 @@ yydestroyGLRState (char const *yymsg, yyGLRState *yys) { YYFPRINTF (stderr, "%s unresolved ", yymsg); yysymprint (stderr, yystos[yys->yylrState], - &yys->yysemantics.yysval]b4_location_if([, &yys->yyloc])[); + &yys->yysemantics.yysval]b4_location_if([, &yys->yyloc])[]b4_user_args[); YYFPRINTF (stderr, "\n"); } #endif @@ -925,7 +928,7 @@ yydestroyGLRState (char const *yymsg, yyGLRState *yys) for (yyrh = yyoption->yystate, yyn = yyrhsLength (yyoption->yyrule); yyn > 0; yyrh = yyrh->yypred, yyn -= 1) - yydestroyGLRState (yymsg, yyrh); + yydestroyGLRState (yymsg, yyrh]b4_user_args[); } } } @@ -1282,11 +1285,18 @@ yydoAction (yyGLRStack* yystack, size_t yyk, yyRuleNum yyrule, } 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; yyGLRState* yys; yyGLRStackItem yyrhsVals[YYMAXRHS + YYMAXLEFT + 1]; 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) { yys = yys->yypred; @@ -1306,7 +1316,7 @@ yydoAction (yyGLRStack* yystack, size_t yyk, yyRuleNum yyrule, do { \ if (yydebug) \ yy_reduce_print (K, Rule); \ -} while (0) +} while (/*CONSTCOND*/ 0) /*----------------------------------------------------------. | Report that the RULE is going to be reduced on stack #K. | @@ -1560,7 +1570,10 @@ yyresolveAction (yySemanticOption* yyopt, yyGLRStack* yystack, yynrhs = yyrhsLength (yyopt->yyrule); 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, yyrhsVals + YYMAXRHS + YYMAXLEFT - 1, yyvalp, yylocp, yystack]b4_user_args[); @@ -1621,9 +1634,8 @@ static void yyreportAmbiguity (yySemanticOption* yyx0, yySemanticOption* yyx1, yyGLRStack* yystack]b4_pure_formals[) { - /* `Unused' warnings. */ - (void) yyx0; - (void) yyx1; + YYUSE (yyx0); + YYUSE (yyx1); #if YYDEBUG YYFPRINTF (stderr, "Ambiguity detected.\n"); @@ -1836,9 +1848,8 @@ static void yyreportSyntaxError (yyGLRStack* yystack, YYSTYPE* yylvalp, YYLTYPE* yyllocp]b4_user_formals[) { - /* `Unused' warnings. */ - (void) yylvalp; - (void) yyllocp; + YYUSE (yylvalp); + YYUSE (yyllocp); if (yystack->yyerrState == 0) { @@ -1968,7 +1979,7 @@ yyrecoverSyntaxError (yyGLRStack* yystack, yyerror_range[2].yystate.yyloc = *yyllocp; YYLLOC_DEFAULT (yys->yyloc, yyerror_range, 2);]])[ yydestruct ("Error: discarding", - *yytokenp, yylvalp]b4_location_if([, yyllocp])[); + *yytokenp, yylvalp]b4_location_if([, yyllocp])[]b4_user_args[); } YYDPRINTF ((stderr, "Reading a token: ")); yychar = YYLEX; @@ -2023,7 +2034,7 @@ yyrecoverSyntaxError (yyGLRStack* yystack, } } ]b4_location_if([[ yystack->yyerror_range[1].yystate.yyloc = yys->yyloc;]])[ - yydestroyGLRState ("Error: popping", yys); + yydestroyGLRState ("Error: popping", yys]b4_user_args[); yystack->yytops.yystates[0] = yys->yypred; yystack->yynextFree -= 1; yystack->yyspaceLeft += 1; @@ -2046,7 +2057,7 @@ yyrecoverSyntaxError (yyGLRStack* yystack, default: \ goto yybuglab; \ } \ - } while (0) + } while (/*CONSTCOND*/ 0) /*----------. @@ -2218,7 +2229,7 @@ b4_syncline([@oline@], [@ofile@])])dnl yyreturn: if (yytoken != YYEOF && yytoken != YYEMPTY) yydestruct ("Cleanup: discarding lookahead", - yytoken, yylvalp]b4_location_if([, yyllocp])[); + yytoken, yylvalp]b4_location_if([, yyllocp])[]b4_user_args[); /* If the stack is well-formed, pop the stack until it is empty, destroying its entries as we go. But free the stack regardless @@ -2231,7 +2242,7 @@ b4_syncline([@oline@], [@ofile@])])dnl { yyGLRState *yys = yystates[0]; ]b4_location_if([[ yystack.yyerror_range[1].yystate.yyloc = yys->yyloc;]] -)[ yydestroyGLRState ("Cleanup: popping", yys); +)[ yydestroyGLRState ("Cleanup: popping", yys]b4_user_args[); yystates[0] = yys->yypred; yystack.yynextFree -= 1; yystack.yyspaceLeft += 1; @@ -2321,7 +2332,7 @@ m4_if(b4_defines_flag, 0, [], b4_copyright([Skeleton parser for GLR parsing with Bison], [2002, 2003, 2004, 2005]) -b4_token_enums_defines(b4_tokens) +b4_token_enums(b4_tokens) #if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED) m4_ifdef([b4_stype],