bison-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

diagnostics: let redundant definitions be only warnings


From: Akim Demaille
Subject: diagnostics: let redundant definitions be only warnings
Date: Tue, 22 Jan 2019 06:35:57 +0100

commit 2b81dcf7ddc0ac656801cc20a0a84341754c90f4
Author: Akim Demaille <address@hidden>
Date:   Mon Jan 21 19:37:36 2019 +0100

    diagnostics: let redundant definitions be only warnings
    
    After all, this is clearly harmless.
    
    * src/muscle-tab.c (muscle_percent_define_insert): Let equal
    definitions of a %define variable be only a warning.
    Adjust test cases.

diff --git a/src/muscle-tab.c b/src/muscle-tab.c
index 618e4d5f..8a1b00fc 100644
--- a/src/muscle-tab.c
+++ b/src/muscle-tab.c
@@ -520,22 +520,28 @@ muscle_percent_define_insert (char const *var, location 
variable_loc,
 
   /* Command-line options are processed before the grammar file.  */
   bool warned = false;
-  if (how == MUSCLE_PERCENT_DEFINE_GRAMMAR_FILE
-      && muscle_find_const (name))
+  if (how == MUSCLE_PERCENT_DEFINE_GRAMMAR_FILE)
     {
-      muscle_percent_define_how how_old = atoi (muscle_find_const (how_name));
+      char const *current_value = muscle_find_const (name);
+      if (current_value)
+        {
+          muscle_percent_define_how how_old
+            = atoi (muscle_find_const (how_name));
           if (how_old == MUSCLE_PERCENT_DEFINE_F)
             goto end;
           unsigned i = 0;
-      complain_indent (&variable_loc, complaint, &i,
+          /* If assigning the same value, make it a warning.  */
+          warnings warn = STREQ (value, current_value) ? Wother : complaint;
+          complain_indent (&variable_loc, warn, &i,
                            _("%%define variable %s redefined"),
                            quote (variable));
           i += SUB_INDENT;
           location loc = muscle_percent_define_get_loc (variable);
-      complain_indent (&loc, complaint, &i, _("previous definition"));
+          complain_indent (&loc, warn, &i, _("previous definition"));
           fixits_register (&variable_loc, "");
           warned = true;
         }
+    }
 
   if (!warned && old && upd)
     deprecated_directive (&variable_loc, old, upd);
diff --git a/tests/input.at b/tests/input.at
index 22bcfe87..d7cc1093 100644
--- a/tests/input.at
+++ b/tests/input.at
@@ -1740,7 +1740,7 @@ start: %empty;
 ]])
 
 AT_BISON_CHECK([[input-redefined.y]], [[1]], [],
-[[input-redefined.y:2.1-20: error: %define variable 'var' redefined
+[[input-redefined.y:2.1-20: warning: %define variable 'var' redefined [-Wother]
 input-redefined.y:1.1-20:     previous definition
 input-redefined.y:3.2-21: error: %define variable 'var' redefined
 input-redefined.y:2.1-20:     previous definition
@@ -2008,7 +2008,7 @@ input.y:2.1-40: warning: deprecated directive, use 
'%define lr.keep-unreachable-
 input.y:3.1-23: warning: deprecated directive, use '%define api.namespace 
{foo}' [-Wdeprecated]
  %define namespace "foo"
  ^~~~~~~~~~~~~~~~~~~~~~~
-input.y:4.1-27: error: %define variable 'api.namespace' redefined
+input.y:4.1-27: warning: %define variable 'api.namespace' redefined [-Wother]
  %define api.namespace {foo}
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~
 input.y:3.1-23:     previous definition
@@ -2020,6 +2020,9 @@ input.y:5.1-15: warning: deprecated directive, use 
'%define api.value.type varia
 input.y:6.1-34: warning: deprecated directive, use '%define api.parser.class 
{parser}' [-Wdeprecated]
  %define parser_class_name {parser}
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+input.y:2.1-40: error: invalid value for %define Boolean variable 
'lr.keep-unreachable-state'
+ %define lr.keep_unreachable_states maybe
+ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 input.y: warning: fix-its can be applied.  Rerun with option '--update'. 
[-Wother]
 ]])
 
@@ -2337,8 +2340,8 @@ AT_CLEANUP
 
 AT_SETUP([[Redefined %union name]])
 
-# AT_TEST(DIRECTIVES, ERROR)
-# --------------------------
+# AT_TEST(DIRECTIVES, EXIT-STATUS, ERROR)
+# ---------------------------------------
 m4_pushdef([AT_TEST],
 [AT_DATA([[input.y]],
 [$1
@@ -2346,27 +2349,28 @@ m4_pushdef([AT_TEST],
 exp: %empty;
 ])
 
-AT_BISON_CHECK([[input.y]], [[1]], [[]],
-[$2])
+AT_BISON_CHECK([[input.y]], [$2], [[]],
+[$3])
 ])
 
 AT_TEST([[%union foo {};
 %union {};
 %union foo {};
 %define api.value.union.name foo]],
-[[input.y:3.8-10: error: %define variable 'api.value.union.name' redefined
+[0],
+[[input.y:3.8-10: warning: %define variable 'api.value.union.name' redefined 
[-Wother]
 input.y:1.8-10:     previous definition
-input.y:4.1-32: error: %define variable 'api.value.union.name' redefined
+input.y:4.1-32: warning: %define variable 'api.value.union.name' redefined 
[-Wother]
 input.y:3.8-10:     previous definition
 input.y: warning: fix-its can be applied.  Rerun with option '--update'. 
[-Wother]
 ]])
 
-AT_TEST([[%define api.value.union.name {foo}]],
+AT_TEST([[%define api.value.union.name {foo}]], [1],
 [[input.y:1.1-34: error: %define variable 'api.value.union.name' requires 
keyword values
 input.y:1.1-34: error: %define variable 'api.value.union.name' is not used
 ]])
 
-AT_TEST([[%define api.value.union.name "foo"]],
+AT_TEST([[%define api.value.union.name "foo"]], [1],
 [[input.y:1.1-34: error: %define variable 'api.value.union.name' requires 
keyword values
 input.y:1.1-34: error: %define variable 'api.value.union.name' is not used
 ]])
@@ -2547,7 +2551,7 @@ 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: error: %define variable 'parse.error' redefined
+input.y:27.1-14: warning: %define variable 'parse.error' redefined [-Wother]
 input.y:11.1-14:     previous definition
 fix-it:"input.y":{27:1-27:15}:""
 input.y:29.1-18: warning: duplicate directive: '%name-prefix "bar"' [-Wother]
@@ -2557,16 +2561,18 @@ input.y: warning: fix-its can be applied.  Rerun with 
option '--update'. [-Wothe
 ]])
 
 AT_CHECK([cp errors-all experr])
-AT_BISON_CHECK([[-ffixit input.y]], [[1]], [[]], [experr])
+AT_BISON_CHECK([[-ffixit input.y]], [], [], [experr])
 
 AT_CHECK([[sed -e '/^fix-it:/d' errors-all >experr]])
-AT_BISON_CHECK([[input.y]], [[1]], [[]], [experr])
+AT_BISON_CHECK([[input.y]], [], [], [experr])
 
 # Update the input file.
 AT_CHECK([cp input.y input.y.orig])
 AT_CHECK([sed -e '/fix-it/d' <errors-all >experr])
 AT_CHECK([echo "bison: file 'input.y' was updated (backup: 'input.y~')" 
>>experr])
-AT_BISON_CHECK([[--update input.y]], [[1]], [[]], [experr])
+AT_CHECK([ls], [], [ignore])
+AT_BISON_CHECK([[--update input.y]], [], [[]], [experr])
+AT_CHECK([ls], [], [ignore])
 
 # Check the backup.
 AT_CHECK([diff input.y.orig input.y~])
@@ -2632,10 +2638,11 @@ 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: error: %define variable 'parse.error' redefined
+input.y:13.16-29: warning: %define variable 'parse.error' redefined [-Wother]
 input.y:13.1-14:      previous definition
-input.y:14.16-29: error: %define variable 'parse.error' redefined
+input.y:14.16-29: warning: %define variable 'parse.error' redefined [-Wother]
 input.y:13.16-29:     previous definition
+input.y: error: reduce/reduce conflicts: 0 found, 42 expected
 input.y: warning: fix-its can be applied.  Rerun with option '--update'. 
[-Wother]
 ]])
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]