mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-18 16:53:02 +00:00
style: reduce scopes in muscle-tab.c
This commit is contained in:
130
src/muscle-tab.c
130
src/muscle-tab.c
@@ -175,9 +175,6 @@ muscle_grow (const char *key, const char *val,
|
|||||||
const char *separator, const char *terminator)
|
const char *separator, const char *terminator)
|
||||||
{
|
{
|
||||||
muscle_entry *entry = muscle_lookup (key);
|
muscle_entry *entry = muscle_lookup (key);
|
||||||
size_t vals = strlen (val);
|
|
||||||
size_t terms = strlen (terminator);
|
|
||||||
|
|
||||||
if (entry)
|
if (entry)
|
||||||
{
|
{
|
||||||
obstack_sgrow (&muscle_obstack, entry->value);
|
obstack_sgrow (&muscle_obstack, entry->value);
|
||||||
@@ -189,12 +186,14 @@ muscle_grow (const char *key, const char *val,
|
|||||||
|
|
||||||
obstack_sgrow (&muscle_obstack, val);
|
obstack_sgrow (&muscle_obstack, val);
|
||||||
|
|
||||||
|
size_t vals = strlen (val);
|
||||||
|
size_t terms = strlen (terminator);
|
||||||
if (terms <= vals
|
if (terms <= vals
|
||||||
&& STRNEQ (val + vals - terms, terminator))
|
&& STRNEQ (val + vals - terms, terminator))
|
||||||
obstack_sgrow (&muscle_obstack, terminator);
|
obstack_sgrow (&muscle_obstack, terminator);
|
||||||
|
|
||||||
{
|
{
|
||||||
char *new_val = obstack_finish0 (&muscle_obstack);
|
char const *new_val = obstack_finish0 (&muscle_obstack);
|
||||||
entry->value = entry->storage = xstrdup (new_val);
|
entry->value = entry->storage = xstrdup (new_val);
|
||||||
obstack_free (&muscle_obstack, new_val);
|
obstack_free (&muscle_obstack, new_val);
|
||||||
}
|
}
|
||||||
@@ -208,12 +207,11 @@ muscle_grow (const char *key, const char *val,
|
|||||||
static void
|
static void
|
||||||
muscle_syncline_grow (char const *key, location loc)
|
muscle_syncline_grow (char const *key, location loc)
|
||||||
{
|
{
|
||||||
char *extension = NULL;
|
|
||||||
obstack_printf (&muscle_obstack, "]b4_syncline(%d, ", loc.start.line);
|
obstack_printf (&muscle_obstack, "]b4_syncline(%d, ", loc.start.line);
|
||||||
obstack_quote (&muscle_obstack,
|
obstack_quote (&muscle_obstack,
|
||||||
quotearg_style (c_quoting_style, loc.start.file));
|
quotearg_style (c_quoting_style, loc.start.file));
|
||||||
obstack_sgrow (&muscle_obstack, ")[");
|
obstack_sgrow (&muscle_obstack, ")[");
|
||||||
extension = obstack_finish0 (&muscle_obstack);
|
char const *extension = obstack_finish0 (&muscle_obstack);
|
||||||
muscle_grow (key, extension, "", "");
|
muscle_grow (key, extension, "", "");
|
||||||
obstack_free (&muscle_obstack, extension);
|
obstack_free (&muscle_obstack, extension);
|
||||||
}
|
}
|
||||||
@@ -236,13 +234,12 @@ void
|
|||||||
muscle_pair_list_grow (const char *muscle,
|
muscle_pair_list_grow (const char *muscle,
|
||||||
const char *a1, const char *a2)
|
const char *a1, const char *a2)
|
||||||
{
|
{
|
||||||
char *pair;
|
|
||||||
obstack_sgrow (&muscle_obstack, "[");
|
obstack_sgrow (&muscle_obstack, "[");
|
||||||
obstack_quote (&muscle_obstack, a1);
|
obstack_quote (&muscle_obstack, a1);
|
||||||
obstack_sgrow (&muscle_obstack, ", ");
|
obstack_sgrow (&muscle_obstack, ", ");
|
||||||
obstack_quote (&muscle_obstack, a2);
|
obstack_quote (&muscle_obstack, a2);
|
||||||
obstack_sgrow (&muscle_obstack, "]");
|
obstack_sgrow (&muscle_obstack, "]");
|
||||||
pair = obstack_finish0 (&muscle_obstack);
|
char const *pair = obstack_finish0 (&muscle_obstack);
|
||||||
muscle_grow (muscle, pair, ",\n", "");
|
muscle_grow (muscle, pair, ",\n", "");
|
||||||
obstack_free (&muscle_obstack, pair);
|
obstack_free (&muscle_obstack, pair);
|
||||||
}
|
}
|
||||||
@@ -275,11 +272,10 @@ muscle_find (char const *key)
|
|||||||
static void
|
static void
|
||||||
muscle_boundary_grow (char const *key, boundary bound)
|
muscle_boundary_grow (char const *key, boundary bound)
|
||||||
{
|
{
|
||||||
char *extension;
|
|
||||||
obstack_sgrow (&muscle_obstack, "[[");
|
obstack_sgrow (&muscle_obstack, "[[");
|
||||||
obstack_escape (&muscle_obstack, bound.file);
|
obstack_escape (&muscle_obstack, bound.file);
|
||||||
obstack_printf (&muscle_obstack, ":%d.%d]]", bound.line, bound.column);
|
obstack_printf (&muscle_obstack, ":%d.%d]]", bound.line, bound.column);
|
||||||
extension = obstack_finish0 (&muscle_obstack);
|
char const *extension = obstack_finish0 (&muscle_obstack);
|
||||||
muscle_grow (key, extension, "", "");
|
muscle_grow (key, extension, "", "");
|
||||||
obstack_free (&muscle_obstack, extension);
|
obstack_free (&muscle_obstack, extension);
|
||||||
}
|
}
|
||||||
@@ -322,9 +318,6 @@ static char *
|
|||||||
string_decode (char const *key)
|
string_decode (char const *key)
|
||||||
{
|
{
|
||||||
char const *value = muscle_find_const (key);
|
char const *value = muscle_find_const (key);
|
||||||
char *value_decoded;
|
|
||||||
char *result;
|
|
||||||
|
|
||||||
if (!value)
|
if (!value)
|
||||||
return NULL;
|
return NULL;
|
||||||
do {
|
do {
|
||||||
@@ -337,20 +330,20 @@ string_decode (char const *key)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} while (*value++);
|
} while (*value++);
|
||||||
value_decoded = obstack_finish (&muscle_obstack);
|
char const *value_decoded = obstack_finish (&muscle_obstack);
|
||||||
result = xstrdup (value_decoded);
|
char *res = xstrdup (value_decoded);
|
||||||
obstack_free (&muscle_obstack, value_decoded);
|
obstack_free (&muscle_obstack, value_decoded);
|
||||||
return result;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Reverse of muscle_location_grow. */
|
/* Reverse of muscle_location_grow. */
|
||||||
static location
|
static location
|
||||||
location_decode (char const *value)
|
location_decode (char const *value)
|
||||||
{
|
{
|
||||||
location loc;
|
|
||||||
aver (value);
|
aver (value);
|
||||||
aver (*value == '[');
|
aver (*value == '[');
|
||||||
++value; aver (*value == '[');
|
++value; aver (*value == '[');
|
||||||
|
location loc;
|
||||||
while (*++value)
|
while (*++value)
|
||||||
switch (*value)
|
switch (*value)
|
||||||
{
|
{
|
||||||
@@ -359,29 +352,26 @@ location_decode (char const *value)
|
|||||||
aver (false);
|
aver (false);
|
||||||
break;
|
break;
|
||||||
case ']':
|
case ']':
|
||||||
{
|
++value; aver (*value == ']');
|
||||||
char *boundary_str;
|
char *boundary_str = obstack_finish0 (&muscle_obstack);
|
||||||
++value; aver (*value == ']');
|
switch (*++value)
|
||||||
boundary_str = obstack_finish0 (&muscle_obstack);
|
{
|
||||||
switch (*++value)
|
case ',':
|
||||||
{
|
boundary_set_from_string (&loc.start, boundary_str);
|
||||||
case ',':
|
obstack_free (&muscle_obstack, boundary_str);
|
||||||
boundary_set_from_string (&loc.start, boundary_str);
|
++value; aver (*value == ' ');
|
||||||
obstack_free (&muscle_obstack, boundary_str);
|
++value; aver (*value == '[');
|
||||||
++value; aver (*value == ' ');
|
++value; aver (*value == '[');
|
||||||
++value; aver (*value == '[');
|
break;
|
||||||
++value; aver (*value == '[');
|
case '\0':
|
||||||
break;
|
boundary_set_from_string (&loc.end, boundary_str);
|
||||||
case '\0':
|
obstack_free (&muscle_obstack, boundary_str);
|
||||||
boundary_set_from_string (&loc.end, boundary_str);
|
return loc;
|
||||||
obstack_free (&muscle_obstack, boundary_str);
|
break;
|
||||||
return loc;
|
default:
|
||||||
break;
|
aver (false);
|
||||||
default:
|
break;
|
||||||
aver (false);
|
}
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
aver (false);
|
aver (false);
|
||||||
@@ -446,21 +436,21 @@ muscle_percent_variable_update (char const *variable, location variable_loc,
|
|||||||
} conversion_type;
|
} conversion_type;
|
||||||
const conversion_type conversion[] =
|
const conversion_type conversion[] =
|
||||||
{
|
{
|
||||||
{ "api.push_pull", "api.push-pull", },
|
{ "api.push_pull", "api.push-pull", },
|
||||||
{ "api.tokens.prefix", "api.token.prefix", },
|
{ "api.tokens.prefix", "api.token.prefix", },
|
||||||
{ "lex_symbol", "api.token.constructor", },
|
{ "lex_symbol", "api.token.constructor", },
|
||||||
{ "location_type", "api.location.type", },
|
{ "location_type", "api.location.type", },
|
||||||
{ "lr.default-reductions", "lr.default-reduction", },
|
{ "lr.default-reductions", "lr.default-reduction", },
|
||||||
{ "lr.keep-unreachable-states", "lr.keep-unreachable-state", },
|
{ "lr.keep-unreachable-states", "lr.keep-unreachable-state", },
|
||||||
{ "lr.keep_unreachable_states", "lr.keep-unreachable-state", },
|
{ "lr.keep_unreachable_states", "lr.keep-unreachable-state", },
|
||||||
{ "namespace", "api.namespace", },
|
{ "namespace", "api.namespace", },
|
||||||
{ "stype", "api.value.type", },
|
{ "stype", "api.value.type", },
|
||||||
{ "variant=", "api.value.type=variant", },
|
{ "variant=", "api.value.type=variant", },
|
||||||
{ "variant=true", "api.value.type=variant", },
|
{ "variant=true", "api.value.type=variant", },
|
||||||
{ NULL, NULL, }
|
{ NULL, NULL, }
|
||||||
};
|
};
|
||||||
conversion_type const *c;
|
|
||||||
for (c = conversion; c->obsolete; ++c)
|
for (conversion_type const *c = conversion; c->obsolete; ++c)
|
||||||
{
|
{
|
||||||
char const *eq = strchr (c->obsolete, '=');
|
char const *eq = strchr (c->obsolete, '=');
|
||||||
if (eq
|
if (eq
|
||||||
@@ -474,14 +464,12 @@ muscle_percent_variable_update (char const *variable, location variable_loc,
|
|||||||
free (old);
|
free (old);
|
||||||
free (upd);
|
free (upd);
|
||||||
char *res = xstrdup (c->updated);
|
char *res = xstrdup (c->updated);
|
||||||
{
|
char *eq2 = strchr (res, '=');
|
||||||
char *eq2 = strchr (res, '=');
|
if (eq2)
|
||||||
if (eq2)
|
{
|
||||||
{
|
*eq2 = '\0';
|
||||||
*eq2 = '\0';
|
*value = eq2 + 1;
|
||||||
*value = eq2 + 1;
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -507,9 +495,9 @@ muscle_percent_define_insert (char const *var, location variable_loc,
|
|||||||
&& muscle_find_const (name))
|
&& muscle_find_const (name))
|
||||||
{
|
{
|
||||||
muscle_percent_define_how how_old = atoi (muscle_find_const (how_name));
|
muscle_percent_define_how how_old = atoi (muscle_find_const (how_name));
|
||||||
unsigned i = 0;
|
|
||||||
if (how_old == MUSCLE_PERCENT_DEFINE_F)
|
if (how_old == MUSCLE_PERCENT_DEFINE_F)
|
||||||
goto end;
|
goto end;
|
||||||
|
unsigned i = 0;
|
||||||
complain_indent (&variable_loc, complaint, &i,
|
complain_indent (&variable_loc, complaint, &i,
|
||||||
_("%%define variable %s redefined"),
|
_("%%define variable %s redefined"),
|
||||||
quote (variable));
|
quote (variable));
|
||||||
@@ -645,16 +633,16 @@ bool
|
|||||||
muscle_percent_define_flag_if (char const *variable)
|
muscle_percent_define_flag_if (char const *variable)
|
||||||
{
|
{
|
||||||
uniqstr invalid_boolean_name = muscle_name (variable, "invalid_boolean");
|
uniqstr invalid_boolean_name = muscle_name (variable, "invalid_boolean");
|
||||||
bool result = false;
|
bool res = false;
|
||||||
|
|
||||||
if (muscle_percent_define_ifdef (variable))
|
if (muscle_percent_define_ifdef (variable))
|
||||||
{
|
{
|
||||||
char *value = muscle_percent_define_get (variable);
|
char *value = muscle_percent_define_get (variable);
|
||||||
muscle_percent_define_check_kind (variable, muscle_keyword);
|
muscle_percent_define_check_kind (variable, muscle_keyword);
|
||||||
if (value[0] == '\0' || STREQ (value, "true"))
|
if (value[0] == '\0' || STREQ (value, "true"))
|
||||||
result = true;
|
res = true;
|
||||||
else if (STREQ (value, "false"))
|
else if (STREQ (value, "false"))
|
||||||
result = false;
|
res = false;
|
||||||
else if (!muscle_find_const (invalid_boolean_name))
|
else if (!muscle_find_const (invalid_boolean_name))
|
||||||
{
|
{
|
||||||
muscle_insert (invalid_boolean_name, "");
|
muscle_insert (invalid_boolean_name, "");
|
||||||
@@ -669,7 +657,7 @@ muscle_percent_define_flag_if (char const *variable)
|
|||||||
complain (NULL, fatal, _("%s: undefined %%define variable %s"),
|
complain (NULL, fatal, _("%s: undefined %%define variable %s"),
|
||||||
"muscle_percent_define_flag", quote (variable));
|
"muscle_percent_define_flag", quote (variable));
|
||||||
|
|
||||||
return result;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -705,14 +693,12 @@ muscle_percent_define_check_values (char const * const *values)
|
|||||||
if (value)
|
if (value)
|
||||||
{
|
{
|
||||||
for (++values; *values; ++values)
|
for (++values; *values; ++values)
|
||||||
{
|
if (STREQ (value, *values))
|
||||||
if (STREQ (value, *values))
|
break;
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (!*values)
|
if (!*values)
|
||||||
{
|
{
|
||||||
unsigned i = 0;
|
|
||||||
location loc = muscle_percent_define_get_loc (*variablep);
|
location loc = muscle_percent_define_get_loc (*variablep);
|
||||||
|
unsigned i = 0;
|
||||||
complain_indent (&loc, complaint, &i,
|
complain_indent (&loc, complaint, &i,
|
||||||
_("invalid value for %%define variable %s: %s"),
|
_("invalid value for %%define variable %s: %s"),
|
||||||
quote (*variablep), quote_n (1, value));
|
quote (*variablep), quote_n (1, value));
|
||||||
@@ -722,10 +708,8 @@ muscle_percent_define_check_values (char const * const *values)
|
|||||||
_("accepted value: %s"), quote (*values));
|
_("accepted value: %s"), quote (*values));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
while (*values)
|
||||||
while (*values)
|
++values;
|
||||||
++values;
|
|
||||||
}
|
|
||||||
free (value);
|
free (value);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
Reference in New Issue
Block a user