Commit Graph

916 Commits

Author SHA1 Message Date
Akim Demaille
b5aee13b82 doc: fix typo
Reported by Kaz Kylheku.
https://lists.gnu.org/r/bison-patches/2020-11/msg00019.html

* doc/bison.texi (Versioning): here.
2020-11-07 07:55:12 +01:00
Adela Vais
660f3d4732 d: doc: add D Action Features section
* doc/bison.texi (D Action Features section): New.
2020-11-07 07:55:12 +01:00
Kaz Kylheku
fa8aca1ed4 doc: document best deployment practices.
* doc/bison.texi (Versioning): New node about practices
regarding dealing with multiple versions of Bison.
2020-11-05 06:04:23 +01:00
Akim Demaille
829ac9caed java: lac: more tests, and some doc
* doc/bison.texi: C++ and Java support LAC.
* tests/input.at (LAC: Errors for %define): Generalize the test, and
apply it to Java.
2020-11-04 07:28:13 +01:00
Akim Demaille
57848d9262 doc: fix incorrect section title
Reported by Gaurav Singh <gaurav.singh199709@yahoo.com>.
https://lists.gnu.org/r/bug-bison/2020-11/msg00000.html

* doc/bison.texi (Rpcalc Expr): Rename as...
(Rpcalc Exp): this, as the nterm is named 'exp'.
2020-11-01 09:15:24 +01:00
Nick Gasson
8d7cd5e84d doc: minor grammar fixes in counterexamples section
* doc/bison.texi: Minor fixes in counterexamples section.
2020-10-28 06:33:40 +01:00
Adela Vais
0cd16ae964 d: create the Parser.Context class
This will provide the user an interface for creating custom error messages.

* data/skeletons/lalr1.d: Add the Context class.
* doc/bison.texi: Document it.
2020-10-27 07:39:00 +01:00
Akim Demaille
2347e959d4 doc: D comes before Java in alphabetical order
* doc/bison.texi: Keep languages sorted.
2020-10-07 06:29:24 +02:00
Adela Vais
7cd195b30a d: change api.token.raw default value to true
Generate consecutive values for enum TokenKind, as D's yylex()
returns TokenKind and collisions can't happen.

* data/skeletons/d.m4: Change default value.
* tests/scanner.at, tests/d.at: Check it.
2020-10-03 17:17:32 +02:00
Adela Vais
72360b51a5 d: document support
* doc/bison.texi: Various fixes.
(D Parsers): New section.
2020-10-02 06:46:32 +02:00
Adela Vais
4bbda69f1e d: remove the default prefix for SymbolKind's enum elements
This is not needed in D, since the kinds are "scoped".

* data/skeletons/d.m4: Remove the default prefix.
* doc/bison.text: Document it.
2020-10-02 06:46:32 +02:00
Akim Demaille
b327f38832 deprecate %defines in favor of %header
This is consistent with --defines being deprecated in favor of
--header.  The directive %defines is also too similar to %define.
And %header matches nicely with api.header.name.

* src/scan-gram.l (%defines): Deprecate to %header.
(%header): Scan it.
* src/parse-gram.y (PERCENT_DEFINES): Replace with...
(PERCENT_HEADER): this.
* data/skeletons/lalr1.java
* doc/bison.texi
* tests/actions.at, tests/c++.at, tests/calc.at, tests/conflicts.at,
* tests/input.at, tests/java.at, tests/local.at, tests/output.at,
* tests/synclines.at, tests/types.at:
Convert most tests to check %header instead of %defines.
2020-09-19 17:49:03 +02:00
Akim Demaille
75c3746ce2 options: rename --defines as --header
The name "defines" is incorrect, the generated file contains far more
than just #defines.

* src/getargs.h, src/getargs.c (-H, --header): New option.
With optional argument, just like --defines, --xml, etc.
(defines_flag): Rename as...
(header_flag): this.
Adjust dependencies.
* data/skeletons/bison.m4, data/skeletons/c.m4, data/skeletons/glr.c,
* data/skeletons/glr.cc, data/skeletons/glr2.cc, data/skeletons/lalr1.cc,
* data/skeletons/yacc.c:
Adjust.
* examples, doc/bison.texi: Adjust.
* tests/headers.at, tests/local.at, tests/output.at: Convert most
tests from using --defines to using --header.
2020-09-19 08:31:49 +02:00
Akim Demaille
5d711972b8 Merge branch 'maint' (i.e., Bison 3.7.2)
* upstream/maint:
  maint: post-release administrivia
  version 3.7.2
  build: disable syntax-check warning
  gnulib: update
  build: fix incorrect dependencies
  doc: updates
  gnulib: update
  tests: beware of sed portability issues
