X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/f0250de62e88cff12f9e5cb45b7757792a10e9fe..e601aa1d35f9c87e3828aa1574d7e46408849cba:/src/lalr.c diff --git a/src/lalr.c b/src/lalr.c index 9dda7f05..e1e2719d 100644 --- a/src/lalr.c +++ b/src/lalr.c @@ -1,5 +1,6 @@ /* Compute look-ahead criteria for bison, - Copyright 1984, 1986, 1989, 2000, 2001 Free Software Foundation, Inc. + Copyright (C) 1984, 1986, 1989, 2000, 2001, 2002 + Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. @@ -25,6 +26,7 @@ #include "system.h" #include "bitset.h" +#include "bitsetv.h" #include "reader.h" #include "types.h" #include "LR0.h" @@ -39,8 +41,8 @@ /* All the decorated states, indexed by the state number. */ state_t **states = NULL; -short *LAruleno = NULL; -bitset *LA = NULL; +rule_t **LArule = NULL; +bitsetv LA = NULL; size_t nLA; static int ngotos; @@ -50,7 +52,7 @@ short *to_state = NULL; /* And for the famous F variable, which name is so descriptive that a comment is hardly needed. . */ -static bitset *F = NULL; +static bitsetv F = NULL; static short **includes; static shorts **lookback; @@ -133,23 +135,21 @@ initialize_LA (void) { size_t i; int j; - short *np; + rule_t **np; /* Avoid having to special case 0. */ if (!nLA) nLA = 1; - LA = XCALLOC (bitset, nLA); - for (i = 0; i < nLA; ++i) - LA[i] = bitset_create (ntokens, BITSET_FIXED); - LAruleno = XCALLOC (short, nLA); + LA = bitsetv_create (nLA, ntokens, BITSET_FIXED); + LArule = XCALLOC (rule_t *, nLA); lookback = XCALLOC (shorts *, nLA); - np = LAruleno; + np = LArule; for (i = 0; i < nstates; i++) if (!states[i]->consistent) for (j = 0; j < states[i]->reductions->nreds; j++) - *np++ = states[i]->reductions->rules[j]; + *np++ = &rules[states[i]->reductions->rules[j]]; } @@ -253,9 +253,7 @@ initialize_F (void) int i; - F = XCALLOC (bitset, ngotos); - for (i = 0; i < ngotos; ++i) - F[i] = bitset_create (ntokens, BITSET_FIXED); + F = bitsetv_create (ngotos, ntokens, BITSET_FIXED); for (i = 0; i < ngotos; i++) { @@ -299,10 +297,10 @@ add_lookback_edge (state_t *state, int ruleno, int gotono) shorts *sp; for (i = 0; i < state->nlookaheads; ++i) - if (LAruleno[state->lookaheadsp + i] == ruleno) + if (LArule[state->lookaheadsp + i]->number == ruleno) break; - assert (LAruleno[state->lookaheadsp + i] == ruleno); + assert (LArule[state->lookaheadsp + i]->number == ruleno); sp = XCALLOC (shorts, 1); sp->next = lookback[state->lookaheadsp + i]; @@ -420,7 +418,7 @@ build_relations (void) state_t *state = states[from_state[i]]; states1[0] = state->number; - for (rp = &ritem[rules[*rulep].rhs]; *rp >= 0; rp++) + for (rp = rules[*rulep].rhs; *rp >= 0; rp++) { shifts *sp = state->shifts; int j; @@ -500,9 +498,7 @@ compute_lookaheads (void) LIST_FREE (shorts, lookback[i]); XFREE (lookback); - for (i = 0; i < (unsigned) ngotos; ++i) - bitset_free (F[i]); - XFREE (F); + bitsetv_free (F); } @@ -566,7 +562,7 @@ lookaheads_print (FILE *out) if (bitset_test (LA[states[i]->lookaheadsp + j], j)) fprintf (out, " on %d (%s) -> rule %d\n", k, symbols[k]->tag, - -LAruleno[states[i]->lookaheadsp + j] - 1); + LArule[states[i]->lookaheadsp + j]->number - 1); } fprintf (out, "Lookaheads: END\n"); }