mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-13 22:33:03 +00:00
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:
@@ -95,6 +95,9 @@
|
||||
/* Handle a %skeleton directive. */
|
||||
static void do_skeleton (location const *loc, char const *skel);
|
||||
|
||||
/* Handle a %yacc directive. */
|
||||
static void do_yacc (location const *loc, char const *directive);
|
||||
|
||||
static void gram_error (location const *, char const *);
|
||||
|
||||
/* A string that describes a char (e.g., 'a' -> "'a'"). */
|
||||
@@ -201,8 +204,9 @@
|
||||
|
||||
%type <uniqstr>
|
||||
BRACKETED_ID ID ID_COLON
|
||||
PERCENT_ERROR_VERBOSE PERCENT_FLAG PERCENT_NAME_PREFIX TAG
|
||||
tag tag.opt variable
|
||||
PERCENT_ERROR_VERBOSE PERCENT_FLAG PERCENT_NAME_PREFIX
|
||||
PERCENT_YACC
|
||||
TAG tag tag.opt variable
|
||||
%printer { fputs ($$, yyo); } <uniqstr>
|
||||
%printer { fprintf (yyo, "[%s]", $$); } BRACKETED_ID
|
||||
%printer { fprintf (yyo, "%s:", $$); } ID_COLON
|
||||
@@ -329,7 +333,7 @@ prologue_declaration:
|
||||
| "%skeleton" STRING { do_skeleton (&@2, $2); }
|
||||
| "%token-table" { token_table_flag = true; }
|
||||
| "%verbose" { report_flag |= report_states; }
|
||||
| "%yacc" { yacc_flag = true; }
|
||||
| "%yacc" { do_yacc (&@$, $1); }
|
||||
| error ";" { current_class = unknown_sym; yyerrok; }
|
||||
| /*FIXME: Err? What is this horror doing here? */ ";"
|
||||
;
|
||||
@@ -956,6 +960,25 @@ do_skeleton (location const *loc, char const *skel)
|
||||
skeleton_arg (skeleton_user, grammar_prio, *loc);
|
||||
}
|
||||
|
||||
static void
|
||||
do_yacc (location const *loc, char const *directive)
|
||||
{
|
||||
bison_directive (loc, directive);
|
||||
bool warned = false;
|
||||
|
||||
if (location_empty (yacc_loc))
|
||||
yacc_loc = *loc;
|
||||
else
|
||||
{
|
||||
duplicate_directive (directive, yacc_loc, *loc);
|
||||
warned = true;
|
||||
}
|
||||
|
||||
if (!warned
|
||||
&& STRNEQ (directive, "%fixed-output-files")
|
||||
&& STRNEQ (directive, "%yacc"))
|
||||
deprecated_directive (loc, directive, "%fixed-output-files");
|
||||
}
|
||||
|
||||
static void
|
||||
gram_error (location const *loc, char const *msg)
|
||||
|
||||
Reference in New Issue
Block a user