c++: style: reorder generated code

The implementation of yy::parser::symbol_name is emitted even before
the implementation of yy::parser::parser.  This makes little sense.

* data/skeletons/lalr1.cc (symbol_name): Move its implementation in
the same place as in the class definition: after "error" and before
"context".
This commit is contained in:
Akim Demaille
2020-05-10 10:06:11 +02:00
parent bf98d94f4f
commit 091943f265

View File

@@ -613,83 +613,6 @@ m4_if(b4_prefix, [yy], [],
#define YYRECOVERING() (!!yyerrstatus_)
]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[
};]b4_has_translations_if([[
/* YYTRANSLATABLE[SYMBOL-NUM] -- Whether YY_SNAME[SYMBOL-NUM] is
internationalizable. */
static ]b4_int_type_for([b4_translatable])[ yytranslatable[] =
{
]b4_translatable[
};
return (yysymbol < YYNTOKENS && yytranslatable[yysymbol]
? _(yy_sname[yysymbol])
: yy_sname[yysymbol]);]], [[
return yy_sname[yysymbol];]])[
}
]],
[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).
YYSTR is taken from yytname. */
std::string
]b4_parser_class[::yytnamerr_ (const char *yystr)
{
if (*yystr == '"')
{
std::string yyr;
char const *yyp = yystr;
for (;;)
switch (*++yyp)
{
case '\'':
case ',':
goto do_not_strip_quotes;
case '\\':
if (*++yyp != '\\')
goto do_not_strip_quotes;
else
goto append;
append:
default:
yyr += *yyp;
break;
case '"':
return yyr;
}
do_not_strip_quotes: ;
}
return yystr;
}
std::string
]b4_parser_class[::symbol_name (symbol_kind_type yysymbol)
{
return yytnamerr_ (yytname_[yysymbol]);
}
]])[
/// Build a parser object.
]b4_parser_class::b4_parser_class[ (]b4_parse_param_decl[)
#if ]b4_api_PREFIX[DEBUG
@@ -1273,8 +1196,86 @@ b4_dollar_popdef])[]dnl
{
error (]b4_join(b4_locations_if([yyexc.location]),
[[yyexc.what ()]])[);
}]b4_parse_error_bmatch([custom\|detailed\|verbose], [[
}
]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[
};]b4_has_translations_if([[
/* YYTRANSLATABLE[SYMBOL-NUM] -- Whether YY_SNAME[SYMBOL-NUM] is
internationalizable. */
static ]b4_int_type_for([b4_translatable])[ yytranslatable[] =
{
]b4_translatable[
};
return (yysymbol < YYNTOKENS && yytranslatable[yysymbol]
? _(yy_sname[yysymbol])
: yy_sname[yysymbol]);]], [[
return yy_sname[yysymbol];]])[
}
]],
[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).
YYSTR is taken from yytname. */
std::string
]b4_parser_class[::yytnamerr_ (const char *yystr)
{
if (*yystr == '"')
{
std::string yyr;
char const *yyp = yystr;
for (;;)
switch (*++yyp)
{
case '\'':
case ',':
goto do_not_strip_quotes;
case '\\':
if (*++yyp != '\\')
goto do_not_strip_quotes;
else
goto append;
append:
default:
yyr += *yyp;
break;
case '"':
return yyr;
}
do_not_strip_quotes: ;
}
return yystr;
}
std::string
]b4_parser_class[::symbol_name (symbol_kind_type yysymbol)
{
return yytnamerr_ (yytname_[yysymbol]);
}
]])[
]b4_parse_error_bmatch([custom\|detailed\|verbose], [[
// ]b4_parser_class[::context.
]b4_parser_class[::context::context (const ]b4_parser_class[& yyparser, const symbol_type& yyla)
: yyparser_ (yyparser)