Commit Graph

1400 Commits

Author SHA1 Message Date
Akim Demaille
94f70bd861 c++: clean a few issues wrt special tokens
The C++ implementation of LAC did not skip the $undefined token,
probably because it was not exposed.  Expose it, and use clearer
names.

* data/skeletons/c++.m4: Don't define undef_token_ in yytranslate_,
but...
* data/skeletons/lalr1.cc (yy_undef_token_): here.
Use a more precise type to define yy_undef_token_ and yy_error_token_.
Unfortunately we move from a compile-time value defined via an enum to
a static const member.  Eventually we should make it constexpr.
Make LAC implementation more alike yacc.c's one.
2019-12-01 08:08:19 +01:00
Akim Demaille
9b4f0970fe d, java: improve yytranslate and neighbors
* data/skeletons/lalr1.d, data/skeletons/lalr1.java: Don't expose
yyuser_token_number_max_ and yyundef_token_.  Do as in C++: scope them
into yytranslate_, and only when api.token.raw is not defined.
(yyterror_): Rename as...
(yy_error_token_): this.
* data/skeletons/lalr1.d (token_number_type): New.
Use it.
Can't be done in the Java backend, as Java does not have type aliases.
2019-12-01 07:59:23 +01:00
Akim Demaille
869028a66d d, java: get rid of a useless table
* data/skeletons/lalr1.d, data/skeletons/lalr1.java (yytoken_number_):
Remove, useless.
Was used in ancient C skeletons to support YYPRINT, long obsoleted by
%printer.
2019-12-01 07:38:31 +01:00
Akim Demaille
6f92a7f664 c++, d, java: remove yyerrcode
It is not used at all.  We will remove it also from yacc.c, but
later (see TODO).

* data/skeletons/lalr1.cc, data/skeletons/lalr1.d,
* data/skeletons/lalr1.java (yyerrcode_):
Remove.
2019-11-30 17:30:48 +01:00
Akim Demaille
6a61b6b17e c++: improve typing
* data/skeletons/lalr1.cc (yysyntax_error_): symbol_type::type_get
returns a symbol_number_type (which is indeed an int).
2019-11-30 17:30:48 +01:00
Akim Demaille
a4bf7cdf9e c++: remove useless cast about yyeof_
Reported by Frank Heckenbach.
https://lists.gnu.org/archive/html/bug-bison/2019-11/msg00016.html

* data/skeletons/c++.m4 (b4_yytranslate_define): Don't use yyeof_ as
if it had two different types.
It is used once against the input argument, which is the value
returned by yylex, which is an "external token number", typically an
int.  It is also used as output type, an "internal symbol number".
It turns out that in both cases we mean "0", but let's keep yyeof_
only for the case "internal symbol number", i.e., _after_ conversion
by yytranslate.
This frees us from one cast.
2019-11-30 17:30:48 +01:00
Akim Demaille
9471a5ffe9 glr: style change
* data/skeletons/glr.c (YYDPRINTF): Expand into an empty statement,
instead of nothing.
Simplify callers.
2019-11-30 14:41:16 +01:00
Akim Demaille
24c5214ae8 glr: remove useless casts
Reported by GCC's -Wuseless-cast.

