Commit Graph

6320 Commits

Author SHA1 Message Date
Akim Demaille
9260e5ca4f api.location.type: support it in C
Reported by Balázs Scheidler.

* data/skeletons/c.m4 (b4_location_type_define): Use api.location.type
if defined.
* doc/bison.texi: Document it.
* tests/local.at (AT_C_IF, AT_LANG_CASE): New.
Support Span in C.
* tests/calc.at (Span): Convert it to be usable in C and C++.
Check api.location.type with yacc.c and glr.c.
2019-04-25 20:20:59 +02:00
Akim Demaille
971e72514f updates: insert/remove %empty
* src/reader.c (grammar_rule_check_and_complete): Generate fixits for
adding/removing %empty.
* tests/actions.at, tests/diagnostics.at, tests/existing.at: Adjust.
2019-04-24 13:21:24 +02:00
Akim Demaille
0ee5ac5367 regen 2019-04-24 13:08:51 +02:00
Akim Demaille
935d119c82 diagnostics: better rule locations
The "identifier and colon" of a rule is implemented as a single token,
but whose location is only that of the identifier (so that messages
about the lhs of a rule are accurate).  When reducing empty rules, the
default location is the single point location on the end of the
previous symbol.  As a consequence, when Bison parses a grammar, the
location of the right-hand side of an empty rule is based on the
lhs, *independently of the position of the colon*.  And the colon can
be way farther, separated by comments, white spaces, including empty
lines.

As a result, some messages look really bad.  For instance:

    $ cat foo.y
    %%
    foo     : /* empty */
    bar
    : /* empty */

gives

    $ bison -Wall foo.y
    foo.y:2.4: warning: empty rule without %empty [-Wempty-rule]
        2 | foo     : /* empty */
          |    ^
    foo.y:3.4: warning: empty rule without %empty [-Wempty-rule]
        3 | bar
          |    ^

The carets are not at the right column, not even the right line.

This commit passes the colon "again" after the "id colon" token, which
gives more accurate locations for these messages:

    $ bison -Wall foo.y
    foo.y:2.10: warning: empty rule without %empty [-Wempty-rule]
        2 | foo     : /* empty */
          |          ^
    foo.y:4.2: warning: empty rule without %empty [-Wempty-rule]
        4 | : /* empty */
          |  ^

* src/scan-gram.l (SC_AFTER_IDENTIFIER): Rollback the colon, so that
we scan it again afterwards.
(INITIAL): Scan colons.
* src/parse-gram.y (COLON): New.
(rules): Parse the colon after the rule's id_colon (and possible
named reference).
* tests/actions.at, tests/conflicts.at, tests/diagnostics.at,
* tests/existing.at: Adjust.
2019-04-24 13:08:51 +02:00
Akim Demaille
01fe32ee53 fixits: track byte-columns, not character-columns
Because the fix-its were ready the character-based columns, but were
applied on byte-based columns, the result with multibyte characters or
tabs could be "interesting".  For instance

	    %fixed-output_files
            %fixed_output-files
    %fixed-output-files
    %define api.prefix {foo}
    %no-default-prec

would give

         %fixed-%fixed-output-files  %fixed_output-files
    %fixed-orefix= "foo"
    o_default-prec

* src/fixits.c (fixit_print, fixits_run): Work on byte-base columns.
* tests/input.at: Check it.
2019-04-24 07:18:22 +02:00
Akim Demaille
19ea6b1405 diagnostics: expose a means to know whether a warning is enabled
* src/complain.h, src/complain.c (warning_is_enabled): New.
2019-04-24 07:18:22 +02:00
Akim Demaille
a4d33cdf48 gnulib: let it use its own PO domain
See
https://www.gnu.org/software/gnulib/manual/html_node/Localization.html.

