[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 10/12] diagnostics: improve the accuracy for %error-verbose
From: |
Akim Demaille |
Subject: |
[PATCH 10/12] diagnostics: improve the accuracy for %error-verbose |
Date: |
Sun, 13 Jan 2019 15:24:05 +0100 |
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.
---
src/muscle-tab.c | 6 +++++-
src/parse-gram.y | 17 ++++++++++++++++-
src/scan-gram.l | 4 ++--
tests/input.at | 24 ++++++++++--------------
4 files changed, 33 insertions(+), 18 deletions(-)
diff --git a/src/muscle-tab.c b/src/muscle-tab.c
index 653b95bb..9170c752 100644
--- a/src/muscle-tab.c
+++ b/src/muscle-tab.c
@@ -446,6 +446,8 @@ muscle_percent_variable_update (char const *variable,
} conversion_type;
const conversion_type conversion[] =
{
+ { "%error-verbose", "parse.error=verbose",
muscle_keyword },
+ { "%error_verbose", "parse.error=verbose",
muscle_keyword },
{ "abstract", "api.parser.abstract",
muscle_keyword },
{ "annotations", "api.parser.annotations", muscle_code },
{ "api.push_pull", "api.push-pull",
muscle_keyword },
@@ -477,7 +479,9 @@ muscle_percent_variable_update (char const *variable,
: STREQ (c->obsolete, variable))
{
/* Generate the deprecation warning. */
- *old = define_directive (c->obsolete, kind, *value);
+ *old = c->obsolete[0] == '%'
+ ? xstrdup (c->obsolete)
+ : define_directive (c->obsolete, kind, *value);
*upd = define_directive (c->updated, c->kind, *value);
/* Update the variable and its value. */
{
diff --git a/src/parse-gram.y b/src/parse-gram.y
index 85597421..e0496d5a 100644
--- a/src/parse-gram.y
+++ b/src/parse-gram.y
@@ -82,6 +82,9 @@
string from the scanner (should be CODE). */
static char const *translate_code_braceless (char *code, location loc);
+ /* Handle a %error-verbose directive. */
+ static void do_error_verbose (location const *loc, char const *directive);
+
/* Handle a %name-prefix directive. */
static void do_name_prefix (location const *loc,
char const *directive, char const *value);
@@ -151,6 +154,7 @@
PERCENT_DEFAULT_PREC "%default-prec"
PERCENT_DEFINE "%define"
PERCENT_DEFINES "%defines"
+ PERCENT_ERROR_VERBOSE "%error-verbose"
PERCENT_EXPECT "%expect"
PERCENT_EXPECT_RR "%expect-rr"
PERCENT_FLAG "%<flag>"
@@ -196,7 +200,8 @@
%printer { fprintf (yyo, "{\n%s\n}", $$); } <char*>
%type <uniqstr>
- BRACKETED_ID ID ID_COLON PERCENT_FLAG PERCENT_NAME_PREFIX TAG
+ BRACKETED_ID ID ID_COLON
+ PERCENT_ERROR_VERBOSE PERCENT_FLAG PERCENT_NAME_PREFIX TAG
tag tag.opt variable
%printer { fputs ($$, yyo); } <uniqstr>
%printer { fprintf (yyo, "[%s]", $$); } BRACKETED_ID
@@ -300,6 +305,7 @@ prologue_declaration:
defines_flag = true;
spec_defines_file = xstrdup ($2);
}
+| "%error-verbose" { do_error_verbose (&@$, $1); }
| "%expect" INT { expected_sr_conflicts = $2; }
| "%expect-rr" INT { expected_rr_conflicts = $2; }
| "%file-prefix" STRING { spec_file_prefix = $2; }
@@ -853,6 +859,15 @@ add_param (param_type type, char *decl, location loc)
}
+static void
+do_error_verbose (location const *loc, char const *directive)
+{
+ bison_directive (loc, directive);
+ muscle_percent_define_insert (directive, *loc, muscle_keyword, "",
+ MUSCLE_PERCENT_DEFINE_GRAMMAR_FILE);
+}
+
+
static void
do_name_prefix (location const *loc,
char const *directive, char const *value)
diff --git a/src/scan-gram.l b/src/scan-gram.l
index 86097b07..2eaa1606 100644
--- a/src/scan-gram.l
+++ b/src/scan-gram.l
@@ -263,7 +263,7 @@ eqopt ({sp}=)?
/* Deprecated since Bison 3.0 (2013-07-25), but the warning is
issued only since Bison 3.3. */
- "%error-verbose" DEPRECATED ("%define parse.error verbose");
+ "%error-verbose" RETURN_VALUE (PERCENT_ERROR_VERBOSE,
uniqstr_new (yytext));
/* Deprecated since Bison 2.6 (2012-07-19), but the warning is
issued only since Bison 3.3. */
@@ -271,7 +271,7 @@ eqopt ({sp}=)?
/* Deprecated since Bison 2.7.90, 2012. */
"%default"[-_]"prec" DEPRECATED ("%default-prec");
- "%error"[-_]"verbose" DEPRECATED ("%define parse.error verbose");
+ "%error"[-_]"verbose" RETURN_VALUE (PERCENT_ERROR_VERBOSE,
uniqstr_new (yytext));
"%expect"[-_]"rr" DEPRECATED ("%expect-rr");
"%file-prefix"{eqopt} DEPRECATED ("%file-prefix");
"%fixed"[-_]"output"[-_]"files" DEPRECATED ("%fixed-output-files");
diff --git a/tests/input.at b/tests/input.at
index ea30991c..f6b68d5e 100644
--- a/tests/input.at
+++ b/tests/input.at
@@ -2537,10 +2537,8 @@ input.y:25.1-12: warning: deprecated directive:
'%pure_parser', use '%pure-parse
fix-it:"input.y":{25:1-25:13}:"%pure-parser"
input.y:26.1-12: warning: deprecated directive: '%token_table', use
'%token-table' [-Wdeprecated]
fix-it:"input.y":{26:1-26:13}:"%token-table"
-input.y:27.1-14: warning: deprecated directive: '%error-verbose', use '%define
parse.error verbose' [-Wdeprecated]
-fix-it:"input.y":{27:1-27:15}:"%define parse.error verbose"
-input.y:27-14: error: %define variable 'parse.error' redefined
-input.y:11-14: previous definition
+input.y:27.1-14: error: %define variable 'parse.error' redefined
+input.y:11.1-14: previous definition
input.y:29.1-18: warning: deprecated directive: '%name-prefix "bar"', use
'%define api.prefix {bar}' [-Wdeprecated]
fix-it:"input.y":{29:1-29:19}:"%define api.prefix {bar}"
]])
@@ -2587,7 +2585,7 @@ AT_CHECK([cat input.y], [],
%output "foo"
%pure-parser
%token-table
-%define parse.error verbose
+%error-verbose
%glr-parser
%define api.prefix {bar}
%%
@@ -2597,9 +2595,9 @@ exp : '0'
# Unfortunately so far we don't remove duplicate definitions,
# so there are still warnings.
AT_BISON_CHECK([[-fcaret input.y]], [[1]], [],
-[[input.y:26.1-27: error: %define variable 'parse.error' redefined
- %define parse.error verbose
- ^~~~~~~~~~~~~~~~~~~~~~~~~~~
+[[input.y:26.1-14: error: %define variable 'parse.error' redefined
+ %error-verbose
+ ^~~~~~~~~~~~~~
input.y:11.1-27: previous definition
%define parse.error verbose
^~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -2642,12 +2640,10 @@ AT_BISON_CHECK([[input.y]], [[1]], [[]],
input.y:11.15-24: warning: deprecated directive: '%expect_rr', use
'%expect-rr' [-Wdeprecated]
input.y:12.15-24: warning: deprecated directive: '%expect_rr', use
'%expect-rr' [-Wdeprecated]
input.y:13.1-14: warning: deprecated directive: '%error_verbose', use '%define
parse.error verbose' [-Wdeprecated]
-input.y:13.16-29: warning: deprecated directive: '%error_verbose', use
'%define parse.error verbose' [-Wdeprecated]
-input.y:13.3-29: error: %define variable 'parse.error' redefined
-input.y:13-14: previous definition
-input.y:14.16-29: warning: deprecated directive: '%error_verbose', use
'%define parse.error verbose' [-Wdeprecated]
-input.y:14.3-29: error: %define variable 'parse.error' redefined
-input.y:13.3-29: previous definition
+input.y:13.16-29: error: %define variable 'parse.error' redefined
+input.y:13.1-14: previous definition
+input.y:14.16-29: error: %define variable 'parse.error' redefined
+input.y:13.16-29: previous definition
]])
AT_CLEANUP
--
2.20.1
- [PATCH 00/12] RFC: fixits and --update, Akim Demaille, 2019/01/13
- [PATCH 12/12] diagnostics: add fixit support for duplicate removal, Akim Demaille, 2019/01/13
- [PATCH 01/12] diagnostics: style: avoid allocating memory when not needed, Akim Demaille, 2019/01/13
- [PATCH 02/12] diagnostics: improve them for %name-prefix, Akim Demaille, 2019/01/13
- [PATCH 09/12] diagnostics: avoid duplicate warnings for deprecated directives, Akim Demaille, 2019/01/13
- [PATCH 10/12] diagnostics: improve the accuracy for %error-verbose,
Akim Demaille <=
- [PATCH 06/12] diagnostics: keep the fixits, Akim Demaille, 2019/01/13
- [PATCH 04/12] diagnostics: prefer ^~~~ to ^^^^ to underline code, Akim Demaille, 2019/01/13
- [PATCH 05/12] diagnostics: add -ffixit support for deprecated features, Akim Demaille, 2019/01/13
- [PATCH 08/12] diagnostics: update the grammar file, Akim Demaille, 2019/01/13
- [PATCH 07/12] diagnostics: improve accuracy for deprecated %define variables, Akim Demaille, 2019/01/13