[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: FYI: maint: style: reduce scopes
From: |
Akim Demaille |
Subject: |
Re: FYI: maint: style: reduce scopes |
Date: |
Sat, 18 Aug 2018 08:20:41 +0200 |
> Le 18 août 2018 à 07:36, Akim Demaille <address@hidden> a écrit :
>
> Installed in master.
Another one.
commit ffe54e14feee472f7edb5987ee1622b099966326
Author: Akim Demaille <address@hidden>
Date: Sat Aug 18 08:18:51 2018 +0200
style: reduce scopes
* src/scan-code.l: here.
diff --git a/src/scan-code.l b/src/scan-code.l
index faa620ff..4d19aa70 100644
--- a/src/scan-code.l
+++ b/src/scan-code.l
@@ -395,9 +395,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 +418,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 +434,9 @@ parse_ref (char *cp, symbol_list *rule, int rule_length,
}
}
+ char *cp_end;
+ bool explicit_bracketing;
+
if ('[' == *cp)
{
/* Ignore the brackets. */
@@ -473,16 +467,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 +488,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 +627,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 +642,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 +721,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 +737,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 +766,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 +776,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;