c++: always define symbol_name

* data/skeletons/lalr1.cc (symbol_name): Always define it, even when
it's actually yytname which is used.
This commit is contained in:
Akim Demaille
2020-04-26 09:17:32 +02:00
parent cbbbe12e02
commit 7fec669e42
2 changed files with 59 additions and 35 deletions

View File

@@ -305,27 +305,36 @@ m4_define([b4_shared_declarations],
/// In theory \a t should be a token_kind_type, but character literals
/// are valid, yet not members of the token_type enum.
static symbol_kind_type yytranslate_ (int t);
]b4_parse_error_bmatch([custom\|detailed], [[
/// The user-facing name of the symbol whose (internal) number is
/// YYSYMBOL. No bounds checking.
static const char *symbol_name (symbol_kind_type yysymbol);
]b4_parse_error_bmatch(
[custom\|detailed],
[[ /// The user-facing name of the symbol whose (internal) number is
/// YYSYMBOL. No bounds checking.
static const char *symbol_name (symbol_kind_type yysymbol);]],
[simple],
[[#if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[
/// The user-facing name of the symbol whose (internal) number is
/// YYSYMBOL. No bounds checking.
static const char *symbol_name (symbol_kind_type yysymbol);
/// For a symbol, its name in clear.
static const char* const yytname_[];
#endif // #if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[
]],
[verbose],
[[ /// The user-facing name of the symbol whose (internal) number is
/// YYSYMBOL. No bounds checking.
static std::string symbol_name (symbol_kind_type yysymbol);
/// Convert the symbol name \a n to a form suitable for a diagnostic.
static std::string yytnamerr_ (const char *yystr);
/// For a symbol, its name in clear.
static const char* const yytname_[];
]])[
// Tables.
]b4_parser_tables_declare[
]b4_parse_error_case([verbose], [[
/// Convert the symbol name \a n to a form suitable for a diagnostic.
static std::string yytnamerr_ (const char *n);
/// For a symbol, its name in clear.
static const char* const yytname_[];
]],
[b4_token_table_if([], [[
#if ]b4_api_PREFIX[DEBUG
/// For a symbol, its name in clear.
static const char* const yytname_[];
#endif
]])])[
#if ]b4_api_PREFIX[DEBUG
]b4_integral_parser_table_declare([rline], [b4_rline],
@@ -587,16 +596,15 @@ m4_if(b4_prefix, [yy], [],
#define YYERROR goto yyerrorlab
#define YYRECOVERING() (!!yyerrstatus_)
]b4_namespace_open[]b4_parse_error_bmatch([custom\|detailed], [[
/* The user-facing name of the symbol whose (internal) number is
YYSYMBOL. No bounds checking. */
const char *
]b4_namespace_open[
]b4_parse_error_bmatch([custom\|detailed],
[[ const char *
]b4_parser_class[::symbol_name (symbol_kind_type yysymbol)
{
static const char *const yy_sname[] =
{
]b4_symbol_names[
};]m4_ifdef([b4_translatable], [[
};]b4_has_translations_if([[
/* YYTRANSLATABLE[SYMBOL-NUM] -- Whether YY_SNAME[SYMBOL-NUM] is
internationalizable. */
static ]b4_int_type_for([b4_translatable])[ yytranslatable[] =
@@ -608,10 +616,18 @@ m4_if(b4_prefix, [yy], [],
: yy_sname[yysymbol]);]], [[
return yy_sname[yysymbol];]])[
}
]])
b4_parse_error_case([verbose], [[
/* Return YYSTR after stripping away unnecessary quotes and
]],
[simple],
[[#if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[
const char *
]b4_parser_class[::symbol_name (symbol_kind_type yysymbol)
{
return yytname_[yysymbol];
}
#endif // #if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[
]],
[verbose],
[[ /* Return YYSTR after stripping away unnecessary quotes and
backslashes, so that it's suitable for yyerror. The heuristic is
that double-quoting is unnecessary unless the string contains an
apostrophe, a comma, or backslash (other than backslash-backslash).
@@ -650,6 +666,12 @@ b4_parse_error_case([verbose], [[
return yystr;
}
std::string
]b4_parser_class[::symbol_name (symbol_kind_type yysymbol)
{
return yytnamerr_ (yytname_[yysymbol]);
}
]])[
/// Build a parser object.
@@ -786,7 +808,7 @@ b4_parse_error_case([verbose], [[
std::abort ();
#endif
yyo << (yykind < YYNTOKENS ? "token" : "nterm")
<< ' ' << yytname_[yykind] << " ("]b4_locations_if([
<< ' ' << symbol_name (yykind) << " ("]b4_locations_if([
<< yysym.location << ": "])[;
]b4_symbol_actions([printer])[
yyo << ')';
@@ -1298,7 +1320,7 @@ b4_dollar_popdef])[]dnl
yylac_stack_.clear ();
// Reduce until we encounter a shift and thereby accept the token.
#if ]b4_api_PREFIX[DEBUG
YYCDEBUG << "LAC: checking lookahead " << yytname_[yytoken] << ':';
YYCDEBUG << "LAC: checking lookahead " << symbol_name (yytoken) << ':';
#endif
std::ptrdiff_t lac_top = 0;
while (true)
@@ -1398,7 +1420,7 @@ b4_dollar_popdef])[]dnl
{
#if ]b4_api_PREFIX[DEBUG
YYCDEBUG << "LAC: initial context established for "
<< yytname_[yytoken] << '\n';
<< symbol_name (yytoken) << '\n';
#endif
yy_lac_established_ = true;
return yy_lac_check_ (yytoken);
@@ -1507,9 +1529,7 @@ b4_dollar_popdef])[]dnl
for (char const* yyp = yyformat; *yyp; ++yyp)
if (yyp[0] == '%' && yyp[1] == 's' && yyi < yycount)
{
yyres += ]b4_parse_error_case([verbose],
[[yytnamerr_ (yytname_[yyarg[yyi++]])]],
[[symbol_name (yyarg[yyi++])]])[;
yyres += symbol_name (yyarg[yyi++]);
++yyp;
}
else
@@ -1524,7 +1544,8 @@ b4_dollar_popdef])[]dnl
]b4_parser_tables_define[
]b4_tname_if([], [[#if ]b4_api_PREFIX[DEBUG]])[
]b4_parse_error_bmatch([simple\|verbose],
[[#if ]b4_api_PREFIX[DEBUG]b4_tname_if([[ || 1]])[
// YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
// First, the terminals, then, starting at \a YYNTOKENS, nonterminals.
const char*
@@ -1532,7 +1553,8 @@ b4_dollar_popdef])[]dnl
{
]b4_tname[
};
]b4_tname_if([], [[#endif]])[
#endif
]])[
#if ]b4_api_PREFIX[DEBUG][
]b4_integral_parser_table_define([rline], [b4_rline])[