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.
This commit is contained in:
Akim Demaille
2019-01-16 07:45:54 +01:00
parent 2c8fb4d126
commit b6b397b7f0
11 changed files with 73 additions and 21 deletions

View File

@@ -2526,8 +2526,12 @@ input.y:14.1-15.2: warning: deprecated directive: '%file-prefix\n =', use '%file
fix-it:"input.y":{14:1-15:3}:"%file-prefix"
input.y:17.1-19: warning: deprecated directive: '%fixed-output_files', use '%fixed-output-files' [-Wdeprecated]
fix-it:"input.y":{17:1-17:20}:"%fixed-output-files"
input.y:18.1-19: warning: deprecated directive: '%fixed_output-files', use '%fixed-output-files' [-Wdeprecated]
fix-it:"input.y":{18:1-18:20}:"%fixed-output-files"
input.y:18.1-19: warning: duplicate directive: %fixed_output-files [-Wother]
input.y:17.1-19: previous declaration
fix-it:"input.y":{18:1-18:20}:""
input.y:19.1-19: warning: duplicate directive: %fixed-output-files [-Wother]
input.y:17.1-19: previous declaration
fix-it:"input.y":{19:1-19:20}:""
input.y:20.1-19: warning: deprecated directive: '%name-prefix= "foo"', use '%define api.prefix {foo}' [-Wdeprecated]
fix-it:"input.y":{20:1-20:20}:"%define api.prefix {foo}"
input.y:21.1-16: warning: deprecated directive: '%no-default_prec', use '%no-default-prec' [-Wdeprecated]
@@ -2550,12 +2554,12 @@ fix-it:"input.y":{29:1-29:19}:"%define api.prefix {bar}"
input.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother]
]])
AT_CHECK([[sed -e '/^fix-it:/d' errors-all >experr]])
AT_BISON_CHECK([[input.y]], [[1]], [[]], [experr])
AT_CHECK([cp errors-all experr])
AT_BISON_CHECK([[-ffixit input.y]], [[1]], [[]], [experr])
AT_CHECK([[sed -e '/^fix-it:/d' errors-all >experr]])
AT_BISON_CHECK([[input.y]], [[1]], [[]], [experr])
# Update the input file.
AT_CHECK([cp input.y input.y.orig])
AT_CHECK([sed -e '/fix-it/d' <errors-all >experr])
@@ -2583,8 +2587,6 @@ AT_CHECK([cat input.y], [],
%file-prefix
"bar"
%fixed-output-files
%fixed-output-files
%fixed-output-files
%define api.prefix {foo}
%no-default-prec
%no-default-prec
@@ -2599,10 +2601,10 @@ exp : '0'
]])
AT_BISON_CHECK([[-fcaret input.y]], [[1]], [],
[[input.y:27.1-24: error: %define variable 'api.prefix' redefined
[[input.y:25.1-24: error: %define variable 'api.prefix' redefined
%define api.prefix {bar}
^~~~~~~~~~~~~~~~~~~~~~~~
input.y:19.1-24: previous definition
input.y:17.1-24: previous definition
%define api.prefix {foo}
^~~~~~~~~~~~~~~~~~~~~~~~
input.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother]