Prefer signed types for indexes in skeletons

* NEWS: Mention this.
* data/skeletons/c.m4 (b4_int_type):
Prefer char if it will do, and prefer signed types to unsigned if
either will do.
* data/skeletons/glr.c (yy_reduce_print): No need to
convert rule line to unsigned long.
(yyrecoverSyntaxError): Put action into an int to
avoid GCC warning of using a char subscript.
* data/skeletons/lalr1.cc (yy_lac_check_, yysyntax_error_):
Prefer ptrdiff_t to size_t.
* data/skeletons/yacc.c (b4_int_type):
Prefer signed types to unsigned if either will do.
* data/skeletons/yacc.c (b4_declare_parser_state_variables):
(YYSTACK_RELOCATE, YYCOPY, yy_lac_stack_realloc, yy_lac)
(yytnamerr, yysyntax_error, yyparse): Prefer ptrdiff_t to size_t.
(YYPTRDIFF_T, YYPTRDIFF_MAXIMUM): New macros.
(YYSIZE_T): Fix "! defined YYSIZE_T" typo.
(YYSIZE_MAXIMUM): Take the minimum of PTRDIFF_MAX and SIZE_MAX.
(YYSIZEOF): New macro.
(YYSTACK_GAP_MAXIMUM, YYSTACK_BYTES, YYSTACK_RELOCATE)
(yy_lac_stack_realloc, yyparse): Use it.
(YYCOPY, yy_lac_stack_realloc): Cast to YYSIZE_T to pacify GCC.
(yy_reduce_print): Use int instead of unsigned long when int
will do.
(yy_lac_stack_realloc): Prefer long to unsigned long when
either will do.
* tests/regression.at: Adjust to these changes.
This commit is contained in:
Paul Eggert
2019-10-01 01:28:45 -07:00
committed by Akim Demaille
parent 2ca6b71967
commit 4d9ff272cf
6 changed files with 112 additions and 82 deletions

View File

@@ -1155,11 +1155,11 @@ b4_dollar_popdef])[]dnl
#if ]b4_api_PREFIX[DEBUG
YYCDEBUG << "LAC: checking lookahead " << yytname_[yytoken] << ':';
#endif
size_t lac_top = 0;
ptrdiff_t lac_top = 0;
while (true)
{
state_type top_state = (yylac_stack_.empty ()
? yystack_[lac_top].state
? yystack_[(size_t) lac_top].state
: yylac_stack_.back ());
int yyrule = yypact_[top_state];
if (yy_pact_value_is_default_ (yyrule)
@@ -1194,12 +1194,12 @@ b4_dollar_popdef])[]dnl
YYCDEBUG << " R" << yyrule - 1;
// Pop the corresponding number of values from the stack.
{
size_t yylen = yyr2_[yyrule];
ptrdiff_t yylen = yyr2_[yyrule];
// First pop from the LAC stack as many tokens as possible.
size_t lac_size = yylac_stack_.size ();
ptrdiff_t lac_size = (ptrdiff_t) yylac_stack_.size ();
if (yylen < lac_size)
{
yylac_stack_.resize (lac_size - yylen);
yylac_stack_.resize ((size_t) (lac_size - yylen));
yylen = 0;
}
else if (lac_size)
@@ -1207,13 +1207,13 @@ b4_dollar_popdef])[]dnl
yylac_stack_.clear ();
yylen -= lac_size;
}
// Only aftwerwards look at the main stack.
// Only afterwards look at the main stack.
// We simulate popping elements by incrementing lac_top.
lac_top += yylen;
}
// Keep top_state in sync with the updated stack.
top_state = (yylac_stack_.empty ()
? yystack_[lac_top].state
? yystack_[(size_t) lac_top].state
: yylac_stack_.back ());
// Push the resulting state of the reduction.
state_type state = yy_lr_goto_state_ (top_state, yyr1_[yyrule]);
@@ -1292,7 +1292,7 @@ b4_error_verbose_if([state_type yystate, const symbol_type& yyla],
{]b4_error_verbose_if([[
// Number of reported tokens (one for the "unexpected", one per
// "expected").
size_t yycount = 0;
ptrdiff_t yycount = 0;
// Its maximum.
enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
// Arguments of yyformat.
@@ -1387,7 +1387,7 @@ b4_error_verbose_if([state_type yystate, const symbol_type& yyla],
std::string yyres;
// Argument number.
size_t yyi = 0;
ptrdiff_t yyi = 0;
for (char const* yyp = yyformat; *yyp; ++yyp)
if (yyp[0] == '%' && yyp[1] == 's' && yyi < yycount)
{
@@ -1436,7 +1436,7 @@ b4_error_verbose_if([state_type yystate, const symbol_type& yyla],
void
]b4_parser_class[::yy_reduce_print_ (int yyrule)
{
unsigned yylno = yyrline_[yyrule];
int yylno = yyrline_[yyrule];
int yynrhs = yyr2_[yyrule];
// Print the symbols being reduced, and their result.
*yycdebug_ << "Reducing stack by rule " << yyrule - 1