Commit Graph

7278 Commits

Author SHA1 Message Date
Akim Demaille
e088b4f90f style: reduce scopes
* src/scan-gram.l (STRING_GROW_ESCAPE): Move the static_assert about
type sizes here.
2020-06-13 15:20:56 +02:00
Akim Demaille
c857ed4f72 style: prefer 'FOO ()' to 'FOO' for function-like macros
* src/flex-scanner.h (STRING_GROW, STRING_FINISH, STRING_FREE):
Make them function-like macros.
Adjust dependencies.
2020-06-13 15:20:56 +02:00
Akim Demaille
1998606a90 regen 2020-06-11 19:11:33 +02:00
Akim Demaille
b0bb4cde2e cex: suggest -Wcounterexamples when there are unexpected conflicts
Suggesting -Wcounterexamples when there are conflicts is probably not
what the user wants.  If she knows her conflicts and has set
%expect/%expect-rr appropriately, we shouldn't warn.

The commit also swaps the counterexamples and the report of conflicts,
into, IMHO, a more natural order: from

    Shift/reduce conflict on token B:
    1:    3 a: A .
    1:    8 y: A . B
    Example              A • B C
    First derivation     s ::=[ a ::=[ A • ] x ::=[ B C ] ]
    Example              A • B C
    Second derivation    s ::=[ y ::=[ A • B ] c ::=[ C ] ]

    input.y: warning: 1 shift/reduce conflict [-Wconflicts-sr]
    input.y:4.4: warning: rule useless in parser due to conflicts [-Wother]

to

    input.y: warning: 1 shift/reduce conflict [-Wconflicts-sr]
    Shift/reduce conflict on token B:
    1:    3 a: A .
    1:    8 y: A . B
    Example              A • B C
    First derivation     s ::=[ a ::=[ A • ] x ::=[ B C ] ]
    Example              A • B C
    Second derivation    s ::=[ y ::=[ A • B ] c ::=[ C ] ]

    input.y:4.4: warning: rule useless in parser due to conflicts [-Wother]

* src/conflicts.c (rule_conflicts_print): Rename as...
(report_rule_expectation_mismatches): this.
Move the handling of report_counterexamples to...
(conflicts_print): Here.
Display this warning when applicable.
2020-06-10 09:51:39 +02:00
Akim Demaille
d2acc4b401 cex: rename -Wcounterexample as -Wcounterexamples, and support -Wcex
Plural vs. singular is always a problem...

But we already have conflicts-sr and conflicts-rr, so counterexamples
makes more sense than counterexample.  Besides, -Wcounterexample will
still be accepted as an unambiguous prefix of -Wcounterexamples.

Add -Wcex as a convenient alias.

While at it, use only "counterexample", never "counter example".

* src/complain.h, src/complain.c
(Wcounterexample, warning_counterexample): Rename as...
(Wcounterexamples, warning_counterexamples): these.
(argmatch_warning_docs): Rename -Wcounterexample as -Wcounterexamples.
(argmatch_warning_args): Likewise.
Add support for -Wcex.
Adjust dependencies.
2020-06-10 07:53:44 +02:00
Akim Demaille
a53c6026cd api.header.include: document it, and fix its default value
While defining api.header.include worked as expected, its default
value was incorrectly defined.  As a result, by default, the generated
parsers still duplicated the content of the generated header instead
of including it.

* data/skeletons/yacc.c (api.header.include): Fix its default value.
* tests/output.at: Check it.
* doc/bison.texi (%define Summary): Document api.header.include.
While at it, move the definition of api.namespace at the proper
place.
2020-06-09 08:09:26 +02:00
Akim Demaille
ae5edcc23b cex: color the counterexamples
Use colors to show the counterexamples and the derivations in color,
to highlight their structure.  Align the outputs, and add i18n
support. Reduce width by using a one-space separator instead of
two-space.

