Commit Graph

6145 Commits

Author SHA1 Message Date
Akim Demaille
05b70f47e8 style: prefer bool to char
* src/state.h, src/state.c (state::consistent): Make it a bool.
Adjust dependencies.
2019-01-20 18:31:41 +01:00
Akim Demaille
626d2f2dca glr.cc: be more alike lalr1.cc 2019-01-20 17:35:15 +01:00
Akim Demaille
5c797b1627 style: formatting changes
* data/skeletons/c++.m4: Un-remove an end-of-line.
2019-01-20 08:56:14 +01:00
Akim Demaille
ac692b572a NEWS: fixes 2019-01-20 08:25:31 +01:00
Akim Demaille
2f208ee43a maint: post-release administrivia
* NEWS: Add header line for next release.
* .prev-version: Record previous version.
* cfg.mk (old_NEWS_hash): Auto-update.
2019-01-19 07:38:00 +01:00
Akim Demaille
013a695add version 3.2.91
* NEWS: Record release date.
v3.2.91
2019-01-19 07:25:25 +01:00
Akim Demaille
54ed577da0 style: various fixes
Some reported by syntax-check.

* po/POTFILES.in: Add fixits.cc.
* src/muscle-tab.c: Don't cast for free.
* src/files.c: Reduce scopes.
* cfg.mk: We need the cast for free in muscle_percent_define_insert.
2019-01-18 08:43:06 +01:00
Akim Demaille
4a690d3d19 doc: document -ffixit and --update
* doc/bison.texi (Bison Options): here.
2019-01-18 06:55:01 +01:00
Akim Demaille
cd1a9f076c doc: style fixes
* doc/bison.texi: Use @kbd where appropriate.
Update ^~~~ marks for caret-errors.
* build-aux/cross-options.pl: Do not add quotes to %define's argument.
2019-01-18 06:55:01 +01:00
Akim Demaille
7a0f681cb8 NEWS: update for fixits and --update 2019-01-18 06:55:01 +01:00
Akim Demaille
eb0f3e79e0 fixits: handle duplicates of %name-prefix
The test case "Deprecated directives" (currently 56) no longer emits
warnings after 'bison -u'!

* src/files.h, src/files.c (spec_name_prefix_loc): New.
* src/parse-gram.y (handle_name_prefix): Emit fixits for duplicate
%name-prefix.
* tests/input.at (Deprecated directives): Adjust.
2019-01-17 18:09:38 +01:00
Akim Demaille
25b7421c40 regen 2019-01-17 18:09:38 +01:00
Akim Demaille
e86adac52d fixits: handle %file-prefix
* src/files.h, src/files.c (spec_file_prefix_loc): New.
* src/scan-gram.l (%file-prefix): Delegate diagnostics to...
* src/parse-gram.y (handle_file_prefix): here.
* src/complain.c (duplicate_directive): Quote the directive.
* tests/input.at: Adjust.
2019-01-17 18:09:38 +01:00
Akim Demaille
5879c8dc5a fixits: handle per-rule duplicates
* src/complain.c (duplicate_rule_directive): Here.
* tests/actions.at (Invalid uses of %empty): Check it.
2019-01-17 18:09:38 +01:00
Akim Demaille
d5d148630a fixits: fix warnings about duplicates
* src/complain.c (duplicate_directive): Fix the complaint level.
* tests/input.at: Adjust.
2019-01-17 18:09:32 +01:00
Akim Demaille
b443932991 diagnostics: properly indent the "previous declaration" message
* src/complain.c (duplicate_directive, duplicate_rule_directive):
Here.
2019-01-16 08:40:47 +01:00
Akim Demaille
f5a646c390 regen 2019-01-16 08:40:47 +01:00
Akim Demaille
f038f0b12f style: rename some functions for consistency
"handle_" is the prefix used in scan-code.l for instance.

* src/parse-gram.y (do_error_verbose, do_name_prefix, do_require)
(do_skeleton, do_yacc):
Rename as...
(handle_error_verbose, handle_name_prefix, handle_require)
(handle_skeleton, handle_yacc):
these.
2019-01-16 08:40:47 +01:00
Akim Demaille
b6b397b7f0 fixits: report duplicate %yacc directives
We should use -ffixit and --update to clean files with duplicate
directives.  And we should complain only once about duplicate obsolete
directives: keep only the "duplicate" warning.  Let's start with %yacc.

