X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/a845a69707ff13ac1382ae28378c890b584e36a4..84b113cd22554d6660b94033199d148138b3ad33:/src/lalr.c diff --git a/src/lalr.c b/src/lalr.c index ce076d4d..42cd05ef 100644 --- a/src/lalr.c +++ b/src/lalr.c @@ -1,5 +1,5 @@ /* 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. @@ -48,9 +48,13 @@ short *to_state; 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. . */ +static unsigned *F = NULL; +#define F(Rule) (F + (Rule) * tokensetsize) + static short **includes; static shorts **lookback; static short **R; @@ -74,8 +78,8 @@ traverse (int i) 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) @@ -89,7 +93,7 @@ traverse (int i) INDEX[i] = INDEX[j]; fp1 = base; - fp2 = F + j * tokensetsize; + fp2 = F (j); while (fp1 < fp3) *fp1++ |= *fp2++; @@ -107,7 +111,7 @@ traverse (int i) break; fp1 = base; - fp2 = F + j * tokensetsize; + fp2 = F (j); while (fp1 < fp3) *fp2++ = *fp1++; @@ -132,15 +136,18 @@ digraph (short **relation) 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) { @@ -205,8 +212,9 @@ 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; @@ -228,7 +236,7 @@ set_maxrhs (void) } } - maxrhs = max; + return max; } @@ -426,10 +434,7 @@ initialize_F (void) digraph (reads); for (i = 0; i < ngotos; i++) - { - if (reads[i]) - XFREE (reads[i]); - } + XFREE (reads[i]); XFREE (reads); XFREE (edge); @@ -542,7 +547,7 @@ build_relations (void) 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++) { @@ -556,7 +561,7 @@ build_relations (void) 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; @@ -625,10 +630,7 @@ compute_FOLLOWS (void) digraph (includes); for (i = 0; i < ngotos; i++) - { - if (includes[i]) - XFREE (includes[i]); - } + XFREE (includes[i]); XFREE (includes); } @@ -638,38 +640,20 @@ static void 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); @@ -682,7 +666,6 @@ lalr (void) tokensetsize = WORDSIZE (ntokens); set_state_table (); - set_maxrhs (); initialize_LA (); set_goto_map (); initialize_F ();