From

    Example  A  •  B  C
    First  derivation  s ::=[ a ::=[ A  • ]  x ::=[ B  C ] ]
    Second derivation  s ::=[ y ::=[ A  •  B ]  c ::=[ C ] ]

to

    Example              A • B C
    First derivation     s ::=[ a ::=[ A • ] x ::=[ B C ] ]
    Example              A • B C
    Second derivation    s ::=[ y ::=[ A • B ] c ::=[ C ] ]

with colors.

* data/bison-default.css (cex-dot, cex-0, cex-1, cex-2, cex-3, cex-4)
(cex-5, cex-6, cex-7, cex-step, cex-leaf): New.
* src/derivation.c (derivation_print_styled_impl): New.
(derivation_print, derivation_print_leaves): Use it.
* src/counterexample.c: Reformat the output.
* tests/counterexample.at: Adjust.
2020-06-07 09:18:58 +02:00
Akim Demaille
296e2f90ab cex: enforce case for tokens/nonterminals
It's unfortunate that the traditions between formal language theory
and Yacc differs, but here, tokens should be upper case, and
nonterminals should be lower case.

* tests/counterexample.at: Comply with this.
2020-06-07 09:18:58 +02:00
Akim Demaille
1ccb4be02b cex: reformat the s/r and r/r reports
In Bison we refer to "shift/reduce" conflicts, not "shift-reduce" (in
Bison 3.6.3 186 occurrences vs 15).  Enforce consistency on this.

Instead of "spending" a second line for each conflict to report the
lookaheads, put that on the same line as the type of conflict.  Also,
prefer "token" to "symbol".  Maybe we should even prefer "lookahead".
While at it, enable internationalization, with plurals where
appropriate.

As a consequence, instead of

    Shift-Reduce Conflict:
    6:    3 b: . %empty
    6:    6 d: c . A
    On Symbol: A

display

    Shift/reduce conflict on token A:
    6:    3 b: . %empty
    6:    6 d: c . A

* NEWS, doc/bison.texi, src/conflicts.c: Spell it "shift/reduce", not
"shift-reduce".
* src/counterexample.c (counterexample_report_shift_reduce)
(counterexample_report_reduce_reduce): Reformat and internationalize
output.
* tests/counterexample.at: Adjust expectations.
2020-06-07 09:18:58 +02:00
Akim Demaille
421662ec88 style: fix syntax-check issues
* src/counterexample.c, src/files.c, src/files.h, src/lssi.c,
* src/state-item.c: here.
2020-06-07 09:18:58 +02:00
Akim Demaille
39be113b1f all: show the rules in comments before the user actions
For instance, in the case of Bison's own parser:

    -  case 40:
    +  case 40:  /* grammar_declaration: "%code" "identifier" "{...}"  */
         {
           muscle_percent_code_grow ((yyvsp[-1].ID), (yylsp[-1]),
                                     translate_code_braceless ((yyvsp[0].BRACED_CODE), (yylsp[0])),
                                     (yylsp[0]));
           code_scanner_last_string_free ();
         }
         break;

* data/skeletons/c.m4: Modified.
* data/skeletons/d.m4: Modified.
* data/skeletons/java.m4: Modified.
* src/output.c (output_escaped): New.
(quoted_output): Use it, and rename as...
(output_quoted): this.
Adjust dependencies.
(rule_output): New.
(user_actions_output): Use it.
* data/skeletons/c.m4, data/skeletons/d.m4, data/skeletons/java.m4
(b4_case): Add support for $3, an optional comment.
2020-06-07 06:50:58 +02:00
Akim Demaille
2101b0e210 CI: use GCC10 on ppc too
We were still using GCC9, because GCC10 was failing.

