Commit Graph

2462 Commits

Author SHA1 Message Date
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
dff7454371 doc: sort the warning categories
* doc/bison.texi, src/getargs.c: 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
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
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
0dd97f7c87 regen 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
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
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
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
941cdf921d regen 2019-03-17 16:36:05 +01:00
Akim Demaille
58ae95670b style: rename spec_defines_file as spec_header_file
The variable spec_defines_file denotes the name of the generated
header.  Its name is derived from --defines/%defines, whose name in
turn is derived from the fact that the header, in Yacc, contained the

Not only does the header now contain a lot more than just the token
definitions, but we no longer even generate macros, but an enum...

Let's modernize our vocabulary.

* src/files.h, src/files.c (spec_defines_file): Rename as...
(spec_header_file): this.
2019-03-17 16:36:05 +01:00
Akim Demaille
4e19ab9fcd yacc.c: provide a means to include the header in the implementation
Currently when --defines is used, we generate a header, and paste an
exact copy of it into the generated parser implementation file.  Let's
provide a means to #include it instead.

We don't do it by default because of the Autotools' ylwrap.  This
program wraps invocations of yacc (that uses a fixed output name:
y.tab.c, y.tab.h, y.output) to support a more modern naming
scheme (dir/foo.y -> dir/foo.tab.c, dir/foo.tab.h, etc.).  It does
that by renaming the generated files, and then by running sed to
propagate these renamings inside the files themselves.

Unfortunately Automake's Makefiles uses Bison as if it were Yacc (with
--yacc or with -o y.tab.c) and invoke bison via ylwrap.  As a
consequence, as far as Bison is concerned, the output files are
y.tab.c and y.tab.h, so it emits '#include "y.tab.h"'.  So far, so
good.  But now ylwrap processes this '#include "y.tab.h"' into
'#include "dir/foo.tab.h"', which is not guaranteed to always work.

So, let's do the Right Thing when the output file is not y.tab.c, in
which case the user should %define api.header.include.  Binding this
behavior to --yacc is tempting, but we recently told people to stop
using --yacc (as it also enables the Yacc warnings), but rather to use
-o y.tab.c.

Yacc.c is the only skeleton concerned: all the others do include their
header.

* data/skeletons/yacc.c (b4_header_include_if): New.
(api.header.include): Provide a default value when the output is not
y.tab.c.
* src/parse-gram.y (api.header.include): Define.
2019-03-17 16:36:05 +01:00
Akim Demaille
35add841ee address warnings from GCC's UB sanitizer
Running with CC='gcc-mp-8 -fsanitize=undefined' revealed Undefined
Behaviors.
https://lists.gnu.org/archive/html/bison-patches/2019-03/msg00008.html

* src/state.c (errs_new): Don't call memcpy with NULL as source.
* src/location.c (add_column_width): Don't assume that the column
argument is nonnegative: the scanner sometimes "backtracks" (e.g., see
ROLLBACK_CURRENT_TOKEN and DEPRECATED) in which case we can have
negative column numbers (temporarily).
Found in test 3 (Invalid inputs).
2019-03-17 13:21:25 +01:00
Akim Demaille
f6e38d7ac9 diagnostics: use libtextstyle for colored output
Bruno Haible released libtextstyle, a library for colored output based
on CSS.  Let's use it to generate colored diagnostics, provided
libtextstyle is available.

See
https://lists.gnu.org/archive/html/bug-gnulib/2019-01/msg00176.html
https://lists.gnu.org/archive/html/bison-patches/2019-02/msg00073.html
https://lists.gnu.org/archive/html/bison-patches/2019-02/msg00084.html
https://lists.gnu.org/archive/html/bison-patches/2019-03/msg00007.html

* bootstrap.conf (gnulib_modules): Use libtextstyle when possible.
* data/diagnostics.css: New.
* src/complain.c (begin_use_class, end_use_class, flush)
(severity_style, complain_init_color): New.
Use them.
* src/getargs.c (getargs_colors): New.
(getargs): Use it.
Skip --color and --style.
* src/location.h, src/location.c (location_print): Use a style.

