From: Akim Demaille Date: Sat, 15 Dec 2012 21:14:16 +0000 (+0100) Subject: diagnostics: treat obsolete %define variable names as obsolete directives X-Git-Tag: v2.7.90~227 X-Git-Url: https://git.saurik.com/bison.git/commitdiff_plain/53f8e4096d887c53d04e180f759016d3d12013db diagnostics: treat obsolete %define variable names as obsolete directives 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. --- diff --git a/src/muscle-tab.c b/src/muscle-tab.c index 86363f50..28cfe561 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 a5d8d92b..50af0a86 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 ]])