Port better to C++ platforms

* data/skeletons/yacc.c (YYPTRDIFF_T, YYPTRDIFF_MAXIMUM):
Default to long, not int.
(yy_lac_stack_realloc, yy_lac, yytnamerr, yyparse):
Avoid casts to YYPTRDIFF_T that were masking the problem.
This commit is contained in:
Paul Eggert
2019-10-06 11:58:10 -07:00
parent beceb2fa93
commit 6373b90fc8
2 changed files with 10 additions and 15 deletions

13
TODO
View File

@@ -107,15 +107,10 @@ name they have in gcc, clang, etc. Likewise for the complain_* series of
functions. functions.
* Modernization * Modernization
Remove some casts made for old compilers, such as Clang++ 3.3 and 3.4 when Fix data/skeletons/yacc.c so that it defines YYPTRDIFF_T properly for modern
compiling yacc.c code: and older C++ compilers. Currently the code defaults to defining it to
'long' for non-GCC compilers, but it should use the proper C++ magic to
YYPTRDIFF_T yysize = (YYPTRDIFF_T) (yyssp - yyss + 1); define it to the same type as the C ptrdiff_t type.
YYPTRDIFF_T yysize_old =
*yytop == yytop_empty ? 0 : (YYPTRDIFF_T) (*yytop - *yybottom + 1);
YYPTRDIFF_T yysize = (YYPTRDIFF_T) (yyesp - *yyes + 1);
* Completion * Completion
Several features are not available in all the backends. Several features are not available in all the backends.

View File

@@ -425,9 +425,9 @@ typedef short yytype_int16;
# include <stdint.h> /* INFRINGES ON USER NAME SPACE */ # include <stdint.h> /* INFRINGES ON USER NAME SPACE */
# define YYPTRDIFF_MAXIMUM PTRDIFF_MAX # define YYPTRDIFF_MAXIMUM PTRDIFF_MAX
# else # else
# define YYPTRDIFF_T int # define YYPTRDIFF_T long
# include <limits.h> /* INFRINGES ON USER NAME SPACE */ # include <limits.h> /* INFRINGES ON USER NAME SPACE */
# define YYPTRDIFF_MAXIMUM INT_MAX # define YYPTRDIFF_MAXIMUM LONG_MAX
# endif # endif
#endif #endif
@@ -857,7 +857,7 @@ yy_lac_stack_realloc (YYPTRDIFF_T *yycapacity, YYPTRDIFF_T yyadd,
yy_state_num **yytop, yy_state_num *yytop_empty) yy_state_num **yytop, yy_state_num *yytop_empty)
{ {
YYPTRDIFF_T yysize_old = YYPTRDIFF_T yysize_old =
*yytop == yytop_empty ? 0 : (YYPTRDIFF_T) (*yytop - *yybottom + 1); *yytop == yytop_empty ? 0 : *yytop - *yybottom + 1;
YYPTRDIFF_T yysize_new = yysize_old + yyadd; YYPTRDIFF_T yysize_new = yysize_old + yyadd;
if (*yycapacity < yysize_new) if (*yycapacity < yysize_new)
{ {
@@ -1024,7 +1024,7 @@ yy_lac (yy_state_num *yyesa, yy_state_num **yyes,
YYDPRINTF ((stderr, " R%d", yyrule - 1)); YYDPRINTF ((stderr, " R%d", yyrule - 1));
if (yyesp != yyes_prev) if (yyesp != yyes_prev)
{ {
YYPTRDIFF_T yysize = (YYPTRDIFF_T) (yyesp - *yyes + 1); YYPTRDIFF_T yysize = yyesp - *yyes + 1;
if (yylen < yysize) if (yylen < yysize)
{ {
yyesp -= yylen; yyesp -= yylen;
@@ -1155,7 +1155,7 @@ yytnamerr (char *yyres, const char *yystr)
} }
if (yyres) if (yyres)
return (YYPTRDIFF_T) (yystpcpy (yyres, yystr) - yyres); return yystpcpy (yyres, yystr) - yyres;
else else
return yystrlen (yystr); return yystrlen (yystr);
} }
@@ -1535,7 +1535,7 @@ yysetstate:
#else #else
{ {
/* Get the current used size of the three stacks, in elements. */ /* Get the current used size of the three stacks, in elements. */
YYPTRDIFF_T yysize = (YYPTRDIFF_T) (yyssp - yyss + 1); YYPTRDIFF_T yysize = yyssp - yyss + 1;
# if defined yyoverflow # if defined yyoverflow
{ {