2020-09-06 13:19:03 +02:00
Akim Demaille
f7b642cff7 build: fix incorrect dependencies
Commit af000bab11 ("doc: work around
Texinfo 6.7 bug"), published in 3.4.91, added a dependency on the
"all" target.

This is a super bad idea, since "make all" will run this
target *before* "all", which builds bison.  It turns out that this new
dependency actually needed bison to be built.  So all the regular
process (i) build $(BUILT_SOURCES) and then (ii) build bison, was
wrecked since some of the $(BUILT_SOURCES) depended on bison...

It was "easy" to see in the logs of "make V=1" because we were
building bison files (such as src/files.o) *before* displaying the
banner for "all-recursive".  With this fix, we finally get again the
proper sequence:

    rm -f examples/c/reccalc/scan.stamp examples/c/reccalc/scan.stamp.tmp
    /opt/local/libexec/gnubin/mkdir -p examples/c/reccalc
    touch examples/c/reccalc/scan.stamp.tmp
    flex   -oexamples/c/reccalc/scan.c --header=examples/c/reccalc/scan.h ./examples/c/reccalc/scan.l
    mv examples/c/reccalc/scan.stamp.tmp examples/c/reccalc/scan.stamp
    rm -f lib/fcntl.h-t lib/fcntl.h && \
    { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
      ...
    } > lib/fcntl.h-t && \
    mv lib/fcntl.h-t lib/fcntl.h
    ...
    mv -f lib/alloca.h-t lib/alloca.h
    make  all-recursive

Reported by Mingli Yu <mingli.yu@windriver.com>.
https://github.com/akimd/bison/issues/31
https://lists.gnu.org/r/bison-patches/2020-05/msg00055.html

Reported by Claudio Calvelli <bugb@w42.org>.
https://lists.gnu.org/r/bug-bison/2020-09/msg00001.html
https://bugs.gentoo.org/716516

* doc/local.mk (all): Rename as...
(all-local): this.
So that we don't compete with BUILT_SOURCES.
2020-09-05 17:42:20 +02:00
Akim Demaille
0d8407440c doc: simplify the extraction of example snippets
* doc/bison.texi: Use qualified paths.
* examples/extexi: Comment changes.
2020-09-05 09:19:39 +02:00
Akim Demaille
325ec7d324 cex: always show ε/%empty in counterexamples
On a case such as
    %%
    exp
    : empty "a"
    | "a" empty

    empty
    : %empty

we used to display

    warning: shift/reduce conflict on token "a" [-Wcounterexamples]
    Example: • "a"
    Shift derivation
      exp
      ↳ 2: • "a" empty
                 ↳ 2: ε
    Example: • "a"
    Reduce derivation
      exp
      ↳ 1: empty  "a"
           ↳ 3: •

where the shift derivation shows an item "2: empty → ε", with an
explicit "ε", but the reduce derivation shows "3: empty → •", without
"ε".

For consistency, let's always show ε/%empty in rules with an empty
rhs:

    Reduce derivation
      exp
      ↳ 1: empty    "a"
           ↳ 3: ε •

* src/derivation.c (derivation_width, derivation_print_tree_impl):
Always show ε/%empty in counterexamples.
* tests/diagnostics.at: Check that case.
* tests/conflicts.at, tests/counterexample.at: Adjust.
2020-09-02 07:31:55 +02:00
Akim Demaille
3c36d871fa cex: display the rule numbers
From

    Example: "if" expr "then" "if" expr "then" stmt • "else" stmt
    Shift derivation
      if_stmt
      ↳ "if" expr "then" stmt
                         ↳ if_stmt
                           ↳ "if" expr "then" stmt • "else" stmt
    Reduce derivation
      if_stmt
      ↳ "if" expr "then" stmt                        "else" stmt
                         ↳ if_stmt
                           ↳ "if" expr "then" stmt •

to

    Example: "if" expr "then" "if" expr "then" stmt • "else" stmt
    Shift derivation
      if_stmt
      ↳ 3: "if" expr "then" stmt
                            ↳ 2: if_stmt
                                 ↳ 4: "if" expr "then" stmt • "else" stmt
    Example: "if" expr "then" "if" expr "then" stmt • "else" stmt
    Reduce derivation
      if_stmt
      ↳ 4: "if" expr "then" stmt                              "else" stmt
                            ↳ 2: if_stmt
                                 ↳ 3: "if" expr "then" stmt •

* src/state-item.h, src/state-item.c (state_item_rule): New.
* src/derivation.h, src/derivation.c (struct derivation): Add a rule
member.
Adjust dependencies.
* src/counterexample.c, src/parse-simulation.c: Pass the rule to
derivation_new.
* src/derivation.c (fprintf_if): New.
(derivation_width, derivation_print_tree_impl): Take the rule number
into account.

* tests/conflicts.at, tests/counterexample.at, tests/diagnostics.at,
* tests/report.at: Adjust.

* doc/bison.texi: Adjust.
2020-08-30 19:20:49 +02:00
Akim Demaille
0522047c96 doc: history of api.prefix
Reported by Matthew Fernandez <matthew.fernandez@gmail.com>.
https://lists.gnu.org/r/help-bison/2020-08/msg00015.html

* doc/bison.texi (api.prefix): We move to {} in 3.0.
2020-08-30 09:29:00 +02:00
Akim Demaille
6accee7716 doc: refer to cex from sections dealing with conflicts
The documentation about -Wcex should be put forward.

* doc/bison.texi: Refer to -Wcex from the sections about conflicts.
2020-07-28 07:45:07 +02:00
Akim Demaille
e63f22703e doc: factor ifnottex/iftex examples
* doc/bison.texi: Factor the common bits out of ifnottex/iftex.
2020-07-28 07:45:07 +02:00
Akim Demaille
fa390dc311 doc: fix colors
The original Texinfo macros introducing colors were made for
diagnostics, which are printed in bold.  So by copy-paste accident the
styles we introduced for counterexamples were also in bold.  They
should not.

* doc/bison.texi: Separate the styling of diagnostics from the styling
for counterexamples.
Don't use bold in the latter case.
2020-07-28 07:45:07 +02:00
Akim Demaille
17fdf5eca2 doc: fixes
* doc/bison.texi: Fix spello.
Fix missing colors, and factor.
2020-07-28 07:45:07 +02:00
Akim Demaille
79e68b6c4d doc: fix definition of -Wall
* doc/bison.texi (Diagnostics): here.
2020-07-23 09:17:18 +02:00
Akim Demaille
7d5474e979 doc: catch up with the current display of cex
Unfortunately I found no way to use the ↳ glyph in Texinfo, so I used
@arrow{} instead, which has a different width, so we have to have all
the examples doubled, once for TeX, another for the rest of the world.

* doc/bison.texi: Use the current display in the examples.
* doc/calc.y, doc/ids.y, doc/if-then-else.y, doc/sequence.y: New.
2020-07-22 07:36:02 +02:00
Akim Demaille
01f3e2969b doc: add anchors for warnings
Unfortunately Texinfo somewhat mangles anchors such as `-Werror` into
`g_t_002dWerror`, so let's not include the dash.

* doc/bison.texi (Diagnostics): here.
2020-07-19 17:28:45 +02:00
Akim Demaille
88bd814bf1 doc: update GLR sections
Reported by Christian Schoenebeck.

* doc/bison.texi (GLR Parsers): Minor fixes.
(Compiler Requirements for GLR): Remove, quite useless today.
2020-07-14 06:56:15 +02:00
Akim Demaille
4f9ae5de07 cex: display shifts before reductions
When reporting counterexamples for s/r conflicts, put the shift first.
This is more natural, and displays the default resolution first, which
is also what happens for r/r conflicts where the smallest rule number
is displayed first, and "wins".

* src/counterexample.c (counterexample): Add a shift_reduce member.
(new_counterexample): Adjust.
Swap the derivations when this is a s/r conflict.
(print_counterexample): For s/r conflicts, prefer "Shift derivation"
and "Reduce derivation" rather than "First/Second derivation".

* tests/conflicts.at, tests/counterexample.at, tests/report.at: Adjust.
* NEWS, doc/bison.texi: Ditto.
2020-07-14 06:48:48 +02:00
Akim Demaille
121dd98508 doc: makeinfo wants @arrow{}, not @arrow
* doc/bison.texi: here.
2020-07-12 08:15:44 +02:00
Akim Demaille
ee86ea8839 cex: prefer → to ::=
It does not make a lot of sense to use ::= in our counterexamples,
that's not something that belongs to the Bison "vocabulary".  Using
the colon makes sense, but it's too discreet.  Let's use the arrow,
which we already use in some reports (HTML and Dot).

* src/gram.h (print_dot_fallback): Generalize into...
(print_fallback): this.
(print_arrow): New.
* src/derivation.c: Use it.

* NEWS, tests/conflicts.at, tests/counterexample.at,
* tests/diagnostics.at, tests/report.at: Adjust.
* doc/bison.texi: Ditto.
Unfortunately the literal `→` is output as `↦`.  So we need to use
@arrow.
2020-07-11 18:43:46 +02:00
Akim Demaille
70fb574717 examples: add license headers
Prompted by Rici Lake.
https://stackoverflow.com/questions/62658368/#comment110853985_62661621
Discussed with Paul Eggert.

* doc/bison.texi, examples/c/bistromathic/parse.y,
* examples/c/lexcalc/parse.y, examples/c/lexcalc/scan.l,
* examples/c/pushcalc/calc.y, examples/c/reccalc/parse.y,
* examples/c/reccalc/scan.l, examples/d/calc.y,
* examples/java/calc/Calc.y, examples/java/simple/Calc.y:
Install the GPL3+ header.
2020-07-08 22:19:37 +02:00
Akim Demaille
156e548341 cex: give more details about -Wcex and -rcex
* data/bison-default.css: Cobalt does not seem to be supported.
* doc/bison.texi (Counterexamples): A new section.
(Understanding): Show the counterexamples as it shows in the report:
with its items.
(Bison Options): Document -Wcex and -rcex.
2020-07-04 11:43:35 +02:00
Akim Demaille
d7f7fcd9c7 dot: also use a dot in the output
* src/print-graph.c (print_core): Use a dot instead of a point.
* doc/figs/example-reduce.gv, doc/figs/example-reduce.txt,
* doc/figs/example-shift.gv, doc/figs/example-shift.txt,
* doc/figs/example.gv: Update.
* tests/output.at, tests/report.at: Adjust.
2020-07-03 06:51:57 +02:00
Akim Demaille
0fd542c3e0 doc: improve a sentence
* doc/bison.texi: here.
2020-07-02 07:21:33 +02:00
Akim Demaille
5234c8390f doc: clarify that the pcontext interface is *.c only
Reported by Rici Lake.
https://lists.gnu.org/r/bug-bison/2020-06/msg00054.html

* doc/bison.texi (Syntax Error Reporting Function): Make it clear that
this is not exported.
Remove C++ details that landed in the C doc.
2020-06-30 20:16:31 +02:00
Akim Demaille
21f7690570 doc: use color in the cex examples
* doc/bison.texi: here.
And use smallexample when it no longer fits in PDF.
2020-06-30 20:16:31 +02:00
Akim Demaille
edb39c29a2 doc: repair the references to the Bibliography
In commit c80cdf2db2 ("doc: simplify
uses of @ref", Jan 27 2020, released in Bison 3.6), I broke the
references to the Bibliography.  For instance:

     For a more detailed exposition of the mysterious behavior in LALR parsers
    -and the benefits of IELR, @pxref{Bibliography,,Denny 2008 March}, and
    -@ref{Bibliography,,Denny 2010 November}.
    +and the benefits of IELR, @pxref{Bibliography}, and
    +@ref{Bibliography}.

which results in "see Bibliography" twice, instead of the more precise
reference.

* doc/bison.texi (@pcite, @tcite): New.
Use them instead of @ref to Bibliography.
Cite only the first author (that's what we did for the other entries).
2020-06-30 08:01:40 +02:00
Vincent Imbimbo
1247d94ba6 doc: cex documentation
* NEWS, doc/bison.texi: Add documentation for conflict counterexample
generation.
2020-06-30 08:01:40 +02:00
Akim Demaille
ed9a821caa doc: update Doxygen template file
* doc/Doxyfile.in: here.
2020-06-30 08:01:40 +02:00
Akim Demaille
330552ea49 yacc.c: push: don't clear the parser state when accepting/rejecting
Currently when a push parser finishes its parsing (i.e., it did not
return YYPUSH_MORE), it also clears its state.  It is therefore
impossible to see if it had parse errors.

In the context of autocompletion, because error recovery might have
fired, the parser is actually already in a different state.  For
instance on `(1 + + <TAB>` in the bistromathic, because there's a
`exp: "(" error ")"` recovery rule, `1 + +` tokens have already been
popped, replaced by `error`, and autocompletions think we are ready
for the closing ")".  So here, we would like to see if there was a
syntax error, yet `yynerrs` was cleared.

In the case of a successful parse, we still have a problem: if error
recovery succeeded, we won't know it, since, again, `yynerrs` is
clearer.

It seems much more natural to leave the parser state available for
analysis when there is a failure.

To reuse the parser, we should either:

1. provide an explicit means to reinitialize a parser state for future
   parses.

2. automatically reset the parser state when it is used in a new
   parse.

Option 2 requires to check whether we need to reinitialize the parser
each time we call `yypush_parse`, i.e., each time we give a new token.
This seems expensive compared to Option 1, but benchmarks revealed no
difference.  Option 1 is incompatible with the documentation
("After `yypush_parse` returns a status other than `YYPUSH_MORE`, the
parser instance `yyps` may be reused for a new parse.").

So Option 2 wins, reusing the private `yynew` member to record that a
parse was finished, and therefore that the state must reset in the
next call to `yypull_parse`.

While at it, this implementation now reuses the previously enlarged
stacks from one parse to another.

* data/skeletons/yacc.c (yypstate_new): Set up the stacks in their
initial configurations (setting their bottom to the stack array), and
use yypstate_clear to reset them (moving their top to their bottom).
(yypstate_delete): Adjust.
(yypush_parse): At the beginning, clear yypstate if needed, and at the
end, record when yypstate needs to be clearer.

* examples/c/bistromathic/parse.y (expected_tokens): Do not propose
autocompletion when there are parse errors.
* examples/c/bistromathic/bistromathic.test: Check that case.
2020-06-29 19:36:41 +02:00
Akim Demaille
e0b0a67b86 java: rename package as api.package
* data/skeletons/lalr1.java: here.
* doc/bison.texi: Update.
* src/muscle-tab.c: Ensure backward compat.
* tests/java.at: Check it.
2020-06-28 09:49:00 +02:00
Akim Demaille
0895858d8e style: use 'nonterminal' consistently
* doc/bison.texi: Formatting changes.
* src/gram.h, src/gram.c (nvars): Rename as...
(nnterms): this.
Adjust dependencies.
(section): New.  Use it.
Replace "non terminal" and "non-terminal" by "nonterminal".
2020-06-27 11:39:32 +02:00
Akim Demaille
4efb2f7bd2 doc: parse.assert in C++ requires RTTI
* doc/bison.texi (%define Summary): Say it.
2020-06-27 10:31:59 +02:00
Akim Demaille
eeafc706e8 c++: by default, use const std::string for file names
Reported by Martin Blais and Yuriy Solodkyy.
https://lists.gnu.org/r/help-bison/2020-05/msg00011.html
https://lists.gnu.org/r/bug-bison/2020-06/msg00038.html

While at it, modernize filename_type as api.filename.type and document
it properly.

* data/skeletons/c++.m4 (filename_type): Rename as...
(api.filename.type): this.
Default to const std::string.
* data/skeletons/location.cc (position, location): Expose the
filename_type type.
Use api.filename.type.
* doc/bison.texi (%define Summary): Document api.filename.type.
(C++ Location Values): Document position::filename_type.
* src/muscle-tab.c (muscle_percent_variable_update): Ensure backward
compatibility.
* tests/c++.at: Check that using const file names is ok.
tests/input.at: Check backward compat.
2020-06-27 10:06:00 +02:00
Akim Demaille
c4b1a2b68f doc: use dot/'•' rather than point/'.'
AFAICT, "dotted rule" is a more frequent synonym of "item" than
"pointed rule".  So let's migrate to using "dot" only.

* doc/bison.texi: Use dot/'•' rather than point/'.'.

* src/print-xml.c (print_core): Use dot rather than point.  This is
not backward compatible, but AFAICT, we don't have actual user of the
XML output (but ourselves).  So...
* data/xslt/xml2dot.xsl, data/xslt/xml2text.xsl,
* data/xslt/xml2xhtml.xsl, tests/report.at: ... adjust.
2020-06-23 07:37:29 +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
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
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
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
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