c++: fix old cast warnings

We still have a few old C casts in lalr1.cc, let's get rid of them.
Reported by Frank Heckenbach.

Actually, let's monitor all our casts using easy to grep macros.
Let's use these macros to use the C++ standard casts when we are in
C++.

* data/skeletons/c.m4 (b4_cast_define): New.
* data/skeletons/glr.c, data/skeletons/glr.cc,
* data/skeletons/lalr1.cc, data/skeletons/stack.hh,
* data/skeletons/yacc.c:
Use it and/or its casts.

* tests/actions.at, tests/cxx-type.at,
* tests/glr-regression.at, tests/headers.at, tests/torture.at,
* tests/types.at:
Use YY_CAST instead of C casts.

* configure.ac (warn_cxx): Add -Wold-style-cast.
* doc/bison.texi: Disable it.
This commit is contained in:
Akim Demaille
2019-11-01 16:13:46 +01:00
parent 2bd1d9e20f
commit 3398b0fa90
14 changed files with 186 additions and 137 deletions

View File

@@ -107,7 +107,8 @@ if test "$enable_gcc_warnings" = yes; then
-Wpointer-arith -Wshadow -Wpointer-arith -Wshadow
-Wwrite-strings' -Wwrite-strings'
warn_c='-Wbad-function-cast -Wstrict-prototypes' warn_c='-Wbad-function-cast -Wstrict-prototypes'
warn_cxx='-Wextra-semi -Wnoexcept -Wundefined-func-template -Wweak-vtables' warn_cxx='-Wextra-semi -Wnoexcept -Wold-style-cast -Wundefined-func-template
-Wweak-vtables'
# Warnings for the test suite only. # Warnings for the test suite only.
# #
# -fno-color-diagnostics: Clang's use of colors in the error # -fno-color-diagnostics: Clang's use of colors in the error

View File

@@ -346,6 +346,21 @@ m4_define([b4_attribute_define],
]]) ]])
# b4_cast_define
# --------------
m4_define([b4_cast_define],
[# ifndef YY_CAST
# ifdef __cplusplus
# define YY_CAST(Type, Val) static_cast<Type> (Val)
# define YY_REINTERPRET_CAST(Type, Val) reinterpret_cast<Type> (Val)
# else
# define YY_CAST(Type, Val) ((Type) (Val))
# define YY_REINTERPRET_CAST(Type, Val) ((Type) (Val))
# endif
# endif[]dnl
])
# b4_null_define # b4_null_define
# -------------- # --------------
# Portability issues: define a YY_NULLPTR appropriate for the current # Portability issues: define a YY_NULLPTR appropriate for the current

View File