For instance on:

    %fixed-output_files
    %fixed-output-files
    %yacc
    %%
    exp:

This run of bison:

    $ bison /tmp/foo.y -u
    foo.y:1.1-19: warning: deprecated directive, use '%fixed-output-files' [-Wdeprecated]
     %fixed-output_files
     ^~~~~~~~~~~~~~~~~~~
    foo.y:2.1-19: warning: duplicate directive [-Wother]
     %fixed-output-files
     ^~~~~~~~~~~~~~~~~~~
    foo.y:1.1-19: previous declaration
     %fixed-output_files
     ^~~~~~~~~~~~~~~~~~~
    foo.y:3.1-5: warning: duplicate directive [-Wother]
     %yacc
     ^~~~~
    foo.y:1.1-19: previous declaration
     %fixed-output_files
     ^~~~~~~~~~~~~~~~~~~
    bison: file 'foo.y' was updated (backup: 'foo.y~')

gives:

    %fixed-output-files
    %%
    exp:

* src/location.h, src/location.c (location_empty): New.
* src/complain.h, src/complain.c (duplicate_directive): New.

* src/getargs.h, src/getargs.c (yacc_flag): Instead of a Boolean, be
the location of the definition.
Update dependencies.

* src/scan-gram.l (%yacc, %fixed-output-files): Move the handling of
its warnings to...
* src/parse-gram.y (do_yacc): This new function.

* tests/input.at (Deprecated Directives): Adjust expectations.
2019-01-16 08:40:39 +01:00
Akim Demaille
2c8fb4d126 style: rename duplicate_directive as duplicate_rule_directive
* src/complain.h, src/complain.c: here.
Adjust callers.
2019-01-16 07:59:25 +01:00
Akim Demaille
169fe80c7f fixits: suggest running --update if there are fixits
* src/fixits.h, src/fixits.c (fixits_empty): New.
* src/complain.c (deprecated_directive): Register the Wdeprecated
fixits only if -Wdeprecated was enabled, so that we don't apply
updates if the user didn't ask for them.
* src/main.c (main): If there were fixits, issue a warning suggesting
running with --update.
Free uniqstrs after the fixits, since the latter use the former.
* tests/headers.at, tests/input.at: Update expectations.
2019-01-16 07:59:16 +01:00
Akim Demaille
b7e0d3131d fixits: avoid generating empty lines
* src/fixits.c (fixits_run): If erase the content of a line, also
erase the following \n.
* tests/input.at (Deprecated directives): Update expectations.
2019-01-16 06:55:47 +01:00
Akim Demaille
a634aad9e6 configure: don't try to run C++ warnings on C
Reported by Derek Clegg.
https://lists.gnu.org/archive/html/bison-patches/2019-01/msg00066.html

* configure.ac: here.
2019-01-15 20:43:27 +01:00
Akim Demaille
ad326ada91 c, c++: avoid implicit fall-throw
Reported by Derek Clegg.
http://lists.gnu.org/archive/html/bug-bison/2019-01/msg00004.html

* configure.ac (warn_common): Add -Wimplicit-fallthrough.
This does trigger failures in the test suite.
* data/skeletons/glr.c, data/skeletons/lalr1.cc,
* data/skeletons/yacc.c, tests/c++.at:
Make fall-throws explicit.
2019-01-15 18:07:00 +01:00
Akim Demaille
a049509d04 c++: avoid -Wundefined-func-template warnings from clang
Reported by Derek Clegg.
http://lists.gnu.org/archive/html/bug-bison/2019-01/msg00006.html

Clang does not like this:

    template <typename D>
    struct basic_symbol : D
    {
      basic_symbol();
    };

    struct by_type {};

    struct symbol_type : basic_symbol<by_type>
    {
      symbol_type(){}
    };

It gives:

    $ clang++-mp-7.0 -Wundefined-func-template foo.cc -c
    foo.cc:11:3: warning: instantiation of function 'basic_symbol<by_type>::basic_symbol'
                 required here, but no definition is available [-Wundefined-func-template]
      symbol_type(){}
      ^
    foo.cc:4:3: note: forward declaration of template entity is here
      basic_symbol();
      ^
    foo.cc:11:3: note: add an explicit instantiation declaration to suppress this warning
                 if 'basic_symbol<by_type>::basic_symbol' is explicitly instantiated in
                 another translation unit
      symbol_type(){}
      ^
    1 warning generated.

