glr.c, yacc.c: propagate yysymbol_type_t

Now that yacc.c and glr.c both know yysymbol_type_t, convert the
common routines.

* data/skeletons/c.m4 (yydestruct, yy_symbol_value_print)
(yy_symbol_print): Use yysymbol_type_t instead of int.
* data/skeletons/glr.c: Use yySymbol where appropriate.
* data/skeletons/yacc.c (YY_ACCESSING_SYMBOL): New wrapper around
yystos.
Use it.
* tests/local.at (yyreport_syntax_error): Use yysymbol_type_t where
appropriate.
This commit is contained in:
Akim Demaille
2020-03-29 11:51:31 +02:00
parent 39792f57fb
commit 086506bf23
4 changed files with 16 additions and 13 deletions

View File

@@ -620,7 +620,7 @@ m4_define_default([b4_yydestruct_define],
static void static void
yydestruct (const char *yymsg, yydestruct (const char *yymsg,
int yytype, YYSTYPE *yyvaluep]b4_locations_if(dnl yysymbol_type_t yytype, YYSTYPE *yyvaluep]b4_locations_if(dnl
[[, YYLTYPE *yylocationp]])[]b4_user_formals[) [[, YYLTYPE *yylocationp]])[]b4_user_formals[)
{ {
]b4_parse_param_use([yyvaluep], [yylocationp])dnl ]b4_parse_param_use([yyvaluep], [yylocationp])dnl
@@ -646,7 +646,7 @@ m4_define_default([b4_yy_symbol_print_define],
static void static void
yy_symbol_value_print (FILE *yyo, yy_symbol_value_print (FILE *yyo,
int yytype, YYSTYPE const * const yyvaluep]b4_locations_if(dnl yysymbol_type_t yytype, YYSTYPE const * const yyvaluep]b4_locations_if(dnl
[[, YYLTYPE const * const yylocationp]])[]b4_user_formals[) [[, YYLTYPE const * const yylocationp]])[]b4_user_formals[)
{ {
FILE *yyoutput = yyo; FILE *yyoutput = yyo;
@@ -674,7 +674,7 @@ b4_percent_code_get([[post-printer]])dnl
static void static void
yy_symbol_print (FILE *yyo, yy_symbol_print (FILE *yyo,
int yytype, YYSTYPE const * const yyvaluep]b4_locations_if(dnl yysymbol_type_t yytype, YYSTYPE const * const yyvaluep]b4_locations_if(dnl
[[, YYLTYPE const * const yylocationp]])[]b4_user_formals[) [[, YYLTYPE const * const yylocationp]])[]b4_user_formals[)
{ {
YYFPRINTF (yyo, "%s %s (", YYFPRINTF (yyo, "%s %s (",

View File

@@ -1482,7 +1482,7 @@ yyglrReduce (yyGLRStack* yystackp, ptrdiff_t yyk, yyRuleNum yyrule,
YY_CAST (long, yyk), yyrule - 1, yyrline[yyrule - 1])); YY_CAST (long, yyk), yyrule - 1, yyrline[yyrule - 1]));
if (yyflag != yyok) if (yyflag != yyok)
return yyflag; return yyflag;
YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyrule], &yysval, &yyloc); YY_SYMBOL_PRINT ("-> $$ =", yylhsNonterm (yyrule), &yysval, &yyloc);
yyglrShift (yystackp, yyk, yyglrShift (yystackp, yyk,
yyLRgotoState (yystackp->yytops.yystates[yyk]->yylrState, yyLRgotoState (yystackp->yytops.yystates[yyk]->yylrState,
yylhsNonterm (yyrule)), yylhsNonterm (yyrule)),
@@ -2131,10 +2131,10 @@ static int
yyreport_syntax_error (const yyGLRStack* yystackp]b4_user_formals[); yyreport_syntax_error (const yyGLRStack* yystackp]b4_user_formals[);
/* The token type of the lookahead of this context. */ /* The token type of the lookahead of this context. */
static int static yySymbol
yyparse_context_token (const yyGLRStack *yystackp) YY_ATTRIBUTE_UNUSED; yyparse_context_token (const yyGLRStack *yystackp) YY_ATTRIBUTE_UNUSED;
static int static yySymbol
yyparse_context_token (const yyGLRStack *yystackp) yyparse_context_token (const yyGLRStack *yystackp)
{ {
YYUSE (yystackp); YYUSE (yystackp);

View File

@@ -649,6 +649,9 @@ static const ]b4_int_type_for([b4_translate])[ yytranslate[] =
[[YYRLINE[YYN] -- Source line where rule number YYN was defined.]])[ [[YYRLINE[YYN] -- Source line where rule number YYN was defined.]])[
#endif #endif
/** Accessing symbol of state STATE. */
#define YY_ACCESSING_SYMBOL(State) YY_CAST (yysymbol_type_t, yystos[State])
#if ]b4_parse_error_case([simple], [b4_api_PREFIX[DEBUG || ]b4_token_table_flag], [[1]])[ #if ]b4_parse_error_case([simple], [b4_api_PREFIX[DEBUG || ]b4_token_table_flag], [[1]])[
/* The user-facing name of the symbol whose (internal) number is /* The user-facing name of the symbol whose (internal) number is
YYSYMBOL. No bounds checking. */ YYSYMBOL. No bounds checking. */
@@ -819,7 +822,7 @@ yy_reduce_print (yy_state_t *yyssp, YYSTYPE *yyvsp,]b4_locations_if([[ YYLTYPE *
{ {
YYFPRINTF (stderr, " $%d = ", yyi + 1); YYFPRINTF (stderr, " $%d = ", yyi + 1);
yy_symbol_print (stderr, yy_symbol_print (stderr,
yystos[+yyssp[yyi + 1 - yynrhs]], YY_ACCESSING_SYMBOL (+yyssp[yyi + 1 - yynrhs]),
&]b4_rhs_value(yynrhs, yyi + 1)[ &]b4_rhs_value(yynrhs, yyi + 1)[
]b4_locations_if([, &]b4_rhs_location(yynrhs, yyi + 1))[]dnl ]b4_locations_if([, &]b4_rhs_location(yynrhs, yyi + 1))[]dnl
b4_user_args[); b4_user_args[);
@@ -1866,7 +1869,7 @@ yyreduce:
case of YYERROR or YYBACKUP, subsequent parser actions might lead case of YYERROR or YYBACKUP, subsequent parser actions might lead
to an incorrect destructor call or verbose syntax error message to an incorrect destructor call or verbose syntax error message
before the lookahead is translated. */ before the lookahead is translated. */
YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc); YY_SYMBOL_PRINT ("-> $$ =", YY_CAST (yysymbol_type_t, yyr1[yyn]), &yyval, &yyloc);
YYPOPSTACK (yylen); YYPOPSTACK (yylen);
yylen = 0; yylen = 0;
@@ -2018,7 +2021,7 @@ yyerrlab1:
]b4_locations_if([[ yyerror_range[1] = *yylsp;]])[ ]b4_locations_if([[ yyerror_range[1] = *yylsp;]])[
yydestruct ("Error: popping", yydestruct ("Error: popping",
yystos[yystate], yyvsp]b4_locations_if([, yylsp])[]b4_user_args[); YY_ACCESSING_SYMBOL (yystate), yyvsp]b4_locations_if([, yylsp])[]b4_user_args[);
YYPOPSTACK (1); YYPOPSTACK (1);
yystate = *yyssp; yystate = *yyssp;
YY_STACK_PRINT (yyss, yyssp); YY_STACK_PRINT (yyss, yyssp);
@@ -2039,7 +2042,7 @@ yyerrlab1:
*++yylsp = yyloc;]])[ *++yylsp = yyloc;]])[
/* Shift the error token. */ /* Shift the error token. */
YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp); YY_SYMBOL_PRINT ("Shifting", YY_ACCESSING_SYMBOL (yyn), yyvsp, yylsp);
yystate = yyn; yystate = yyn;
goto yynewstate; goto yynewstate;
@@ -2091,7 +2094,7 @@ yyreturn:
while (yyssp != yyss) while (yyssp != yyss)
{ {
yydestruct ("Cleanup: popping", yydestruct ("Cleanup: popping",
yystos[+*yyssp], yyvsp]b4_locations_if([, yylsp])[]b4_user_args[); YY_ACCESSING_SYMBOL (+*yyssp), yyvsp]b4_locations_if([, yylsp])[]b4_user_args[);
YYPOPSTACK (1); YYPOPSTACK (1);
} }
#ifndef yyoverflow #ifndef yyoverflow

View File

@@ -633,13 +633,13 @@ yyreport_syntax_error (const yyparse_context_t *ctx]AT_PARAM_IF([, AT_PARSE_PARA
fprintf (stderr, ": ");]])[ fprintf (stderr, ": ");]])[
fprintf (stderr, "syntax error"); fprintf (stderr, "syntax error");
{ {
int la = yyparse_context_token (ctx); yysymbol_type_t la = yyparse_context_token (ctx);
if (la != YYEMPTY) if (la != YYEMPTY)
fprintf (stderr, " on token [%s]", yysymbol_name (la)); fprintf (stderr, " on token [%s]", yysymbol_name (la));
} }
{ {
enum { TOKENMAX = 10 }; enum { TOKENMAX = 10 };
int expected[TOKENMAX]; yysymbol_type_t expected[TOKENMAX];
int n = yyexpected_tokens (ctx, expected, TOKENMAX); int n = yyexpected_tokens (ctx, expected, TOKENMAX);
/* Forward errors to yyparse. */ /* Forward errors to yyparse. */
if (n < 0) if (n < 0)