* .travis.yml (PPC64le): Use GCC10.
While at it, use -O2 instead of -O3: it's certainly nicer for the
CPUs, and allows to test different sets of compiler flags (we use -O3
in several other configurations).
2020-06-06 07:48:40 +02:00
Akim Demaille
b1327c56f7 examples: fix missing includes
* examples/c/bistromathic/parse.y: Use abort rather than assert so
that the "unused result" warning is silenced even with -DNDEBUG.
2020-06-06 07:37:20 +02:00
Akim Demaille
ae03b16785 warnings: fix -Wmissing-prototypes issues
* src/counterexample.c, src/lssi.c, src/parse-simulation.c,
* src/state-item.c:
Here.
2020-06-03 08:31:08 +02:00
Akim Demaille
7e16bd2cae Merge maint into HEAD
* upstream/maint:
  maint: post-release administrivia
  version 3.6.3
  build: check -Wmissing-prototypes
  tests: show logs
  c++: fix printing of state number on streams
2020-06-03 08:12:10 +02:00
Akim Demaille
508ac09939 maint: post-release administrivia
* NEWS: Add header line for next release.
* .prev-version: Record previous version.
* cfg.mk (old_NEWS_hash): Auto-update.
2020-06-03 07:52:30 +02:00
Akim Demaille
0535d2a608 version 3.6.3
* NEWS: Record release date.
v3.6.3
2020-06-03 07:31:43 +02:00
Akim Demaille
94f7606db6 build: check -Wstrict-aliasing
* configure.ac (warn_common): Add -Wstrict-aliasing.
2020-06-01 18:52:23 +02:00
Akim Demaille
de5be4a693 doc: using asan
* README-hacking.md: here.
2020-06-01 18:52:23 +02:00
Akim Demaille
03a6b439f6 style: fix includes
* src/fixits.c: Follow our usual pattern.
* src/scan-code.l, src/scan-gram.l, src/scan-skel.l: Prefer "" to
include src/ headers.
* README-hacking.md: Document the pattern.
2020-06-01 18:52:22 +02:00
Akim Demaille
742910838e lists: fix various issues with the use of gnulib's list
First, we should avoid code such as

    gl_list_iterator_t it = gl_list_iterator (deriv->children);
    derivation *child = NULL;
    while (gl_list_iterator_next (&it, (const void **) &child, NULL))
      {
        derivation_print (child, f);

because of -Wstrict-aliasing (whose job is to catch type-punning
issues).  See https://lists.gnu.org/r/bug-bison/2020-05/msg00039.html.

Rather we need

    gl_list_iterator_t it = gl_list_iterator (deriv->children);
    const void **p = NULL;
    while (gl_list_iterator_next (&it, &p, NULL))
      {
        derivation *child = (derivation *) p;
        derivation_print (child, f);

Second, list iterators actually have destructors.  Even though they
are noop in the case of linked-lists, we should use them.

Let's address both issues with typed wrappers (such as
derivation_list_next) that take care of both issues, and besides allow
to scope the iterators within the loop:

    derivation *child;
    for (gl_list_iterator_t it = gl_list_iterator (deriv->children);
         derivation_list_next (&it, &child);
         )
      {
        derivation_print (child, f);

* src/derivation.h, src/derivation.c (derivation_list_next): New.
Use it where appropriate.
* src/counterexample.c (search_state_list_next): New.
Use it where appropriate.
* src/parse-simulation.h, src/parse-simulation.c
* src/state-item.h (state_item_list_next): New.
Use it where appropriate.
2020-06-01 18:50:35 +02:00
Akim Demaille
52ce2a008b build: check -Wmissing-prototypes
pstate_clear is lacking a prototype.
Reported by Ryan
https://lists.gnu.org/r/bug-bison/2020-05/msg00101.html

Besides, none of the C examples were compiled with the warning flags.

* configure.ac (warn_c): Add -Wmissing-prototypes.
* data/skeletons/yacc.c (pstate_clear): Make it static.
* examples/local.mk (TEST_CFLAGS): New.
* examples/c/bistromathic/local.mk, examples/c/calc/local.mk,
* examples/c/lexcalc/local.mk, examples/c/mfcalc/local.mk,
* examples/c/pushcalc/local.mk, examples/c/reccalc/local.mk,
* examples/c/rpcalc/local.mk:
Use it.

GCC's warn_unused_result is not silenced by a cast to void, so we have
to "use" scanf's result.
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=25509
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66425

Flex generated code produces too many warnings, including things such
as, with ICC:

    examples/c/lexcalc/scan.c(1088): error #1682: implicit conversion
              of a 64-bit integral type to a smaller integral type (potential portability problem)
    2259                YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]),
    2260                ^
    2261
    2262

