Prefer signed to unsigned integers

This patch contains more fixes to prefer signed to unsigned
integer types, as modern tools like 'gcc -fsanitize=undefined'
can check for signed integer overflow but not unsigned overflow.
* NEWS: Document the API change.
* boostrap.conf (gnulib_modules): Add intprops.
* data/skeletons/glr.c: Include stddef.h and stdint.h,
since this skeleton can assume C99 or later.
(YYSIZEMAX): Now signed, and the minimum of SIZE_MAX and PTRDIFF_MAX.
(yybool) [!__cplusplus]: Now signed (which is how bool behaves).
(YYTRANSLATE): Avoid use of unsigned, and make the macro
safe even for values greater than UINT_MAX.
(yytnamerr, struct yyGLRState, struct yyGLRStateSet, struct yyGLRStack)
(yyaddDeferredAction, yyinitStateSet, yyinitGLRStack)
(yyexpandGLRStack, yymarkStackDeleted, yyremoveDeletes)
(yyglrShift, yyglrShiftDefer, yy_reduce_print, yydoAction)
(yyglrReduce, yysplitStack, yyreportTree, yycompressStack)
(yyprocessOneStack, yyreportSyntaxError, yyrecoverSyntaxError)
(yyparse, yy_yypstack, yypstack, yypdumpstack):
* tests/input.at (Torturing the Scanner):
Prefer ptrdiff_t to size_t.
* data/skeletons/c++.m4 (b4_yytranslate_define):
* src/AnnotationList.c (AnnotationList__computePredecessorAnnotations):
* src/AnnotationList.h (AnnotationIndex):
* src/InadequacyList.h (InadequacyListNodeCount):
* src/closure.c (closure_new):
* src/complain.c (error_message, complains, complain_indent)
(complain_args, duplicate_directive, duplicate_rule_directive):
* src/gram.c (nritems, ritem_print, grammar_dump):
* src/ielr.c (ielr_compute_ritem_sees_lookahead_set)
(ielr_item_has_lookahead, ielr_compute_annotation_lists)
(ielr_compute_lookaheads):
* src/location.c (columns, boundary_print, location_print):
* src/muscle-tab.c (muscle_percent_define_insert)
(muscle_percent_define_check_values):
* src/output.c (prepare_rules, prepare_actions):
* src/parse-gram.y (id, handle_require):
* src/reader.c (record_merge_function_type, packgram):
* src/reduce.c (nuseless_productions, nuseless_nonterminals)
(inaccessable_symbols):
* src/relation.c (relation_print):
* src/scan-code.l (variant, variant_table_size, variant_count)
(variant_add, get_at_spec, show_sub_message, show_sub_messages)
(parse_ref):
* src/scan-gram.l (<SC_ESCAPED_STRING,SC_ESCAPED_CHARACTER>)
(scan_integer, convert_ucn_to_byte, handle_syncline):
* src/scan-skel.l (at_complain):
* src/symtab.c (complain_symbol_redeclared)
(complain_semantic_type_redeclared, complain_class_redeclared)
(symbol_class_set, complain_user_token_number_redeclared):
* src/tables.c (conflict_tos, conflrow, conflict_table)
(conflict_list, save_row, pack_vector):
* tests/local.at (AT_YYLEX_DEFINE(c)):
Prefer signed to unsigned integer.
* data/skeletons/lalr1.cc (yy_lac_check_):
* tests/actions.at (_AT_CHECK_PRINTER_AND_DESTRUCTOR):
* tests/local.at (AT_YYLEX_DEFINE(c)):
Omit now-unnecessary casts.
* data/skeletons/location.cc (b4_location_define):
* doc/bison.texi (Mfcalc Lexer, C++ position, C++ location):
Prefer int to unsigned for line and column numbers.
Change example to abort explicitly on memory exhaustion,
and fix an off-by-one bug that led to undefined behavior.
* data/skeletons/stack.hh (stack::operator[]):
Also allow ptrdiff_t indexes.
(stack::pop, slice::slice, slice::operator[]):
Index arg is now ptrdiff_t, not int.
(stack::ssize): New method.
(slice::range_): Now ptrdiff_t, not int.
* data/skeletons/yacc.c (b4_state_num_type): Remove.
All uses replaced by b4_int_type.
(YY_CONVERT_INT_BEGIN, YY_CONVERT_INT_END): New macros.
(yylac, yyparse): Use them around conversions that -Wconversion
would give false alarms about. 	Omit unnecessary casts.
(yy_stack_print): Use int rather than unsigned, and omit
a cast that doesn’t seem to be needed here any more.
* examples/c++/variant.yy (yylex):
* examples/c++/variant-11.yy (yylex):
Omit no-longer-needed conversions to unsigned.
* src/InadequacyList.c (InadequacyList__new_conflict):
Don’t assume *node_count is unsigned.
* src/output.c (muscle_insert_unsigned_table):
Remove; no longer used.
This commit is contained in:
Paul Eggert
2019-10-02 16:56:32 -07:00
parent 4d9ff272cf
commit 133edcd248
41 changed files with 326 additions and 299 deletions

View File