@@ -125,7 +125,7 @@ m4_define([b4_lhs_value],
# ----------------------------- # -----------------------------
# See README. # See README.
m4_define([b4_rhs_data], m4_define([b4_rhs_data],
[((yyGLRStackItem const *)yyvsp)@{YYFILL (b4_subtract([$2], [$1]))@}.yystate]) [YY_CAST (yyGLRStackItem const *, yyvsp)@{YYFILL (b4_subtract([$2], [$1]))@}.yystate])
# b4_rhs_value(RULE-LENGTH, POS, SYMBOL-NUM, [TYPE]) # b4_rhs_value(RULE-LENGTH, POS, SYMBOL-NUM, [TYPE])
@@ -235,7 +235,7 @@ b4_copyright([Skeleton implementation for Bison GLR parsers in C],
#define yylloc ]b4_prefix[lloc]])]))[ #define yylloc ]b4_prefix[lloc]])]))[
]b4_user_pre_prologue[ ]b4_user_pre_prologue[
]b4_cast_define[
]b4_null_define[ ]b4_null_define[
]b4_defines_if([[#include "@basename(]b4_spec_header_file[@)"]], ]b4_defines_if([[#include "@basename(]b4_spec_header_file[@)"]],
@@ -289,7 +289,8 @@ static YYLTYPE yyloc_default][]b4_yyloc_default;])[
# define YYREALLOC realloc # define YYREALLOC realloc
#endif #endif
#define YYSIZEMAX (PTRDIFF_MAX < SIZE_MAX ? PTRDIFF_MAX : (ptrdiff_t) SIZE_MAX) #define YYSIZEMAX \
(PTRDIFF_MAX < SIZE_MAX ? PTRDIFF_MAX : YY_CAST (ptrdiff_t, SIZE_MAX))
#ifdef __cplusplus #ifdef __cplusplus
typedef bool yybool; typedef bool yybool;
@@ -617,7 +618,7 @@ yytnamerr (char *yyres, const char *yystr)
if (yyres) if (yyres)
return yystpcpy (yyres, yystr) - yyres; return yystpcpy (yyres, yystr) - yyres;
else else
return (ptrdiff_t) strlen (yystr); return YY_CAST (ptrdiff_t, strlen (yystr));
} }
# endif # endif
@@ -845,7 +846,8 @@ yyuserAction (yyRuleNum yyn, int yyrhslen, yyGLRStackItem* yyvsp,
yyGLRStack* yystackp, yyGLRStack* yystackp,
YYSTYPE* yyvalp]b4_locuser_formals[) YYSTYPE* yyvalp]b4_locuser_formals[)
{ {
yybool yynormal YY_ATTRIBUTE_UNUSED = (yybool) (yystackp->yysplitPoint == YY_NULLPTR); yybool yynormal YY_ATTRIBUTE_UNUSED
= YY_CAST (yybool, yystackp->yysplitPoint == YY_NULLPTR);
int yylow; int yylow;
]b4_parse_param_use([yyvalp], [yylocp])dnl ]b4_parse_param_use([yyvalp], [yylocp])dnl
[ YYUSE (yyrhslen); [ YYUSE (yyrhslen);
@@ -980,7 +982,7 @@ yylhsNonterm (yyRuleNum yyrule)
static inline yybool static inline yybool
yyisDefaultedState (yyStateNum yystate) yyisDefaultedState (yyStateNum yystate)
{ {
return (yybool) yypact_value_is_default (yypact[yystate]); return YY_CAST (yybool, yypact_value_is_default (yypact[yystate]));
} }
/** The default reduction for YYSTATE, assuming it has one. */ /** The default reduction for YYSTATE, assuming it has one. */
@@ -1040,13 +1042,13 @@ yyLRgotoState (yyStateNum yystate, yySymbol yysym)
static inline yybool static inline yybool
yyisShiftAction (int yyaction) yyisShiftAction (int yyaction)
{ {
return (yybool) (0 < yyaction); return YY_CAST (yybool, 0 < yyaction);
} }
static inline yybool static inline yybool
yyisErrorAction (int yyaction) yyisErrorAction (int yyaction)
{ {
return (yybool) (yyaction == 0); return YY_CAST (yybool, yyaction == 0);
} }
/* GLRStates */ /* GLRStates */
@@ -1102,21 +1104,24 @@ yyinitStateSet (yyGLRStateSet* yyset)
yyset->yysize = 1; yyset->yysize = 1;
yyset->yycapacity = 16; yyset->yycapacity = 16;
yyset->yystates yyset->yystates
= (yyGLRState**) YYMALLOC ((size_t) yyset->yycapacity = YY_CAST(yyGLRState**,
* sizeof yyset->yystates[0]); YYMALLOC (YY_CAST (size_t, yyset->yycapacity)
* sizeof yyset->yystates[0]));
if (! yyset->yystates) if (! yyset->yystates)
return yyfalse; return yyfalse;
yyset->yystates[0] = YY_NULLPTR; yyset->yystates[0] = YY_NULLPTR;
yyset->yylookaheadNeeds yyset->yylookaheadNeeds
= (yybool*) YYMALLOC ((size_t) yyset->yycapacity = YY_CAST (yybool*,
* sizeof yyset->yylookaheadNeeds[0]); YYMALLOC (YY_CAST (size_t, yyset->yycapacity)
* sizeof yyset->yylookaheadNeeds[0]));
if (! yyset->yylookaheadNeeds) if (! yyset->yylookaheadNeeds)
{ {
YYFREE (yyset->yystates); YYFREE (yyset->yystates);
return yyfalse; return yyfalse;
} }
memset (yyset->yylookaheadNeeds, memset (yyset->yylookaheadNeeds,
0, (size_t) yyset->yycapacity * sizeof yyset->yylookaheadNeeds[0]); 0,
YY_CAST (size_t, yyset->yycapacity) * sizeof yyset->yylookaheadNeeds[0]);
return yytrue; return yytrue;
} }
@@ -1134,9 +1139,10 @@ yyinitGLRStack (yyGLRStack* yystackp, ptrdiff_t yysize)
yystackp->yyerrState = 0; yystackp->yyerrState = 0;
yynerrs = 0; yynerrs = 0;
yystackp->yyspaceLeft = yysize; yystackp->yyspaceLeft = yysize;
yystackp->yyitems = yystackp->yyitems
(yyGLRStackItem*) YYMALLOC ((size_t) yysize = YY_CAST (yyGLRStackItem*,
* sizeof yystackp->yynextFree[0]); YYMALLOC (YY_CAST (size_t, yysize)
* sizeof yystackp->yynextFree[0]));
if (!yystackp->yyitems) if (!yystackp->yyitems)
return yyfalse; return yyfalse;
yystackp->yynextFree = yystackp->yyitems; yystackp->yynextFree = yystackp->yyitems;
@@ -1147,8 +1153,9 @@ yyinitGLRStack (yyGLRStack* yystackp, ptrdiff_t yysize)
#if YYSTACKEXPANDABLE #if YYSTACKEXPANDABLE
# define YYRELOC(YYFROMITEMS,YYTOITEMS,YYX,YYTYPE) \ # define YYRELOC(YYFROMITEMS, YYTOITEMS, YYX, YYTYPE) \
&((YYTOITEMS) - ((YYFROMITEMS) - (yyGLRStackItem*) (YYX)))->YYTYPE &((YYTOITEMS) \
- ((YYFROMITEMS) - YY_REINTERPRET_CAST (yyGLRStackItem*, (YYX))))->YYTYPE
/** If *YYSTACKP is expandable, extend it. WARNING: Pointers into the /** If *YYSTACKP is expandable, extend it. WARNING: Pointers into the
stack from outside should be considered invalid after this call. stack from outside should be considered invalid after this call.
@@ -1168,8 +1175,10 @@ yyexpandGLRStack (yyGLRStack* yystackp)
yynewSize = 2*yysize; yynewSize = 2*yysize;
if (YYMAXDEPTH < yynewSize) if (YYMAXDEPTH < yynewSize)
yynewSize = YYMAXDEPTH; yynewSize = YYMAXDEPTH;
yynewItems = (yyGLRStackItem*) YYMALLOC ((size_t) yynewSize yynewItems
* sizeof yynewItems[0]); = YY_CAST (yyGLRStackItem*,
YYMALLOC (YY_CAST (size_t, yynewSize)
* sizeof yynewItems[0]));
if (! yynewItems) if (! yynewItems)
yyMemoryExhausted (yystackp); yyMemoryExhausted (yystackp);
for (yyp0 = yystackp->yyitems, yyp1 = yynewItems, yyn = yysize; for (yyp0 = yystackp->yyitems, yyp1 = yynewItems, yyn = yysize;
@@ -1177,7 +1186,7 @@ yyexpandGLRStack (yyGLRStack* yystackp)
yyn -= 1, yyp0 += 1, yyp1 += 1) yyn -= 1, yyp0 += 1, yyp1 += 1)
{ {
*yyp1 = *yyp0; *yyp1 = *yyp0;
if (*(yybool *) yyp0) if (*YY_REINTERPRET_CAST (yybool *, yyp0))
{ {
yyGLRState* yys0 = &yyp0->yystate; yyGLRState* yys0 = &yyp0->yystate;
yyGLRState* yys1 = &yyp1->yystate; yyGLRState* yys1 = &yyp1->yystate;
@@ -1282,7 +1291,7 @@ yyremoveDeletes (yyGLRStack* yystackp)
if (yyj != yyi) if (yyj != yyi)
{ {
YYDPRINTF ((stderr, "Rename stack %ld -> %ld.\n", YYDPRINTF ((stderr, "Rename stack %ld -> %ld.\n",
(long) yyi, (long) yyj)); YY_CAST (long, yyi), YY_CAST (long, yyj)));
} }
yyj += 1; yyj += 1;
} }
@@ -1353,7 +1362,7 @@ yy_reduce_print (yybool yynormal, yyGLRStackItem* yyvsp, ptrdiff_t yyk,
int yylow = 1;])[ int yylow = 1;])[
int yyi; int yyi;
YYFPRINTF (stderr, "Reducing stack %ld by rule %d (line %d):\n", YYFPRINTF (stderr, "Reducing stack %ld by rule %d (line %d):\n",
(long) yyk, yyrule - 1, yyrline[yyrule]); YY_CAST (long, yyk), yyrule - 1, yyrline[yyrule]);
if (! yynormal) if (! yynormal)
yyfillin (yyvsp, 1, -yynrhs); yyfillin (yyvsp, 1, -yynrhs);
/* The symbols being reduced. */ /* The symbols being reduced. */
@@ -1387,7 +1396,8 @@ yydoAction (yyGLRStack* yystackp, ptrdiff_t yyk, yyRuleNum yyrule,
if (yystackp->yysplitPoint == YY_NULLPTR) if (yystackp->yysplitPoint == YY_NULLPTR)
{ {
/* Standard special case: single stack. */ /* Standard special case: single stack. */
yyGLRStackItem* yyrhs = (yyGLRStackItem*) yystackp->yytops.yystates[yyk]; yyGLRStackItem* yyrhs
= YY_REINTERPRET_CAST (yyGLRStackItem*, yystackp->yytops.yystates[yyk]);
YYASSERT (yyk == 0); YYASSERT (yyk == 0);
yystackp->yynextFree -= yynrhs; yystackp->yynextFree -= yynrhs;
yystackp->yyspaceLeft += yynrhs; yystackp->yyspaceLeft += yynrhs;
@@ -1445,7 +1455,7 @@ yyglrReduce (yyGLRStack* yystackp, ptrdiff_t yyk, yyRuleNum yyrule,
{ {
YYDPRINTF ((stderr, YYDPRINTF ((stderr,
"Parse on stack %ld rejected by rule %d (line %d).\n", "Parse on stack %ld rejected by rule %d (line %d).\n",
(long) yyk, yyrule - 1, yyrline[yyrule - 1])); YY_CAST (long, yyk), yyrule - 1, yyrline[yyrule - 1]));
} }
if (yyflag != yyok) if (yyflag != yyok)
return yyflag; return yyflag;
@@ -1473,7 +1483,7 @@ yyglrReduce (yyGLRStack* yystackp, ptrdiff_t yyk, yyRuleNum yyrule,
YYDPRINTF ((stderr, YYDPRINTF ((stderr,
"Reduced stack %ld by rule %d (line %d); action deferred. " "Reduced stack %ld by rule %d (line %d); action deferred. "
"Now in state %d.\n", "Now in state %d.\n",
(long) yyk, yyrule - 1, yyrline[yyrule - 1], yynewLRState)); YY_CAST(long, yyk), yyrule - 1, yyrline[yyrule - 1], yynewLRState));
for (yyi = 0; yyi < yystackp->yytops.yysize; yyi += 1) for (yyi = 0; yyi < yystackp->yytops.yysize; yyi += 1)
if (yyi != yyk && yystackp->yytops.yystates[yyi] != YY_NULLPTR) if (yyi != yyk && yystackp->yytops.yystates[yyi] != YY_NULLPTR)
{ {
@@ -1486,7 +1496,7 @@ yyglrReduce (yyGLRStack* yystackp, ptrdiff_t yyk, yyRuleNum yyrule,
yyaddDeferredAction (yystackp, yyk, yyp, yys0, yyrule); yyaddDeferredAction (yystackp, yyk, yyp, yys0, yyrule);
yymarkStackDeleted (yystackp, yyk); yymarkStackDeleted (yystackp, yyk);
YYDPRINTF ((stderr, "Merging stack %ld into stack %ld.\n", YYDPRINTF ((stderr, "Merging stack %ld into stack %ld.\n",
(long) yyk, (long) yyi)); YY_CAST (long, yyk), YY_CAST (long, yyi)));
return yyok; return yyok;
} }
yyp = yyp->yypred; yyp = yyp->yypred;
@@ -1517,18 +1527,20 @@ yysplitStack (yyGLRStack* yystackp, ptrdiff_t yyk)
yyMemoryExhausted (yystackp); yyMemoryExhausted (yystackp);
yystackp->yytops.yycapacity *= 2; yystackp->yytops.yycapacity *= 2;
yynewStates = yynewStates
(yyGLRState**) YYREALLOC (yystackp->yytops.yystates, = YY_CAST (yyGLRState**,
((size_t) yystackp->yytops.yycapacity YYREALLOC (yystackp->yytops.yystates,
* sizeof yynewStates[0])); (YY_CAST (size_t, yystackp->yytops.yycapacity)
* sizeof yynewStates[0])));
if (yynewStates == YY_NULLPTR) if (yynewStates == YY_NULLPTR)
yyMemoryExhausted (yystackp); yyMemoryExhausted (yystackp);
yystackp->yytops.yystates = yynewStates; yystackp->yytops.yystates = yynewStates;
yynewLookaheadNeeds = yynewLookaheadNeeds
(yybool*) YYREALLOC (yystackp->yytops.yylookaheadNeeds, = YY_CAST (yybool*,
((size_t) yystackp->yytops.yycapacity YYREALLOC (yystackp->yytops.yylookaheadNeeds,
* sizeof yynewLookaheadNeeds[0])); (YY_CAST (size_t, yystackp->yytops.yycapacity)
* sizeof yynewLookaheadNeeds[0])));
if (yynewLookaheadNeeds == YY_NULLPTR) if (yynewLookaheadNeeds == YY_NULLPTR)
yyMemoryExhausted (yystackp); yyMemoryExhausted (yystackp);
yystackp->yytops.yylookaheadNeeds = yynewLookaheadNeeds; yystackp->yytops.yylookaheadNeeds = yynewLookaheadNeeds;
@@ -1731,8 +1743,8 @@ yyreportTree (yySemanticOption* yyx, int yyindent)
else else
YYFPRINTF (stderr, "%*s%s -> <Rule %d, tokens %ld .. %ld>\n", YYFPRINTF (stderr, "%*s%s -> <Rule %d, tokens %ld .. %ld>\n",
yyindent, "", yytokenName (yylhsNonterm (yyx->yyrule)), yyindent, "", yytokenName (yylhsNonterm (yyx->yyrule)),
yyx->yyrule - 1, (long) (yys->yyposn + 1), yyx->yyrule - 1, YY_CAST (long, yys->yyposn + 1),
(long) yyx->yystate->yyposn); YY_CAST (long, yyx->yystate->yyposn));
for (yyi = 1; yyi <= yynrhs; yyi += 1) for (yyi = 1; yyi <= yynrhs; yyi += 1)
{ {
if (yystates[yyi]->yyresolved) if (yystates[yyi]->yyresolved)
@@ -1743,8 +1755,8 @@ yyreportTree (yySemanticOption* yyx, int yyindent)
else else
YYFPRINTF (stderr, "%*s%s <tokens %ld .. %ld>\n", yyindent+2, "", YYFPRINTF (stderr, "%*s%s <tokens %ld .. %ld>\n", yyindent+2, "",
yytokenName (yystos[yystates[yyi]->yylrState]), yytokenName (yystos[yystates[yyi]->yylrState]),
(long) (yystates[yyi-1]->yyposn + 1), YY_CAST (long, yystates[yyi-1]->yyposn + 1),
(long) yystates[yyi]->yyposn); YY_CAST (long, yystates[yyi]->yyposn));
} }
else else
yyreportTree (yystates[yyi]->yysemantics.yyfirstVal, yyindent+2); yyreportTree (yystates[yyi]->yysemantics.yyfirstVal, yyindent+2);
@@ -1940,7 +1952,7 @@ yycompressStack (yyGLRStack* yystackp)
yyp->yypred = yyr; yyp->yypred = yyr;
yystackp->yyspaceLeft += yystackp->yynextFree - yystackp->yyitems; yystackp->yyspaceLeft += yystackp->yynextFree - yystackp->yyitems;
yystackp->yynextFree = ((yyGLRStackItem*) yystackp->yysplitPoint) + 1; yystackp->yynextFree = YY_REINTERPRET_CAST (yyGLRStackItem*, yystackp->yysplitPoint) + 1;
yystackp->yyspaceLeft -= yystackp->yynextFree - yystackp->yyitems; yystackp->yyspaceLeft -= yystackp->yynextFree - yystackp->yyitems;
yystackp->yysplitPoint = YY_NULLPTR; yystackp->yysplitPoint = YY_NULLPTR;
yystackp->yylastDeleted = YY_NULLPTR; yystackp->yylastDeleted = YY_NULLPTR;
@@ -1973,7 +1985,7 @@ yyprocessOneStack (yyGLRStack* yystackp, ptrdiff_t yyk,
yyRuleNum yyrule = yydefaultAction (yystate); yyRuleNum yyrule = yydefaultAction (yystate);
if (yyrule == 0) if (yyrule == 0)
{ {
YYDPRINTF ((stderr, "Stack %ld dies.\n", (long) yyk)); YYDPRINTF ((stderr, "Stack %ld dies.\n", YY_CAST (long, yyk)));
yymarkStackDeleted (yystackp, yyk); yymarkStackDeleted (yystackp, yyk);
return yyok; return yyok;
} }
@@ -1983,7 +1995,7 @@ yyprocessOneStack (yyGLRStack* yystackp, ptrdiff_t yyk,
YYDPRINTF ((stderr, YYDPRINTF ((stderr,
"Stack %ld dies " "Stack %ld dies "
"(predicate failure or explicit user error).\n", "(predicate failure or explicit user error).\n",
(long) yyk)); YY_CAST (long, yyk)));
yymarkStackDeleted (yystackp, yyk); yymarkStackDeleted (yystackp, yyk);
return yyok; return yyok;
} }
@@ -2002,7 +2014,7 @@ yyprocessOneStack (yyGLRStack* yystackp, ptrdiff_t yyk,
YYRESULTTAG yyflag; YYRESULTTAG yyflag;
ptrdiff_t yynewStack = yysplitStack (yystackp, yyk); ptrdiff_t yynewStack = yysplitStack (yystackp, yyk);
YYDPRINTF ((stderr, "Splitting off stack %ld from %ld.\n", YYDPRINTF ((stderr, "Splitting off stack %ld from %ld.\n",
(long) yynewStack, (long) yyk)); YY_CAST (long, yynewStack), YY_CAST (long, yyk)));
yyflag = yyglrReduce (yystackp, yynewStack, yyflag = yyglrReduce (yystackp, yynewStack,
*yyconflicts, *yyconflicts,
yyimmediate[*yyconflicts]]b4_user_args[); yyimmediate[*yyconflicts]]b4_user_args[);
@@ -2011,7 +2023,7 @@ yyprocessOneStack (yyGLRStack* yystackp, ptrdiff_t yyk,
yyposn]b4_pure_args[)); yyposn]b4_pure_args[));
else if (yyflag == yyerr) else if (yyflag == yyerr)
{ {
YYDPRINTF ((stderr, "Stack %ld dies.\n", (long) yynewStack)); YYDPRINTF ((stderr, "Stack %ld dies.\n", YY_CAST (long, yynewStack)));
yymarkStackDeleted (yystackp, yynewStack); yymarkStackDeleted (yystackp, yynewStack);
} }
else else
@@ -2023,7 +2035,7 @@ yyprocessOneStack (yyGLRStack* yystackp, ptrdiff_t yyk,
break; break;
else if (yyisErrorAction (yyaction)) else if (yyisErrorAction (yyaction))
{ {
YYDPRINTF ((stderr, "Stack %ld dies.\n", (long) yyk)); YYDPRINTF ((stderr, "Stack %ld dies.\n", YY_CAST (long, yyk)));
yymarkStackDeleted (yystackp, yyk); yymarkStackDeleted (yystackp, yyk);
break; break;
} }
@@ -2036,7 +2048,7 @@ yyprocessOneStack (yyGLRStack* yystackp, ptrdiff_t yyk,
YYDPRINTF ((stderr, YYDPRINTF ((stderr,
"Stack %ld dies " "Stack %ld dies "
"(predicate failure or explicit user error).\n", "(predicate failure or explicit user error).\n",
(long) yyk)); YY_CAST (long, yyk)));
yymarkStackDeleted (yystackp, yyk); yymarkStackDeleted (yystackp, yyk);
break; break;
} }
@@ -2147,7 +2159,7 @@ yyreportSyntaxError (yyGLRStack* yystackp]b4_user_formals[)
} }
{ {
ptrdiff_t yysz = (ptrdiff_t) strlen (yyformat); ptrdiff_t yysz = YY_CAST (ptrdiff_t, strlen (yyformat));
if (YYSIZEMAX - yysize < yysz) if (YYSIZEMAX - yysize < yysz)
yysize_overflow = yytrue; yysize_overflow = yytrue;
else else
@@ -2155,7 +2167,7 @@ yyreportSyntaxError (yyGLRStack* yystackp]b4_user_formals[)
} }
if (!yysize_overflow) if (!yysize_overflow)
yymsg = (char *) YYMALLOC ((size_t) yysize); yymsg = YY_CAST (char *, YYMALLOC (YY_CAST (size_t, yysize)));
if (yymsg) if (yymsg)
{ {
@@ -2389,7 +2401,7 @@ b4_dollar_popdef])[]dnl
ptrdiff_t yys; ptrdiff_t yys;
for (yys = 0; yys < yystack.yytops.yysize; yys += 1) for (yys = 0; yys < yystack.yytops.yysize; yys += 1)
yystackp->yytops.yylookaheadNeeds[yys] = (yybool) (yychar != YYEMPTY); yystackp->yytops.yylookaheadNeeds[yys] = YY_CAST (yybool, yychar != YYEMPTY);
/* yyprocessOneStack returns one of three things: /* yyprocessOneStack returns one of three things:
@@ -2440,12 +2452,12 @@ b4_dollar_popdef])[]dnl
int yyaction = yygetLRActions (yystate, yytoken_to_shift, int yyaction = yygetLRActions (yystate, yytoken_to_shift,
&yyconflicts); &yyconflicts);
/* Note that yyconflicts were handled by yyprocessOneStack. */ /* Note that yyconflicts were handled by yyprocessOneStack. */
YYDPRINTF ((stderr, "On stack %ld, ", (long) yys)); YYDPRINTF ((stderr, "On stack %ld, ", YY_CAST (long, yys)));
YY_SYMBOL_PRINT ("shifting", yytoken_to_shift, &yylval, &yylloc); YY_SYMBOL_PRINT ("shifting", yytoken_to_shift, &yylval, &yylloc);
yyglrShift (&yystack, yys, yyaction, yyposn, yyglrShift (&yystack, yys, yyaction, yyposn,
&yylval]b4_locations_if([, &yylloc])[); &yylval]b4_locations_if([, &yylloc])[);
YYDPRINTF ((stderr, "Stack %ld now in state #%d\n", YYDPRINTF ((stderr, "Stack %ld now in state #%d\n",
(long) yys, YY_CAST (long, yys),
yystack.yytops.yystates[yys]->yylrState)); yystack.yytops.yystates[yys]->yylrState));
} }
@@ -2527,7 +2539,7 @@ yy_yypstack (yyGLRState* yys)
yy_yypstack (yys->yypred); yy_yypstack (yys->yypred);
YYFPRINTF (stderr, " -> "); YYFPRINTF (stderr, " -> ");
} }
YYFPRINTF (stderr, "%d@@%ld", yys->yylrState, (long) yys->yyposn); YYFPRINTF (stderr, "%d@@%ld", yys->yylrState, YY_CAST (long, yys->yyposn));
} }
static void static void
@@ -2546,31 +2558,31 @@ yypstack (yyGLRStack* yystackp, ptrdiff_t yyk)
yypstates (yystackp->yytops.yystates[yyk]); yypstates (yystackp->yytops.yystates[yyk]);
} }
#define YYINDEX(YYX) \
((YYX) == YY_NULLPTR ? -1 : (yyGLRStackItem*) (YYX) - yystackp->yyitems)
static void static void
yypdumpstack (yyGLRStack* yystackp) yypdumpstack (yyGLRStack* yystackp)
{ {
#define YYINDEX(YYX) \
YY_CAST (long, \
((YYX) \
? YY_REINTERPRET_CAST (yyGLRStackItem*, (YYX)) - yystackp->yyitems \
: -1))
yyGLRStackItem* yyp; yyGLRStackItem* yyp;
ptrdiff_t yyi;
for (yyp = yystackp->yyitems; yyp < yystackp->yynextFree; yyp += 1) for (yyp = yystackp->yyitems; yyp < yystackp->yynextFree; yyp += 1)
{ {
YYFPRINTF (stderr, "%3ld. ", YYFPRINTF (stderr, "%3ld. ",
(long) (yyp - yystackp->yyitems)); YY_CAST (long, yyp - yystackp->yyitems));
if (*(yybool *) yyp) if (*YY_REINTERPRET_CAST (yybool *, yyp))
{ {
YYASSERT (yyp->yystate.yyisState); YYASSERT (yyp->yystate.yyisState);
YYASSERT (yyp->yyoption.yyisState); YYASSERT (yyp->yyoption.yyisState);
YYFPRINTF (stderr, "Res: %d, LR State: %d, posn: %ld, pred: %ld", YYFPRINTF (stderr, "Res: %d, LR State: %d, posn: %ld, pred: %ld",
yyp->yystate.yyresolved, yyp->yystate.yylrState, yyp->yystate.yyresolved, yyp->yystate.yylrState,
(long) yyp->yystate.yyposn, YY_CAST (long, yyp->yystate.yyposn),
(long) YYINDEX (yyp->yystate.yypred)); YYINDEX (yyp->yystate.yypred));
if (! yyp->yystate.yyresolved) if (! yyp->yystate.yyresolved)
YYFPRINTF (stderr, ", firstVal: %ld", YYFPRINTF (stderr, ", firstVal: %ld",
(long) YYINDEX (yyp->yystate YYINDEX (yyp->yystate.yysemantics.yyfirstVal));
.yysemantics.yyfirstVal));
} }
else else
{ {
@@ -2578,16 +2590,21 @@ yypdumpstack (yyGLRStack* yystackp)
YYASSERT (!yyp->yyoption.yyisState); YYASSERT (!yyp->yyoption.yyisState);
YYFPRINTF (stderr, "Option. rule: %d, state: %ld, next: %ld", YYFPRINTF (stderr, "Option. rule: %d, state: %ld, next: %ld",
yyp->yyoption.yyrule - 1, yyp->yyoption.yyrule - 1,
(long) YYINDEX (yyp->yyoption.yystate), YYINDEX (yyp->yyoption.yystate),
(long) YYINDEX (yyp->yyoption.yynext)); YYINDEX (yyp->yyoption.yynext));
} }
YYFPRINTF (stderr, "\n"); YYFPRINTF (stderr, "\n");
} }
YYFPRINTF (stderr, "Tops:"); YYFPRINTF (stderr, "Tops:");
for (yyi = 0; yyi < yystackp->yytops.yysize; yyi += 1) {
YYFPRINTF (stderr, "%ld: %ld; ", (long) yyi, ptrdiff_t yyi;
(long) YYINDEX (yystackp->yytops.yystates[yyi])); for (yyi = 0; yyi < yystackp->yytops.yysize; yyi += 1)
YYFPRINTF (stderr, "\n"); YYFPRINTF (stderr, "%ld: %ld; ", YY_CAST (long, yyi),
YYINDEX (yystackp->yytops.yystates[yyi]));
YYFPRINTF (stderr, "\n");
}
#undef YYINDEX
} }
#endif #endif