* bootstrap.conf: Create gnulib-po.
* Makefile.am, configure.ac: Use it.
* po/POTFILES.in: Remove files now in gnulib.
* src/main.c: Open the bison-gnulib domain.
2019-04-23 19:28:08 +02:00
Akim Demaille
a992a3cb9e diagnostics: don't try to quote special files
Based on a report by Todd Freed.
http://lists.gnu.org/archive/html/bug-bison/2019-04/msg00000.html
See also https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90034

* src/location.c (caret_info): Also track the file name.
(location_caret): Don't quote special files.
2019-04-23 18:29:10 +02:00
Akim Demaille
95d688957f diagnostics: document the change of format
* doc/bison.texiL Adjust output.
Also, Graphviz has no uppercsae V.
* NEWS: Explain the format change.
2019-04-23 18:29:10 +02:00
Akim Demaille
a9b350fb3a diagnostics: copy GCC9's format
Currently, when we quote the source file, we indent it with one space,
and preserve tabulations, so there is a discrepancy and the visual
rendering is bad.  One way out is to indent with a tab instead of a
space, but then this space can be used for more information.  This is
what GCC9 does.  Let's play copy cats.

See
https://lists.gnu.org/archive/html/bison-patches/2019-04/msg00025.html
https://developers.redhat.com/blog/2019/03/08/usability-improvements-in-gcc-9/
https://gcc.gnu.org/onlinedocs/gccint/Guidelines-for-Diagnostics.html#Guidelines-for-Diagnostics

* src/location.c (location_caret): Prefix quoted lines with the line
number and a pipe, fitting 8 columns.

* tests/actions.at, tests/c++.at, tests/conflicts.at,
* tests/diagnostics.at, tests/input.at, tests/java.at,
* tests/named-refs.at, tests/reduce.at, tests/regression.at,
* tests/sets.at: Adjust expectations.
Partly by "./build-aux/update-test tests/testsuite.dir/*/testsuite.log"
repeatedly, and partly by hand.
2019-04-23 18:29:10 +02:00
Akim Demaille
afe7dfd3b9 diagnostics: fix the handling of multibyte characters
This is a pity: efforts were invested in computing correctly the
number of screen columns consumed by multibyte characters, but the
routines that do that were fed by single-byte inputs...

As a consequence Bison never displayed correctly locations when there
are multibyte characters.

* src/scan-gram.l (mbchar): New.
Use it instead of . in the catch-all clause.
* tests/diagnostics.at (Tabulations): Enhance into...
(Tabulations and multibyte characters): this.
2019-04-23 18:29:10 +02:00
Akim Demaille
6b6c3de2ae diagnostics: check the handling of tabulations
* tests/diagnostics.at (Tabulations): here.
2019-04-23 18:29:10 +02:00
Akim Demaille
1b70f687fa diagnostics: fix styling issues
Single point locations (equal boundaries) are troublesome, and we were
incorrectly ending the style in their case.  Which results in an abort
in libtextstyle.

There is also a confusion between columns as displayed on the
screen (which take into account multibyte characters and tabulations),
and the number of bytes.  Counting the screen-column
incrementally (character by character) is uneasy (because of multibyte
characters), and I don't want to maintain a buffer of the current line
when displaying the diagnostic.  So I believe the simplest solution is
to track the byte number in addition to the screen column.

* src/location.h, src/location.c (boundary): Add the byte-column.
Adjust dependencies.
* src/getargs.c, src/scan-gram.l: Adjust.
* tests/diagnostics.at: Check zero-width locations.
2019-04-23 18:29:10 +02:00
Akim Demaille
520d474ec6 diagnostics: check the styling
Enable checking of styles even when libtextstyle is not installed.

