Commit Graph

6599 Commits

Author SHA1 Message Date
Akim Demaille
97d6da0c5b parser: clarify version checking
* src/parse-gram.y: Use the same conventions for gnulib as elsewhere:
<header.h>.
(str_to_version): New.
(handle_require): Use it.
Prefer < to >.
2019-10-20 17:57:28 +02:00
Akim Demaille
e31f92495c build: disable -Wtype-limits, except in the test suite
The current implementation of lib/intprops.h results in "unsigned < 0"
comparisons, which triggers warnings.  See

https://lists.gnu.org/archive/html/bug-bison/2019-10/msg00061.html

* configure.ac (warn_common): Disable -Wtype-limits.
(warn_tests): Restore it.
2019-10-20 08:55:44 +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
693e69f289 regen 2019-10-17 11:51:20 -07:00
Paul Eggert
5c2c9fcb17 tests: port to Solaris 10 grep
* tests/scanner.at (Token numbers: $1): Use $EGREP, not grep -E.
2019-10-17 11:51:20 -07:00
Paul Eggert
071f43d5b7 tests: port to Solaris 10 sed
As documented in the Autoconf manual, Solaris 10 sed rejects
script labels contianing more than 7 characters.  POSIX requires
support for at least 8 characters, but we might as well be portable
to Solaris 10 which is still supported.
* tests/local.at (AT_SETS_CHECK): Use only the first 7 characters
in sed labels.
2019-10-17 11:51:20 -07:00
Paul Eggert
8a4ec5d4e4 bison: check for int overflow in token numbers
* src/symtab.c: Include intprops.h
(symbol_user_token_number_set): Don’t allow user_token_number ==
INT_MAX because too much other code adds 1 to the user token number.
(symbols_token_translations_init): Complain on integer overflow
instead of indulging in undefined behavior.
2019-10-17 11:51:20 -07:00
Paul Eggert
052215a138 bison: check for int overflow when scanning
* src/scan-gram.l: Include errno.h, for errno.
(scan_integer, handle_syncline): Check for integer overflow.
* tests/input.at (too-large.y): Adjust to match new diagnostics.
2019-10-17 11:51:20 -07:00
Paul Eggert
15c1b913cf bison: check version numbers more carefully
* src/parse-gram.y: Include intprops.h.
(handle_require): Don’t indulge in undefined behavior if the major
or minor number is out of range.  Instead, check that the
resulting value is nonnegative, fits in int, and that the minor
number is less than 100.  Also, check that a number was parsed.
2019-10-17 11:51:20 -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
Paul Eggert
08dd5e9feb gnulib:update 2019-10-17 11:51:20 -07:00
Paul Eggert
68cc2631a4 autoconf:update 2019-10-17 11:51:20 -07:00
Akim Demaille
b47340982b TODO: more updates 2019-10-15 08:40:50 +02:00
Akim Demaille
ee35055b49 TODO: update 2019-10-15 07:28:33 +02: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
2a0185b693 tests: avoid $(...)
Reported by Paul Eggert.

* tests/local.at (AT_DATA_NO_FINAL_EOL): here.
2019-10-15 07:01:06 +02:00
Akim Demaille
ab3621678a tests: use a portable 'truncate' implementation
Suggested by Paul Eggert.
https://lists.gnu.org/archive/html/bison-patches/2019-10/msg00044.html

* tests/local.at (AT_DATA_NO_FINAL_EOL): Use dd instead of perl.
2019-10-14 07:58:36 +02:00
Akim Demaille
8631f35bf9 tests: factor the generation of files without the final eol
AFAICT Autotest 2.69 still does not support AT_DATA without the final
eol.

* tests/local.at (AT_DATA_NO_FINAL_EOL): New.
* tests/input.at: Use it.
2019-10-13 09:55:44 +02:00
Akim Demaille
c483b6593f tests: refactor the handling of Perl
Let's make a difference between places where Perl is required for the
test (AT_PERL_REQUIRE), and the places where it's used to run the
test, but it's not not to run the test (AT_PERL_CHECK).

* tests/local.at (AT_REQUIRE): New.
(AT_PERL_CHECK, AT_PERL_REQUIRE): New.
Use them where appropriate.

* tests/local.mk ($(TESTSUITE)): Beware not to start the line with
'-pi' if Perl is empty, as Make understands this as "it's ok to fail".
Which it is not.
2019-10-13 09:22:05 +02:00
Akim Demaille
59cb1f421c d: comment changes
* data/skeletons/lalr1.d: Here.
2019-10-12 12:11:42 +02:00
Akim Demaille
d9d37a1196 i18n: don't push too hard for '…'
Suggested by Paul Eggert.