I am tired of trying to fix Flex's output.  The project does not seem
maintained.  We ought to avoid it.  So, for the time being, don't try
to enable warnings with Flex.

* examples/c/bistromathic/parse.y, examples/c/reccalc/scan.l: Fix
warnings.
* doc/bison.texi: Discard scanf's return value to defeat
-Werror=unused-result.
2020-06-01 08:29:53 +02:00
Akim Demaille
bb311cfbed gnulib: update 2020-05-31 12:49:08 +02:00
Akim Demaille
518dc6ca26 style: make item_index a truly different type from item_number
See previous commit.

* src/gram.h (item_index): Make it unsigned.
Fix remaiming issues.
2020-05-25 07:41:05 +02:00
Vincent Imbimbo
6a1a681fd2 style: decouple different uses of item_number
item_number is used for elements of ritem as well as indices into
ritem which is fairly confusing.  Introduce item_index to represent
indices into ritem.

* src/gram.h (item_index): Introduce it for ritem indices.
* src/closure.h, src/closure.c, src/ielr.c, src/lr0.c,
* src/print-graph.c, src/state.h, src/state.h:
Replace uses of item_number with item_index where appropriate.
2020-05-25 07:14:34 +02:00
Joshua Watt
dd878d1851 bison: add command line option to map file prefixes
Teaches bison about a new command line option, --file-prefix-map OLD=NEW
(based on the -ffile-prefix-map option from GCC) which causes it to
replace and file path of OLD in the text of the output file with NEW,
mainly for header guards and comments. The primary use of this is to
make builds reproducible with different input paths, and in particular
the debugging information produced when the source code is compiled. For
example, a distro may know that the bison source code will be located at
"/usr/src/bison" and thus can generate bison files that are reproducible
with the following command:

    bison --output=/build/bison/parse.c -d --file-prefix-map=/build/bison/=/usr/src/bison/ parse.y

Importantly, this will change the header guards and #line directives
from:

    #ifndef YY_BUILD_BISON_PARSE_H
    #line 100 "/build/bison/parse.h"

to

    #ifndef YY_USR_SRC_BISON_PARSE_H
    #line 100 "/usr/src/bison/parse.h"

which is reproducible.

See https://lists.gnu.org/r/bison-patches/2020-05/msg00016.html
Signed-off-by: Joshua Watt <JPEWhacker@gmail.com>

* src/files.h, src/files.c (spec_mapped_header_file)
(mapped_dir_prefix, map_file_name, add_prefix_map): New.
* src/getargs.c (-M, --file-prefix-map): New option.
* src/output.c (prepare): Define b4_mapped_dir_prefix and
b4_spec_header_file.
* src/scan-skel.l (@ofile@): Output the mapped file name.
* data/skeletons/glr.c, data/skeletons/glr.cc,
* data/skeletons/lalr1.cc, data/skeletons/location.cc,
* data/skeletons/yacc.c:
Adjust.
* doc/bison.texi: Document.
* tests/input.at, tests/output.at: Check.
2020-05-24 15:17:15 +02:00
Akim Demaille
6ed813c122 tests: fix expectations
Should have been part of 1ec93ca2a2.

* tests/counterexample.at: here.
2020-05-24 15:17:14 +02:00
Akim Demaille
1ec93ca2a2 cex: clean the display of conflicted symbols
Instead of `On Symbols: {b,c,}`, display `On Symbols: b, c`.