The same applies for the basic_symbol's destructor and `clear()`.

* configure.ac (warn_cxx): Add -Wundefined-func-template.
This triggered one failure in the test suite:
* tests/headers.at (Sane headers): here, where we check that we can
compile the generated headers in other compilation units than the
parser's.
Add a variant type to make sure that basic_symbol and symbol_type are
properly generated in this case.
* data/skeletons/c++.m4 (basic_symbol): Inline the definitions of the
destructor and of `clear` in the class definition.
2019-01-15 07:10:29 +01:00
Akim Demaille
7c5e508b39 Revert the last two commits
They should not have been pushed, sorry about that.

This reverts
- commit 8575bd06ae.
- commit 55bf52860e.
2019-01-14 20:04:38 +01:00
Akim Demaille
55bf52860e c++: avoid warnings about extraneous semi-colons
Reported by Derek Clegg.

* configure.ac (warn_common): Add -Wextra-semi.
* data/skeletons/c++.m4: Remove extraneous semi-colon.
2019-01-14 19:57:37 +01:00
Akim Demaille
8575bd06ae WIP 2019-01-14 19:57:37 +01:00
Akim Demaille
7c63cc1f6b diagnostics: add fixit support for duplicate removal
* src/muscle-tab.c (muscle_percent_define_insert): Register a fixit
for duplicate removal.
* tests/input.at: Adjust expectations.
2019-01-14 19:57:37 +01:00
Akim Demaille
4a41a8ec51 regen 2019-01-14 19:57:37 +01:00
Akim Demaille
ba469451d8 diagnostics: improve the accuracy for %error-verbose
Avoid duplicate warnings about %error-verbose, once for deprecation,
another for duplicate.  Keep only the duplicate warning for the second
occurrence of %error-verbose.

This will help removal fixits.

* src/scan-gram.l (%error-verbose): Return as a PERCENT_ERROR_VERBOSE
token.
* src/parse-gram.y (do_error_verbose): New.
Use it.
* src/muscle-tab.c (muscle_percent_variable_update): Handle pseudo
variables such as %error-verbose.
2019-01-14 19:57:37 +01:00
Akim Demaille
8580b268c3 diagnostics: avoid duplicate warnings for deprecated directives
Currently, on

    %define parser_class_name "Parser"
    %define parser_class_name "Parser"
    %%
    exp:;

we issue:

    foo.y:1.9-25: warning: deprecated directive, use '%define api.parser.class {Parser}' [-Wdeprecated]
     %define parser_class_name "Parser"
             ^~~~~~~~~~~~~~~~~
    foo.y:2.9-25: warning: deprecated directive, use '%define api.parser.class {Parser}' [-Wdeprecated]
     %define parser_class_name "Parser"
             ^~~~~~~~~~~~~~~~~
    foo.y:2.9-25: error: %define variable 'api.parser.class' redefined
     %define parser_class_name "Parser"
             ^~~~~~~~~~~~~~~~~
    foo.y:1.9-25:     previous definition
     %define parser_class_name "Parser"
             ^~~~~~~~~~~~~~~~~

Let's get rid of the second warning about the deprecated variable
parser_class_name.  This is noise, but it will also be a problem with
fixits for removing duplicates, as we will first generate the update,
and then it's too late to remove it: fixits do not edit the result of
previous fixits.

So generate this instead:

    foo.y:1.1-34: warning: deprecated directive, use '%define api.parser.class {Parser}' [-Wdeprecated]
     %define parser_class_name "Parser"
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    foo.y:2.1-34: error: %define variable 'api.parser.class' redefined
     %define parser_class_name "Parser"
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    foo.y:1.1-34:     previous definition
     %define parser_class_name "Parser"
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

* src/muscle-tab.c (muscle_percent_variable_update): Pass the warning
to the caller, instead of issuing it.
(muscle_percent_define_insert): Issue this warning only if we don't
have to complain about a duplicate definition.
* tests/input.at: Adjust expectations.
2019-01-14 19:57:37 +01:00
Akim Demaille
41aaa8374c diagnostics: update the grammar file
Let's use the fixits to actually update the grammar files.

