X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/135bc829bd90e60e58ae16bc442647043a2d9362..b50d2359d7608270561abd5c3cbf6e84834c2019:/data/glr.c diff --git a/data/glr.c b/data/glr.c index 3ce4703d..0f466131 100644 --- a/data/glr.c +++ b/data/glr.c @@ -154,7 +154,7 @@ m4_if(b4_prefix[], [yy], [], #define yynerrs b4_prefix[]nerrs #define yylloc b4_prefix[]lloc]) -b4_token_defines(b4_tokens) +b4_token_enums(b4_tokens) /* Copy the first part of user declarations. */ b4_pre_prologue[ @@ -179,7 +179,7 @@ b4_pre_prologue[ #if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED) ]m4_ifdef([b4_stype], -[b4_syncline([b4_stype_line], [b4_filename]) +[b4_syncline([b4_stype_line], [b4_file_name]) typedef union m4_bregexp(b4_stype, [^{], [YYSTYPE ])b4_stype YYSTYPE; /* Line __line__ of glr.c. */ b4_syncline([@oline@], [@ofile@])], @@ -221,7 +221,6 @@ b4_syncline([@oline@], [@ofile@]) #include #include #include -#include #ifndef YY_ # if YYENABLE_NLS @@ -255,25 +254,32 @@ b4_syncline([@oline@], [@ofile@]) #define yytrue 1 #define yyfalse 0 +#ifndef YYSETJMP +# include +# define YYJMP_BUF jmp_buf +# define YYSETJMP(env) setjmp (env) +# define YYLONGJMP(env, val) longjmp (env, val) +#endif + /*-----------------. | GCC extensions. | `-----------------*/ #ifndef __attribute__ /* This feature is available in gcc versions 2.5 and later. */ -# if !defined (__GNUC__) || __GNUC__ < 2 || \ -(__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__ +# if (!defined (__GNUC__) || __GNUC__ < 2 \ + || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__) # define __attribute__(Spec) /* empty */ -# else -]b4_location_if([# define YYOPTIONAL_LOC(Name) Name],[ -# if defined (__cplusplus) -# define YYOPTIONAL_LOC(Name) /* empty */ -# else -# define YYOPTIONAL_LOC(Name) Name __attribute__ ((__unused__)) -# endif])[ # endif #endif +]b4_location_if([#define YYOPTIONAL_LOC(Name) Name],[ +#ifdef __cplusplus +# define YYOPTIONAL_LOC(Name) /* empty */ +#else +# define YYOPTIONAL_LOC(Name) Name __attribute__ ((__unused__)) +#endif])[ + #ifndef YYASSERT # define YYASSERT(condition) ((void) ((condition) || (abort (), 0))) #endif @@ -532,6 +538,7 @@ do { \ YYFPRINTF (stderr, "%s ", Title); \ yysymprint (stderr, \ Type, Value]b4_location_if([, Location])[); \ + YYFPRINTF (stderr, "\n"); \ } \ } while (0) @@ -727,7 +734,7 @@ struct yyGLRStack { int yyrawchar; ])[ yySymbol* yytokenp; - jmp_buf yyexception_buffer; + YYJMP_BUF yyexception_buffer; yyGLRStackItem* yyitems; yyGLRStackItem* yynextFree; size_t yyspaceLeft; @@ -745,7 +752,7 @@ yyFail (yyGLRStack* yystack]b4_pure_formals[, const char* yymsg) { if (yymsg != NULL) yyerror (]b4_yyerror_args[yymsg); - longjmp (yystack->yyexception_buffer, 1); + YYLONGJMP (yystack->yyexception_buffer, 1); } static void yyMemoryExhausted (yyGLRStack* yystack) @@ -753,7 +760,7 @@ static void yyMemoryExhausted (yyGLRStack* yystack) static void yyMemoryExhausted (yyGLRStack* yystack) { - longjmp (yystack->yyexception_buffer, 2); + YYLONGJMP (yystack->yyexception_buffer, 2); } #if YYDEBUG || YYERROR_VERBOSE @@ -885,13 +892,44 @@ yyuserMerge (int yyn, YYSTYPE* yy0, YYSTYPE* yy1) ]b4_yydestruct_generate([b4_c_ansi_function_def])[ -/** Number of symbols composing the right hand side of rule #RULE. */ +/** Number of symbols composing the right hand side of rule #RULE. */ static inline int yyrhsLength (yyRuleNum yyrule) { return yyr2[yyrule]; } +static void +yydestroyGLRState (char const *yymsg, yyGLRState *yys) +{ + if (yys->yyresolved) + yydestruct (yymsg, yystos[yys->yylrState], + &yys->yysemantics.yysval]b4_location_if([, &yys->yyloc])[); + else + { +#if YYDEBUG + if (yydebug) + { + YYFPRINTF (stderr, "%s unresolved ", yymsg); + yysymprint (stderr, yystos[yys->yylrState], + &yys->yysemantics.yysval]b4_location_if([, &yys->yyloc])[); + YYFPRINTF (stderr, "\n"); + } +#endif + + if (yys->yysemantics.yyfirstVal) + { + yySemanticOption *yyoption = yys->yysemantics.yyfirstVal; + yyGLRState *yyrh; + int yyn; + for (yyrh = yyoption->yystate, yyn = yyrhsLength (yyoption->yyrule); + yyn > 0; + yyrh = yyrh->yypred, yyn -= 1) + yydestroyGLRState (yymsg, yyrh); + } + } +} + /** Left-hand-side symbol for rule #RULE. */ static inline yySymbol yylhsNonterm (yyRuleNum yyrule) @@ -1606,35 +1644,49 @@ yyresolveValue (yySemanticOption* yyoptionList, yyGLRStack* yystack, YYSTYPE* yyvalp, YYLTYPE* yylocp]b4_user_formals[) { yySemanticOption* yybest; - yySemanticOption* yyp; + yySemanticOption** yypp; yybool yymerge; yybest = yyoptionList; yymerge = yyfalse; - for (yyp = yyoptionList->yynext; yyp != NULL; yyp = yyp->yynext) + for (yypp = &yyoptionList->yynext; *yypp != NULL; ) { + yySemanticOption* yyp = *yypp; + if (yyidenticalOptions (yybest, yyp)) - yymergeOptionSets (yybest, yyp); + { + yymergeOptionSets (yybest, yyp); + *yypp = yyp->yynext; + } else - switch (yypreference (yybest, yyp)) - { - case 0: - yyreportAmbiguity (yybest, yyp, yystack]b4_pure_args[); - break; - case 1: - yymerge = yytrue; - break; - case 2: - break; - case 3: - yybest = yyp; - yymerge = yyfalse; - break; - } + { + switch (yypreference (yybest, yyp)) + { + case 0: + yyreportAmbiguity (yybest, yyp, yystack]b4_pure_args[); + break; + case 1: + yymerge = yytrue; + break; + case 2: + break; + case 3: + yybest = yyp; + yymerge = yyfalse; + break; + default: + /* This cannot happen so it is not worth a YYASSERT (yyfalse), + but some compilers complain if the default case is + omitted. */ + break; + } + yypp = &yyp->yynext; + } } if (yymerge) { + yySemanticOption* yyp; int yyprec = yydprec[yybest->yyrule]; YYCHK (yyresolveAction (yybest, yystack, yyvalp, yylocp]b4_user_args[)); for (yyp = yybest->yynext; yyp != NULL; yyp = yyp->yynext) @@ -1739,7 +1791,6 @@ yyprocessOneStack (yyGLRStack* yystack, size_t yyk, yychar = YYLEX; *yytokenp = YYTRANSLATE (yychar); YY_SYMBOL_PRINT ("Next token is", *yytokenp, yylvalp, yyllocp); - YYDPRINTF ((stderr, "\n")); } yygetLRActions (yystate, *yytokenp, &yyaction, &yyconflicts); @@ -1762,7 +1813,8 @@ yyprocessOneStack (yyGLRStack* yystack, size_t yyk, YY_SYMBOL_PRINT ("shifting", *yytokenp, yylvalp, yyllocp); yyglrShift (yystack, yyk, yyaction, yyposn+1, *yylvalp, yyllocp); - YYDPRINTF ((stderr, ", now in state #%d\n", + YYDPRINTF ((stderr, "Stack %lu now in state #%d\n", + (unsigned long int) yyk, yystack->yytops.yystates[yyk]->yylrState)); break; } @@ -1922,7 +1974,6 @@ yyrecoverSyntaxError (yyGLRStack* yystack, yychar = YYLEX; *yytokenp = YYTRANSLATE (yychar); YY_SYMBOL_PRINT ("Next token is", *yytokenp, yylvalp, yyllocp); - YYDPRINTF ((stderr, "\n")); yyj = yypact[yystack->yytops.yystates[0]->yylrState]; if (yyis_pact_ninf (yyj)) return; @@ -1965,7 +2016,6 @@ yyrecoverSyntaxError (yyGLRStack* yystack, YYLLOC_DEFAULT (yyerrloc, yystack->yyerror_range, 2);]])[ YY_SYMBOL_PRINT ("Shifting", yystos[yytable[yyj]], yylvalp, &yyerrloc); - YYDPRINTF ((stderr, "\n")); yyglrShift (yystack, 0, yytable[yyj], yys->yyposn, *yylvalp, &yyerrloc); yys = yystack->yytops.yystates[0]; @@ -1973,9 +2023,7 @@ yyrecoverSyntaxError (yyGLRStack* yystack, } } ]b4_location_if([[ yystack->yyerror_range[1].yystate.yyloc = yys->yyloc;]])[ - yydestruct ("Error: popping", - yystos[yys->yylrState], - &yys->yysemantics.yysval]b4_location_if([, &yys->yyloc])[); + yydestroyGLRState ("Error: popping", yys); yystack->yytops.yystates[0] = yys->yypred; yystack->yynextFree -= 1; yystack->yyspaceLeft += 1; @@ -1987,7 +2035,7 @@ yyrecoverSyntaxError (yyGLRStack* yystack, #define YYCHK1(YYE) \ do { \ switch (YYE) { \ - default: \ + case yyok: \ break; \ case yyabort: \ goto yyabortlab; \ @@ -1995,6 +2043,8 @@ yyrecoverSyntaxError (yyGLRStack* yystack, goto yyacceptlab; \ case yyerr: \ goto yyuser_error; \ + default: \ + goto yybuglab; \ } \ } while (0) @@ -2042,10 +2092,12 @@ b4_syncline([@oline@], [@ofile@])])dnl [ if (! yyinitGLRStack (&yystack, YYINITDEPTH)) goto yyexhaustedlab; - switch (setjmp (yystack.yyexception_buffer)) + switch (YYSETJMP (yystack.yyexception_buffer)) { + case 0: break; case 1: goto yyabortlab; case 2: goto yyexhaustedlab; + default: goto yybuglab; } yystack.yytokenp = &yytoken; yyglrShift (&yystack, 0, 0, 0, yylval, &yylloc); @@ -2086,7 +2138,6 @@ b4_syncline([@oline@], [@ofile@])])dnl yychar = YYLEX; yytoken = YYTRANSLATE (yychar); YY_SYMBOL_PRINT ("Next token is", yytoken, yylvalp, yyllocp); - YYDPRINTF ((stderr, "\n")); } yygetLRActions (yystate, yytoken, &yyaction, &yyconflicts); if (*yyconflicts != 0) @@ -2094,7 +2145,6 @@ b4_syncline([@oline@], [@ofile@])])dnl if (yyisShiftAction (yyaction)) { YY_SYMBOL_PRINT ("Shifting", yytoken, yylvalp, yyllocp); - YYDPRINTF ((stderr, "\n")); if (yytoken != YYEOF) yytoken = YYEMPTY; yyposn += 1; @@ -2152,6 +2202,10 @@ b4_syncline([@oline@], [@ofile@])])dnl yyresult = 0; goto yyreturn; + yybuglab: + YYASSERT (yyfalse); + /* Fall through. */ + yyabortlab: yyresult = 1; goto yyreturn; @@ -2163,7 +2217,7 @@ b4_syncline([@oline@], [@ofile@])])dnl yyreturn: if (yytoken != YYEOF && yytoken != YYEMPTY) - yydestruct ("Error: discarding lookahead", + yydestruct ("Cleanup: discarding lookahead", yytoken, yylvalp]b4_location_if([, yyllocp])[); /* If the stack is well-formed, pop the stack until it is empty, @@ -2177,9 +2231,7 @@ b4_syncline([@oline@], [@ofile@])])dnl { yyGLRState *yys = yystates[0]; ]b4_location_if([[ yystack.yyerror_range[1].yystate.yyloc = yys->yyloc;]] -)[ yydestruct ("Error: popping", - yystos[yys->yylrState], - &yys->yysemantics.yysval]b4_location_if([, &yys->yyloc])[); +)[ yydestroyGLRState ("Cleanup: popping", yys); yystates[0] = yys->yypred; yystack.yynextFree -= 1; yystack.yyspaceLeft += 1; @@ -2269,11 +2321,11 @@ m4_if(b4_defines_flag, 0, [], b4_copyright([Skeleton parser for GLR parsing with Bison], [2002, 2003, 2004, 2005]) -b4_token_defines(b4_tokens) +b4_token_enums(b4_tokens) #if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED) m4_ifdef([b4_stype], -[b4_syncline([b4_stype_line], [b4_filename]) +[b4_syncline([b4_stype_line], [b4_file_name]) typedef union m4_bregexp(b4_stype, [^{], [YYSTYPE ])b4_stype YYSTYPE; /* Line __line__ of glr.c. */ b4_syncline([@oline@], [@ofile@])],