mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 04:13:03 +00:00
yacc.c: use yysymbol_type_t instead of int for yytoken
Now that we have a proper type for internal symbol numbers, let's use
it. More code needs conversion, e.g., printers and destructors, but
they are shared with glr.c, which is not ready yet for this change.
It will also help us deal with warnings such as (GCC9 on GNU/Linux):
input.c: In function 'int yyparse()':
input.c:475:37: error: enumeral and non-enumeral type in conditional expression [-Werror=extra]
475 | (0 <= (YYX) && (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYSYMBOL_YYUNDEF)
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
input.c:1024:17: note: in expansion of macro 'YYTRANSLATE'
1024 | yytoken = YYTRANSLATE (yychar);
| ^~~~~~~~~~~
* data/skeletons/yacc.c (yytranslate, yysymbol_name)
(yyparse_context_t, yyexpected_tokens, yypstate_expected_tokens)
(yysyntax_error_arguments):
Use yysymbol_type_t instead of int.
This commit is contained in:
@@ -637,7 +637,7 @@ union yyalloc
|
|||||||
|
|
||||||
/* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM
|
/* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM
|
||||||
as returned by yylex. */
|
as returned by yylex. */
|
||||||
static const ]b4_int_type_for([b4_translate])[ yytranslate[] =
|
static const yysymbol_type_t yytranslate[] =
|
||||||
{
|
{
|
||||||
]b4_translate[
|
]b4_translate[
|
||||||
};]])[
|
};]])[
|
||||||
@@ -650,7 +650,7 @@ static const ]b4_int_type_for([b4_translate])[ yytranslate[] =
|
|||||||
#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. */
|
||||||
static const char *yysymbol_name (int yysymbol) YY_ATTRIBUTE_UNUSED;
|
static const char *yysymbol_name (yysymbol_type_t yysymbol) YY_ATTRIBUTE_UNUSED;
|
||||||
|
|
||||||
]b4_parse_error_bmatch([simple\|verbose],
|
]b4_parse_error_bmatch([simple\|verbose],
|
||||||
[[/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
|
[[/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
|
||||||
@@ -661,12 +661,12 @@ static const char *const yytname[] =
|
|||||||
};
|
};
|
||||||
|
|
||||||
static const char *
|
static const char *
|
||||||
yysymbol_name (int yysymbol)
|
yysymbol_name (yysymbol_type_t yysymbol)
|
||||||
{
|
{
|
||||||
return yytname[yysymbol];
|
return yytname[yysymbol];
|
||||||
}]],
|
}]],
|
||||||
[[static const char *
|
[[static const char *
|
||||||
yysymbol_name (int yysymbol)
|
yysymbol_name (yysymbol_type_t yysymbol)
|
||||||
{
|
{
|
||||||
static const char *const yy_sname[] =
|
static const char *const yy_sname[] =
|
||||||
{
|
{
|
||||||
@@ -1013,7 +1013,7 @@ do { \
|
|||||||
any old *YYES other than YYESA. */
|
any old *YYES other than YYESA. */
|
||||||
static int
|
static int
|
||||||
yy_lac (yy_state_t *yyesa, yy_state_t **yyes,
|
yy_lac (yy_state_t *yyesa, yy_state_t **yyes,
|
||||||
YYPTRDIFF_T *yyes_capacity, yy_state_t *yyssp, int yytoken)
|
YYPTRDIFF_T *yyes_capacity, yy_state_t *yyssp, yysymbol_type_t yytoken)
|
||||||
{
|
{
|
||||||
yy_state_t *yyes_prev = yyssp;
|
yy_state_t *yyes_prev = yyssp;
|
||||||
yy_state_t *yyesp = yyes_prev;
|
yy_state_t *yyesp = yyes_prev;
|
||||||
@@ -1125,7 +1125,7 @@ typedef struct
|
|||||||
yy_state_t *yyesa;
|
yy_state_t *yyesa;
|
||||||
yy_state_t **yyes;
|
yy_state_t **yyes;
|
||||||
YYPTRDIFF_T *yyes_capacity;]])])[
|
YYPTRDIFF_T *yyes_capacity;]])])[
|
||||||
int yytoken;]b4_locations_if([[
|
yysymbol_type_t yytoken;]b4_locations_if([[
|
||||||
YYLTYPE *yylloc;]])[
|
YYLTYPE *yylloc;]])[
|
||||||
} yyparse_context_t;
|
} yyparse_context_t;
|
||||||
|
|
||||||
@@ -1137,10 +1137,10 @@ typedef struct
|
|||||||
YYARG up to YYARGN. */]b4_push_if([[
|
YYARG up to YYARGN. */]b4_push_if([[
|
||||||
static int
|
static int
|
||||||
yypstate_expected_tokens (yypstate *yyps,
|
yypstate_expected_tokens (yypstate *yyps,
|
||||||
int yyarg[], int yyargn)]], [[
|
yysymbol_type_t yyarg[], int yyargn)]], [[
|
||||||
static int
|
static int
|
||||||
yyexpected_tokens (const yyparse_context_t *yyctx,
|
yyexpected_tokens (const yyparse_context_t *yyctx,
|
||||||
int yyarg[], int yyargn)]])[
|
yysymbol_type_t yyarg[], int yyargn)]])[
|
||||||
{
|
{
|
||||||
/* Actual size of YYARG. */
|
/* Actual size of YYARG. */
|
||||||
int yycount = 0;
|
int yycount = 0;
|
||||||
@@ -1193,7 +1193,7 @@ yyexpected_tokens (const yyparse_context_t *yyctx,
|
|||||||
/* Similar to the previous function. */
|
/* Similar to the previous function. */
|
||||||
static int
|
static int
|
||||||
yyexpected_tokens (const yyparse_context_t *yyctx,
|
yyexpected_tokens (const yyparse_context_t *yyctx,
|
||||||
int yyarg[], int yyargn)
|
yysymbol_type_t yyarg[], int yyargn)
|
||||||
{
|
{
|
||||||
return yypstate_expected_tokens (yyctx->yyps, yyarg, yyargn);
|
return yypstate_expected_tokens (yyctx->yyps, yyarg, yyargn);
|
||||||
}]])[
|
}]])[
|
||||||
@@ -1202,10 +1202,10 @@ yyexpected_tokens (const yyparse_context_t *yyctx,
|
|||||||
]b4_parse_error_bmatch(
|
]b4_parse_error_bmatch(
|
||||||
[custom],
|
[custom],
|
||||||
[[/* The token type of the lookahead of this context. */
|
[[/* The token type of the lookahead of this context. */
|
||||||
static int
|
static yysymbol_type_t
|
||||||
yyparse_context_token (const yyparse_context_t *yyctx) YY_ATTRIBUTE_UNUSED;
|
yyparse_context_token (const yyparse_context_t *yyctx) YY_ATTRIBUTE_UNUSED;
|
||||||
|
|
||||||
static int
|
static yysymbol_type_t
|
||||||
yyparse_context_token (const yyparse_context_t *yyctx)
|
yyparse_context_token (const yyparse_context_t *yyctx)
|
||||||
{
|
{
|
||||||
return yyctx->yytoken;
|
return yyctx->yytoken;
|
||||||
@@ -1316,7 +1316,7 @@ yytnamerr (char *yyres, const char *yystr)
|
|||||||
|
|
||||||
static int
|
static int
|
||||||
yysyntax_error_arguments (const yyparse_context_t *yyctx,
|
yysyntax_error_arguments (const yyparse_context_t *yyctx,
|
||||||
int yyarg[], int yyargn)
|
yysymbol_type_t yyarg[], int yyargn)
|
||||||
{
|
{
|
||||||
/* Actual size of YYARG. */
|
/* Actual size of YYARG. */
|
||||||
int yycount = 0;
|
int yycount = 0;
|
||||||
@@ -1383,7 +1383,7 @@ yysyntax_error (YYPTRDIFF_T *yymsg_alloc, char **yymsg,
|
|||||||
const char *yyformat = YY_NULLPTR;
|
const char *yyformat = YY_NULLPTR;
|
||||||
/* Arguments of yyformat: reported tokens (one for the "unexpected",
|
/* Arguments of yyformat: reported tokens (one for the "unexpected",
|
||||||
one per "expected"). */
|
one per "expected"). */
|
||||||
int yyarg[YYARGS_MAX];
|
yysymbol_type_t yyarg[YYARGS_MAX];
|
||||||
/* Cumulated lengths of YYARG. */
|
/* Cumulated lengths of YYARG. */
|
||||||
YYPTRDIFF_T yysize = 0;
|
YYPTRDIFF_T yysize = 0;
|
||||||
|
|
||||||
@@ -1576,7 +1576,7 @@ yyparse (]m4_ifset([b4_parse_param], [b4_formals(b4_parse_param)], [void])[)]])[
|
|||||||
/* The return value of yyparse. */
|
/* The return value of yyparse. */
|
||||||
int yyresult;
|
int yyresult;
|
||||||
/* Lookahead token as an internal (translated) token number. */
|
/* Lookahead token as an internal (translated) token number. */
|
||||||
int yytoken = 0;
|
yysymbol_type_t yytoken = 0;
|
||||||
/* The variables used to return semantic value and location from the
|
/* The variables used to return semantic value and location from the
|
||||||
action routines. */
|
action routines. */
|
||||||
YYSTYPE yyval;]b4_locations_if([[
|
YYSTYPE yyval;]b4_locations_if([[
|
||||||
|
|||||||
@@ -289,7 +289,7 @@ yyreport_syntax_error (const yyparse_context_t *ctx)
|
|||||||
fprintf (stderr, ": syntax error");
|
fprintf (stderr, ": syntax error");
|
||||||
{
|
{
|
||||||
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);
|
||||||
if (n < 0)
|
if (n < 0)
|
||||||
// Forward errors to yyparse.
|
// Forward errors to yyparse.
|
||||||
@@ -300,7 +300,7 @@ yyreport_syntax_error (const yyparse_context_t *ctx)
|
|||||||
i == 0 ? ": expected" : " or", yysymbol_name (expected[i]));
|
i == 0 ? ": expected" : " or", yysymbol_name (expected[i]));
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
int lookahead = yyparse_context_token (ctx);
|
yysymbol_type_t lookahead = yyparse_context_token (ctx);
|
||||||
if (lookahead != YYEMPTY)
|
if (lookahead != YYEMPTY)
|
||||||
fprintf (stderr, " before %s", yysymbol_name (lookahead));
|
fprintf (stderr, " before %s", yysymbol_name (lookahead));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -807,11 +807,11 @@ yyreport_syntax_error (const yyparse_context_t *ctx)
|
|||||||
enum { ARGS_MAX = 5 };
|
enum { ARGS_MAX = 5 };
|
||||||
const char *argv[ARGS_MAX];
|
const char *argv[ARGS_MAX];
|
||||||
int argc = 0;
|
int argc = 0;
|
||||||
int unexpected = yyparse_context_token (ctx);
|
yysymbol_type_t unexpected = yyparse_context_token (ctx);
|
||||||
if (unexpected != YYEMPTY)
|
if (unexpected != YYEMPTY)
|
||||||
{
|
{
|
||||||
argv[argc++] = yysymbol_name (unexpected);
|
argv[argc++] = yysymbol_name (unexpected);
|
||||||
int expected[ARGS_MAX - 1];
|
yysymbol_type_t expected[ARGS_MAX - 1];
|
||||||
int nexpected = yyexpected_tokens (ctx, expected, ARGS_MAX - 1);
|
int nexpected = yyexpected_tokens (ctx, expected, ARGS_MAX - 1);
|
||||||
if (nexpected < 0)
|
if (nexpected < 0)
|
||||||
res = nexpected;
|
res = nexpected;
|
||||||
|
|||||||
Reference in New Issue
Block a user