* src/location.c (ellipsis): Clarify comment for translators.
2019-10-12 10:43:53 +02:00
Akim Demaille
c3db1394a1 regen 2019-10-11 08:52:04 +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
Akim Demaille
0c56c195e0 tests: be really robust to Perl missing
My previous tests (with ./configure PERL=false) have been fooled by
configure, that managed to find perl anyway.  This time, I ran this on
a Fedora in Docker, without Perl.

* tests/calc.at, tests/diagnostics.at, tests/headers.at,
* tests/input.at, tests/local.at, tests/named-refs.at,
* tests/output.at, tests/regression.at, tests/skeletons.at,
* tests/synclines.at, tests/torture.at: Don't require Perl.
2019-10-11 06:53:45 +02:00
Akim Demaille
3dd2ae4415 configure: perl is not required
But it's used in various places, including in some tests.

* configure.ac: here.
2019-10-10 21:57:50 +02:00
Akim Demaille
d50df39f1a news: update 2019-10-10 21:57:50 +02:00
Akim Demaille
2c66acfec0 diagnostics: prefer "…" to "..." if the locale supports it
* src/location.c (ellipsis, ellipsize): New.
Use them.
2019-10-10 21:57:50 +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
f41e0cf73c tests: do not depend on config.h
Currently we face test suite failures in different environments,
because of a conflict between the definitions of isnan by gnulib, and
by the C++ library:

    262. headers.at:186: testing Sane headers: %locations %debug c++ ...
    ./headers.at:186: COLUMNS=1000; export COLUMNS;  bison --color=no -fno-caret -d -o input.cc input.y
    ./headers.at:186: $CXX $CXXFLAGS $CPPFLAGS  -c -o input.o input.cc
    stderr:
    In file included from /usr/include/c++/4.8.2/cmath:44:0,
                     from /usr/include/c++/4.8.2/random:38,
                     from /usr/include/c++/4.8.2/bits/stl_algo.h:65,
                     from /usr/include/c++/4.8.2/algorithm:62,
                     from location.hh:41,
                     from input.hh:90,
                     from input.cc:50:
    /u/cs/fac/eggert/src/gnu/bison/lib/math.h: In function 'bool isnan(double)':
    /u/cs/fac/eggert/src/gnu/bison/lib/math.h:2849:1: error: new declaration 'bool isnan(double)'
     _GL_MATH_CXX_REAL_FLOATING_DECL_2 (isnan, isnan, bool)
     ^
    In file included from /usr/include/features.h:375:0,
                     from /usr/include/c++/4.8.2/x86_64-redhat-linux/bits/os_defines.h:39,
                     from /usr/include/c++/4.8.2/x86_64-redhat-linux/bits/c++config.h:2097,
                     from /usr/include/c++/4.8.2/cstdlib:41,
                     from input.hh:48,
                     from input.cc:50:
    /usr/include/bits/mathcalls.h:235:1: error: ambiguates old declaration 'int isnan(double)'
     __MATHDECL_1 (int,isnan,, (_Mdouble_ __value)) __attribute__ ((__const__));
     ^

There might be something to do in gnulib about this, but I believe
that gnulib should not be used in the test suite in the first place.

The test suite should work with other compilers than the one used to
compile the package.  For a start, Bison sources are more
demanding (C99) than the generated parsers.  Last time I tried, tcc
for example, was not able to compile Bison, yet our generated parsers
should compile cleanly with it.

Besides the problem at hand is with the C++ compiler, with is not the
one used to set up gnulib at configuration-time (config.h is mainly
built from probing the C compiler).

We should really not depend on gnulib in tests.

This was introduced in 2001 to check whether including
stdlib.h/string.h is safe thanks to STDC_HEADERS
(2ce1014469).  Today, we assume at least
a C90 compiler, it should be safe enough.

* tests/local.at, tests/testsuite.h: Do not include config.h.
* tests/atlocal.in (conftest.cc): Likewise.
(CPPFLAGS): Do not expose lib/, as because of this we might picked up
gnulib replacement headers for system headers.