* src/getargs.h, src/getargs.c (update_flag): New.
* src/fixits.h, src/fixits.c (fixits_run): New.
* src/main.c (main): Invoke fixits_run when --update is passed.
* tests/input.at (Deprecated directives): Check --update.
2019-01-14 19:57:37 +01:00
Akim Demaille
79e79be298 diagnostics: improve accuracy for deprecated %define variables
* src/parse-gram.y: Use the location of the whole definition to record
the location of a %define variable, instead of just the name of the
variable.
Adjust tests.
2019-01-14 19:57:37 +01:00
Akim Demaille
ffe2e4aaec diagnostics: keep the fixits
Introduce proper support for fixits, instead of just printing them on
demand.

* bootstrap.conf: We need gnulib's xlists.
* src/fixits.h, src/fixits.c: New.
* src/complain.c (deprecated_directive): Use fixits_register.
* src/main.c (main): Use fixits_free.
2019-01-14 19:57:37 +01:00
Akim Demaille
dad14ec3e4 diagnostics: add -ffixit support for deprecated features
Issue directives for IDE/editors to fix the source file.
http://clang.llvm.org/docs/UsersManual.html#cmdoption-fdiagnostics-parseable-fixits

Do it for deprecated features.  For instance:

    $ cat foo.y
    %error-verbose

    %name-prefix = "foo"
    %name-prefix="bar"
    %define parser_class_name "Parser"

    %%
    exp:;

    $ LC_ALL=C ./_build/8d/tests/bison -ffixit /tmp/foo.yy
    /tmp/foo.yy:1.1-14: warning: deprecated directive, use '%define parse.error verbose' [-Wdeprecated]
     %error-verbose
     ^^^^^^^^^^^^^^
    fix-it:"/tmp/foo.yy":{1:1-1:15}:"%define parse.error verbose"
    /tmp/foo.yy:3.1-20: warning: deprecated directive, use '%define api.prefix {foo}' [-Wdeprecated]
     %name-prefix = "foo"
     ^^^^^^^^^^^^^^^^^^^^
    fix-it:"/tmp/foo.yy":{3:1-3:21}:"%define api.prefix {foo}"
    /tmp/foo.yy:4.1-18: warning: deprecated directive, use '%define api.prefix {bar}' [-Wdeprecated]
     %name-prefix="bar"
     ^^^^^^^^^^^^^^^^^^
    fix-it:"/tmp/foo.yy":{4:1-4:19}:"%define api.prefix {bar}"
    /tmp/foo.yy:5.9-25: warning: deprecated directive, use '%define api.parser.class {Parser}' [-Wdeprecated]
     %define parser_class_name "Parser"
             ^^^^^^^^^^^^^^^^^
    fix-it:"/tmp/foo.yy":{5:9-5:26}:"%define api.parser.class {Parser}"
    /tmp/foo.yy:5.9-25: error: %define variable 'api.parser.class' is not used
     %define parser_class_name "Parser"
             ^^^^^^^^^^^^^^^^^

* src/getargs.h, src/getargs.c (feature_fixit_parsable): New.
(feature_types, feature_args): Use it.
* src/complain.c (deprecated_directive): Use it.

* tests/input.at: Check it.
2019-01-14 19:57:37 +01:00
Akim Demaille
a7ff1c75be diagnostics: prefer ^~~~ to ^^^^ to underline code
That's what both GCC and Clang do, and it is indeed much nicer to
read.  From:

    foo.y:1.1-14: warning: deprecated directive, use '%define parse.error verbose' [-Wdeprecated]
     %error-verbose
     ^^^^^^^^^^^^^^
    foo.y:4.1-20: warning: deprecated directive, use '%define api.prefix {foo}' [-Wdeprecated]
     %name-prefix = "foo"
     ^^^^^^^^^^^^^^^^^^^^

to:

    foo.y:1.1-14: warning: deprecated directive, use '%define parse.error verbose' [-Wdeprecated]
     %error-verbose
     ^~~~~~~~~~~~~~
    foo.y:4.1-20: warning: deprecated directive, use '%define api.prefix {foo}' [-Wdeprecated]
     %name-prefix = "foo"
     ^~~~~~~~~~~~~~~~~~~~