View File

@@ -257,6 +257,14 @@ b4_percent_code_get([[requires]])[
]b4_attribute_define[ ]b4_attribute_define[
]b4_null_define[ ]b4_null_define[
// This skeleton is based on C, yet compiles it as C++.
// So expect warnings about C style casts.
#if defined __clang__ && 306 <= __clang_major__ * 100 + __clang_minor__
# pragma clang diagnostic ignored "-Wold-style-cast"
#elif defined __GNUC__ && 406 <= __GNUC__ * 100 + __GNUC_MINOR__
# pragma GCC diagnostic ignored "-Wold-style-cast"
#endif
// Whether we are compiled with exception support. // Whether we are compiled with exception support.
#ifndef YY_EXCEPTIONS #ifndef YY_EXCEPTIONS
# if defined __GNUC__ && !defined __EXCEPTIONS # if defined __GNUC__ && !defined __EXCEPTIONS

View File

@@ -174,6 +174,7 @@ m4_define([b4_shared_declarations],
]b4_variant_if([b4_variant_includes])[ ]b4_variant_if([b4_variant_includes])[
]b4_attribute_define[ ]b4_attribute_define[
]b4_cast_define[
]b4_null_define[ ]b4_null_define[
]b4_YYDEBUG_define[ ]b4_YYDEBUG_define[
@@ -1195,10 +1196,10 @@ b4_dollar_popdef])[]dnl
{ {
std::ptrdiff_t yylen = yyr2_[yyrule]; std::ptrdiff_t yylen = yyr2_[yyrule];
// First pop from the LAC stack as many tokens as possible. // First pop from the LAC stack as many tokens as possible.
std::ptrdiff_t lac_size = (std::ptrdiff_t) yylac_stack_.size (); std::ptrdiff_t lac_size = std::ptrdiff_t (yylac_stack_.size ());
if (yylen < lac_size) if (yylen < lac_size)
{ {
yylac_stack_.resize ((std::size_t) (lac_size - yylen)); yylac_stack_.resize (std::size_t (lac_size - yylen));
yylen = 0; yylen = 0;
} }
else if (lac_size) else if (lac_size)

View File

@@ -90,10 +90,11 @@ m4_define([b4_stack_define],
{ {
return index_type (seq_.size ()); return index_type (seq_.size ());
} }
std::ptrdiff_t std::ptrdiff_t
ssize () const YY_NOEXCEPT ssize () const YY_NOEXCEPT
{ {
return (std::ptrdiff_t) size (); return std::ptrdiff_t (size ());
} }
/// Iterator on top of the stack (going downwards). /// Iterator on top of the stack (going downwards).

View File

@@ -339,13 +339,13 @@ m4_if(b4_api_prefix, [yy], [],
#define yylex ]b4_prefix[lex #define yylex ]b4_prefix[lex
#define yyerror ]b4_prefix[error #define yyerror ]b4_prefix[error
#define yydebug ]b4_prefix[debug #define yydebug ]b4_prefix[debug
#define yynerrs ]b4_prefix[nerrs #define yynerrs ]b4_prefix[nerrs]]b4_pure_if([], [[
]]b4_pure_if([], [[
#define yylval ]b4_prefix[lval #define yylval ]b4_prefix[lval
#define yychar ]b4_prefix[char]b4_locations_if([[ #define yychar ]b4_prefix[char]b4_locations_if([[
#define yylloc ]b4_prefix[lloc]])]))[ #define yylloc ]b4_prefix[lloc]])]))[
]b4_user_pre_prologue[ ]b4_user_pre_prologue[
]b4_cast_define[
]b4_null_define[ ]b4_null_define[
/* Enabling verbose error messages. */ /* Enabling verbose error messages. */
@@ -400,10 +400,13 @@ m4_if(b4_api_prefix, [yy], [],
# endif # endif
#endif #endif
#define YYSIZE_MAXIMUM ((YYPTRDIFF_T) (YYPTRDIFF_MAXIMUM < (YYSIZE_T) -1 \ #define YYSIZE_MAXIMUM \
? YYPTRDIFF_MAXIMUM : (YYSIZE_T) -1)) YY_CAST (YYPTRDIFF_T, \
(YYPTRDIFF_MAXIMUM < YY_CAST (YYSIZE_T, -1) \
? YYPTRDIFF_MAXIMUM \
: YY_CAST (YYSIZE_T, -1)))
#define YYSIZEOF(X) ((YYPTRDIFF_T) sizeof (X)) #define YYSIZEOF(X) YY_CAST (YYPTRDIFF_T, sizeof (X))
/* Stored state numbers (used for stacks). */ /* Stored state numbers (used for stacks). */
typedef ]b4_int_type(0, m4_eval(b4_states_number - 1))[ yy_state_t; typedef ]b4_int_type(0, m4_eval(b4_states_number - 1))[ yy_state_t;
@@ -557,7 +560,7 @@ union yyalloc
# ifndef YYCOPY # ifndef YYCOPY
# if defined __GNUC__ && 1 < __GNUC__ # if defined __GNUC__ && 1 < __GNUC__
# define YYCOPY(Dst, Src, Count) \ # define YYCOPY(Dst, Src, Count) \
__builtin_memcpy (Dst, Src, (YYSIZE_T) (Count) * sizeof (*(Src))) __builtin_memcpy (Dst, Src, YY_CAST (YYSIZE_T, (Count)) * sizeof (*(Src)))
# else # else
# define YYCOPY(Dst, Src, Count) \ # define YYCOPY(Dst, Src, Count) \
do \ do \
@@ -832,8 +835,8 @@ yy_lac_stack_realloc (YYPTRDIFF_T *yycapacity, YYPTRDIFF_T yyadd,
if (YYMAXDEPTH < yyalloc) if (YYMAXDEPTH < yyalloc)
yyalloc = YYMAXDEPTH; yyalloc = YYMAXDEPTH;
yybottom_new = yybottom_new =
(yy_state_t *) YYSTACK_ALLOC ((YYSIZE_T) YY_CAST(yy_state_t *,
(yyalloc * YYSIZEOF (*yybottom_new))); YYSTACK_ALLOC (YY_CAST (YYSIZE_T, yyalloc * YYSIZEOF (*yybottom_new))));
if (!yybottom_new) if (!yybottom_new)
{ {
YYDPRINTF ((stderr, "%srealloc failed%s", yydebug_prefix, YYDPRINTF ((stderr, "%srealloc failed%s", yydebug_prefix,
@@ -851,7 +854,7 @@ yy_lac_stack_realloc (YYPTRDIFF_T *yycapacity, YYPTRDIFF_T yyadd,
*yycapacity = yyalloc;]m4_if(b4_percent_define_get([[parse.lac.memory-trace]]), *yycapacity = yyalloc;]m4_if(b4_percent_define_get([[parse.lac.memory-trace]]),
[full], [[ [full], [[
YYDPRINTF ((stderr, "%srealloc to %ld%s", yydebug_prefix, YYDPRINTF ((stderr, "%srealloc to %ld%s", yydebug_prefix,
(long) yyalloc, yydebug_suffix));]])[ YY_CAST (long, yyalloc), yydebug_suffix));]])[
} }
return 0; return 0;
} }
@@ -1008,7 +1011,7 @@ yy_lac (yy_state_t *yyesa, yy_state_t **yyes,
if (yyesp == yyes_prev) if (yyesp == yyes_prev)
{ {
yyesp = *yyes; yyesp = *yyes;
*yyesp = (yy_state_t) yystate; *yyesp = YY_CAST (yy_state_t, yystate);
} }
else else
{ {
@@ -1021,7 +1024,7 @@ yy_lac (yy_state_t *yyesa, yy_state_t **yyes,
YYDPRINTF ((stderr, "\n")); YYDPRINTF ((stderr, "\n"));
return 2; return 2;
} }
*++yyesp = (yy_state_t) yystate; *++yyesp = YY_CAST (yy_state_t, yystate);
} }
YYDPRINTF ((stderr, " G%d", yystate)); YYDPRINTF ((stderr, " G%d", yystate));
} }
@@ -1033,7 +1036,7 @@ yy_lac (yy_state_t *yyesa, yy_state_t **yyes,
# ifndef yystrlen # ifndef yystrlen
# if defined __GLIBC__ && defined _STRING_H # if defined __GLIBC__ && defined _STRING_H
# define yystrlen(S) ((YYPTRDIFF_T) strlen (S)) # define yystrlen(S) (YY_CAST (YYPTRDIFF_T, strlen (S)))
# else # else
/* Return the length of YYSTR. */ /* Return the length of YYSTR. */
]b4_function_define([yystrlen], [static YYPTRDIFF_T], ]b4_function_define([yystrlen], [static YYPTRDIFF_T],
@@ -1342,7 +1345,7 @@ b4_function_define([[yyparse]], [[int]], b4_parse_param)[
yypstate *yyps;]b4_pure_if([], [[ yypstate *yyps;]b4_pure_if([], [[
if (yypstate_allocated) if (yypstate_allocated)
return YY_NULLPTR;]])[ return YY_NULLPTR;]])[
yyps = (yypstate *) malloc (sizeof *yyps); yyps = YY_CAST (yypstate *, malloc (sizeof *yyps));
if (!yyps) if (!yyps)
return YY_NULLPTR; return YY_NULLPTR;
yyps->yynew = 1;]b4_pure_if([], [[ yyps->yynew = 1;]b4_pure_if([], [[
@@ -1484,7 +1487,7 @@ yynewstate:
yysetstate: yysetstate:
YYDPRINTF ((stderr, "Entering state %d\n", yystate)); YYDPRINTF ((stderr, "Entering state %d\n", yystate));
YY_ASSERT (0 <= yystate && yystate < YYNSTATES); YY_ASSERT (0 <= yystate && yystate < YYNSTATES);
*yyssp = (yy_state_t) yystate; *yyssp = YY_CAST (yy_state_t, yystate);
if (yyss + yystacksize - 1 <= yyssp) if (yyss + yystacksize - 1 <= yyssp)
#if !defined yyoverflow && !defined YYSTACK_RELOCATE #if !defined yyoverflow && !defined YYSTACK_RELOCATE
@@ -1527,8 +1530,8 @@ yysetstate:
{ {
yy_state_t *yyss1 = yyss; yy_state_t *yyss1 = yyss;
union yyalloc *yyptr = union yyalloc *yyptr =
(union yyalloc *) YYSTACK_ALLOC ((YYSIZE_T) YY_CAST (union yyalloc *,
YYSTACK_BYTES (yystacksize)); YYSTACK_ALLOC (YY_CAST (YYSIZE_T, YYSTACK_BYTES (yystacksize))));
if (! yyptr) if (! yyptr)
goto yyexhaustedlab; goto yyexhaustedlab;
YYSTACK_RELOCATE (yyss_alloc, yyss); YYSTACK_RELOCATE (yyss_alloc, yyss);
@@ -1545,7 +1548,7 @@ yysetstate:
yylsp = yyls + yysize - 1;])[ yylsp = yyls + yysize - 1;])[
YYDPRINTF ((stderr, "Stack size increased to %ld\n", YYDPRINTF ((stderr, "Stack size increased to %ld\n",
(long) yystacksize)); YY_CAST (long, yystacksize)));
if (yyss + yystacksize - 1 <= yyssp) if (yyss + yystacksize - 1 <= yyssp)
YYABORT; YYABORT;
@@ -1758,7 +1761,7 @@ yyerrlab:
{ {
if (yymsg != yymsgbuf) if (yymsg != yymsgbuf)
YYSTACK_FREE (yymsg); YYSTACK_FREE (yymsg);
yymsg = (char *) YYSTACK_ALLOC ((YYSIZE_T) yymsg_alloc); yymsg = YY_CAST (char *, YYSTACK_ALLOC (YY_CAST (YYSIZE_T, yymsg_alloc)));
if (!yymsg) if (!yymsg)
{ {
yymsg = yymsgbuf; yymsg = yymsgbuf;

View File

@@ -12251,10 +12251,12 @@ then the parser's to get the set of defined tokens.
# pragma GCC diagnostic ignored "-Wnull-dereference" # pragma GCC diagnostic ignored "-Wnull-dereference"
#endif #endif
// Of course, when compiling C as C++, expect warnings about NULL. // This example uses Flex's C backend, yet compiles it as C++.
// So expect warnings about C style casts and NULL.
#if defined __clang__ #if defined __clang__
# pragma clang diagnostic ignored "-Wzero-as-null-pointer-constant" # pragma clang diagnostic ignored "-Wzero-as-null-pointer-constant"
#elif defined __GNUC__ && 407 <= __GNUC__ * 100 + __GNUC_MINOR__ #elif defined __GNUC__ && 407 <= __GNUC__ * 100 + __GNUC_MINOR__
# pragma GCC diagnostic ignored "-Wold-style-cast"
# pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant" # pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant"
#endif #endif

View File

@@ -772,10 +772,10 @@ static
static int counter = 0; static int counter = 0;
int c = ]AT_VAL[]m4_ifval([$6], [.ival])[ = counter++; int c = ]AT_VAL[]m4_ifval([$6], [.ival])[ = counter++;
assert (c <= YY_CAST (int, strlen (source)));
/* As in BASIC, line numbers go from 10 to 10. */ /* As in BASIC, line numbers go from 10 to 10. */
]AT_LOC_FIRST_LINE[ = ]AT_LOC_FIRST_COLUMN[ = (10 * c); ]AT_LOC_FIRST_LINE[ = ]AT_LOC_FIRST_COLUMN[ = (10 * c);
]AT_LOC_LAST_LINE[ = ]AT_LOC_LAST_COLUMN[ = ]AT_LOC_FIRST_LINE[ + 9; ]AT_LOC_LAST_LINE[ = ]AT_LOC_LAST_COLUMN[ = ]AT_LOC_FIRST_LINE[ + 9;
assert (c <= (int) strlen (source));
if (source[c]) if (source[c])
fprintf (stderr, "sending: '%c'", source[c]); fprintf (stderr, "sending: '%c'", source[c]);
else else
@@ -1780,7 +1780,8 @@ float: UNTYPED INT
yy::parser::token::INT, yy::parser::token::INT,
EOF}]], EOF}]],
[[{UNTYPED, INT, EOF}]]), [[{UNTYPED, INT, EOF}]]),
[AT_VAL.ival = (int) toknum * 10; AT_VAL.fval = (float) toknum / 10.0f;])[ [AT_VAL.ival = YY_CAST (int, toknum) * 10;
AT_VAL.fval = YY_CAST (float, toknum) / 10.0f;])[
]AT_MAIN_DEFINE[ ]AT_MAIN_DEFINE[
]]) ]])
@@ -1805,7 +1806,6 @@ AT_CLEANUP
]) ])
m4_map_args([AT_TEST], [yacc.c], [glr.c], [lalr1.cc], [glr.cc]) m4_map_args([AT_TEST], [yacc.c], [glr.c], [lalr1.cc], [glr.cc])
m4_popdef([AT_TEST]) m4_popdef([AT_TEST])
## -------------------------------------------------- ## ## -------------------------------------------------- ##
@@ -1897,7 +1897,7 @@ exp:
%% %%
]AT_YYERROR_DEFINE[ ]AT_YYERROR_DEFINE[
]AT_YYLEX_DEFINE(["bcd"], [*lvalp = (int) ((toknum + 1) * 10)])[ ]AT_YYLEX_DEFINE(["bcd"], [*lvalp = YY_CAST (int, (toknum + 1) * 10)])[
]AT_MAIN_DEFINE[ ]AT_MAIN_DEFINE[
]]) ]])
AT_BISON_OPTION_POPDEFS AT_BISON_OPTION_POPDEFS