* tests/input.at: Use int instead of ptrdiff_t, for easier portability
(some machine on the CI did not find ptrdiff_t).
* tests/c++.at: Add missing include for getchar.
2019-10-10 17:53:48 +02:00
Akim Demaille
d6ce0521cf doc: spell check
* doc/bison.texi: Remove the index about yyoutput, it is no longer
documented.
Spell check.
2019-10-10 17:53:48 +02:00
Akim Demaille
cf298ebb7d tests: style changes
* tests/actions.at: Prefer printf to fprintf.
Prefer yyo to yyoutput in %printer.
2019-10-10 17:53:48 +02:00
Akim Demaille
734db67004 tests: formatting changes
* tests/actions.at, tests/local.at: here.
2019-10-10 17:53:48 +02:00
Akim Demaille
7d47d51962 tests: add missing includes
* tests/actions.at, tests/c++.at, tests/headers.at,
* tests/regression.at: here.
2019-10-10 17:53:32 +02: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
Akim Demaille
825150b085 configure: don't require Flex
Flex should not be required to build Bison or run the test suite (of
course it is needed for maintaining Bison).  Yet the Automake
conditional FLEX_WORKS does not work.

* m4/flex.m4 (_AC_PROG_LEX_YYTEXT_DECL): Since this is called
conditionally, don't define LEX_IS_FLEX here, but rather...
(AC_PROG_LEX): here.
* configure.ac: Be more cautious about possibly undefined variables.
2019-10-09 07:28:26 +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
58302c6079 regen 2019-10-06 17:48:51 +02:00
Akim Demaille
d2a7a28438 tests: make recheck
* tests/local.mk (recheck): New.
2019-10-06 12:15:12 +02:00
Akim Demaille
9e6c5328d3 diagnostics: also show suggested %empty
* src/reader.c (grammar_rule_check_and_complete): Suggest to add %empty.
* tests/actions.at, tests/diagnostics.at: Adjust expectations.
2019-10-06 12:15:12 +02:00
Akim Demaille
fec13ce2db diagnostics: sort symbols per location
Because the checking of the grammar is made by phases after the whole
grammar was read, we sometimes have diagnostics that look weird.  In
some case, within one type of checking, the entities are not checked
in the order in which they appear in the file.  For instance, checking
symbols is done on the list of symbols sorted by tag:

    foo.y:1.20-22: warning: symbol BAR is used, but is not defined as a token and has no rules [-Wother]
        1 | %destructor {} QUX BAR
          |                    ^~~
    foo.y:1.16-18: warning: symbol QUX is used, but is not defined as a token and has no rules [-Wother]
        1 | %destructor {} QUX BAR
          |                ^~~

Let's sort them by location instead:

    foo.y:1.16-18: warning: symbol 'QUX' is used, but is not defined as a token and has no rules [-Wother]
        1 | %destructor {} QUX BAR
          |                ^~~
    foo.y:1.20-22: warning: symbol 'BAR' is used, but is not defined as a token and has no rules [-Wother]
        1 | %destructor {} QUX BAR
          |                    ^~~

* src/location.h (location_cmp): Be robust to empty file names.
* src/symtab.c (symbol_cmp): Sort by location.
* tests/input.at: Adjust expectations.
2019-10-06 09:54:25 +02: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
126c4622de style: isolate complain_symbol_undeclared
* src/symtab.c (complain_symbol_undeclared): New.
Use it.
Use quote on the guilty symbol (like GCC does, and we also do
elsewhere).
* tests/input.at: Adjust.
2019-10-06 09:54:25 +02:00
Akim Demaille
dd64eaf9db style: simplify the handling of symbol and semantic_type tables
Both are stored in a hash, and back in the days, we used to iterate
over these tables using hash_do_for_each.  However, the order of
traversal was not deterministic, which was a nuisance for
deterministic output (and therefore also a problem for tests).  So at
some point (83b60c97ee) we generated a
sorted list of these symbols, and symbols_do actually iterated on that
list.  But we kept the constraints of using hash_do_for_each, which
requires a lot of ceremonial code, and makes it hard/unnatural to
preserve data between iterations (see the next commit).

Alas, this is C, not C++.

Let's remove this abstraction, and directly iterate on the sorted
tables.

* src/symtab.c (symbols_do): Remove.
Adjust callers to use a simple for-loop instead.
(table_sort): New.
(symbols_check_defined): Use it.
(symbol_check_defined_processor, symbol_pack_processor)
(semantic_type_check_defined_processor, symbol_translation_processor):
Remove.
Simplify the corresponding functions (that no longer need to return a
bool).
2019-10-06 09:54:20 +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