bison-patches
[Top][All Lists]
Advanced

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

[PATCH 09/12] diagnostics: avoid duplicate warnings for deprecated direc


From: Akim Demaille
Subject: [PATCH 09/12] diagnostics: avoid duplicate warnings for deprecated directives
Date: Sun, 13 Jan 2019 15:24:04 +0100

Currently, on

    %define parser_class_name "Parser"
    %define parser_class_name "Parser"
    %%
    exp:;

we issue:

    foo.y:1.9-25: warning: deprecated directive, use '%define api.parser.class 
{Parser}' [-Wdeprecated]
     %define parser_class_name "Parser"
             ^~~~~~~~~~~~~~~~~
    foo.y:2.9-25: warning: deprecated directive, use '%define api.parser.class 
{Parser}' [-Wdeprecated]
     %define parser_class_name "Parser"
             ^~~~~~~~~~~~~~~~~
    foo.y:2.9-25: error: %define variable 'api.parser.class' redefined
     %define parser_class_name "Parser"
             ^~~~~~~~~~~~~~~~~
    foo.y:1.9-25:     previous definition
     %define parser_class_name "Parser"
             ^~~~~~~~~~~~~~~~~

Let's get rid of the second warning about the deprecated variable
parser_class_name.  This is noise, but it will also be a problem with
fixits for removing duplicates, as we will first generate the update,
and then it's too late to remove it: fixits do not edit the result of
previous fixits.

So generate this instead:

    foo.y:1.1-34: warning: deprecated directive, use '%define api.parser.class 
{Parser}' [-Wdeprecated]
     %define parser_class_name "Parser"
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    foo.y:2.1-34: error: %define variable 'api.parser.class' redefined
     %define parser_class_name "Parser"
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    foo.y:1.1-34:     previous definition
     %define parser_class_name "Parser"
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

* src/muscle-tab.c (muscle_percent_variable_update): Pass the warning
to the caller, instead of issuing it.
(muscle_percent_define_insert): Issue this warning only if we don't
have to complain about a duplicate definition.
* tests/input.at: Adjust expectations.
---
 src/muscle-tab.c | 26 ++++++++++++++++----------
 1 file changed, 16 insertions(+), 10 deletions(-)

diff --git a/src/muscle-tab.c b/src/muscle-tab.c
index 4c17baa4..653b95bb 100644
--- a/src/muscle-tab.c
+++ b/src/muscle-tab.c
@@ -433,9 +433,10 @@ define_directive (char const *assignment,
  * value is exactly \a variable.  */
 static
 char const *
-muscle_percent_variable_update (char const *variable, location variable_loc,
+muscle_percent_variable_update (char const *variable,
                                 muscle_kind kind,
-                                char const **value)
+                                char const **value,
+                                char **old, char **upd)
 {
   typedef struct
   {
@@ -476,13 +477,8 @@ muscle_percent_variable_update (char const *variable, 
location variable_loc,
           : STREQ (c->obsolete, variable))
         {
           /* Generate the deprecation warning. */
-          {
-            char *old = define_directive (c->obsolete, kind, *value);
-            char *upd = define_directive (c->updated, c->kind, *value);
-            deprecated_directive (&variable_loc, old, upd);
-            free (old);
-            free (upd);
-          }
+          *old = define_directive (c->obsolete, kind, *value);
+          *upd = define_directive (c->updated, c->kind, *value);
           /* Update the variable and its value.  */
           {
             char *res = xstrdup (c->updated);
@@ -506,8 +502,11 @@ muscle_percent_define_insert (char const *var, location 
variable_loc,
                               muscle_percent_define_how how)
 {
   /* Backward compatibility.  */
+  char *old = NULL;
+  char *upd = NULL;
   char const *variable
-    = muscle_percent_variable_update (var, variable_loc, kind, &value);
+    = muscle_percent_variable_update (var, kind,
+                                      &value, &old, &upd);
   uniqstr name = muscle_name (variable, NULL);
   uniqstr loc_name = muscle_name (variable, "loc");
   uniqstr syncline_name = muscle_name (variable, "syncline");
@@ -515,6 +514,7 @@ muscle_percent_define_insert (char const *var, location 
variable_loc,
   uniqstr kind_name = muscle_name (variable, "kind");
 
   /* Command-line options are processed before the grammar file.  */
+  bool warned = false;
   if (how == MUSCLE_PERCENT_DEFINE_GRAMMAR_FILE
       && muscle_find_const (name))
     {
@@ -528,8 +528,12 @@ muscle_percent_define_insert (char const *var, location 
variable_loc,
       i += SUB_INDENT;
       location loc = muscle_percent_define_get_loc (variable);
       complain_indent (&loc, complaint, &i, _("previous definition"));
+      warned = true;
     }
 
+  if (!warned && old && upd)
+    deprecated_directive (&variable_loc, old, upd);
+
   MUSCLE_INSERT_STRING (name, value);
   muscle_insert (loc_name, "");
   muscle_location_grow (loc_name, variable_loc);
@@ -540,6 +544,8 @@ muscle_percent_define_insert (char const *var, location 
variable_loc,
   MUSCLE_INSERT_INT (how_name, how);
   MUSCLE_INSERT_STRING (kind_name, muscle_kind_string (kind));
  end:
+  free (old);
+  free (upd);
   if (variable != var)
     free ((char *) variable);
 }
-- 
2.20.1




reply via email to

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