* tests/bison.in: Force --color=yes when stderr is a tty.
* tests/local.at: Disable colors during the test suite.
* tests/input.at: Adjust expectations to the extra options passed on
the command line.
2019-03-16 16:46:17 +01:00
Akim Demaille
855fbf1c11 style: clean up complain.c
* src/complain.c (severity_prefix): New.
(error_message): Take the severity as argument, instead of the prefix.
2019-03-16 16:46:17 +01:00
Akim Demaille
d57751d2fb lalr: clarify the count of lookaheads
* src/lalr.c (state_lookahead_tokens_count): Remove wierd `+=` that is
actually an `=`.
2019-02-28 06:47:19 +01:00
Akim Demaille
e062b9f70d lalr: clarify the API
* src/state.h, src/state.c (state_reduction_find): Clarify.
Die on errors.
* src/lalr.c (goto_list_new): New.
Use it.
2019-02-28 06:47:19 +01:00
Akim Demaille
c837141832 lalr: improve traces
* src/lalr.c (follows_print): Just print the symbol tag.
Take and print a title.
Indent the output.
Use it to print the various steps of the computation.
(lookahead_tokens_print): Fix a lie: the number displayed is not the
number of tokens.
Don't display states that don't even have reductions.
2019-02-28 06:47:19 +01:00
Akim Demaille
a415a78d71 lalr: print the 'reads' relation
* src/relation.h, src/relation.c (relation_print): Accept and use a
title.
Don't print empty rows.
Indent the output.
Adjust dependencies.
* src/lalr.c (initialize_goto_follows): Print 'reads' in traces.
2019-02-27 19:06:32 +01:00
Akim Demaille
5255b919ae style: comment changes
* src/lr0.c: here.
2019-02-27 19:06:32 +01:00
Akim Demaille
d04962f788 style: eliminate useless indirection
* src/relation.h, src/relation.c (relation_digraph): Don't take the
biteetv as a pointer, it is already a pointer (as it's an array).
2019-02-25 06:19:55 +01:00
Akim Demaille
ec8142391a style: rename function for clarity
Commit db34f79889 renames the variable F
as goto_follows, but forgot to rename this function.

* src/lalr.c (initialize_F): Rename as...
(initialize_goto_follows): this.
2019-02-25 06:19:55 +01:00
Akim Demaille
59bec5fade lalr: more debug traces
I need to be able to read includes and goto_follows.

* src/relation.h, src/relation.c (relation_print): Provide a means to
pretty-print the nodes of the relation.
* src/lalr.c (goto_print, follows_print): New.
(set_goto_map): Use goto_print.
(build_relations): Show INCLUDES.
(compute_FOLLOWS): Rename as...
(compute_follows): this.
Show FOLLOWS.
2019-02-25 06:19:54 +01:00
Akim Demaille
5230e610fc style: minor changes
* examples/c/calc/calc.y, src/lalr.c: Reduce scope.
* src/gram.c: Prefer < to >.
2019-02-24 19:08:01 +01:00
Akim Demaille
b81419a9fd style: clarify the computation of the lookback edges
* src/lalr.c (build_relations): Reduce the scopes.
Instead of keeping rp alive in two different loops, clarify the second
one by having an index on the path we traverse (i.e., use that index
to compute the source state _and_ the symbol that labels the
transition).
This allows to turn an obscure 'while'-loop in a clearer (IMHO)
'for'-loop.  We also consume more variables (by introducing p instead
of making more side effects on length), but we're in 2019, I don't
think this matters.  What does matter is that (IMHO again), this is
now clearer.
Also, use clearer names.
2019-02-24 19:07:32 +01:00
Akim Demaille
2b9ee006d8 style: scope reduction in tables.c
* src/tables.c: here.
* src/lalr.c: Prefer < to >.
2019-02-24 12:00:44 +01:00
Akim Demaille
bd55d43333 graph: prefer *.gv to *.dot
Reported by Hans Åberg.
https://lists.gnu.org/archive/html/help-bison/2019-02/msg00064.html

* src/files.c (spec_graph_file): Use `*.gv` when 3.4 or better,
otherwise `*.dot`.
* src/parse-gram.y (handle_require): Pretend we are already 3.4.
* doc/bison.texi: Adjust.
* tests/local.at, tests/output.at: Exercise this.
2019-02-21 06:46:07 +01:00
Akim Demaille
d7ec136ffb style: move pkgdatadir to files.*
Let's move it to a more logical place.

* src/output.h, src/output.c (pkgdatadir): Move to...
* src/files.h, src/files.c: here.
2019-02-16 07:26:16 +01:00
Akim Demaille
dbdf2878ab style: rename cleanup_caret as caret_free
* src/location.c, src/location.h, src/main.c: here.
2019-02-14 18:53:01 +01:00
Akim Demaille
8654fca058 style: avoid default in switch on enums
* src/assoc.c (assoc_to_string): here.
2019-02-14 06:27:03 +01:00
Akim Demaille
fb83319d9c style: comment and names changes in map_goto
* src/lalr.h, src/lalr.c: Use clearer names.
2019-02-12 06:19:10 +01:00
Akim Demaille
ad7d8af6d1 style: factor printing of rules
* src/gram.h, src/gram.c (rule_print): New.
Use it.
2019-02-09 08:59:55 +01:00
Akim Demaille
f293345aa8 style: use lower case for variable names
* src/relation.c (INDEX, VERTICES): Rename as...
(indexes, vertices): these.
2019-02-09 08:58:12 +01:00
Akim Demaille
e18ad5a96b style: scope reduction in relation.c 2019-02-09 08:58:12 +01:00