@@ -542,12 +542,12 @@ m4_define([b4_yytranslate_define],
{
]b4_translate[
};
const unsigned user_token_number_max_ = ]b4_user_token_number_max[;
const int user_token_number_max_ = ]b4_user_token_number_max[;
const token_number_type undef_token_ = ]b4_undef_token_number[;
if (static_cast<int> (t) <= yyeof_)
return yyeof_;
else if (static_cast<unsigned> (t) <= user_token_number_max_)
else if (static_cast<int> (t) <= user_token_number_max_)
return translate_table[t];
else
return undef_token_;]])[

View File

@@ -183,7 +183,7 @@ m4_define([b4_int_type],
# b4_int_type_for(NAME)
# ---------------------
# Return the smallest int type able to handle numbers ranging from
# Return a narrow int type able to handle numbers ranging from
# 'NAME_min' to 'NAME_max' (included).
m4_define([b4_int_type_for],
[b4_int_type($1_min, $1_max)])

View File

@@ -259,7 +259,9 @@ static YYLTYPE yyloc_default][]b4_yyloc_default;])[
]b4_user_post_prologue[
]b4_percent_code_get[]dnl
[#include <stdio.h>
[#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -285,7 +287,7 @@ static YYLTYPE yyloc_default][]b4_yyloc_default;])[
# define YYREALLOC realloc
#endif
#define YYSIZEMAX ((size_t) -1)
#define YYSIZEMAX (PTRDIFF_MAX < SIZE_MAX ? PTRDIFF_MAX : (ptrdiff_t) SIZE_MAX)
#ifdef __cplusplus
typedef bool yybool;
@@ -293,7 +295,7 @@ static YYLTYPE yyloc_default][]b4_yyloc_default;])[
# define yyfalse false
#else
/* When we move to stdbool, get rid of the various casts to yybool. */
typedef unsigned char yybool;
typedef signed char yybool;
# define yytrue 1
# define yyfalse 0
#endif
@@ -349,7 +351,7 @@ static YYLTYPE yyloc_default][]b4_yyloc_default;])[
]b4_api_token_raw_if(dnl
[[#define YYTRANSLATE(YYX) (YYX)]],
[[#define YYTRANSLATE(YYX) \
((unsigned) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
(0 <= (YYX) && (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
/* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM
as returned by yylex. */
@@ -490,7 +492,7 @@ typedef enum { yyok, yyaccept, yyabort, yyerr } YYRESULTTAG;
int yydebug;
struct yyGLRStack;
static void yypstack (struct yyGLRStack* yystackp, size_t yyk)
static void yypstack (struct yyGLRStack* yystackp, ptrdiff_t yyk)
YY_ATTRIBUTE_UNUSED;
static void yypdumpstack (struct yyGLRStack* yystackp)
YY_ATTRIBUTE_UNUSED;
@@ -574,12 +576,12 @@ yystpcpy (char *yydest, const char *yysrc)
backslash-backslash). YYSTR is taken from yytname. If YYRES is
null, do not copy; instead, return the length of what the result
would have been. */
static size_t
static ptrdiff_t
yytnamerr (char *yyres, const char *yystr)
{
if (*yystr == '"')
{
size_t yyn = 0;
ptrdiff_t yyn = 0;
char const *yyp = yystr;
for (;;)
@@ -611,9 +613,9 @@ yytnamerr (char *yyres, const char *yystr)
}
if (! yyres)
return strlen (yystr);
return (ptrdiff_t) strlen (yystr);
return (size_t) (yystpcpy (yyres, yystr) - yyres);
return yystpcpy (yyres, yystr) - yyres;
}
# endif
@@ -648,7 +650,7 @@ struct yyGLRState {
/** Preceding state in this stack */
yyGLRState* yypred;
/** Source position of the last token produced by my symbol */
size_t yyposn;
ptrdiff_t yyposn;
union {
/** First in a chain of alternative reductions producing the
* nonterminal corresponding to this state, threaded through
@@ -668,7 +670,7 @@ struct yyGLRStateSet {
* operation, yylookaheadNeeds[0] is not maintained since it would merely
* duplicate yychar != YYEMPTY. */
yybool* yylookaheadNeeds;
size_t yysize, yycapacity;
ptrdiff_t yysize, yycapacity;
};
struct yySemanticOption {
@@ -708,7 +710,7 @@ struct yyGLRStack {
YYJMP_BUF yyexception_buffer;
yyGLRStackItem* yyitems;
yyGLRStackItem* yynextFree;
size_t yyspaceLeft;
ptrdiff_t yyspaceLeft;
yyGLRState* yysplitPoint;
yyGLRState* yylastDeleted;
yyGLRStateSet yytops;
@@ -1066,7 +1068,7 @@ yynewGLRStackItem (yyGLRStack* yystackp, yybool yyisState)
* alternative actions for YYSTATE. Assumes that YYRHS comes from
* stack #YYK of *YYSTACKP. */
static void
yyaddDeferredAction (yyGLRStack* yystackp, size_t yyk, yyGLRState* yystate,
yyaddDeferredAction (yyGLRStack* yystackp, ptrdiff_t yyk, yyGLRState* yystate,
yyGLRState* yyrhs, yyRuleNum yyrule)
{
yySemanticOption* yynewOption =
@@ -1097,19 +1099,21 @@ yyinitStateSet (yyGLRStateSet* yyset)
yyset->yysize = 1;
yyset->yycapacity = 16;
yyset->yystates
= (yyGLRState**) YYMALLOC (yyset->yycapacity * sizeof yyset->yystates[0]);
= (yyGLRState**) YYMALLOC ((size_t) yyset->yycapacity
* sizeof yyset->yystates[0]);
if (! yyset->yystates)
return yyfalse;
yyset->yystates[0] = YY_NULLPTR;
yyset->yylookaheadNeeds
= (yybool*) YYMALLOC (yyset->yycapacity * sizeof yyset->yylookaheadNeeds[0]);
= (yybool*) YYMALLOC ((size_t) yyset->yycapacity
* sizeof yyset->yylookaheadNeeds[0]);
if (! yyset->yylookaheadNeeds)
{
YYFREE (yyset->yystates);
return yyfalse;
}
memset (yyset->yylookaheadNeeds,
0, yyset->yycapacity * sizeof yyset->yylookaheadNeeds[0]);
0, (size_t) yyset->yycapacity * sizeof yyset->yylookaheadNeeds[0]);
return yytrue;
}
@@ -1122,13 +1126,14 @@ static void yyfreeStateSet (yyGLRStateSet* yyset)
/** Initialize *YYSTACKP to a single empty stack, with total maximum
* capacity for all stacks of YYSIZE. */
static yybool
yyinitGLRStack (yyGLRStack* yystackp, size_t yysize)
yyinitGLRStack (yyGLRStack* yystackp, ptrdiff_t yysize)
{
yystackp->yyerrState = 0;
yynerrs = 0;
yystackp->yyspaceLeft = yysize;
yystackp->yyitems =
(yyGLRStackItem*) YYMALLOC (yysize * sizeof yystackp->yynextFree[0]);
(yyGLRStackItem*) YYMALLOC ((size_t) yysize
* sizeof yystackp->yynextFree[0]);
if (!yystackp->yyitems)
return yyfalse;
yystackp->yynextFree = yystackp->yyitems;
@@ -1152,15 +1157,16 @@ yyexpandGLRStack (yyGLRStack* yystackp)
{
yyGLRStackItem* yynewItems;
yyGLRStackItem* yyp0, *yyp1;
size_t yynewSize;
size_t yyn;
size_t yysize = (size_t) (yystackp->yynextFree - yystackp->yyitems);
ptrdiff_t yynewSize;
ptrdiff_t yyn;
ptrdiff_t yysize = yystackp->yynextFree - yystackp->yyitems;
if (YYMAXDEPTH - YYHEADROOM < yysize)
yyMemoryExhausted (yystackp);
yynewSize = 2*yysize;
if (YYMAXDEPTH < yynewSize)
yynewSize = YYMAXDEPTH;
yynewItems = (yyGLRStackItem*) YYMALLOC (yynewSize * sizeof yynewItems[0]);
yynewItems = (yyGLRStackItem*) YYMALLOC ((size_t) yynewSize
* sizeof yynewItems[0]);
if (! yynewItems)
yyMemoryExhausted (yystackp);
for (yyp0 = yystackp->yyitems, yyp1 = yynewItems, yyn = yysize;
@@ -1224,7 +1230,7 @@ yyupdateSplit (yyGLRStack* yystackp, yyGLRState* yys)
/** Invalidate stack #YYK in *YYSTACKP. */
static inline void
yymarkStackDeleted (yyGLRStack* yystackp, size_t yyk)
yymarkStackDeleted (yyGLRStack* yystackp, ptrdiff_t yyk)
{
if (yystackp->yytops.yystates[yyk] != YY_NULLPTR)
yystackp->yylastDeleted = yystackp->yytops.yystates[yyk];
@@ -1248,7 +1254,7 @@ yyundeleteLastStack (yyGLRStack* yystackp)
static inline void
yyremoveDeletes (yyGLRStack* yystackp)
{
size_t yyi, yyj;
ptrdiff_t yyi, yyj;
yyi = yyj = 0;
while (yyj < yystackp->yytops.yysize)
{
@@ -1272,8 +1278,8 @@ yyremoveDeletes (yyGLRStack* yystackp)
yystackp->yytops.yylookaheadNeeds[yyi];
if (yyj != yyi)
{
YYDPRINTF ((stderr, "Rename stack %lu -> %lu.\n",
(unsigned long) yyi, (unsigned long) yyj));
YYDPRINTF ((stderr, "Rename stack %ld -> %ld.\n",
(long) yyi, (long) yyj));
}
yyj += 1;
}
@@ -1285,8 +1291,8 @@ yyremoveDeletes (yyGLRStack* yystackp)
* state YYLRSTATE, at input position YYPOSN, with (resolved) semantic
* value *YYVALP and source location *YYLOCP. */
static inline void
yyglrShift (yyGLRStack* yystackp, size_t yyk, yyStateNum yylrState,
size_t yyposn,
yyglrShift (yyGLRStack* yystackp, ptrdiff_t yyk, yyStateNum yylrState,
ptrdiff_t yyposn,
YYSTYPE* yyvalp]b4_locations_if([, YYLTYPE* yylocp])[)
{
yyGLRState* yynewState = &yynewGLRStackItem (yystackp, yytrue)->yystate;
@@ -1306,8 +1312,8 @@ yyglrShift (yyGLRStack* yystackp, size_t yyk, yyStateNum yylrState,
* state YYLRSTATE, at input position YYPOSN, with the (unresolved)
* semantic value of YYRHS under the action for YYRULE. */
static inline void
yyglrShiftDefer (yyGLRStack* yystackp, size_t yyk, yyStateNum yylrState,
size_t yyposn, yyGLRState* yyrhs, yyRuleNum yyrule)
yyglrShiftDefer (yyGLRStack* yystackp, ptrdiff_t yyk, yyStateNum yylrState,
ptrdiff_t yyposn, yyGLRState* yyrhs, yyRuleNum yyrule)
{
yyGLRState* yynewState = &yynewGLRStackItem (yystackp, yytrue)->yystate;
YYASSERT (yynewState->yyisState);
@@ -1337,15 +1343,14 @@ yyglrShiftDefer (yyGLRStack* yystackp, size_t yyk, yyStateNum yylrState,
`----------------------------------------------------------------------*/
static inline void
yy_reduce_print (yybool yynormal, yyGLRStackItem* yyvsp, size_t yyk,
yy_reduce_print (yybool yynormal, yyGLRStackItem* yyvsp, ptrdiff_t yyk,
yyRuleNum yyrule]b4_user_formals[)
{
int yynrhs = yyrhsLength (yyrule);]b4_locations_if([
int yylow = 1;])[
int yyi;
YYFPRINTF (stderr, "Reducing stack %lu by rule %d (line %d):\n",
(unsigned long) yyk, yyrule - 1,
yyrline[yyrule]);
YYFPRINTF (stderr, "Reducing stack %ld by rule %d (line %d):\n",
(long) yyk, yyrule - 1, yyrline[yyrule]);
if (! yynormal)
yyfillin (yyvsp, 1, -yynrhs);
/* The symbols being reduced. */
@@ -1371,7 +1376,7 @@ yy_reduce_print (yybool yynormal, yyGLRStackItem* yyvsp, size_t yyk,
* and *YYLOCP to the computed location (if any). Return value is as
* for userAction. */
static inline YYRESULTTAG
yydoAction (yyGLRStack* yystackp, size_t yyk, yyRuleNum yyrule,
yydoAction (yyGLRStack* yystackp, ptrdiff_t yyk, yyRuleNum yyrule,
YYSTYPE* yyvalp]b4_locuser_formals[)
{
int yynrhs = yyrhsLength (yyrule);
@@ -1382,7 +1387,7 @@ yydoAction (yyGLRStack* yystackp, size_t yyk, yyRuleNum yyrule,
yyGLRStackItem* yyrhs = (yyGLRStackItem*) yystackp->yytops.yystates[yyk];
YYASSERT (yyk == 0);
yystackp->yynextFree -= yynrhs;
yystackp->yyspaceLeft += (size_t) yynrhs;
yystackp->yyspaceLeft += yynrhs;
yystackp->yytops.yystates[0] = & yystackp->yynextFree[-1].yystate;
YY_REDUCE_PRINT ((yytrue, yyrhs, yyk, yyrule]b4_user_args[));
return yyuserAction (yyrule, yynrhs, yyrhs, yystackp,
@@ -1422,10 +1427,10 @@ yydoAction (yyGLRStack* yystackp, size_t yyk, yyRuleNum yyrule,
* added to the options for the existing state's semantic value.
*/
static inline YYRESULTTAG
yyglrReduce (yyGLRStack* yystackp, size_t yyk, yyRuleNum yyrule,
yyglrReduce (yyGLRStack* yystackp, ptrdiff_t yyk, yyRuleNum yyrule,
yybool yyforceEval]b4_user_formals[)
{
size_t yyposn = yystackp->yytops.yystates[yyk]->yyposn;
ptrdiff_t yyposn = yystackp->yytops.yystates[yyk]->yyposn;
if (yyforceEval || yystackp->yysplitPoint == YY_NULLPTR)
{
@@ -1435,8 +1440,8 @@ yyglrReduce (yyGLRStack* yystackp, size_t yyk, yyRuleNum yyrule,
YYRESULTTAG yyflag = yydoAction (yystackp, yyk, yyrule, &yysval]b4_locuser_args([&yyloc])[);
if (yyflag == yyerr && yystackp->yysplitPoint != YY_NULLPTR)
{
YYDPRINTF ((stderr, "Parse on stack %lu rejected by rule #%d.\n",
(unsigned long) yyk, yyrule - 1));
YYDPRINTF ((stderr, "Parse on stack %ld rejected by rule #%d.\n",
(long) yyk, yyrule - 1));
}
if (yyflag != yyok)
return yyflag;
@@ -1448,7 +1453,7 @@ yyglrReduce (yyGLRStack* yystackp, size_t yyk, yyRuleNum yyrule,
}
else
{
size_t yyi;
ptrdiff_t yyi;
int yyn;
yyGLRState* yys, *yys0 = yystackp->yytops.yystates[yyk];
yyStateNum yynewLRState;
@@ -1462,9 +1467,9 @@ yyglrReduce (yyGLRStack* yystackp, size_t yyk, yyRuleNum yyrule,
yyupdateSplit (yystackp, yys);
yynewLRState = yyLRgotoState (yys->yylrState, yylhsNonterm (yyrule));
YYDPRINTF ((stderr,
"Reduced stack %lu by rule #%d; action deferred. "
"Reduced stack %ld by rule #%d; action deferred. "
"Now in state %d.\n",
(unsigned long) yyk, yyrule - 1, yynewLRState));
(long) yyk, yyrule - 1, yynewLRState));
for (yyi = 0; yyi < yystackp->yytops.yysize; yyi += 1)
if (yyi != yyk && yystackp->yytops.yystates[yyi] != YY_NULLPTR)
{
@@ -1476,9 +1481,8 @@ yyglrReduce (yyGLRStack* yystackp, size_t yyk, yyRuleNum yyrule,
{
yyaddDeferredAction (yystackp, yyk, yyp, yys0, yyrule);
yymarkStackDeleted (yystackp, yyk);
YYDPRINTF ((stderr, "Merging stack %lu into stack %lu.\n",
(unsigned long) yyk,
(unsigned long) yyi));
YYDPRINTF ((stderr, "Merging stack %ld into stack %ld.\n",
(long) yyk, (long) yyi));
return yyok;
}
yyp = yyp->yypred;
@@ -1490,8 +1494,8 @@ yyglrReduce (yyGLRStack* yystackp, size_t yyk, yyRuleNum yyrule,
return yyok;
}
static size_t
yysplitStack (yyGLRStack* yystackp, size_t yyk)
static ptrdiff_t
yysplitStack (yyGLRStack* yystackp, ptrdiff_t yyk)
{
if (yystackp->yysplitPoint == YY_NULLPTR)
{
@@ -1502,15 +1506,15 @@ yysplitStack (yyGLRStack* yystackp, size_t yyk)
{
yyGLRState** yynewStates = YY_NULLPTR;
yybool* yynewLookaheadNeeds;
ptrdiff_t half_max_capacity = YYSIZEMAX / (2 * sizeof yynewStates[0]);
if (yystackp->yytops.yycapacity
> (YYSIZEMAX / (2 * sizeof yynewStates[0])))
if (half_max_capacity < yystackp->yytops.yycapacity)
yyMemoryExhausted (yystackp);
yystackp->yytops.yycapacity *= 2;
yynewStates =
(yyGLRState**) YYREALLOC (yystackp->yytops.yystates,
(yystackp->yytops.yycapacity
((size_t) yystackp->yytops.yycapacity
* sizeof yynewStates[0]));
if (yynewStates == YY_NULLPTR)
yyMemoryExhausted (yystackp);
@@ -1518,7 +1522,7 @@ yysplitStack (yyGLRStack* yystackp, size_t yyk)
yynewLookaheadNeeds =
(yybool*) YYREALLOC (yystackp->yytops.yylookaheadNeeds,
(yystackp->yytops.yycapacity
((size_t) yystackp->yytops.yycapacity
* sizeof yynewLookaheadNeeds[0]));
if (yynewLookaheadNeeds == YY_NULLPTR)
yyMemoryExhausted (yystackp);
@@ -1720,10 +1724,10 @@ yyreportTree (yySemanticOption* yyx, int yyindent)
yyindent, "", yytokenName (yylhsNonterm (yyx->yyrule)),
yyx->yyrule - 1);
else
YYFPRINTF (stderr, "%*s%s -> <Rule %d, tokens %lu .. %lu>\n",
YYFPRINTF (stderr, "%*s%s -> <Rule %d, tokens %ld .. %ld>\n",
yyindent, "", yytokenName (yylhsNonterm (yyx->yyrule)),
yyx->yyrule - 1, (unsigned long) (yys->yyposn + 1),
(unsigned long) yyx->yystate->yyposn);
yyx->yyrule - 1, (long) (yys->yyposn + 1),
(long) yyx->yystate->yyposn);
for (yyi = 1; yyi <= yynrhs; yyi += 1)
{
if (yystates[yyi]->yyresolved)
@@ -1732,10 +1736,10 @@ yyreportTree (yySemanticOption* yyx, int yyindent)
YYFPRINTF (stderr, "%*s%s <empty>\n", yyindent+2, "",
yytokenName (yystos[yystates[yyi]->yylrState]));
else
YYFPRINTF (stderr, "%*s%s <tokens %lu .. %lu>\n", yyindent+2, "",
YYFPRINTF (stderr, "%*s%s <tokens %ld .. %ld>\n", yyindent+2, "",
yytokenName (yystos[yystates[yyi]->yylrState]),
(unsigned long) (yystates[yyi-1]->yyposn + 1),
(unsigned long) yystates[yyi]->yyposn);
(long) (yystates[yyi-1]->yyposn + 1),
(long) yystates[yyi]->yyposn);
}
else
yyreportTree (yystates[yyi]->yysemantics.yyfirstVal, yyindent+2);
@@ -1930,9 +1934,9 @@ yycompressStack (yyGLRStack* yystackp)
yyr = yyp, yyp = yyq, yyq = yyp->yypred)
yyp->yypred = yyr;
yystackp->yyspaceLeft += (size_t) (yystackp->yynextFree - yystackp->yyitems);
yystackp->yyspaceLeft += yystackp->yynextFree - yystackp->yyitems;
yystackp->yynextFree = ((yyGLRStackItem*) yystackp->yysplitPoint) + 1;
yystackp->yyspaceLeft -= (size_t) (yystackp->yynextFree - yystackp->yyitems);
yystackp->yyspaceLeft -= yystackp->yynextFree - yystackp->yyitems;
yystackp->yysplitPoint = YY_NULLPTR;
yystackp->yylastDeleted = YY_NULLPTR;
@@ -1948,14 +1952,13 @@ yycompressStack (yyGLRStack* yystackp)
}
static YYRESULTTAG
yyprocessOneStack (yyGLRStack* yystackp, size_t yyk,
size_t yyposn]b4_pure_formals[)
yyprocessOneStack (yyGLRStack* yystackp, ptrdiff_t yyk,
ptrdiff_t yyposn]b4_pure_formals[)
{
while (yystackp->yytops.yystates[yyk] != YY_NULLPTR)
{
yyStateNum yystate = yystackp->yytops.yystates[yyk]->yylrState;
YYDPRINTF ((stderr, "Stack %lu Entering state %d\n",
(unsigned long) yyk, yystate));
YYDPRINTF ((stderr, "Stack %ld Entering state %d\n", yyk, yystate));
YYASSERT (yystate != YYFINAL);
@@ -1965,8 +1968,7 @@ yyprocessOneStack (yyGLRStack* yystackp, size_t yyk,
yyRuleNum yyrule = yydefaultAction (yystate);
if (yyrule == 0)
{
YYDPRINTF ((stderr, "Stack %lu dies.\n",
(unsigned long) yyk));
YYDPRINTF ((stderr, "Stack %ld dies.\n", (long) yyk));
yymarkStackDeleted (yystackp, yyk);
return yyok;
}
@@ -1974,9 +1976,9 @@ yyprocessOneStack (yyGLRStack* yystackp, size_t yyk,
if (yyflag == yyerr)
{
YYDPRINTF ((stderr,
"Stack %lu dies "
"Stack %ld dies "
"(predicate failure or explicit user error).\n",
(unsigned long) yyk));
(long) yyk));
yymarkStackDeleted (yystackp, yyk);
return yyok;
}
@@ -1996,10 +1998,9 @@ yyprocessOneStack (yyGLRStack* yystackp, size_t yyk,
while (*yyconflicts != 0)
{
YYRESULTTAG yyflag;
size_t yynewStack = yysplitStack (yystackp, yyk);
YYDPRINTF ((stderr, "Splitting off stack %lu from %lu.\n",
(unsigned long) yynewStack,
(unsigned long) yyk));
ptrdiff_t yynewStack = yysplitStack (yystackp, yyk);
YYDPRINTF ((stderr, "Splitting off stack %ld from %ld.\n",
(long) yynewStack, (long) yyk));
yyflag = yyglrReduce (yystackp, yynewStack,
*yyconflicts,
yyimmediate[*yyconflicts]]b4_user_args[);
@@ -2008,8 +2009,7 @@ yyprocessOneStack (yyGLRStack* yystackp, size_t yyk,
yyposn]b4_pure_args[));
else if (yyflag == yyerr)
{
YYDPRINTF ((stderr, "Stack %lu dies.\n",
(unsigned long) yynewStack));
YYDPRINTF ((stderr, "Stack %ld dies.\n", (long) yynewStack));
yymarkStackDeleted (yystackp, yynewStack);
}
else
@@ -2021,8 +2021,7 @@ yyprocessOneStack (yyGLRStack* yystackp, size_t yyk,
break;
else if (yyisErrorAction (yyaction))
{
YYDPRINTF ((stderr, "Stack %lu dies.\n",
(unsigned long) yyk));
YYDPRINTF ((stderr, "Stack %ld dies.\n", (long) yyk));
yymarkStackDeleted (yystackp, yyk);
break;
}
@@ -2033,9 +2032,9 @@ yyprocessOneStack (yyGLRStack* yystackp, size_t yyk,
if (yyflag == yyerr)
{
YYDPRINTF ((stderr,
"Stack %lu dies "
"Stack %ld dies "
"(predicate failure or explicit user error).\n",
(unsigned long) yyk));
(long) yyk));
yymarkStackDeleted (yystackp, yyk);
break;
}
@@ -2057,8 +2056,8 @@ yyreportSyntaxError (yyGLRStack* yystackp]b4_user_formals[)
#else
{
yySymbol yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar);
size_t yysize0 = yytnamerr (YY_NULLPTR, yytokenName (yytoken));
size_t yysize = yysize0;
ptrdiff_t yysize0 = yytnamerr (YY_NULLPTR, yytokenName (yytoken));
ptrdiff_t yysize = yysize0;
yybool yysize_overflow = yyfalse;
char* yymsg = YY_NULLPTR;
enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
@@ -2119,10 +2118,11 @@ yyreportSyntaxError (yyGLRStack* yystackp]b4_user_formals[)
}
yyarg[yycount++] = yytokenName (yyx);
{
size_t yysz = yysize + yytnamerr (YY_NULLPTR, yytokenName (yyx));
if (yysz < yysize)
ptrdiff_t yysz = yytnamerr (YY_NULLPTR, yytokenName (yyx));
if (YYSIZEMAX - yysize < yysz)
yysize_overflow = yytrue;
yysize = yysz;
else
yysize += yysz;
}
}
}
@@ -2145,14 +2145,15 @@ yyreportSyntaxError (yyGLRStack* yystackp]b4_user_formals[)
}
{
size_t yysz = yysize + strlen (yyformat);
if (yysz < yysize)
ptrdiff_t yysz = (ptrdiff_t) strlen (yyformat);
if (YYSIZEMAX - yysize < yysz)
yysize_overflow = yytrue;
yysize = yysz;
else
yysize += yysz;
}
if (!yysize_overflow)
yymsg = (char *) YYMALLOC (yysize);
yymsg = (char *) YYMALLOC ((size_t) yysize);
if (yymsg)
{
@@ -2229,7 +2230,7 @@ yyrecoverSyntaxError (yyGLRStack* yystackp]b4_user_formals[)
/* Reduce to one stack. */
{
size_t yyk;
ptrdiff_t yyk;
for (yyk = 0; yyk < yystackp->yytops.yysize; yyk += 1)
if (yystackp->yytops.yystates[yyk] != YY_NULLPTR)
break;
@@ -2303,7 +2304,7 @@ yyrecoverSyntaxError (yyGLRStack* yystackp]b4_user_formals[)
int yyresult;
yyGLRStack yystack;
yyGLRStack* const yystackp = &yystack;
size_t yyposn;
ptrdiff_t yyposn;
YYDPRINTF ((stderr, "Starting parse\n"));
@@ -2383,7 +2384,7 @@ b4_dollar_popdef])[]dnl
while (yytrue)
{
yySymbol yytoken_to_shift;
size_t yys;
ptrdiff_t yys;
for (yys = 0; yys < yystack.yytops.yysize; yys += 1)
yystackp->yytops.yylookaheadNeeds[yys] = (yybool) (yychar != YYEMPTY);
@@ -2437,12 +2438,12 @@ b4_dollar_popdef])[]dnl
int yyaction = yygetLRActions (yystate, yytoken_to_shift,
&yyconflicts);
/* Note that yyconflicts were handled by yyprocessOneStack. */
YYDPRINTF ((stderr, "On stack %lu, ", (unsigned long) yys));
YYDPRINTF ((stderr, "On stack %ld, ", (long) yys));
YY_SYMBOL_PRINT ("shifting", yytoken_to_shift, &yylval, &yylloc);
yyglrShift (&yystack, yys, yyaction, yyposn,
&yylval]b4_locations_if([, &yylloc])[);
YYDPRINTF ((stderr, "Stack %lu now in state #%d\n",
(unsigned long) yys,
YYDPRINTF ((stderr, "Stack %ld now in state #%d\n",
(long) yys,
yystack.yytops.yystates[yys]->yylrState));
}
@@ -2490,8 +2491,8 @@ b4_dollar_popdef])[]dnl
yyGLRState** yystates = yystack.yytops.yystates;
if (yystates)
{
size_t yysize = yystack.yytops.yysize;
size_t yyk;
ptrdiff_t yysize = yystack.yytops.yysize;
ptrdiff_t yyk;
for (yyk = 0; yyk < yysize; yyk += 1)
if (yystates[yyk])
{
@@ -2524,8 +2525,7 @@ yy_yypstack (yyGLRState* yys)
yy_yypstack (yys->yypred);
YYFPRINTF (stderr, " -> ");
}
YYFPRINTF (stderr, "%d@@%lu", yys->yylrState,
(unsigned long) yys->yyposn);
YYFPRINTF (stderr, "%d@@%ld", yys->yylrState, (long) yys->yyposn);
}
static void
@@ -2539,7 +2539,7 @@ yypstates (yyGLRState* yyst)
}
static void
yypstack (yyGLRStack* yystackp, size_t yyk)
yypstack (yyGLRStack* yystackp, ptrdiff_t yyk)
{
yypstates (yystackp->yytops.yystates[yyk]);
}
@@ -2552,18 +2552,18 @@ static void
yypdumpstack (yyGLRStack* yystackp)
{
yyGLRStackItem* yyp;
size_t yyi;
ptrdiff_t yyi;
for (yyp = yystackp->yyitems; yyp < yystackp->yynextFree; yyp += 1)
{
YYFPRINTF (stderr, "%3lu. ",
(unsigned long) (yyp - yystackp->yyitems));
YYFPRINTF (stderr, "%3ld. ",
(long) (yyp - yystackp->yyitems));
if (*(yybool *) yyp)
{
YYASSERT (yyp->yystate.yyisState);
YYASSERT (yyp->yyoption.yyisState);
YYFPRINTF (stderr, "Res: %d, LR State: %d, posn: %lu, pred: %ld",
YYFPRINTF (stderr, "Res: %d, LR State: %d, posn: %ld, pred: %ld",
yyp->yystate.yyresolved, yyp->yystate.yylrState,
(unsigned long) yyp->yystate.yyposn,
(long) yyp->yystate.yyposn,
(long) YYINDEX (yyp->yystate.yypred));
if (! yyp->yystate.yyresolved)
YYFPRINTF (stderr, ", firstVal: %ld",
@@ -2583,7 +2583,7 @@ yypdumpstack (yyGLRStack* yystackp)
}
YYFPRINTF (stderr, "Tops:");
for (yyi = 0; yyi < yystackp->yytops.yysize; yyi += 1)
YYFPRINTF (stderr, "%lu: %ld; ", (unsigned long) yyi,
YYFPRINTF (stderr, "%ld: %ld; ", (long) yyi,
(long) YYINDEX (yystackp->yytops.yystates[yyi]));
YYFPRINTF (stderr, "\n");
}

View File

@@ -1159,7 +1159,7 @@ b4_dollar_popdef])[]dnl
while (true)
{
state_type top_state = (yylac_stack_.empty ()
? yystack_[(size_t) lac_top].state
? yystack_[lac_top].state
: yylac_stack_.back ());
int yyrule = yypact_[top_state];
if (yy_pact_value_is_default_ (yyrule)
@@ -1213,7 +1213,7 @@ b4_dollar_popdef])[]dnl
}
// Keep top_state in sync with the updated stack.
top_state = (yylac_stack_.empty ()
? yystack_[(size_t) lac_top].state
? yystack_[lac_top].state
: yylac_stack_.back ());
// Push the resulting state of the reduction.
state_type state = yy_lr_goto_state_ (top_state, yyr1_[yyrule]);

View File

@@ -65,8 +65,8 @@ m4_define([b4_location_define],
public:]m4_ifdef([b4_location_constructors], [[
/// Construct a position.
explicit position (]b4_percent_define_get([[filename_type]])[* f = YY_NULLPTR,
unsigned l = ]b4_location_initial_line[u,
unsigned c = ]b4_location_initial_column[u)
int l = ]b4_location_initial_line[u,
int c = ]b4_location_initial_column[u)
: filename (f)
, line (l)
, column (c)
@@ -75,8 +75,8 @@ m4_define([b4_location_define],
]])[
/// Initialization.
void initialize (]b4_percent_define_get([[filename_type]])[* fn = YY_NULLPTR,
unsigned l = ]b4_location_initial_line[u,
unsigned c = ]b4_location_initial_column[u)
int l = ]b4_location_initial_line[u,
int c = ]b4_location_initial_column[u)
{
filename = fn;
line = l;
@@ -105,16 +105,15 @@ m4_define([b4_location_define],
/// File name to which this position refers.
]b4_percent_define_get([[filename_type]])[* filename;
/// Current line number.
unsigned line;
int line;
/// Current column number.
unsigned column;
int column;
private:
/// Compute max (min, lhs+rhs).
static unsigned add_ (unsigned lhs, int rhs, int min)
static int add_ (int lhs, int rhs, int min)
{
return static_cast<unsigned> (std::max (min,
static_cast<int> (lhs) + rhs));
return std::max (min, lhs + rhs);
}
};
@@ -197,8 +196,8 @@ m4_define([b4_location_define],
/// Construct a 0-width location in \a f, \a l, \a c.
explicit location (]b4_percent_define_get([[filename_type]])[* f,
unsigned l = ]b4_location_initial_line[u,
unsigned c = ]b4_location_initial_column[u)
int l = ]b4_location_initial_line[u,
int c = ]b4_location_initial_column[u)
: begin (f, l, c)
, end (f, l, c)
{}
@@ -206,8 +205,8 @@ m4_define([b4_location_define],
])[
/// Initialization.
void initialize (]b4_percent_define_get([[filename_type]])[* f = YY_NULLPTR,
unsigned l = ]b4_location_initial_line[u,
unsigned c = ]b4_location_initial_column[u)
int l = ]b4_location_initial_line[u,
int c = ]b4_location_initial_column[u)
{
begin.initialize (f, l, c);
end = begin;
@@ -305,7 +304,7 @@ m4_define([b4_location_define],
std::basic_ostream<YYChar>&
operator<< (std::basic_ostream<YYChar>& ostr, const location& loc)
{
unsigned end_col = 0 < loc.end.column ? loc.end.column - 1 : 0;
int end_col = 0 < loc.end.column ? loc.end.column - 1 : 0;
ostr << loc.begin;
if (loc.end.filename
&& (!loc.begin.filename

View File

@@ -48,10 +48,11 @@ m4_define([b4_stack_define],
{
return seq_[size () - 1 - i];
}
/// Random access.
///
/// Index 0 returns the topmost element.
T&
operator[] (ptrdiff_t i)
{
return operator[] (size_type (i));
}
T&
operator[] (int i)
{
@@ -66,10 +67,11 @@ m4_define([b4_stack_define],
{
return seq_[size () - 1 - i];
}
/// Random access.
///
/// Index 0 returns the topmost element.
const T&
operator[] (ptrdiff_t i) const
{
return operator[] (size_type (i));
}
const T&
operator[] (int i) const
{
@@ -88,7 +90,7 @@ m4_define([b4_stack_define],
/// Pop elements from the stack.
void
pop (int n = 1) YY_NOEXCEPT
pop (ptrdiff_t n = 1) YY_NOEXCEPT
{
for (; 0 < n; --n)
seq_.pop_back ();
@@ -107,6 +109,11 @@ m4_define([b4_stack_define],
{
return seq_.size ();
}
ptrdiff_t
ssize () const YY_NOEXCEPT
{
return (ptrdiff_t) size ();
}
/// Iterator on top of the stack (going downwards).
const_iterator
@@ -126,20 +133,20 @@ m4_define([b4_stack_define],
class slice
{
public:
slice (const stack& stack, int range)
slice (const stack& stack, ptrdiff_t range)
: stack_ (stack)
, range_ (range)
{}
const T&
operator[] (int i) const
operator[] (ptrdiff_t i) const
{
return stack_[range_ - i];
}
private:
const stack& stack_;
int range_;
ptrdiff_t range_;
};
private:

View File

@@ -113,9 +113,8 @@ m4_ifset([b4_parse_param], [b4_args(b4_parse_param), ])])
# b4_int_type(MIN, MAX)
# ---------------------
# Return a narrow int type able to handle numbers ranging from
# MIN to MAX (included). Overwrite the version from c.m4, which
# uses only C89 types, so that the user can override the shorter
# types, and so that pre-C89 compilers are handled correctly.
# MIN to MAX (included). Overwrite the version from c.m4,
# so that the user can override the shorter types.
m4_define([b4_int_type],
[m4_if(b4_ints_in($@, [-127], [127]), [1], [yytype_int8],
b4_ints_in($@, [0], [255]), [1], [yytype_uint8],
@@ -125,18 +124,6 @@ m4_define([b4_int_type],
[int])])
# b4_state_num_type(MIN, MAX)
# ---------------------------
# Likewise, but prefer 'int' to 'unsigned' for large integers.
m4_define([b4_state_num_type],
[m4_if(b4_ints_in($@, [0], [255]), [1], [yytype_uint8],
b4_ints_in($@, [-128], [127]), [1], [yytype_int8],
b4_ints_in($@, [0], [65535]), [1], [yytype_uint16],
b4_ints_in($@, [-32768], [32767]), [1], [yytype_int16],
[int])])
## ----------------- ##
## Semantic Values. ##
@@ -464,7 +451,7 @@ typedef short yytype_int16;
/* State numbers. */
typedef ]b4_state_num_type(0, m4_eval(b4_states_number - 1))[ yy_state_num;
typedef ]b4_int_type(0, m4_eval(b4_states_number - 1))[ yy_state_num;
#ifndef YY_
@@ -481,6 +468,18 @@ typedef ]b4_state_num_type(0, m4_eval(b4_states_number - 1))[ yy_state_num;
]b4_attribute_define[
/* Suppress bogus -Wconversion warnings from GCC. */
#if 4 < __GNUC__ + (7 <= __GNUC_MINOR__)
# define YY_CONVERT_INT_BEGIN \
_Pragma ("GCC diagnostic push") \
_Pragma ("GCC diagnostic ignored \"-Wconversion\"")
# define YY_CONVERT_INT_END \
_Pragma ("GCC diagnostic pop")
#else
# define YY_CONVERT_INT_BEGIN
# define YY_CONVERT_INT_END
#endif
]b4_parse_assert_if([[#ifdef NDEBUG
# define YY_ASSERT(E) ((void) (0 && (E)))
#else
@@ -650,7 +649,7 @@ union yyalloc
]b4_api_token_raw_if(dnl
[[#define YYTRANSLATE(YYX) (YYX)]],
[[#define YYTRANSLATE(YYX) \
((unsigned) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
(0 <= (YYX) && (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
/* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM
as returned by yylex. */
@@ -773,7 +772,10 @@ do { \
{
YYFPRINTF (stderr, "Stack now");
for (; yybottom <= yytop; yybottom++)
YYFPRINTF (stderr, " %u", (unsigned) *yybottom);
{
int yybot = *yybottom;
YYFPRINTF (stderr, " %d", yybot);
}
YYFPRINTF (stderr, "\n");
}
@@ -1015,7 +1017,7 @@ yy_lac (yy_state_num *yyesa, yy_state_num **yyes,
}
else
{
yyrule = (int) yytable[yyrule];
yyrule = yytable[yyrule];
if (yytable_value_is_error (yyrule))
{
YYDPRINTF ((stderr, " Err\n"));
@@ -1052,15 +1054,17 @@ yy_lac (yy_state_num *yyesa, yy_state_num **yyes,
int yystate;
{
const int yylhs = yyr1[yyrule] - YYNTOKENS;
const int yyi = yypgoto[yylhs] + (int) *yyesp;
const int yyi = yypgoto[yylhs] + *yyesp;
yystate = (0 <= yyi && yyi <= YYLAST && yycheck[yyi] == *yyesp
? (int) yytable[yyi]
? yytable[yyi]
: yydefgoto[yylhs]);
}
if (yyesp == yyes_prev)
{
yyesp = *yyes;
*yyesp = (yy_state_num) yystate;
YY_CONVERT_INT_BEGIN
*yyesp = yystate;
YY_CONVERT_INT_END
}
else
{
@@ -1073,7 +1077,9 @@ yy_lac (yy_state_num *yyesa, yy_state_num **yyes,
YYDPRINTF ((stderr, "\n"));
return 2;
}
*++yyesp = (yy_state_num) yystate;
YY_CONVERT_INT_BEGIN
*++yyesp = yystate;
YY_CONVERT_INT_END
}
YYDPRINTF ((stderr, " G%d", yystate));
}
@@ -1536,7 +1542,9 @@ yynewstate:
yysetstate:
YYDPRINTF ((stderr, "Entering state %d\n", yystate));
YY_ASSERT (0 <= yystate && yystate < YYNSTATES);
*yyssp = (yy_state_num) yystate;
YY_CONVERT_INT_BEGIN
*yyssp = yystate;
YY_CONVERT_INT_END
if (yyss + yystacksize - 1 <= yyssp)
#if !defined yyoverflow && !defined YYSTACK_RELOCATE
@@ -1670,7 +1678,7 @@ yyread_pushed_token:]])[
goto yydefault;
}]], [[
goto yydefault;]])[
yyn = (int) yytable[yyn];
yyn = yytable[yyn];
if (yyn <= 0)
{
if (yytable_value_is_error (yyn))
@@ -1772,9 +1780,9 @@ yyreduce:
number reduced by. */
{
const int yylhs = yyr1[yyn] - YYNTOKENS;
const int yyi = yypgoto[yylhs] + (int) *yyssp;
const int yyi = yypgoto[yylhs] + *yyssp;
yystate = (0 <= yyi && yyi <= YYLAST && yycheck[yyi] == *yyssp
? (int) yytable[yyi]
? yytable[yyi]
: yydefgoto[yylhs]);
}
@@ -1890,7 +1898,7 @@ yyerrlab1:
yyn += YYTERROR;
if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
{
yyn = (int) yytable[yyn];
yyn = yytable[yyn];
if (0 < yyn)
break;
}