* src/getargs.h, src/getargs.c (style_debug): New.
(getargs_colors): Set it when --style=debug.
* src/complain.c (begin_use_class, end_use_class): Use it.
* tests/diagnostics.at: New.
2019-04-23 18:29:10 +02:00
Akim Demaille
deec7ca65c TODO: update
Let's prepare 3.4 with more or less what we have.  Schedule some
features for 3.5 and 3.6.  Remove obsolete stuff.
2019-04-23 18:25:30 +02:00
Akim Demaille
dff7454371 doc: sort the warning categories
* doc/bison.texi, src/getargs.c: here.
2019-04-19 20:16:32 +02:00
Akim Demaille
e50eedf3c5 style: formatting changes
* tests/actions.at, tests/calc.at, tests/input.at: here.
2019-04-19 20:16:32 +02:00
Akim Demaille
341776b03b graphviz: move constant computation out of a loop
* src/graphviz.c (output_red): here.
2019-04-19 20:16:32 +02:00
Akim Demaille
79f7afb125 diagnostics: fix memory leak in libtextstyle
* src/complain.h, src/complain.c (complain_free): New.
* src/main.c: Use it.
2019-04-18 22:19:18 +02:00
Akim Demaille
2f3d9717ee tests: remove useless feature
* tests/calc.at (read_signed_integer): Rename as...
(read_integer): this.
We never read signs here.
2019-04-17 08:50:22 +02:00
Akim Demaille
9ad7524659 traces: make closure() less verbose
* src/getargs.h, src/getargs.c (trace_closure): New.
* src/closure.c (closure): Use it.
2019-04-14 18:27:17 +02:00
Akim Demaille
4ec413da32 build: also generate the graph reports
* Makefile.am (AM_YFLAGS_WITH_LINES): here.
2019-04-14 16:04:23 +02:00
Akim Demaille
61d53e606d yacc.c: minor style change
* data/skeletons/yacc.c: To improve consistency with other similar
pieces of code.
2019-04-12 08:38:30 +02:00
Akim Demaille
d67b7daa1d style: scope reduction in lalr.c
* src/lalr.c (initialize_goto_follows): here.
2019-04-12 08:38:30 +02:00
Akim Demaille
2ab70cf0c6 style: comment changes
* src/closure.h, src/closure.c, src/lalr.c: here.
2019-04-12 08:38:30 +02:00
Akim Demaille
99664706e2 traces: improve logs
* src/lalr.c: Move logs to a better place to understand the chronology
of events.
* src/symlist.c (symbol_list_syms_print): Don't dump core on type
elements.
2019-04-12 08:33:34 +02:00
Akim Demaille
a745041b7d doc: minor fixes
* doc/bison.texi: Use consistently $ and @kbd in shell examples.
Prefer sticking to English words: output and file instead of outfile
and infile.
2019-04-07 12:45:45 +02:00
Akim Demaille
0dd97f7c87 regen 2019-04-03 19:20:39 +02:00
Akim Demaille
69a823c72d bison: use no-lines
The 'regen' commit in Bison's history are a nuisance.  They are
especially big because of the #lines.  Let's generate our parse
without these lines in the repository, but generate them in the
tarball.

* Makefile.am (AM_YFLAGS_WITH_LINES): New.
(AM_YFLAGS): Use it.
(dist-hook): Regenerate the parser with #lines.
2019-04-03 19:20:39 +02:00
Akim Demaille
0f193d2d21 no-lines: avoid leaving an empty line instead of the syncline
Currently, with --no-lines, instead of "#line file line\n", we emit
"\n".  Let's emit nothing.

* data/skeletons/bison.m4 (b4_syncline): Emit at end-of-line when enabled.
* data/skeletons/bison.m4, data/skeletons/c.m4, data/skeletons/glr.cc,
* data/skeletons/lalr1.cc, src/output.c: Use dnl after b4_syncline to
avoid spurious empty lines.

* tests/synclines.at (Sync Lines): Make sure that --no-lines is like
grep -v #line.
* tests/calc.at: Make sure that a rich grammar file behaves properly
with %no-lines.
2019-04-03 19:20:39 +02:00
Akim Demaille
9832fdd6ef java: use full locations for diagnostics about destructors
Currently we use the syncline to report errors about a symbol's
destructor/printer.  This is not accurate (only file and line), and
this is incorrect: the file name is double quotes (a recent change,
needed to make sure we escape properly double quotes in it).  And
worst of all: with --no-line, b4_syncline expands to nothing.