* src/counterexample.c (counterexample_report_reduce_reduce): We don't
need braces.
Use commas as a separator, not a terminator.
* tests/counterexample.at: Adjust.
2020-05-23 18:23:07 +02:00
Akim Demaille
12f4091de4 tests: show logs
* examples/c/bistromathic/bistromathic.test, examples/test: here.
2020-05-23 18:02:44 +02:00
Akim Demaille
8ece778cb8 c++: fix printing of state number on streams
Avoid this kind of display:

    LAC: checking lookahead identifier: R4 R3 G^B S5

* data/skeletons/lalr1.cc: Convert state_t to int before printing it.
2020-05-23 18:02:24 +02:00
Akim Demaille
f32ba07f94 c++: fix printing of state number on streams
Avoid this kind of display:

    LAC: checking lookahead identifier: R4 R3 G^B S5

* data/skeletons/lalr1.cc: Convert state_t to int before printing it.
2020-05-23 17:45:03 +02:00
Vincent Imbimbo
50cd3f16de cex: fix pruning crash
Fixes a crash on Cim's grammar.
https://lists.gnu.org/r/bison-patches/2020-05/msg00107.html

* src/state-item.c (prune_disabled_paths): Prune forward and backwards
paths in seperate passes.
(prune_forward, prune_backward): New.
(disable_state_item): Change function argument from state_item_number
to state_item.
(state_items_report): Add disabling to graph print-out.
* src/conflicts.c (find_state_item_number,
report_state_counterexamples): Add SI_DISABLED checks.
2020-05-23 17:35:19 +02:00
Akim Demaille
37da3c4b42 regen 2020-05-23 15:41:29 +02:00
Akim Demaille
79bae4d6bb kinds: use the symbol kinds where applicable
Instead of generating switch statements with numbers, let's use the
symbol kinds.  Not only is this more readable, it also makes reading
diff easier, as a change in symbol numbers won't have such a large
effect on the implementation of symbol actions.

* data/skeletons/bison.m4 (_b4_symbol_case): Use the symbol kind
rather than its number.
2020-05-23 15:41:29 +02:00
Akim Demaille
23f7554188 kinds: also define the possibly qualified symbol kinds
* data/skeletons/bison.m4 (b4_symbol_kind): Rename as...
(b4_symbol_kind_base): this.
(b4_symbol_kind): New, for fully qualified kind name.
* data/skeletons/lalr1.cc (b4_symbol_kind): New.
Adjust to use b4_symbol_kind where appropriate.
* src/parse-gram.h, src/parse-gram.c: regen.
2020-05-23 15:41:29 +02:00
Akim Demaille
3ff248ebfe m4: simplify useless quotation
* data/skeletons/bison.m4: The result of b4_symbol is "quoted"
already, no need for m4_expand.
2020-05-23 15:40:48 +02:00
Akim Demaille
4e1a5aae96 m4: use m4_shift2 etc.
* data/skeletons/bison.m4 (m4_shift4): New.
Use them where applicable.
2020-05-23 14:59:18 +02:00
Akim Demaille
8e70880af1 tests: show logs
* examples/c/bistromathic/bistromathic.test, examples/test: here.
2020-05-23 13:47:31 +02:00
Akim Demaille
3fea8fade8 style: spell fixes
* Makefile.am (codespell): New.
* doc/bison.texi: Fixes.
Use @option for options.
* src/lssi.c, src/lssi.h, src/parse-simulation.h, src/state-item.c:
Fix spellos.
2020-05-23 11:19:27 +02:00
Akim Demaille
e7aff57122 style: rename user_token_number as code
This should have been done in 3.6, but I wanted to avoid introducing
conflicts into Vincent's work on counterexamples.  It turns out it's
completely orthogonal.

