tables: scope reduction

* src/tables.c (matching_state): here.
This commit is contained in:
Akim Demaille
2012-12-26 18:16:55 +01:00
parent 33f7f342c3
commit 465df9c65c

View File

@@ -620,16 +620,12 @@ static state_number
matching_state (vector_number vector) matching_state (vector_number vector)
{ {
vector_number i = order[vector]; vector_number i = order[vector];
size_t t;
int w;
int prev;
/* If VECTOR is a nterm, return -1. */ /* If VECTOR is a nterm, return -1. */
if (nstates <= i) if (i < nstates)
return -1; {
size_t t = tally[i];
t = tally[i]; int w = width[i];
w = width[i]; int prev;
/* If VECTOR has GLR conflicts, return -1 */ /* If VECTOR has GLR conflicts, return -1 */
if (conflict_tos[i] != NULL) if (conflict_tos[i] != NULL)
@@ -640,27 +636,27 @@ matching_state (vector_number vector)
return -1; return -1;
} }
for (prev = vector - 1; prev >= 0; prev--) for (prev = vector - 1; 0 <= prev; prev--)
{ {
vector_number j = order[prev]; vector_number j = order[prev];
int k;
int match = 1;
/* Given how ORDER was computed, if the WIDTH or TALLY is /* Given how ORDER was computed, if the WIDTH or TALLY is
different, there cannot be a matching state. */ different, there cannot be a matching state. */
if (width[j] != w || tally[j] != t) if (width[j] != w || tally[j] != t)
return -1; return -1;
else
{
bool match = true;
int k;
for (k = 0; match && k < t; k++) for (k = 0; match && k < t; k++)
if (tos[j][k] != tos[i][k] if (tos[j][k] != tos[i][k]
|| froms[j][k] != froms[i][k] || froms[j][k] != froms[i][k]
|| (conflict_tos[j] != NULL && conflict_tos[j][k] != 0)) || (conflict_tos[j] != NULL && conflict_tos[j][k] != 0))
match = 0; match = false;
if (match) if (match)
return j; return j;
} }
}
}
return -1; return -1;
} }