[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 2/3] diagnostics: treat obsolete %define variable names as obsole
From: |
Akim Demaille |
Subject: |
[PATCH 2/3] diagnostics: treat obsolete %define variable names as obsolete directives |
Date: |
Fri, 21 Dec 2012 16:13:47 +0100 |
Instead of
warning: deprecated %define variable name: 'namespace', use 'api.namespace'
[-Wdeprecated]
display (in -fno-caret mode):
warning: deprecated directive: '%define namespace foo', use '%define
api.namespace foo' [-Wdeprecated]
and (in -fcaret mode):
warning: deprecated directive, use '%define api.namespace toto' [-Wdeprecated]
%define namespace toto
^^^^^^^^^
This is in preparation of cases where not only the variable is
renamed, but the values are too:
warning: deprecated directive: '%define variant', use '%define api.value.type
variant' [-Wdeprecated]
* src/muscle-tab.c (define_directive): New.
(muscle_percent_variable_update): Take the value as argument, and use it
in the diagnostics.
Loop with a pointer instead of an index.
* tests/input.at (%define backward compatibility): Adjust.
---
src/muscle-tab.c | 35 +++++++++++++++++++++++++----------
tests/input.at | 8 ++++----
2 files changed, 29 insertions(+), 14 deletions(-)
diff --git a/src/muscle-tab.c b/src/muscle-tab.c
index 86363f5..28cfe56 100644
--- a/src/muscle-tab.c
+++ b/src/muscle-tab.c
@@ -384,11 +384,23 @@ muscle_user_name_list_grow (char const *key, char const
*user_name,
muscle_grow (key, "]]", "");
}
+static
+char *
+define_directive (char const *assignment, char const *value)
+{
+ char const *fmt = value && *value ? "%%define %s %s" : "%%define %s";
+ char *res = xmalloc (strlen (fmt) + strlen (assignment)
+ + (value ? strlen (value) : 0));
+ sprintf (res, fmt, assignment, value);
+ return res;
+}
+
/** If the \a variable name is obsolete, return the name to use,
* otherwise \a variable. */
static
char const *
-muscle_percent_variable_update (char const *variable, location variable_loc)
+muscle_percent_variable_update (char const *variable, location variable_loc,
+ char const **value)
{
typedef struct
{
@@ -405,18 +417,21 @@ muscle_percent_variable_update (char const *variable,
location variable_loc)
{ "lr.keep-unreachable-states", "lr.keep-unreachable-state", },
{ "lr.keep_unreachable_states", "lr.keep-unreachable-state", },
{ "namespace", "api.namespace", },
+ { NULL, NULL, }
};
char const *res = variable;
- int i;
- for (i = 0; i < ARRAY_CARDINALITY (conversion); ++i)
- if (STREQ (conversion[i].obsolete, variable))
+ conversion_type const *c;
+ for (c = conversion; c->obsolete; ++c)
+ if (STREQ (c->obsolete, variable))
{
- res = conversion[i].updated;
- complain (&variable_loc, Wdeprecated,
- _("deprecated %%define variable name: %s, use %s"),
- quote (variable), quote_n (1, res));
+ char *old = define_directive (c->obsolete, *value);
+ char *upd = define_directive (c->updated, *value);
+ deprecated_directive (&variable_loc, old, upd);
+ free (old);
+ free (upd);
+ res = c->updated;
break;
- }
+ }
return res;
}
@@ -426,7 +441,7 @@ muscle_percent_define_insert (char const *var, location
variable_loc,
muscle_percent_define_how how)
{
/* Backward compatibility. */
- char const *variable = muscle_percent_variable_update (var, variable_loc);
+ char *variable = muscle_percent_variable_update (var, variable_loc, &value);
char const *name = UNIQSTR_CONCAT ("percent_define(", variable, ")");
char const *loc_name = UNIQSTR_CONCAT ("percent_define_loc(", variable, ")");
char const *syncline_name =
diff --git a/tests/input.at b/tests/input.at
index a5d8d92..50af0a8 100644
--- a/tests/input.at
+++ b/tests/input.at
@@ -1336,7 +1336,7 @@ AT_DATA([[input.y]],
start: ;
]])
AT_BISON_CHECK([[input.y]], [1], [],
-[[input.y:1.9-21: warning: deprecated %define variable name: 'api.push_pull',
use 'api.push-pull' [-Wdeprecated]
+[[input.y:1.9-21: warning: deprecated directive: '%define api.push_pull
neither', use '%define api.push-pull neither' [-Wdeprecated]
input.y:1.9-21: error: invalid value for %define variable 'api.push-pull':
'neither'
input.y:1.9-21: accepted value: 'pull'
input.y:1.9-21: accepted value: 'push'
@@ -1344,7 +1344,7 @@ input.y:1.9-21: accepted value: 'both'
]])
AT_BISON_CHECK([[-fcaret input.y]], [1], [],
-[[input.y:1.9-21: warning: deprecated %define variable name: 'api.push_pull',
use 'api.push-pull' [-Wdeprecated]
+[[input.y:1.9-21: warning: deprecated directive, use '%define api.push-pull
neither' [-Wdeprecated]
%define api.push_pull "neither"
^^^^^^^^^^^^^
input.y:1.9-21: error: invalid value for %define variable 'api.push-pull':
'neither'
@@ -1361,7 +1361,7 @@ AT_DATA([[input.y]],
start: ;
]])
AT_BISON_CHECK([[input.y]], [1], [],
-[[input.y:1.9-34: warning: deprecated %define variable name:
'lr.keep_unreachable_states', use 'lr.keep-unreachable-state' [-Wdeprecated]
+[[input.y:1.9-34: warning: deprecated directive: '%define
lr.keep_unreachable_states maybe', use '%define lr.keep-unreachable-state
maybe' [-Wdeprecated]
input.y:1.9-34: error: invalid value for %define Boolean variable
'lr.keep-unreachable-state'
]])
@@ -1372,7 +1372,7 @@ AT_DATA([[input.y]],
start: ;
]])
AT_BISON_CHECK([[input.y]], [1], [],
-[[input.y:1.9-17: warning: deprecated %define variable name: 'namespace', use
'api.namespace' [-Wdeprecated]
+[[input.y:1.9-17: warning: deprecated directive: '%define namespace foo', use
'%define api.namespace foo' [-Wdeprecated]
input.y:2.9-21: error: %define variable 'api.namespace' redefined
input.y:1.9-17: previous definition
]])
--
1.8.0.2