diagnostics: avoid duplicate warnings for deprecated directives

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.
This commit is contained in:
Akim Demaille
2019-01-13 13:10:34 +01:00
parent 41aaa8374c
commit 8580b268c3

View File

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