mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-19 17:23:02 +00:00
* src/lalr.c (transpose): Free the memory allocated to the
argument, as it is replaced by the results by the unique caller. (build_relations): Merely invoke transpose: it handles the memory deallocation. Improve variable locality. Avoid variables used as mere abbreviations. (compute_lookaheads): Use arrays instead of pointers.
This commit is contained in:
10
ChangeLog
10
ChangeLog
@@ -1,3 +1,13 @@
|
|||||||
|
2001-12-05 Akim Demaille <akim@epita.fr>
|
||||||
|
|
||||||
|
* src/lalr.c (transpose): Free the memory allocated to the
|
||||||
|
argument, as it is replaced by the results by the unique caller.
|
||||||
|
(build_relations): Merely invoke transpose: it handles the memory
|
||||||
|
deallocation.
|
||||||
|
Improve variable locality.
|
||||||
|
Avoid variables used as mere abbreviations.
|
||||||
|
(compute_lookaheads): Use arrays instead of pointers.
|
||||||
|
|
||||||
2001-12-05 Akim Demaille <akim@epita.fr>
|
2001-12-05 Akim Demaille <akim@epita.fr>
|
||||||
|
|
||||||
* src/lalr.c (initialize_F): Improve variable locality.
|
* src/lalr.c (initialize_F): Improve variable locality.
|
||||||
|
|||||||
60
src/lalr.c
60
src/lalr.c
@@ -435,6 +435,11 @@ add_lookback_edge (int stateno, int ruleno, int gotono)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*-------------------------------------------------------------------.
|
||||||
|
| Return the transpose of R_ARG, of size N. Destroy R_ARG, as it is |
|
||||||
|
| replaced with the result. |
|
||||||
|
`-------------------------------------------------------------------*/
|
||||||
|
|
||||||
static short **
|
static short **
|
||||||
transpose (short **R_arg, int n)
|
transpose (short **R_arg, int n)
|
||||||
{
|
{
|
||||||
@@ -479,6 +484,11 @@ transpose (short **R_arg, int n)
|
|||||||
|
|
||||||
XFREE (temp_R);
|
XFREE (temp_R);
|
||||||
|
|
||||||
|
/* Free the input: it is replaced with the result. */
|
||||||
|
for (i = 0; i < n; i++)
|
||||||
|
XFREE (R_arg[i]);
|
||||||
|
XFREE (R_arg);
|
||||||
|
|
||||||
return new_R;
|
return new_R;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -486,44 +496,35 @@ transpose (short **R_arg, int n)
|
|||||||
static void
|
static void
|
||||||
build_relations (void)
|
build_relations (void)
|
||||||
{
|
{
|
||||||
|
short *edge = XCALLOC (short, ngotos + 1);
|
||||||
|
short *states = XCALLOC (short, maxrhs () + 1);
|
||||||
int i;
|
int i;
|
||||||
int j;
|
|
||||||
short *rulep;
|
|
||||||
short *rp;
|
|
||||||
int nedges;
|
|
||||||
int done;
|
|
||||||
int state1;
|
|
||||||
int stateno;
|
|
||||||
int symbol1;
|
|
||||||
short *edge;
|
|
||||||
short *states;
|
|
||||||
short **new_includes;
|
|
||||||
|
|
||||||
includes = XCALLOC (short *, ngotos);
|
includes = XCALLOC (short *, ngotos);
|
||||||
edge = XCALLOC (short, ngotos + 1);
|
|
||||||
states = XCALLOC (short, maxrhs () + 1);
|
|
||||||
|
|
||||||
for (i = 0; i < ngotos; i++)
|
for (i = 0; i < ngotos; i++)
|
||||||
{
|
{
|
||||||
nedges = 0;
|
int nedges = 0;
|
||||||
state1 = from_state[i];
|
int state1 = from_state[i];
|
||||||
symbol1 = state_table[to_state[i]].accessing_symbol;
|
int symbol1 = state_table[to_state[i]].accessing_symbol;
|
||||||
|
short *rulep;
|
||||||
|
|
||||||
for (rulep = derives[symbol1]; *rulep > 0; rulep++)
|
for (rulep = derives[symbol1]; *rulep > 0; rulep++)
|
||||||
{
|
{
|
||||||
|
int done;
|
||||||
int length = 1;
|
int length = 1;
|
||||||
|
int stateno = state1;
|
||||||
|
short *rp;
|
||||||
states[0] = state1;
|
states[0] = state1;
|
||||||
stateno = state1;
|
|
||||||
|
|
||||||
for (rp = ritem + rule_table[*rulep].rhs; *rp > 0; rp++)
|
for (rp = ritem + rule_table[*rulep].rhs; *rp > 0; rp++)
|
||||||
{
|
{
|
||||||
int symbol2 = *rp;
|
|
||||||
shifts *sp = state_table[stateno].shift_table;
|
shifts *sp = state_table[stateno].shift_table;
|
||||||
|
int j;
|
||||||
for (j = 0; j < sp->nshifts; j++)
|
for (j = 0; j < sp->nshifts; j++)
|
||||||
{
|
{
|
||||||
stateno = sp->shifts[j];
|
stateno = sp->shifts[j];
|
||||||
if (state_table[stateno].accessing_symbol == symbol2)
|
if (state_table[stateno].accessing_symbol == *rp)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -552,6 +553,7 @@ build_relations (void)
|
|||||||
|
|
||||||
if (nedges)
|
if (nedges)
|
||||||
{
|
{
|
||||||
|
int j;
|
||||||
includes[i] = XCALLOC (short, nedges + 1);
|
includes[i] = XCALLOC (short, nedges + 1);
|
||||||
for (j = 0; j < nedges; j++)
|
for (j = 0; j < nedges; j++)
|
||||||
includes[i][j] = edge[j];
|
includes[i][j] = edge[j];
|
||||||
@@ -559,16 +561,10 @@ build_relations (void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
new_includes = transpose (includes, ngotos);
|
|
||||||
|
|
||||||
for (i = 0; i < ngotos; i++)
|
|
||||||
XFREE (includes[i]);
|
|
||||||
XFREE (includes);
|
|
||||||
|
|
||||||
includes = new_includes;
|
|
||||||
|
|
||||||
XFREE (edge);
|
XFREE (edge);
|
||||||
XFREE (states);
|
XFREE (states);
|
||||||
|
|
||||||
|
includes = transpose (includes, ngotos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -596,10 +592,10 @@ compute_lookaheads (void)
|
|||||||
for (i = 0; i < state_table[nstates].lookaheads; i++)
|
for (i = 0; i < state_table[nstates].lookaheads; i++)
|
||||||
for (sp = lookback[i]; sp; sp = sp->next)
|
for (sp = lookback[i]; sp; sp = sp->next)
|
||||||
{
|
{
|
||||||
unsigned *fp1 = LA (i);
|
int size = LA (i + 1) - LA (i);
|
||||||
unsigned *fp2 = F (sp->value);
|
int j;
|
||||||
while (fp1 < LA (i + 1))
|
for (j = 0; j < size; ++j)
|
||||||
*fp1++ |= *fp2++;
|
LA (i)[j] |= F (sp->value)[j];
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Free LOOKBACK. */
|
/* Free LOOKBACK. */
|
||||||
|
|||||||
Reference in New Issue
Block a user