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.
This commit is contained in:
Akim Demaille
2019-01-17 06:43:28 +01:00
parent 5879c8dc5a
commit e86adac52d
7 changed files with 51 additions and 16 deletions

View File

@@ -407,7 +407,7 @@ duplicate_directive (char const *directive,
if (feature_flag & feature_caret)
complain_indent (&second, Wother, &i, _("duplicate directive"));
else
complain_indent (&second, Wother, &i, _("duplicate directive: %s"), directive);
complain_indent (&second, Wother, &i, _("duplicate directive: %s"), quote (directive));
i += SUB_INDENT;
complain_indent (&first, Wother, &i, _("previous declaration"));
fixits_register (&second, "");

View File

@@ -43,6 +43,7 @@
char const *spec_outfile = NULL; /* for -o. */
char const *spec_file_prefix = NULL; /* for -b. */
location spec_file_prefix_loc = EMPTY_LOCATION_INIT;
char const *spec_name_prefix = NULL; /* for -p. */
char *spec_verbose_file = NULL; /* for --verbose. */
char *spec_graph_file = NULL; /* for -g. */

View File

@@ -21,6 +21,7 @@
#ifndef FILES_H_
# define FILES_H_
# include "location.h"
# include "uniqstr.h"
/* File name specified with -o for the output file, or 0 if no -o. */
@@ -34,6 +35,7 @@ extern const char *spec_name_prefix;
/* File name prefix specified with -b, or 0 if no -b. */
extern char const *spec_file_prefix;
extern location spec_file_prefix_loc;
/* --verbose. */
extern char *spec_verbose_file;

View File

@@ -85,6 +85,11 @@
/* Handle a %error-verbose directive. */
static void handle_error_verbose (location const *loc, char const *directive);
/* Handle a %file-prefix directive. */
static void handle_file_prefix (location const *loc,
location const *dir_loc,
char const *directive, char const *value);
/* Handle a %name-prefix directive. */
static void handle_name_prefix (location const *loc,
char const *directive, char const *value);
@@ -204,7 +209,7 @@
%type <uniqstr>
BRACKETED_ID ID ID_COLON
PERCENT_ERROR_VERBOSE PERCENT_FLAG PERCENT_NAME_PREFIX
PERCENT_ERROR_VERBOSE PERCENT_FILE_PREFIX PERCENT_FLAG PERCENT_NAME_PREFIX
PERCENT_YACC
TAG tag tag.opt variable
%printer { fputs ($$, yyo); } <uniqstr>
@@ -312,7 +317,7 @@ prologue_declaration:
| "%error-verbose" { handle_error_verbose (&@$, $1); }
| "%expect" INT { expected_sr_conflicts = $2; }
| "%expect-rr" INT { expected_rr_conflicts = $2; }
| "%file-prefix" STRING { spec_file_prefix = $2; }
| "%file-prefix" STRING { handle_file_prefix (&@$, &@1, $1, $2); }
| "%glr-parser"
{
nondeterministic_parser = true;
@@ -872,6 +877,30 @@ handle_error_verbose (location const *loc, char const *directive)
}
static void
handle_file_prefix (location const *loc,
location const *dir_loc,
char const *directive, char const *value)
{
bison_directive (loc, directive);
bool warned = false;
if (location_empty (spec_file_prefix_loc))
{
spec_file_prefix_loc = *loc;
spec_file_prefix = value;
}
else
{
duplicate_directive (directive, spec_file_prefix_loc, *loc);
warned = true;
}
if (!warned
&& STRNEQ (directive, "%file-prefix"))
deprecated_directive (dir_loc, directive, "%file-prefix");
}
static void
handle_name_prefix (location const *loc,
char const *directive, char const *value)

View File

@@ -228,7 +228,7 @@ eqopt ({sp}=)?
"%empty" return BISON_DIRECTIVE (EMPTY);
"%expect" return BISON_DIRECTIVE (EXPECT);
"%expect-rr" return BISON_DIRECTIVE (EXPECT_RR);
"%file-prefix" return BISON_DIRECTIVE (FILE_PREFIX);
"%file-prefix" RETURN_VALUE (PERCENT_FILE_PREFIX, uniqstr_new (yytext));
"%fixed-output-files" RETURN_VALUE (PERCENT_YACC, uniqstr_new (yytext));
"%initial-action" return BISON_DIRECTIVE (INITIAL_ACTION);
"%glr-parser" return BISON_DIRECTIVE (GLR_PARSER);
@@ -273,7 +273,7 @@ eqopt ({sp}=)?
"%default"[-_]"prec" DEPRECATED ("%default-prec");
"%error"[-_]"verbose" RETURN_VALUE (PERCENT_ERROR_VERBOSE, uniqstr_new (yytext));
"%expect"[-_]"rr" DEPRECATED ("%expect-rr");
"%file-prefix"{eqopt} DEPRECATED ("%file-prefix");
"%file-prefix"{eqopt} RETURN_VALUE (PERCENT_FILE_PREFIX, uniqstr_new (yytext));
"%fixed"[-_]"output"[-_]"files" RETURN_VALUE (PERCENT_YACC, uniqstr_new (yytext));
"%no"[-_]"default"[-_]"prec" DEPRECATED ("%no-default-prec");
"%no"[-_]"lines" DEPRECATED ("%no-lines");

View File

@@ -2522,14 +2522,15 @@ input.y:12.1-10: warning: deprecated directive: '%expect_rr', use '%expect-rr' [
fix-it:"input.y":{12:1-12:11}:"%expect-rr"
input.y:13.1-14: warning: deprecated directive: '%file-prefix =', use '%file-prefix' [-Wdeprecated]
fix-it:"input.y":{13:1-13:15}:"%file-prefix"
input.y:14.1-15.2: warning: deprecated directive: '%file-prefix\n =', use '%file-prefix' [-Wdeprecated]
fix-it:"input.y":{14:1-15:3}:"%file-prefix"
input.y:14.1-16.5: warning: duplicate directive: '%file-prefix\n =' [-Wother]
input.y:13.1-20: previous declaration [-Wother]
fix-it:"input.y":{14:1-16:6}:""
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: duplicate directive: %fixed_output-files [-Wother]
input.y:18.1-19: warning: duplicate directive: '%fixed_output-files' [-Wother]
input.y:17.1-19: previous declaration [-Wother]
fix-it:"input.y":{18:1-18:20}:""
input.y:19.1-19: warning: duplicate directive: %fixed-output-files [-Wother]
input.y:19.1-19: warning: duplicate directive: '%fixed-output-files' [-Wother]
input.y:17.1-19: previous declaration [-Wother]
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]
@@ -2584,8 +2585,6 @@ AT_CHECK([cat input.y], [],
%define parse.error verbose
%expect-rr 0
%file-prefix "foo"
%file-prefix
"bar"
%fixed-output-files
%define api.prefix {foo}
%no-default-prec
@@ -2601,10 +2600,10 @@ exp : '0'
]])
AT_BISON_CHECK([[-fcaret input.y]], [[1]], [],
[[input.y:25.1-24: error: %define variable 'api.prefix' redefined
[[input.y:23.1-24: error: %define variable 'api.prefix' redefined
%define api.prefix {bar}
^~~~~~~~~~~~~~~~~~~~~~~~
input.y:17.1-24: previous definition
input.y:15.1-24: previous definition
%define api.prefix {foo}
^~~~~~~~~~~~~~~~~~~~~~~~
input.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother]
@@ -2677,7 +2676,10 @@ AT_DATA_GRAMMAR([[input.y]],
]])
AT_BISON_CHECK([[input.y]], [[0]], [[]],
[[input.y: warning: %expect-rr applies only to GLR parsers [-Wother]
[[input.y:14.1-15.5: warning: duplicate directive: '%file-prefix' [-Wother]
input.y:13.1-18: previous declaration [-Wother]
input.y: warning: %expect-rr applies only to GLR parsers [-Wother]
input.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother]
]])
AT_CLEANUP

View File

@@ -707,8 +707,9 @@ if test "$POSIXLY_CORRECT_IS_EXPORTED" = false; then
# Build expected stderr up to and including the "warnings being
# treated as errors" message.
]AT_DATA([[experr]], [$4])[
$PERL -pi -e 's{(.*): warning: (.*)\[-W(.*)\]$}
{$][1: error: $][2\@<:@-Werror=$][3@:>@}' experr
$PERL -pi -e 's{(.*): warning:}{$][1: error:};' \
-e 's{\[-W(.*)\]$}{@<:@-Werror=$][1@:>@}' \
experr
]AT_CHECK([[sed 's,.*/$,,' stderr 1>&2]], [[0]], [[]], [experr])[
# Now check --warnings=error.