From 28cde9c128f31c77d6ce05a1fa1b1a9cd8304d6f Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Sat, 18 Aug 2018 08:18:51 +0200 Subject: [PATCH] style: reduce scopes * src/scan-code.l: here. --- src/scan-code.l | 53 ++++++++++++++++++++----------------------------- 1 file changed, 22 insertions(+), 31 deletions(-) diff --git a/src/scan-code.l b/src/scan-code.l index faa620ff..5662b76e 100644 --- a/src/scan-code.l +++ b/src/scan-code.l @@ -296,9 +296,7 @@ static variant * variant_add (uniqstr id, location id_loc, unsigned symbol_index, char *cp, char *cp_end, bool explicit_bracketing) { - char *prefix_end; - - prefix_end = find_prefix_end (id, cp, cp_end); + char *prefix_end = find_prefix_end (id, cp, cp_end); if (prefix_end && (prefix_end == cp_end || (!explicit_bracketing && is_dot_or_dash (*prefix_end)))) @@ -340,8 +338,6 @@ show_sub_message (warnings warning, var->id, at_spec); else { - static struct obstack msg_buf; - const char *tail = explicit_bracketing ? "" : cp + strlen (var->id); const char *id; location id_loc; @@ -356,7 +352,10 @@ show_sub_message (warnings warning, id_loc = var->loc; } + const char *tail = explicit_bracketing ? "" : cp + strlen (var->id); + /* Create the explanation message. */ + static struct obstack msg_buf; obstack_init (&msg_buf); obstack_printf (&msg_buf, _("possibly meant: %c"), dollar_or_at); @@ -395,9 +394,7 @@ show_sub_messages (warnings warning, int midrule_rhs_index, char dollar_or_at, unsigned indent) { - unsigned i; - - for (i = 0; i < variant_count; ++i) + for (unsigned i = 0; i < variant_count; ++i) show_sub_message (warning | silent, cp, explicit_bracketing, midrule_rhs_index, dollar_or_at, @@ -420,13 +417,6 @@ parse_ref (char *cp, symbol_list *rule, int rule_length, int midrule_rhs_index, char *text, location text_loc, char dollar_or_at) { - symbol_list *l; - char *cp_end; - bool explicit_bracketing; - unsigned i; - unsigned valid_variants = 0; - unsigned valid_variant_index = 0; - if ('$' == *cp) return LHS_REF; @@ -443,6 +433,9 @@ parse_ref (char *cp, symbol_list *rule, int rule_length, } } + char *cp_end; + bool explicit_bracketing; + if ('[' == *cp) { /* Ignore the brackets. */ @@ -473,16 +466,17 @@ parse_ref (char *cp, symbol_list *rule, int rule_length, /* Add all relevant variants. */ { unsigned symbol_index; + symbol_list *l; variant_count = 0; for (symbol_index = 0, l = rule; !symbol_list_null (l); ++symbol_index, l = l->next) { - variant *var; if (l->content_type != SYMLIST_SYMBOL) continue; - var = variant_add (l->content.sym->tag, l->sym_loc, - symbol_index, cp, cp_end, explicit_bracketing); + variant *var + = variant_add (l->content.sym->tag, l->sym_loc, + symbol_index, cp, cp_end, explicit_bracketing); if (var && l->named_ref) var->hidden_by = l->named_ref; @@ -493,7 +487,9 @@ parse_ref (char *cp, symbol_list *rule, int rule_length, } /* Check errors. */ - for (i = 0; i < variant_count; ++i) + unsigned valid_variants = 0; + unsigned valid_variant_index = 0; + for (unsigned i = 0; i < variant_count; ++i) { variant *var = &variant_table[i]; unsigned symbol_index = var->symbol_index; @@ -630,11 +626,8 @@ fetch_type_name (char *cp, char const **type_name, static void handle_action_dollar (symbol_list *rule, char *text, location dollar_loc) { - char const *type_name = NULL; - char *cp = text + 1; symbol_list *effective_rule; int effective_rule_length; - int n; if (rule->midrule_parent_rule) { @@ -648,10 +641,11 @@ handle_action_dollar (symbol_list *rule, char *text, location dollar_loc) } /* Get the type name if explicit. */ - cp = fetch_type_name (cp, &type_name, dollar_loc); + char const *type_name = NULL; + char *cp = fetch_type_name (text + 1, &type_name, dollar_loc); - n = parse_ref (cp, effective_rule, effective_rule_length, - rule->midrule_parent_rhs_index, text, dollar_loc, '$'); + int n = parse_ref (cp, effective_rule, effective_rule_length, + rule->midrule_parent_rhs_index, text, dollar_loc, '$'); /* End type_name. */ if (type_name) @@ -726,10 +720,8 @@ handle_action_dollar (symbol_list *rule, char *text, location dollar_loc) static void handle_action_at (symbol_list *rule, char *text, location at_loc) { - char *cp = text + 1; symbol_list *effective_rule; int effective_rule_length; - int n; if (rule->midrule_parent_rule) { @@ -744,8 +736,8 @@ handle_action_at (symbol_list *rule, char *text, location at_loc) muscle_percent_define_ensure("locations", at_loc, true); - n = parse_ref (cp, effective_rule, effective_rule_length, - rule->midrule_parent_rhs_index, text, at_loc, '@'); + int n = parse_ref (text + 1, effective_rule, effective_rule_length, + rule->midrule_parent_rhs_index, text, at_loc, '@'); switch (n) { case INVALID_REF: @@ -773,7 +765,6 @@ handle_action_at (symbol_list *rule, char *text, location at_loc) static char const * translate_action (code_props *self, int sc_context) { - char *res; static bool initialized = false; if (!initialized) { @@ -784,7 +775,7 @@ translate_action (code_props *self, int sc_context) loc->start = loc->end = self->location.start; yy_switch_to_buffer (yy_scan_string (self->code)); - res = code_lex (self, sc_context); + char *res = code_lex (self, sc_context); yy_delete_buffer (YY_CURRENT_BUFFER); return res;