[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 17/21] glr.c, yacc.c: propagate yysymbol_type_t
From: |
Akim Demaille |
Subject: |
[PATCH 17/21] glr.c, yacc.c: propagate yysymbol_type_t |
Date: |
Wed, 1 Apr 2020 08:37:43 +0200 |
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.
---
data/skeletons/c.m4 | 6 +++---
data/skeletons/glr.c | 6 +++---
data/skeletons/yacc.c | 13 ++++++++-----
tests/local.at | 4 ++--
4 files changed, 16 insertions(+), 13 deletions(-)
diff --git a/data/skeletons/c.m4 b/data/skeletons/c.m4
index d0aade36..37891363 100644
--- a/data/skeletons/c.m4
+++ b/data/skeletons/c.m4
@@ -620,7 +620,7 @@ m4_define_default([b4_yydestruct_define],
static void
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[)
{
]b4_parse_param_use([yyvaluep], [yylocationp])dnl
@@ -646,7 +646,7 @@ m4_define_default([b4_yy_symbol_print_define],
static void
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[)
{
FILE *yyoutput = yyo;
@@ -674,7 +674,7 @@ b4_percent_code_get([[post-printer]])dnl
static void
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[)
{
YYFPRINTF (yyo, "%s %s (",
diff --git a/data/skeletons/glr.c b/data/skeletons/glr.c
index 7745ae0d..393f0560 100644
--- a/data/skeletons/glr.c
+++ b/data/skeletons/glr.c
@@ -1482,7 +1482,7 @@ yyglrReduce (yyGLRStack* yystackp, ptrdiff_t yyk,
yyRuleNum yyrule,
YY_CAST (long, yyk), yyrule - 1, yyrline[yyrule - 1]));
if (yyflag != yyok)
return yyflag;
- YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyrule], &yysval, &yyloc);
+ YY_SYMBOL_PRINT ("-> $$ =", yylhsNonterm (yyrule), &yysval, &yyloc);
yyglrShift (yystackp, yyk,
yyLRgotoState (yystackp->yytops.yystates[yyk]->yylrState,
yylhsNonterm (yyrule)),
@@ -2131,10 +2131,10 @@ static int
yyreport_syntax_error (const yyGLRStack* yystackp]b4_user_formals[);
/* The token type of the lookahead of this context. */
-static int
+static yySymbol
yyparse_context_token (const yyGLRStack *yystackp) YY_ATTRIBUTE_UNUSED;
-static int
+static yySymbol
yyparse_context_token (const yyGLRStack *yystackp)
{
YYUSE (yystackp);
diff --git a/data/skeletons/yacc.c b/data/skeletons/yacc.c
index 5505b982..d1460b4a 100644
--- a/data/skeletons/yacc.c
+++ b/data/skeletons/yacc.c
@@ -649,6 +649,9 @@ static const ]b4_int_type_for([b4_translate])[
yytranslate[] =
[[YYRLINE[YYN] -- Source line where rule number YYN was defined.]])[
#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]])[
/* The user-facing name of the symbol whose (internal) number is
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);
yy_symbol_print (stderr,
- yystos[+yyssp[yyi + 1 - yynrhs]],
+ YY_ACCESSING_SYMBOL (+yyssp[yyi + 1 - yynrhs]),
&]b4_rhs_value(yynrhs, yyi + 1)[
]b4_locations_if([, &]b4_rhs_location(yynrhs, yyi +
1))[]dnl
b4_user_args[);
@@ -1866,7 +1869,7 @@ yyreduce:
case of YYERROR or YYBACKUP, subsequent parser actions might lead
to an incorrect destructor call or verbose syntax error message
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);
yylen = 0;
@@ -2018,7 +2021,7 @@ yyerrlab1:
]b4_locations_if([[ yyerror_range[1] = *yylsp;]])[
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);
yystate = *yyssp;
YY_STACK_PRINT (yyss, yyssp);
@@ -2039,7 +2042,7 @@ yyerrlab1:
*++yylsp = yyloc;]])[
/* Shift the error token. */
- YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
+ YY_SYMBOL_PRINT ("Shifting", YY_ACCESSING_SYMBOL (yyn), yyvsp, yylsp);
yystate = yyn;
goto yynewstate;
@@ -2091,7 +2094,7 @@ yyreturn:
while (yyssp != yyss)
{
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);
}
#ifndef yyoverflow
diff --git a/tests/local.at b/tests/local.at
index fdb715c9..43a51f8b 100644
--- a/tests/local.at
+++ b/tests/local.at
@@ -633,13 +633,13 @@ yyreport_syntax_error (const yyparse_context_t
*ctx]AT_PARAM_IF([, AT_PARSE_PARA
fprintf (stderr, ": ");]])[
fprintf (stderr, "syntax error");
{
- int la = yyparse_context_token (ctx);
+ yysymbol_type_t la = yyparse_context_token (ctx);
if (la != YYEMPTY)
fprintf (stderr, " on token [%s]", yysymbol_name (la));
}
{
enum { TOKENMAX = 10 };
- int expected[TOKENMAX];
+ yysymbol_type_t expected[TOKENMAX];
int n = yyexpected_tokens (ctx, expected, TOKENMAX);
/* Forward errors to yyparse. */
if (n < 0)
--
2.26.0
- [PATCH 07/21] yacc.c: prefer YYSYMBOL_YYERROR to YYSYMBOL_error, (continued)
- [PATCH 07/21] yacc.c: prefer YYSYMBOL_YYERROR to YYSYMBOL_error, Akim Demaille, 2020/04/01
- [PATCH 09/21] bistromathic: use symbol numbers instead of YYTRANSLATE, Akim Demaille, 2020/04/01
- [PATCH 11/21] regen, Akim Demaille, 2020/04/01
- [PATCH 10/21] yysymbol_type_t: always assign an enumerator, Akim Demaille, 2020/04/01
- [PATCH 12/21] yacc.c: revert to not using yysymbol_type_t in the yytranslate table, Akim Demaille, 2020/04/01
- [PATCH 13/21] regen, Akim Demaille, 2020/04/01
- [PATCH 14/21] yacc.c: fix more errors from make maintainer-check-g++, Akim Demaille, 2020/04/01
- [PATCH 15/21] regen, Akim Demaille, 2020/04/01
- [PATCH 16/21] glr.c: use yysymbol_type_t, YYSYMBOL_YYEOF etc., Akim Demaille, 2020/04/01
- [PATCH 18/21] regen, Akim Demaille, 2020/04/01
- [PATCH 17/21] glr.c, yacc.c: propagate yysymbol_type_t,
Akim Demaille <=
- [PATCH 19/21] glr.c: remove the yySymbol alias, Akim Demaille, 2020/04/01
- [PATCH 21/21] c++: replace symbol_number_type with symbol_type_type, Akim Demaille, 2020/04/01
- [PATCH 20/21] c++: also use symbol_type_type, Akim Demaille, 2020/04/01