X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/bb8e56ff67d289d15f1a4dc7f5e1502cd3bbfc24..9a9130f26d8df2c1fe2051c5881e0da804ba8e9c:/src/muscle-tab.c?ds=sidebyside diff --git a/src/muscle-tab.c b/src/muscle-tab.c index be97b800..8212895c 100644 --- a/src/muscle-tab.c +++ b/src/muscle-tab.c @@ -1,6 +1,6 @@ /* Muscle table manager for Bison. - Copyright (C) 2001-2012 Free Software Foundation, Inc. + Copyright (C) 2001-2013 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. @@ -384,11 +384,45 @@ muscle_user_name_list_grow (char const *key, char const *user_name, muscle_grow (key, "]]", ""); } + +/** Return an allocated string that represents the %define directive + that performs the assignment. + + @param assignment "VAR", or "VAR=VAL". + @param value default value if VAL \a assignment has no '='. + + For instance: + "foo", NULL => "%define foo" + "foo", "baz" => "%define foo baz" + "foo=bar", NULL => "%define foo bar" + "foo=bar", "baz" => "%define foo bar" + "foo=", NULL => "%define foo" + "foo=", "baz" => "%define foo" + */ + +static +char * +define_directive (char const *assignment, char const *value) +{ + char *eq = strchr (assignment, '='); + char const *fmt = !eq && value && *value ? "%%define %s %s" : "%%define %s"; + char *res = xmalloc (strlen (fmt) + strlen (assignment) + + (value ? strlen (value) : 0)); + sprintf (res, fmt, assignment, value); + eq = strchr (res, '='); + if (eq) + *eq = eq[1] ? ' ' : '\0'; + return res; +} + /** If the \a variable name is obsolete, return the name to use, - * otherwise \a variable. */ + * otherwise \a variable. If the \a value is obsolete, update it too. + * + * Allocates the returned value. */ static -char const * -muscle_percent_variable_update (char const *variable, location variable_loc) +char * +muscle_percent_variable_update (char const *variable, location variable_loc, + char const **value) { typedef struct { @@ -398,41 +432,59 @@ muscle_percent_variable_update (char const *variable, location variable_loc) const conversion_type conversion[] = { { "api.push_pull", "api.push-pull", }, - { "lr.keep_unreachable_states", "lr.keep-unreachable-states", }, + { "api.tokens.prefix", "api.token.prefix", }, + { "lex_symbol", "api.token.constructor", }, + { "location_type", "api.location.type", }, + { "lr.default-reductions", "lr.default-reduction", }, + { "lr.keep-unreachable-states", "lr.keep-unreachable-state", }, + { "lr.keep_unreachable_states", "lr.keep-unreachable-state", }, { "namespace", "api.namespace", }, + { "stype", "api.value.type", }, + { "variant=", "api.value.type=variant", }, + { "variant=true", "api.value.type=variant", }, + { NULL, NULL, } }; - char const *res = variable; - int i; - for (i = 0; i < ARRAY_CARDINALITY (conversion); ++i) - if (STREQ (conversion[i].obsolete, variable)) - { - res = conversion[i].updated; - complain (&variable_loc, Wdeprecated, - _("deprecated %%define variable name: %s, use %s"), - quote (variable), quote_n (1, res)); - break; - } - return res; + conversion_type const *c; + for (c = conversion; c->obsolete; ++c) + { + char const *eq = strchr (c->obsolete, '='); + if (eq + ? (!strncmp (c->obsolete, variable, eq - c->obsolete) + && STREQ (eq + 1, *value)) + : STREQ (c->obsolete, variable)) + { + char *old = define_directive (c->obsolete, *value); + char *upd = define_directive (c->updated, *value); + deprecated_directive (&variable_loc, old, upd); + free (old); + free (upd); + char *res = xstrdup (c->updated); + { + char *eq2 = strchr (res, '='); + if (eq2) + { + *eq2 = '\0'; + *value = eq2 + 1; + } + } + return res; + } + } + return xstrdup (variable); } void -muscle_percent_define_insert (char const *variable, location variable_loc, +muscle_percent_define_insert (char const *var, location variable_loc, char const *value, muscle_percent_define_how how) { - char const *name; - char const *loc_name; - char const *syncline_name; - char const *how_name; - - /* Permit certain names with underscores for backward compatibility. */ - variable = muscle_percent_variable_update (variable, variable_loc); - - name = UNIQSTR_CONCAT ("percent_define(", variable, ")"); - loc_name = UNIQSTR_CONCAT ("percent_define_loc(", variable, ")"); - syncline_name = + /* Backward compatibility. */ + 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 = UNIQSTR_CONCAT ("percent_define_syncline(", variable, ")"); - how_name = UNIQSTR_CONCAT ("percent_define_how(", variable, ")"); + char const *how_name = UNIQSTR_CONCAT ("percent_define_how(", variable, ")"); /* Command-line options are processed before the grammar file. */ if (how == MUSCLE_PERCENT_DEFINE_GRAMMAR_FILE @@ -441,14 +493,13 @@ muscle_percent_define_insert (char const *variable, location variable_loc, muscle_percent_define_how how_old = atoi (muscle_find_const (how_name)); unsigned i = 0; if (how_old == MUSCLE_PERCENT_DEFINE_F) - return; - complain_at_indent (variable_loc, complaint, &i, - _("%%define variable %s redefined"), - quote (variable)); + goto end; + complain_indent (&variable_loc, complaint, &i, + _("%%define variable %s redefined"), + quote (variable)); i += SUB_INDENT; - complain_at_indent (muscle_percent_define_get_loc (variable), - complaint, &i, - _("previous definition")); + location loc = muscle_percent_define_get_loc (variable); + complain_indent (&loc, complaint, &i, _("previous definition")); } MUSCLE_INSERT_STRING (name, value); @@ -459,6 +510,8 @@ muscle_percent_define_insert (char const *variable, location variable_loc, muscle_user_name_list_grow ("percent_define_user_variables", variable, variable_loc); MUSCLE_INSERT_INT (how_name, how); + end: + free (variable); } /* This is used for backward compatibility, e.g., "%define api.pure" @@ -606,14 +659,13 @@ muscle_percent_define_check_values (char const * const *values) { unsigned i = 0; location loc = muscle_percent_define_get_loc (*variablep); - complain_at_indent - (loc, complaint, &i, - _("invalid value for %%define variable %s: %s"), - quote (*variablep), quote_n (1, value)); + complain_indent (&loc, complaint, &i, + _("invalid value for %%define variable %s: %s"), + quote (*variablep), quote_n (1, value)); i += SUB_INDENT; for (values = variablep + 1; *values; ++values) - complain_at_indent (loc, complaint, &i, _("accepted value: %s"), - quote (*values)); + complain_indent (&loc, complaint | no_caret, &i, + _("accepted value: %s"), quote (*values)); } else {