* src/output.c (action_row, save_column, default_goto)

(sort_actions, matching_state, pack_vector): Better variable
locality.
This commit is contained in:
Akim Demaille
2001-12-17 17:31:37 +00:00
parent 796d61fbdd
commit 837491d810
2 changed files with 61 additions and 91 deletions

View File

@@ -1,3 +1,10 @@
2001-12-17 Akim Demaille <akim@epita.fr>
* src/output.c (action_row, save_column, default_goto)
(sort_actions, matching_state, pack_vector): Better variable
locality.
2001-12-17 Akim Demaille <akim@epita.fr> 2001-12-17 Akim Demaille <akim@epita.fr>
* src/output.c: Various formatting changes. * src/output.c: Various formatting changes.

View File

@@ -326,55 +326,44 @@ static int
action_row (int state) action_row (int state)
{ {
int i; int i;
int j;
int m = 0; int m = 0;
int n = 0; int n = 0;
int default_rule; int default_rule = 0;
int nreds; reductions *redp = state_table[state]->reductions;
int rule; int nreds = redp ? redp->nreds : 0;
int shift_state; shifts *shiftp = state_table[state]->shifts;
int symbol; errs *errp = state_table[state]->errs;
reductions *redp; /* set nonzero to inhibit having any default reduction */
shifts *shiftp; int nodefault = 0;
errs *errp;
int nodefault = 0; /* set nonzero to inhibit having any default reduction */
for (i = 0; i < ntokens; i++) for (i = 0; i < ntokens; i++)
actrow[i] = 0; actrow[i] = 0;
default_rule = 0; if (nreds >= 1)
nreds = 0;
redp = state_table[state]->reductions;
if (redp)
{ {
nreds = redp->nreds; int j;
/* loop over all the rules available here which require
lookahead */
m = state_table[state]->lookaheads;
n = state_table[state + 1]->lookaheads;
if (nreds >= 1) for (i = n - 1; i >= m; i--)
{ /* and find each token which the rule finds acceptable
/* loop over all the rules available here which require to come next */
lookahead */ for (j = 0; j < ntokens; j++)
m = state_table[state]->lookaheads; /* and record this rule as the rule to use if that
n = state_table[state + 1]->lookaheads; token follows. */
if (BITISSET (LA (i), j))
for (i = n - 1; i >= m; i--) actrow[j] = -LAruleno[i];
/* and find each token which the rule finds acceptable
to come next */
for (j = 0; j < ntokens; j++)
/* and record this rule as the rule to use if that
token follows. */
if (BITISSET (LA (i), j))
actrow[j] = -LAruleno[i];
}
} }
/* Now see which tokens are allowed for shifts in this state. For /* Now see which tokens are allowed for shifts in this state. For
them, record the shift as the thing to do. So shift is preferred them, record the shift as the thing to do. So shift is preferred
to reduce. */ to reduce. */
shiftp = state_table[state]->shifts;
for (i = 0; i < shiftp->nshifts; i++) for (i = 0; i < shiftp->nshifts; i++)
{ {
shift_state = shiftp->shifts[i]; int symbol;
int shift_state = shiftp->shifts[i];
if (!shift_state) if (!shift_state)
continue; continue;
@@ -393,12 +382,10 @@ action_row (int state)
/* See which tokens are an explicit error in this state (due to /* See which tokens are an explicit error in this state (due to
%nonassoc). For them, record MINSHORT as the action. */ %nonassoc). For them, record MINSHORT as the action. */
errp = state_table[state]->errs;
if (errp) if (errp)
for (i = 0; i < errp->nerrs; i++) for (i = 0; i < errp->nerrs; i++)
{ {
symbol = errp->errs[i]; int symbol = errp->errs[i];
actrow[symbol] = MINSHORT; actrow[symbol] = MINSHORT;
} }
@@ -415,13 +402,12 @@ action_row (int state)
for (i = m; i < n; i++) for (i = m; i < n; i++)
{ {
int count = 0; int count = 0;
rule = -LAruleno[i]; int rule = -LAruleno[i];
int j;
for (j = 0; j < ntokens; j++) for (j = 0; j < ntokens; j++)
{ if (actrow[j] == rule)
if (actrow[j] == rule) count++;
count++;
}
if (count > max) if (count > max)
{ {
@@ -435,11 +421,10 @@ action_row (int state)
if (max > 0) if (max > 0)
{ {
int j;
for (j = 0; j < ntokens; j++) for (j = 0; j < ntokens; j++)
{ if (actrow[j] == default_rule)
if (actrow[j] == default_rule) actrow[j] = 0;
actrow[j] = 0;
}
default_rule = -default_rule; default_rule = -default_rule;
} }
@@ -450,11 +435,9 @@ action_row (int state)
So replace any action which says "error" with "use default". */ So replace any action which says "error" with "use default". */
if (default_rule == 0) if (default_rule == 0)
for (j = 0; j < ntokens; j++) for (i = 0; i < ntokens; i++)
{ if (actrow[i] == MINSHORT)
if (actrow[j] == MINSHORT) actrow[i] = 0;
actrow[j] = 0;
}
return default_rule; return default_rule;
} }
@@ -566,7 +549,7 @@ save_column (int symbol, int default_state)
short *sp1; short *sp1;
short *sp2; short *sp2;
int count; int count;
int symno; int symno = symbol - ntokens + nstates;
short begin = goto_map[symbol]; short begin = goto_map[symbol];
short end = goto_map[symbol + 1]; short end = goto_map[symbol + 1];
@@ -579,8 +562,6 @@ save_column (int symbol, int default_state)
if (count == 0) if (count == 0)
return; return;
symno = symbol - ntokens + nstates;
froms[symno] = sp1 = sp = XCALLOC (short, count); froms[symno] = sp1 = sp = XCALLOC (short, count);
tos[symno] = sp2 = XCALLOC (short, count); tos[symno] = sp2 = XCALLOC (short, count);
@@ -599,13 +580,10 @@ static int
default_goto (int symbol) default_goto (int symbol)
{ {
int i; int i;
int m; int m = goto_map[symbol];
int n; int n = goto_map[symbol + 1];
int default_state; int default_state = -1;
int max; int max = 0;
m = goto_map[symbol];
n = goto_map[symbol + 1];
if (m == n) if (m == n)
return -1; return -1;
@@ -616,9 +594,6 @@ default_goto (int symbol)
for (i = m; i < n; i++) for (i = m; i < n; i++)
state_count[to_state[i]]++; state_count[to_state[i]]++;
max = 0;
default_state = -1;
for (i = 0; i < nstates; i++) for (i = 0; i < nstates; i++)
if (state_count[i] > max) if (state_count[i] > max)
{ {
@@ -669,10 +644,6 @@ static void
sort_actions (void) sort_actions (void)
{ {
int i; int i;
int j;
int k;
int t;
int w;
order = XCALLOC (short, nvectors); order = XCALLOC (short, nvectors);
nentries = 0; nentries = 0;
@@ -680,9 +651,10 @@ sort_actions (void)
for (i = 0; i < nvectors; i++) for (i = 0; i < nvectors; i++)
if (tally[i] > 0) if (tally[i] > 0)
{ {
t = tally[i]; int k;
w = width[i]; int t = tally[i];
j = nentries - 1; int w = width[i];
int j = nentries - 1;
while (j >= 0 && (width[order[j]] < w)) while (j >= 0 && (width[order[j]] < w))
j--; j--;
@@ -702,15 +674,11 @@ sort_actions (void)
static int static int
matching_state (int vector) matching_state (int vector)
{ {
int i; int i = order[vector];
int j;
int k;
int t; int t;
int w; int w;
int match;
int prev; int prev;
i = order[vector];
if (i >= nstates) if (i >= nstates)
return -1; return -1;
@@ -719,11 +687,13 @@ matching_state (int vector)
for (prev = vector - 1; prev >= 0; prev--) for (prev = vector - 1; prev >= 0; prev--)
{ {
j = order[prev]; int j = order[prev];
int k;
int match = 1;
if (width[j] != w || tally[j] != t) if (width[j] != w || tally[j] != t)
return -1; return -1;
match = 1;
for (k = 0; match && k < t; k++) for (k = 0; match && k < t; k++)
if (tos[j][k] != tos[i][k] || froms[j][k] != froms[i][k]) if (tos[j][k] != tos[i][k] || froms[j][k] != froms[i][k])
match = 0; match = 0;
@@ -739,26 +709,19 @@ matching_state (int vector)
static int static int
pack_vector (int vector) pack_vector (int vector)
{ {
int i; int i = order[vector];
int j; int j;
int k; int t = tally[i];
int t;
int loc = 0; int loc = 0;
int ok; short *from = froms[i];
short *from; short *to = tos[i];
short *to;
i = order[vector];
t = tally[i];
assert (t); assert (t);
from = froms[i];
to = tos[i];
for (j = lowzero - from[0]; j < MAXTABLE; j++) for (j = lowzero - from[0]; j < MAXTABLE; j++)
{ {
ok = 1; int k;
int ok = 1;
for (k = 0; ok && k < t; k++) for (k = 0; ok && k < t; k++)
{ {