X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/dd5f2af2bd4a03b08c8dd33a15a4b86b268a804d..7e7b77c1385cc93bdc7934c7c5e12bbe9e2528d3:/data/glr.c diff --git a/data/glr.c b/data/glr.c index 2d1cbc42..342e5b16 100644 --- a/data/glr.c +++ b/data/glr.c @@ -886,13 +886,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 *yyrhs; + int yyn; + for (yyrhs = yyoption->yystate, yyn = yyrhsLength (yyoption->yyrule); + yyn > 0; + yyrhs = yyrhs->yypred, yyn -= 1) + yydestroyGLRState (yymsg, yyrhs); + } + } +} + /** Left-hand-side symbol for rule #RULE. */ static inline yySymbol yylhsNonterm (yyRuleNum yyrule) @@ -1981,9 +2012,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; @@ -2183,9 +2212,7 @@ b4_syncline([@oline@], [@ofile@])])dnl { yyGLRState *yys = yystates[0]; ]b4_location_if([[ yystack.yyerror_range[1].yystate.yyloc = yys->yyloc;]] -)[ yydestruct ("Cleanup: 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;