* data/README.md, data/skeletons/bison.m4, data/skeletons/c++.m4,
* data/skeletons/c.m4, data/skeletons/glr.c, data/skeletons/java.m4,
* data/skeletons/lalr1.d, data/skeletons/lalr1.java,
* data/skeletons/variant.hh, data/skeletons/yacc.c, src/conflicts.c,
* src/derives.c, src/gram.c, src/gram.h, src/output.c,
* src/parse-gram.c, src/parse-gram.y, src/print-xml.c, src/print.c,
* src/reader.c, src/symtab.c, src/symtab.h, tests/input.at,
* tests/types.at:
s/user_token_number/code/g.
Plus minor changes.
2020-05-23 08:43:58 +02:00
Akim Demaille
339d11badf Merge maint into master
* upstream/maint:
  fix generated comments
  traces: provide a means to get short m4 traces
  traces: show the full m4 invocation
2020-05-22 20:35:13 +02:00
Vincent Imbimbo
99260caef9 cex: replace state-item data structures
* src/state-item.h: Add trans, prods, and revs edges to state-item
struct.
(si_trans, si_revs, si_prods_lookup): Remove.
* src/state-item.c, src/lssi.c, src/parse-simulation.c,
* src/counterexample.c: Update state-item API usage accordingly.
2020-05-22 08:45:44 +02:00
Vincent Imbimbo
c19af5cbb4 cex: fix bad reference counting
* src/counterexample.c (si_bfs_free): Fix reference_count
decrementing.
2020-05-22 08:45:44 +02:00
Vincent Imbimbo
b54181ff9b cex: fix miscellaneous leaks
* src/counterexample.c (unifying_counterexample): Always free
stage3result when it exists.
* src/conflicts.c (report_state_counterexamples): free leaked bitset.
* src/state-item.c (prune_disabled_paths): free leaked queue.
2020-05-22 08:45:44 +02:00
Vincent Imbimbo
86c45be582 cex: fix counterexample leak
* src/counterexample.c (free_counterexample): New.
Free counterexamples after printing.
2020-05-22 08:45:44 +02:00
Vincent Imbimbo
b5e0351c3e cex: fix lssi leaks
* src/lssi.c (shortest_path_from_start): Free the root of
shortest_path_from_start search.
Free eligible bitset.
2020-05-22 08:45:44 +02:00
Vincent Imbimbo
150b2318ed cex: fix parse state leaks
* src/parse_simulation.c: Fix bug in parse_state_free.
Free new_root when simulate_reduction generates zero states.

* src/parse-simulation.c, src/parse-simulation.h
(parse_state_list, parse_state_list_append): New.
* src/parse-simulation.c, src/parse-simulation.h,
* src/counterexample.c: Replace all uses of lists of parse states and
appends to parse_state_lists with the new API.
2020-05-22 08:45:44 +02:00
Vincent Imbimbo
35c4a8e65e cex: derivation reference counting
* src/derivation.h, src/derivation.c: Make derivation struct opaque.
Add derivation_list type for clarity.
(derivation_list_new): New.
(derivation_list_append): New.
(derivation_list_prepend): New.
(derivation_new_leaf): New constructor for derivations with no
children.
* src/counterexample.c, src/parse-simulation.c,
* src/parse-simulation.h: Replace uses of gl_list_t containing
derivations with derivation_list and its API.
Replace calls of dervation_new using null children with
derivation_new_leaf.
* src/parse-simulation.c: replace ps_chunk and its API with typed
versions si_chunk and deriv_chunk.
* src/parse-simlation.h, src/parse-simulation.c: Remove
parse_state_retain_deriv in favor of derivation reference counting.
* src/counterexample.c: Remove search_state_retain_deriv.
2020-05-22 08:45:44 +02:00
Akim Demaille
fc39ccab6b cex: style changes in parse-simulation
* src/parse-simulation.c: Formatting changes.
(parse_state_list_new): New.
Use it.
2020-05-22 08:45:44 +02:00
Akim Demaille
9a33fb9317 cex: style: prefer res for returned value
* src/lssi.c, src/parse-simulation.c: here.
2020-05-22 08:45:44 +02:00