/* Compute look-ahead criteria for bison,
- Copyright 1984, 1986, 1989, 2000 Free Software Foundation, Inc.
+ Copyright 1984, 1986, 1989, 2000, 2001 Free Software Foundation, Inc.
This file is part of Bison, the GNU Compiler Compiler.
extern void berror PARAMS ((const char *));
static int infinity;
-static int maxrhs;
static int ngotos;
-static unsigned *F;
+
+/* And for the famous F variable, which named is so descriptive that a
+ comment is hardly needed. <grin>. */
+static unsigned *F = NULL;
+#define F(Rule) (F + (Rule) * tokensetsize)
+
static short **includes;
static shorts **lookback;
static short **R;
VERTICES[++top] = i;
INDEX[i] = height = top;
- base = F + i * tokensetsize;
- fp3 = base + tokensetsize;
+ base = F (i);
+ fp3 = F (i + 1);
rp = R[i];
if (rp)
INDEX[i] = INDEX[j];
fp1 = base;
- fp2 = F + j * tokensetsize;
+ fp2 = F (j);
while (fp1 < fp3)
*fp1++ |= *fp2++;
break;
fp1 = base;
- fp2 = F + j * tokensetsize;
+ fp2 = F (j);
while (fp1 < fp3)
*fp2++ = *fp1++;
INDEX[i] = 0;
for (i = 0; i < ngotos; i++)
- {
- if (INDEX[i] == 0 && R[i])
- traverse (i);
- }
+ if (INDEX[i] == 0 && R[i])
+ traverse (i);
XFREE (INDEX);
XFREE (VERTICES);
}
+
+/*--------------------.
+| Build STATE_TABLE. |
+`--------------------*/
+
static void
set_state_table (void)
{
}
-static void
-set_maxrhs (void)
+/* Return the size of the longest ride hand side of the rules. */
+static size_t
+maxrhs (void)
{
short *itemp;
int length;
}
}
- maxrhs = max;
+ return max;
}
digraph (reads);
for (i = 0; i < ngotos; i++)
- {
- if (reads[i])
- XFREE (reads[i]);
- }
+ XFREE (reads[i]);
XFREE (reads);
XFREE (edge);
includes = XCALLOC (short *, ngotos);
edge = XCALLOC (short, ngotos + 1);
- states = XCALLOC (short, maxrhs + 1);
+ states = XCALLOC (short, maxrhs () + 1);
for (i = 0; i < ngotos; i++)
{
states[0] = state1;
stateno = state1;
- for (rp = ritem + rrhs[*rulep]; *rp > 0; rp++)
+ for (rp = ritem + rule_table[*rulep].rhs; *rp > 0; rp++)
{
symbol2 = *rp;
sp = state_table[stateno].shift_table;
digraph (includes);
for (i = 0; i < ngotos; i++)
- {
- if (includes[i])
- XFREE (includes[i]);
- }
+ XFREE (includes[i]);
XFREE (includes);
}
compute_lookaheads (void)
{
int i;
- int n;
- unsigned *fp1;
- unsigned *fp2;
- unsigned *fp3;
shorts *sp;
- unsigned *rowp;
- shorts *sptmp; /* JF */
- rowp = LA;
for (i = 0; i < state_table[nstates].lookaheads; i++)
- {
- fp3 = rowp + tokensetsize;
- for (sp = lookback[i]; sp; sp = sp->next)
- {
- fp1 = rowp;
- fp2 = F + tokensetsize * sp->value;
- while (fp1 < fp3)
- *fp1++ |= *fp2++;
- }
-
- rowp = fp3;
- }
+ for (sp = lookback[i]; sp; sp = sp->next)
+ {
+ unsigned *fp1 = LA (i);
+ unsigned *fp2 = F (sp->value);
+ while (fp1 < LA (i + 1))
+ *fp1++ |= *fp2++;
+ }
+ /* Free LOOKBACK. */
for (i = 0; i < state_table[nstates].lookaheads; i++)
- {
- /* JF removed ref to freed storage */
- for (sp = lookback[i]; sp; sp = sptmp)
- {
- sptmp = sp->next;
- XFREE (sp);
- }
- }
+ LIST_FREE (shorts, lookback[i]);
XFREE (lookback);
XFREE (F);
tokensetsize = WORDSIZE (ntokens);
set_state_table ();
- set_maxrhs ();
initialize_LA ();
set_goto_map ();
initialize_F ();