* data/skeletons/glr.c: Don't cast to yybool, it's useless.
2019-11-30 14:41:16 +01:00
Akim Demaille
2f7097d1b1 yacc.c, glr.c: fix crash when reporting errors in consistent states
The current code for yysyntax_error for %define parse.error verbose is
fishy (given that YYEMPTY is -2, invalid argument for yytname[]):

    static int
    yysyntax_error ([...])
    {
      YYPTRDIFF_T yysize0 = yytnamerr (YY_NULLPTR, yytname[yytoken]);
    [...]
      if (yytoken != YYEMPTY)

A nearby comment reports

    The only way there can be no lookahead present (in yychar) is if
    this state is a consistent state with a default action.  Thus,
    detecting the absence of a lookahead is sufficient to determine
    that there is no unexpected or expected token to report.  In that
    case, just report a simple "syntax error".

So it _is_ possible to call yysyntax_error with yytoken == YYEMPTY,
albeit quite difficult when meaning to, so virtually impossible by
accident (after all, there was never a bug report about this).

I failed to produce a test case, but Joel E. Denny provided me with
one (added to the test suite below).  The yacc.c skeleton fails on
this, and once fixed dies on a second problem.  The glr.c skeleton was
also dying, but immediately of this second problem.

Indeed we were not allocating space for the error message's final \0.
This was hidden by the fact that we only had error messages with at
least an unexpected token displayed, so with at least one "%s" in the
format string, whose size (2) was included (incorrectly) in the final
size of the message (where the %s have been replaced by the actual
content).

* data/skeletons/glr.c, data/skeletons/yacc.c (yysyntax_error):
Do not invoke yytnamerr on YYEMPTY.
Clarify the computation of the length of the _final_ error message,
with the NUL terminator but without the '%s's.
* tests/conflicts.at (Syntax error in consistent error state):
New, contributed by Joel E. Denny.
2019-11-29 18:21:43 +01:00
Akim Demaille
ad32ec64c8 style: pacify syntax-check
* cfg.mk: No need to translate *.md files.
* data/skeletons/glr.c, data/skeletons/yacc.c: Fix space issues.
2019-11-20 07:10:27 +01:00
Akim Demaille
7bdf7246fb c++: expose the type used to store line and column numbers
* data/skeletons/location.cc (position::counter_type)
(location::counter_type): New.
Use them.
* doc/bison.texi (C++ position, C++ location): Adjust.
2019-11-06 18:20:15 +01:00
Akim Demaille
3398b0fa90 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.
2019-11-02 16:40:50 +01:00
Akim Demaille
28f1e1546c C++: finish propagating the unsigned->signed conversion in locations
* data/skeletons/location.cc: Remove the u (for unsigned) suffix from
the initial line and column.
* NEWS: AFAICT, only C++ backends have their location types changed.
2019-10-29 09:15:25 +01:00
Akim Demaille
fead28d9e3 style: glr.c: comment changes
* data/skeletons/glr.c: here.
2019-10-29 08:59:18 +01:00
Akim Demaille
0cbefb71e8 lalr1.cc: fix previous commit: printing of state numbers
* data/skeletons/lalr1.cc: Printing a char prints... a char.
Print ints instead.
2019-10-24 23:02:26 +02:00
Akim Demaille
402332c4b6 lalr1.cc: use computed state types
This skeleton uses a single stack of state structures, so it is less
likely to benefit from a stack size reduction than yacc.c (which uses
several stacks: state number, value and location).  But it will reduce
the size of the LAC stack.

This skeleton was already using int for state numbers, so, contrary to
yacc.c, this brings nothing for large automata.

Overall, it is still nicer to make the skeletons alike.

* data/skeletons/lalr1.cc (state_type): Here.
2019-10-24 18:16:01 +02:00
kaneko y
c86b7815fc yacc.c: fix a typo
* data/skeletons/yacc.c (yysetstate): fix comment.
2019-10-22 19:05:02 +02:00
Paul Eggert
54c5d5d1b4 c++: port to Sun C++ 5.12
The documentation for Oracle Solaris Studio 12.3 (Sun C++ 5.12
2011/11/16) says it supports C++03.  This compiler rejects the
location.cc use of std::max for some reason; I don’t know why
since I don’t use C++ as a rule.  The simplest workaround is to
open-code ‘max’.
* data/skeletons/location.cc (add_):
Do max by hand rather than relying on std::max.
Don’t include <algorithm.h>; no longer needed.
2019-10-17 12:25:05 -07:00
Paul Eggert
83c9051a64 c: port YY_ATTRIBUTE_UNUSED to Sun C 5.12
Sun C 5.12 defines __SUNPRO_C to 0x5120 but diagnoses
‘__attribute__ ((__unused__))’.  Change the ifdefs to use
the same method as Gnulib in this area.
* data/skeletons/c.m4 (YY_ATTRIBUTE): Remove, since
not all attributes were added in the same compiler version.
(YY_ATTRIBUTE_PURE, YY_ATTRIBUTE_UNUSED):
Use specific GCC version for each attribute.
Pay no attention to __SUNPRO_C.
* tests/headers.at (Several parsers): Tighten tests accordingly.
2019-10-17 11:51:20 -07:00
Paul Eggert
7a557ee7fe c: improve port of stdint.h usage to pre-C99
Oracle Solaris Studio 12.3 (Sun C 5.12 2011/11/16) by default does
not conform to C99; it defines __STDC_VERSION__ to be 199409L, so
the Bison code does not include <stdint.h> (not required by C89
amendment 1) even though this compiler does have <stdint.h>.  On
this platform <limits.h> defines INT_LEAST8_MAX (POSIX allows
this) so the skeleton got confused and thought that <stdint.h> had
been included even though it wasn’t.
* data/skeletons/c.m4 (b4_c99_int_type_define) [!__PTRDIFF_MAX__]:
Always include <limits.h>.
(YY_STDINT_H): Define when <stdint.h> was included.
All uses of expressions like ‘defined INT_LEAST8_MAX’ changed to
‘defined YY_STDINT_H’, since Sun C 5.12 <limits.h> defines macros
like INT_LEAST8_MAX but does not declare types like int_least8_t.
2019-10-17 11:51:20 -07:00
Akim Demaille
e5cbac98b6 yacc: rename types for states
* data/skeletons/yacc.c (yy_state_num): Rename as...
(yy_state_t): this.
(yy_state_fast_t): New.
Use it.
2019-10-15 07:02:26 +02:00
Akim Demaille
d563a01709 glr: style changes
* data/skeletons/glr.c (yytnamerr): here.
(yyprocessOneStack): Initialize variables.
2019-10-15 07:02:26 +02:00
Akim Demaille
a428a9fa6c yacc: style changes
* data/skeletons/yacc.c: Move call to lac discard to clarify the
shifting of the token.
Like in lalr1.cc.
2019-10-15 07:02:26 +02:00
Akim Demaille
59cb1f421c d: comment changes
* data/skeletons/lalr1.d: Here.
2019-10-12 12:11:42 +02:00
Akim Demaille
2c20ae9b41 glr: display line numbers in traces
Suggested by Lars Maier.

* data/skeletons/glr.c: Also display rule locations when rules are
deferred, and rejected.
2019-10-11 08:38:24 +02:00
Paul Eggert
3f320159e3 c: improve patch for UCHAR_MAX etc. problem
* data/skeletons/c.m4 (b4_c99_int_type_define): Reorder to put the
signed types first, since they’re simpler and this keeps similar
code closer.  For signed types, don’t bother checking whether the
type promotes to int since the type must be signed anyway.  For
unsigned types, protect a test like ‘UCHAR_MAX <= INT_MAX’ with
‘!defined __UINT_LEAST8_MAX__’, as otherwise the logic is wrong
for oddball platforms; and once we do that, there should no need
for ‘defined INT_MAX’ so remove that.
2019-10-10 12:08:42 -07:00
Akim Demaille
602d562d6f c: don't assume that UCHAR_MAX, etc. are defined
A number of portability issues with GCC 4.6 .. 4.9 (inclusive):

    input.c:184:7: error: "UCHAR_MAX" is not defined [-Werror=undef]
     #elif UCHAR_MAX <= INT_MAX
           ^
    input.c:184:20: error: "INT_MAX" is not defined [-Werror=undef]
     #elif UCHAR_MAX <= INT_MAX
                        ^
    input.c:202:7: error: "USHRT_MAX" is not defined [-Werror=undef]
     #elif USHRT_MAX <= INT_MAX
           ^
    input.c:202:20: error: "INT_MAX" is not defined [-Werror=undef]
     #elif USHRT_MAX <= INT_MAX
                        ^

* data/skeletons/c.m4 (b4_c99_int_type_define): Don't assume they are
defined.
2019-10-10 16:01:43 +02:00
Paul Eggert
d4b6c86c7f Move the integer-type selection into c.m4
That way, glr.c can use it too.
* data/skeletons/c.m4 (b4_int_type):
Do not special-case ‘char’; it’s not worth the trouble,
as clang complains about char subscripts.
(b4_c99_int_type, b4_c99_int_type_define): New macros,
taken from yacc.c.
* data/skeletons/glr.c: Use b4_int_type_define.
* data/skeletons/yacc.c (b4_int_type): Remove, since there’s
no longer any need to redefine it.
Use b4_c99_int_type_define rather than its body.
2019-10-07 00:08:19 -07:00
Paul Eggert
5463291a91 Use “least” types for integers in Yacc tables
This changes the Yacc skeleton to use “least” integer types to
keep tables smaller on some platforms, which should lessen cache
pressure.  Since Bison uses the Yacc skeleton, it follows suit.
* data/skeletons/yacc.c: Include limits.h and stdint.h if this
seems to be needed.
(yytype_uint8, yytype_int8, yytype_uint16, yytype_int16):
If available, use GCC predefined macros __INT_MAX__ etc. to select
a “least” type, as this avoids namespace hassles.  Otherwise, if
available fall back on selecting a “least” type via the C99 macros
INT_MAX, INT_LEAST8_MAX, etc.  Otherwise, fall further back on one of
the builtin C99 types signed char, short, and int.  Make sure that
any selected type promotes to int.  Ignore any macros YYTYPE_INT16,
YYTYPE_INT8, YYTYPE_UINT16, YYTYPE_UINT8 defined by the user.
(ptrdiff_t, PTRDIFF_MAX): Simplify in the light of the above.
(yytype_uint8, yytype_uint16): Do not assume that unsigned char
and unsigned short promote to int, as this isn’t true on some
platforms (e.g., TI TMS320C55x).
* src/parse-gram.y (YYTYPE_INT16, YYTYPE_INT8, YYTYPE_UINT16)
(YYTYPE_UINT8): Remove, as these are no longer effective.
2019-10-07 00:08:19 -07:00
Paul Eggert
6373b90fc8 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.
2019-10-06 11:59:16 -07:00
Paul Eggert
beceb2fa93 Work around GCC 4.8 false alarms without casts
* data/skeletons/yacc.c (yyparse):
Initialize yyes_capacity with a signed expression.
* tests/local.at (AT_YYLEX_DEFINE(c)):
Use enum to avoid cast.
2019-10-06 11:59:16 -07:00
Akim Demaille
be3cf406af diagnostics: suggest fixes for undeclared symbols
From

    input.y:1.17-19: warning: symbol baz is used, but is not defined as a token and has no rules [-Wother]
         1 | %printer {} foo baz
           |                 ^~~

to

    input.y:1.17-19: warning: symbol 'baz' is used, but is not defined as a token and has no rules; did you mean 'bar'? [-Wother]
        1 | %printer {} foo baz
          |                 ^~~
          |                 bar

* bootstrap.conf: We need fstrcmp.
* src/symtab.c (symbol_from_uniqstr_fuzzy): New.
(complain_symbol_undeclared): Use it.
* tests/diagnostics.at (Suggestions): New.
* data/bison-default.css (insertion): Rename as...
(fixit-insert): this, as this is what GCC uses.
2019-10-06 09:54:25 +02:00
Akim Demaille
0b585c49ae diagnostics: display suggested update after the caret-info
This commit adds the suggestion in green, on the line below the
caret-and-tildes.

    foo.y:1.1-14: warning: deprecated directive: '%error-verbose', use '%define parse.error verbose' [-Wdeprecated]
        1 | %error-verbose
          | ^~~~~~~~~~~~~~
          | %define parse.error verbose

The current approach, with location_caret_suggestion, is fragile:
there's a protocol of calls to the complain functions which is strict.
We should rather have a richer structure describing the diagnostics,
including with submessages such as the suggestions, passed in the end
to the routines in charge of formatting and printing them.

* src/location.h, src/location.c (location_caret_suggestion): New.
* src/complain.c (deprecated_directive): Use it.
* tests/diagnostics.at, tests/input.at: Adjust expectations.
2019-10-06 08:07:57 +02:00
Akim Demaille
32e5a91a91 yacc.c: work around warnings from G++ 4.8
input.c: In function 'int yyparse()':
input.c: error: conversion to 'long int' from 'long unsigned int'
                may change the sign of the result [-Werror=sign-conversion]
   yyes_capacity = sizeof yyesa / sizeof *yyes;
                                ^
cc1plus: all warnings being treated as errors

* data/skeletons/yacc.c: here.
2019-10-06 08:07:40 +02:00
Akim Demaille
5973d763c0 yacc.c: work around warnings from Clang++ 3.3 and 3.4
When we run the test suite with these C++ compilers to compile C code,
we get:

    239. synclines.at:440: testing syncline escapes: yacc.c ...
    ../../tests/synclines.at:440: $CC $CFLAGS $CPPFLAGS \"\\\"\".c -o \"\\\"\" ||
              exit 77
    stderr:
    stdout:
    ../../tests/synclines.at:440: COLUMNS=1000; export COLUMNS;  bison --color=no -fno-caret  -o \"\\\"\".c \"\\\"\".y
    ../../tests/synclines.at:440: $CC $CFLAGS $CPPFLAGS  $LDFLAGS -o \"\\\"\" \"\\\"\".c $LIBS
    stderr:
    "\"".c:1102:41: error: implicit conversion loses integer precision: 'long' to 'int' [-Werror,-Wshorten-64-to-32]
          YYPTRDIFF_T yysize = yyssp - yyss + 1;
                      ~~~~~~   ~~~~~~~~~~~~~^~~
    1 error generated.

    193. conflicts.at:545: testing parse.error=verbose and consistent errors: lr.type=canonical-lr parse.lac=full ...
    input.c:737:75: error: implicit conversion loses integer precision: 'long' to 'int'
                           [-Werror,-Wshorten-64-to-32]
      YYPTRDIFF_T yysize_old = *yytop == yytop_empty ? 0 : *yytop - *yybottom + 1;
                  ~~~~~~~~~~                               ~~~~~~~~~~~~~~~~~~~^~~
    input.c:901:48: error: implicit conversion loses integer precision: 'long' to 'int'
                           [-Werror,-Wshorten-64-to-32]
                YYPTRDIFF_T yysize = yyesp - *yyes + 1;
                            ~~~~~~   ~~~~~~~~~~~~~~^~~

* data/skeletons/yacc.c: Add more casts.
2019-10-06 08:03:43 +02:00
Paul Eggert
e69b47cd18 * data/skeletons/glr.c (yysplitStack): Pacify Clang 8. 2019-10-05 03:42:24 -07:00
Akim Demaille
5709f94a91 yacc.c: use casts instead of pragmas when losing integer width
For instance with Clang 4, 8, etc.:

    input.c:1166:12: error: implicit conversion loses integer precision: 'int' to 'yy_state_num' (aka 'signed char') [-Werror,-Wconversion]
      *yyssp = yystate;
             ~ ^~~~~~~

And GCC 8:

    input.c:1166:12: error: implicit conversion loses integer precision: 'int' to 'yy_state_num' (aka 'signed char') [-Werror,-Wimplicit-int-conversion]
      *yyssp = yystate;
             ~ ^~~~~~~

* data/skeletons/yacc.c (YY_CONVERT_INT_BEGIN): Remove.
Adjust callers.
2019-10-05 09:01:56 +02:00
Akim Demaille
bc96b757ca yacc.c: fix warnings about undefined macros
For instance with GCC 4.9 and --enable-gcc-warnings:

    25. input.at:1201: testing Torturing the Scanner ...
    ../../tests/input.at:1344: $CC $CFLAGS $CPPFLAGS  -c -o input.o input.c
    stderr:
    input.c:239:18: error: "__STDC_VERSION__" is not defined [-Werror=undef]
     # elif 199901 <= __STDC_VERSION__
                      ^
    input.c:256:18: error: "__STDC_VERSION__" is not defined [-Werror=undef]
     # elif 199901 <= __STDC_VERSION__
                      ^

* data/skeletons/yacc.c: Check that __STDC_VERSION__ is defined before
using it.
2019-10-04 06:58:44 +02:00
Akim Demaille
032a52be6e c++: fix comments suggesting to use %require
* data/skeletons/location.cc, data/skeletons/stack.hh: Here.
2019-10-03 09:27:41 +02:00
Akim Demaille
843ef49bc3 lalr1.cc: simplify uses of size_t
* data/skeletons/stack.hh (stack::index_type): New type.
(stack::size, stack::operator[]): Be about an index_type rather than a
size_type and an int.
2019-10-03 09:27:41 +02:00
Akim Demaille
5df33278b4 c++: fixes for old compilers
On the CI with GCC 6:

    examples/c++/calc++/parser.cc:845:5: error: 'ptrdiff_t' was not declared in this scope
         ptrdiff_t yycount = 0;
         ^~~~~~~~~
    examples/c++/calc++/parser.cc:845:5: note: suggested alternatives:
    /usr/include/x86_64-linux-gnu/c++/6/bits/c++config.h:202:28: note:   'std::ptrdiff_t'
       typedef __PTRDIFF_TYPE__ ptrdiff_t;
                                ^~~~~~~~~

* data/skeletons/lalr1.cc: Qualify ptrdiff_t and size_t with std::.
2019-10-03 09:27:41 +02:00
Paul Eggert
133edcd248 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.
2019-10-02 17:11:33 -07:00
Paul Eggert
4d9ff272cf 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.
2019-10-02 07:10:03 +02:00
Akim Demaille
2ca6b71967 yacc: use the most appropriate integral type for state numbers
Currently we properly use the "best" integral type for tables,
including those storing state numbers.  However the variables for
state numbers used in yyparse (and its dependencies such as
yy_stack_print) still use int16_t invariably.  As a consequence, very
large models overflow these variables.

Let's use the "best" type for these variables too.  It turns out that
we can still use 16 bits for twice larger automata: stick to unsigned
types.

However using 'unsigned' when 16 bits are not enough is troublesome
and generates tons of warnings about signedness issues.  Instead,
let's use 'int'.

Reported by Tom Kramer.
https://lists.gnu.org/archive/html/bug-bison/2019-09/msg00018.html

* data/skeletons/yacc.c (b4_state_num_type): New.
(yy_state_num): Be computed from YYNSTATES.
* tests/linear: New.
* tests/torture.at (State number type): New.
Use it.
2019-09-30 18:31:55 +02:00
Akim Demaille
871c02b327 yacc: introduce a type for states
* data/skeletons/yacc.c (yy_state_num): New.
Use it for arrays of states.
2019-09-30 07:26:17 +02:00
Akim Demaille
a57e74a5bf style: prefer symbolic values rather than litterals
Instead of

    #define YYPACT_NINF -130
    #define yypact_value_is_default(Yystate) \
      (!!((Yystate) == (-130)))

generate

    #define YYPACT_NINF (-130)
    #define yypact_value_is_default(Yyn) \
      ((Yyn) == YYPACT_NINF)

* data/skeletons/c.m4 (b4_table_value_equals): Add support for $4.
* data/skeletons/glr.c, data/skeletons/yacc.c: Use it.
Also, use shorter macro argument names, the name of the macro is clear
enough.
2019-09-30 07:25:56 +02:00
Akim Demaille
4971409e39 style: change misleading macro argument name
* data/skeletons/glr.c, data/skeletons/yacc.c
(yypact_value_is_default): It does not take a rule number as argument.
2019-09-30 07:25:48 +02:00
Akim Demaille
b772baef24 Merge remote-tracking branch 'upstream/maint'
* upstream/maint:
  c++: add copy ctors for compatibility with the IAR compiler
  CI: show git status
  CI: disable ICC
  tests: pass -jN from Make to the test suite
  quotearg: avoid leaks
  maint: post-release administrivia
2019-09-28 08:09:33 +02:00
Akim Demaille
406e8c7c02 c++: add copy ctors for compatibility with the IAR compiler
Reported by Andreas Damm.
https://savannah.gnu.org/support/?110032

* data/skeletons/lalr1.cc (stack_symbol_type::operator=): New
overload, const, to please the IAR C++ compiler (version ca 2013).
2019-09-27 08:40:52 +02:00
Akim Demaille
a3e201de02 java: handle eof in yytranslate
* data/skeletons/lalr1.java (yytranslate_): Handle eof here, as is done
in lalr1.cc.
* tests/javapush.at: Adjust.
2019-09-14 10:09:08 +02:00