* src/location.c (location_caret): Use ^~~~.
Adjust tests expectations.
2019-01-14 19:57:37 +01:00
Akim Demaille
8c3a7687e4 regen 2019-01-14 19:57:37 +01:00
Akim Demaille
72c488aa62 diagnostics: improve them for %name-prefix
Currently the diagnostics for %name-prefix are not precise enough.  In
particular, they does not show that braces must be used instead of
quotes.

Before:

    foo.y:3.1-14: warning: deprecated directive, use '%define api.prefix' [-Wdeprecated]
     %name-prefix = "foo"
     ^^^^^^^^^^^^^^

After:

    foo.y:3.1-20: warning: deprecated directive, use '%define api.prefix {foo}' [-Wdeprecated]
     %name-prefix = "foo"
     ^^^^^^^^^^^^^^^^^^^^

To do this we need the value passed to %name-prefix, so move the
warning from the scanner to the parser.

Accuracy will be very important for the forthcoming changes.

* src/parse-gram.y (do_name_prefix): New.
(PERCENT_NAME_PREFIX): Have a semantic value: the raw source, with
possibly underscores, equal sign, and spaces.  This is used to provide
a more accurate message.  It does not take comments into account,
but...
* src/scan-gram.l (%name-prefix): Delegate the warnings to the parser.

* tests/headers.at, tests/input.at: Adjust expectations.
2019-01-14 19:57:37 +01:00
Akim Demaille
a88f8117b0 diagnostics: style: avoid allocating memory when not needed
* src/muscle-tab.c (muscle_percent_variable_update): Avoid allocating
memory when it is not needed, which should be most of the time (when
there's no update to perform).
Adjust callers.
2019-01-14 19:57:37 +01:00
Akim Demaille
3551d51dd9 c++: avoid warnings about extraneous semi-colons
Reported by Derek Clegg.
http://lists.gnu.org/archive/html/bug-bison/2019-01/msg00005.html

* configure.ac (warn_cxx): Add -Wextra-semi.
* data/skeletons/c++.m4: Remove extraneous semi-colon.
2019-01-14 19:45:01 +01:00
Akim Demaille
38b17c36da style: minor changes
* src/muscle-tab.c: Sort alphabetically.
* src/scan-gram.l: Reduce scopes.
Initialize variables.
2019-01-13 12:48:42 +01:00
Akim Demaille
f9db426de6 c++: beware of -Wshadow
This line:

    slice<stack_symbol_type, stack_type> slice (yystack_, yylen);

triggers warnings:

    parse.h:1790:11: note: shadowed declaration is here

Reported by Frank Heckenbach.
http://lists.gnu.org/archive/html/bug-bison/2019-01/msg00002.html

* configure.ac (warn_c): Move -Wshadow to...
(warn_common): here.
* data/skeletons/stack.hh (slice): Define as an inner class of stack.
* data/skeletons/lalr1.cc: Adjust.
Rename the variable as 'range' instead of 'slice'.
2019-01-13 12:26:58 +01:00
Akim Demaille
c927c955c8 maint: post-release administrivia
* NEWS: Add header line for next release.
* .prev-version: Record previous version.
* cfg.mk (old_NEWS_hash): Auto-update.
2019-01-12 10:59:57 +01:00
Akim Demaille
475fd79c8e version 3.2.90
* NEWS: Record release date.
v3.2.90
2019-01-12 10:46:43 +01:00
Akim Demaille
586e2ab0c8 yacc: fix relocatability
* src/yacc.in (prefix): Define it, as it's typically needed for
exec_prefix.
2019-01-12 10:45:21 +01:00
Akim Demaille
7e617dd847 syntax-check: adjust paths
* cfg.mk: here.
(require_config_h): New.
2019-01-12 09:41:15 +01:00
Akim Demaille
3355ee32f0 style: formatting clean up
* data/skeletons/d.m4, examples/d/calc.y, src/output.c,
* src/parse-gram.y:
No tab, no trailing spaces.
Reported by syntax-check.
2019-01-12 09:41:10 +01:00
Akim Demaille
7d545fd23f po: remove bitset/stats.c
* po/POTFILES.in: here.
2019-01-12 09:38:57 +01:00
Akim Demaille
70a4b97daf tests: fix usage of AT_PARSER_CHECK
The parser must be the first command.  Caught by syntax-check.

* tests/c++.at: here.
2019-01-12 09:38:57 +01:00