Rather, push the locations into the backend, and use them.

* src/muscle-tab.h, src/muscle-tab.c (muscle_location_grow): Make it
public.
* src/output.c (prepare_symbol_definitions): Use it to pubish the
location of the printer and destructor.
* data/skeletons/lalr1.java: Use complain_at instead of complain.
* tests/java.at (Java invalid directives): Adjust expectations.
* data/skeletons/bison.m4 (b4_symbol_action_location): Remove.
We should not use b4_syncline this way.
2019-04-03 19:20:39 +02:00
Akim Demaille
507c679b9b java: prefer errors to fatal errors
Fatal errors are inconvenient, and should be reserved to cases where
we cannot continue.  Here, it could even be warnings actually: these
directives will simply be ignored.

* data/skeletons/lalr1.java: Prefer error (b4_complain) to fatal
errors (b4_fatal).
* tests/java.at (Java invalid directives): New.
2019-04-03 19:20:39 +02:00
Akim Demaille
0b42cf8a36 tests: formatting changes
* tests/javapush.at: here.
2019-04-03 19:20:39 +02:00
Akim Demaille
10175e4a65 lalr: offer more flexibility in debugging routines
* src/state.h, src/state.c (state_transitions_print): New, extracted
from...
(state_transitions_set): here.
2019-04-03 07:29:54 +02:00
Akim Demaille
18831f985c lalr: don't overbook memory
I never understood why we book ngotos+1 slots for relations between
gotos: there are at most ngotos images, not ngotos+1 (and "includes"
does have cases where a goto is in relation with itself, so it's not
ngotos-1).

Maybe bbf37f2534 explains the +1: a bug
left us register a goto several times on occasion, and the +1 might
have been a means to avoid this problem in most cases.  Now that this
bug is addressed, we should no longer overbook memory, if only for the
clarity of the code ("why ngotos+1 instead of ngotos?").

* src/lalr.c: A goto has at most ngotos images, not ngotos+1.
While at it, avoid useless repeated call to map_goto introduced in
bbf37f2534.
2019-03-31 13:59:28 +02:00
Akim Demaille
6d4e6bf118 lalr: show lookback for debug
* src/lalr.c (lookback_print): New.
(build_relations): Use it.
Also show edges.
2019-03-30 17:34:56 +01:00
Akim Demaille
a8558bc5a6 diagnostics: don't crash when declaring the error token as an nterm
Reported by wcventure.
http://lists.gnu.org/archive/html/bug-bison/2019-03/msg00008.html

* src/symtab.c (complain_class_redeclared): Don't print empty
locations.
There can only be empty locations for predefined symbols.  And the
only symbol that is lexically available is the error token.  So this
appears to be the only possible way to have an error involving an
empty location.
* tests/input.at (Symbol class redefinition): Check it.
2019-03-30 16:37:47 +01:00
Akim Demaille
bbf37f2534 lalr: fix segmentation violation
The "includes" relation [DeRemer 1982] is between gotos, so of course,
for a given goto, there cannot be more that ngotos (number of gotos)
images.  But we manipulate the set of images of a goto as a list,
without checking that an image was not already introduced.  So we can
"register" way more images than ngotos, leading to a crash (heap
buffer overflow).

Reported by wcventure.
http://lists.gnu.org/archive/html/bug-bison/2019-03/msg00007.html

For the records, this bug is present in the first committed version of
Bison.

* src/lalr.c (build_relations): Don't insert the same goto several
times.
* tests/sets.at (Build Relations): New.
2019-03-30 10:10:39 +01:00
Akim Demaille
d332ff3c77 state: more debug traces
* src/state.c (state_transitions_set): Show the transitions.
2019-03-30 10:10:39 +01:00
Akim Demaille
eb92ec3dc6 style: rename variables for consistency
* src/lalr.c: Use trans for transitions, and reds for reductions, as
elsewhere in the code.
* src/state.h: Comment changes.
2019-03-30 10:10:39 +01:00
Akim Demaille
dee8fbbc1e gram: fix and improve log message
It seems that not many people read these logs: the error was
introduced in 2001 (3067fbef53),