View File

@@ -178,7 +178,7 @@ main (int argc, char **argv)
do do
{ {
buffer[i++] = (char) c; buffer[i++] = YY_CAST (char, c);
colNum += 1; colNum += 1;
assert (i != sizeof buffer - 1); assert (i != sizeof buffer - 1);
c = getchar (); c = getchar ();
@@ -187,8 +187,8 @@ main (int argc, char **argv)
ungetc (c, stdin); ungetc (c, stdin);
buffer[i++] = 0; buffer[i++] = 0;
tok = isupper ((unsigned char) buffer[0]) ? TYPENAME : ID; tok = isupper (YY_CAST (unsigned char, buffer[0])) ? TYPENAME : ID;
yylval = new_term (strcpy ((char *) malloc (i), buffer)); yylval = new_term (strcpy (YY_CAST (char *, malloc (i)), buffer));
} }
else else
{ {
@@ -206,7 +206,7 @@ main (int argc, char **argv)
static Node * static Node *
new_nterm (char const *form, Node *child0, Node *child1, Node *child2) new_nterm (char const *form, Node *child0, Node *child1, Node *child2)
{ {
Node *node = (Node *) malloc (sizeof (Node)); Node *node = YY_CAST (Node *, malloc (sizeof (Node)));
node->nterm.isNterm = 1; node->nterm.isNterm = 1;
node->nterm.parents = 0; node->nterm.parents = 0;
node->nterm.form = form; node->nterm.form = form;
@@ -225,7 +225,7 @@ new_nterm (char const *form, Node *child0, Node *child1, Node *child2)
static Node * static Node *
new_term (char *text) new_term (char *text)
{ {
Node *node = (Node *) malloc (sizeof (Node)); Node *node = YY_CAST (Node *, malloc (sizeof (Node)));
node->term.isNterm = 0; node->term.isNterm = 0;
node->term.parents = 0; node->term.parents = 0;
node->term.text = text; node->term.text = text;
@@ -255,30 +255,27 @@ free_node (Node *node)
static char * static char *
node_to_string (Node *node) node_to_string (Node *node)
{ {
char *child0; char *res;
char *child1;
char *child2;
char *buffer;
if (!node) if (!node)
{ {
buffer = (char *) malloc (1); res = YY_CAST (char *, malloc (1));
buffer[0] = 0; res[0] = 0;
} }
else if (node->nodeInfo.isNterm == 1) else if (node->nodeInfo.isNterm == 1)
{ {
child0 = node_to_string (node->nterm.children[0]); char *child0 = node_to_string (node->nterm.children[0]);
child1 = node_to_string (node->nterm.children[1]); char *child1 = node_to_string (node->nterm.children[1]);
child2 = node_to_string (node->nterm.children[2]); char *child2 = node_to_string (node->nterm.children[2]);
buffer = (char *) malloc (strlen (node->nterm.form) + strlen (child0) res = YY_CAST (char *, malloc (strlen (node->nterm.form) + strlen (child0)
+ strlen (child1) + strlen (child2) + 1); + strlen (child1) + strlen (child2) + 1));
sprintf (buffer, node->nterm.form, child0, child1, child2); sprintf (res, node->nterm.form, child0, child1, child2);
free (child0);
free (child1);
free (child2); free (child2);
free (child1);
free (child0);
} }
else else
buffer = strdup (node->term.text); res = strdup (node->term.text);
return buffer; return res;
} }
]] ]]

View File

@@ -153,7 +153,7 @@ var_list:
{ $$ = $1; } { $$ = $1; }
| var ',' var_list | var ',' var_list
{ {
char *s = (char *) realloc ($1, strlen ($1) + 1 + strlen ($3) + 1); char *s = YY_CAST (char *, realloc ($1, strlen ($1) + 1 + strlen ($3) + 1));
strcat (s, ","); strcat (s, ",");
strcat (s, $3); strcat (s, $3);
free ($3); free ($3);
@@ -172,7 +172,6 @@ int
yylex (void) yylex (void)
{ {
char buf[50]; char buf[50];
char *s;
assert (!feof (stdin)); assert (!feof (stdin));
switch (fscanf (input, " %1[a-z,]", buf)) switch (fscanf (input, " %1[a-z,]", buf))
{ {
@@ -181,15 +180,19 @@ yylex (void)
case EOF: case EOF:
return 0; return 0;
default: default:
if (fscanf (input, "%49s", buf) != 1)
return 0;
else
{
char *s;
assert (strlen (buf) < sizeof buf - 1);
s = YY_CAST (char *, malloc (strlen (buf) + 1));
strcpy (s, buf);
yylval = s;
return 'V';
}
break; break;
} }
if (fscanf (input, "%49s", buf) != 1)
return 0;
assert (strlen (buf) < sizeof buf - 1);
s = (char *) malloc (strlen (buf) + 1);
strcpy (s, buf);
yylval = s;
return 'V';
} }
int int
@@ -419,7 +422,7 @@ make_value (char const *parent, char const *child)
{ {
char const format[] = "%s <- %s"; char const format[] = "%s <- %s";
char *value = *ptrs_next++ = char *value = *ptrs_next++ =
(char *) malloc (strlen (parent) + strlen (child) + sizeof format); YY_CAST (char *, malloc (strlen (parent) + strlen (child) + sizeof format));
sprintf (value, format, parent, child); sprintf (value, format, parent, child);
return value; return value;
} }
@@ -429,7 +432,7 @@ merge (YYSTYPE s1, YYSTYPE s2)
{ {
char const format[] = "merge{ %s and %s }"; char const format[] = "merge{ %s and %s }";
char *value = *ptrs_next++ = char *value = *ptrs_next++ =
(char *) malloc (strlen (s1.ptr) + strlen (s2.ptr) + sizeof format); YY_CAST (char *, malloc (strlen (s1.ptr) + strlen (s2.ptr) + sizeof format));
sprintf (value, format, s1.ptr, s2.ptr); sprintf (value, format, s1.ptr, s2.ptr);
return value; return value;
} }
@@ -601,7 +604,7 @@ stack2: 'a' ;
static int static int
yylex (void) yylex (void)
{ {
yylval.node = (count_node*) malloc (sizeof *yylval.node); yylval.node = YY_CAST (count_node*, malloc (sizeof *yylval.node));
if (!yylval.node) if (!yylval.node)
{ {
fprintf (stderr, "Test inconclusive.\n"); fprintf (stderr, "Test inconclusive.\n");
@@ -1118,7 +1121,7 @@ change_lookahead:
]AT_YYERROR_DEFINE[ ]AT_YYERROR_DEFINE[
]AT_YYLEX_DEFINE(["ab"], ]AT_YYLEX_DEFINE(["ab"],
[yylval.value = (char) (res + 'A' - 'a')])[ [yylval.value = YY_CAST (char, res + 'A' - 'a')])[
static void static void
print_lookahead (char const *reduction) print_lookahead (char const *reduction)
@@ -1319,10 +1322,10 @@ yylex (void)
{ {
static char const input[] = "abcdddd"; static char const input[] = "abcdddd";
static int toknum = 0; static int toknum = 0;
assert (toknum < (int) sizeof input); assert (toknum < YY_CAST (int, sizeof input));
yylloc.first_line = yylloc.last_line = 1; yylloc.first_line = yylloc.last_line = 1;
yylloc.first_column = yylloc.last_column = toknum + 1; yylloc.first_column = yylloc.last_column = toknum + 1;
yylval.value = (char) (input[toknum] + 'A' - 'a'); yylval.value = YY_CAST (char, input[toknum] + 'A' - 'a');
return input[toknum++]; return input[toknum++];
} }
@@ -1349,7 +1352,7 @@ print_lookahead (char const *reduction)
static char static char
merge (union YYSTYPE s1, union YYSTYPE s2) merge (union YYSTYPE s1, union YYSTYPE s2)
{ {
return (char) (s1.value + s2.value); return YY_CAST (char, s1.value + s2.value);
} }
int int
@@ -1577,7 +1580,7 @@ yylex (YYSTYPE *lvalp, YYLTYPE *llocp)
{ {
static char const input[] = "ab"; static char const input[] = "ab";
static int toknum = 0; static int toknum = 0;
assert (toknum < (int) sizeof input); assert (toknum < YY_CAST (int, sizeof input));
lvalp->dummy = 0; lvalp->dummy = 0;
llocp->first_line = llocp->last_line = 2; llocp->first_line = llocp->last_line = 2;
llocp->first_column = toknum + 1; llocp->first_column = toknum + 1;

View File

@@ -322,6 +322,7 @@ AT_PERL_CHECK([[-n -0777 -e '
|YYPUSH_MORE(?:_DEFINED)? |YYPUSH_MORE(?:_DEFINED)?
|YYUSE |YYUSE
|YY_ATTRIBUTE(?:_PURE|_UNUSED) |YY_ATTRIBUTE(?:_PURE|_UNUSED)
|YY(?:_REINTERPRET)?_CAST
|YY_CONSTEXPR |YY_CONSTEXPR
|YY_COPY |YY_COPY
|YY_CPLUSPLUS |YY_CPLUSPLUS

View File

@@ -446,7 +446,7 @@ get_args (int argc, const char **argv)
assert (0 <= res); assert (0 <= res);
assert (res <= INT_MAX); assert (res <= INT_MAX);
assert (errno != ERANGE); assert (errno != ERANGE);
return (int) res; return YY_CAST (int, res);
} }
int int

View File

@@ -166,7 +166,7 @@ m4_foreach([b4_skel], [[yacc.c], [glr.c], [lalr1.cc], [glr.cc]],
[if (res) [if (res)
{ {
AT_VAL.ival = (res - '0') * 10; AT_VAL.ival = (res - '0') * 10;
AT_VAL.fval = (float) (res - '0') / 10.f; AT_VAL.fval = YY_CAST (float, res - '0') / 10.f;
}], }],
[30 0.3]) [30 0.3])
@@ -197,7 +197,7 @@ m4_foreach([b4_skel], [[yacc.c], [glr.c], [lalr1.cc], [glr.cc]],
["12"], ["12"],
[if (res) [if (res)
{ {
AT_VAL.up = (struct u *) malloc (sizeof *AT_VAL.up); AT_VAL.up = YY_CAST (struct u *, malloc (sizeof *AT_VAL.up));
assert (AT_VAL.up); assert (AT_VAL.up);
AT_VAL.up->ival = res - '0'; AT_VAL.up->ival = res - '0';
} }