* src/gram.c (grammar_dump): Fix the headers of the table: remove
duplicate display of "Ritem Range".
While at it, remove duplicate display of the rule number (and remove
an incorrect comment about it: these numbers _are_ equal).
* tests/sets.at (Reduced Grammar): Use useless rule, nterm and token
in the example.
2019-03-30 10:10:39 +01:00
Akim Demaille
75303c61d8 tests: add a tool for mass updates
When we update some output format, too many adjustements must be made
by hand.  This script updates most tests based on the actual output
made during the tests.

* build-aux/update-test: New.
2019-03-30 08:20:31 +01:00
Akim Demaille
af99826ef4 style: remove now useless _GL_UNUSED
* src/getargs.c (getargs_colors): Here.
Useless since 4d34b06fb3.
2019-03-25 08:39:50 +01:00
Theophile Ranquet
af1c6f973a tables: use bitsets for a performance boost
Suggested by Yuri at
<http://lists.gnu.org/archive/html/bison-patches/2012-01/msg00000.html>.

The improvement is marginal for most grammars, but notable for large
grammars (e.g., PosgreSQL's postgre.y), and very large for the
sample.y grammar submitted by Yuri in
http://lists.gnu.org/archive/html/bison-patches/2012-01/msg00012.html.
Measured with --trace=time -fsyntax-only.

parser action tables    postgre.y     sample.y
Before                 0,129 (44%)  37,095 (99%)
After                  0,117 (42%)   5,046 (93%)

* src/tables.c (pos): Replace this set of integer coded as an unsorted
array or integers with...
(pos_set): this bitset.
2019-03-24 19:16:19 +01:00
Akim Demaille
b5cd777ad6 yacc.c: don't suggest api.header.include when --defines is not used
See 4e19ab9fcd: the suggestion to
include the header file should not be emitted when the header is not
generated.

* data/skeletons/yacc.c: Here.
2019-03-24 18:52:58 +01:00
Akim Demaille
ae91c3cce3 reader: clarify variable names
* src/reader.c (grammar_rule_check_and_complete): When 'p' and 'lhs'
are aliases, prefer the latter, for clarity and consistency.
(grammar_current_rule_begin): Avoid 'p', current_rule suffices.
* src/gram.h, src/gram.c: Comment changes.

ptdr#	calc.tab.c
2019-03-24 18:40:46 +01:00
Akim Demaille
5de4e79fc8 diagnostics: style changes
* src/location.c (location_caret): Clarify a bit.
2019-03-24 18:40:46 +01:00
Akim Demaille
4d34b06fb3 diagnostics: use gnulib's libtextstyle-optional
Bruno Haible just added a default implementation of libtextstyle's
interface when the library is not available.
https://lists.gnu.org/archive/html/bison-patches/2019-03/msg00025.html

* gnulib: Update.
* bootstrap.conf: Replace libtextstyle with libtextstyle-optional.
* src/complain.c, src/getargs.c: Remove now useless cpp guards.
2019-03-24 18:40:46 +01:00
Akim Demaille
22a413ce9f diagnostics: fix handling of style in limit cases
* src/location.c (location_caret): Beware of the cases where the start
and end columns are the same, or when the location is multilines.
2019-03-23 10:21:18 +01:00
Akim Demaille
01855ca328 warnings: don't use _Noreturn with G++ 4.7 in C++98 mode
The timevar and bitset modules now use the c99 module which causes
$CXX to now include -std=gnu++11 when possible.  Unfortunately, G++
4.7 does not implement [[noreturn]] in C++11 mode, so our tests of
glr.cc (which uses _Noreturn) fail with

    input.cc:954:1: error: expected unqualified-id before '[' token

right before [[noreturn]].  4.8 works fine.

* data/skeletons/c.m4 (b4_attribute_define): Do not use [[noreturn]]
with GCC 4.7.
2019-03-23 10:15:11 +01:00