From: Akim Demaille Date: Mon, 17 Dec 2001 17:32:59 +0000 (+0000) Subject: * src/state.h (state_t): Rename lookaheads as lookaheadsp. X-Git-Tag: before-m4-back-end~112 X-Git-Url: https://git.saurik.com/bison.git/commitdiff_plain/3877f72ba22f370554165fd4fde836979f8768d5 * src/state.h (state_t): Rename lookaheads as lookaheadsp. nlookaheads is a new member. Adjust all users. * src/lalr.h (nlookaheads): Remove this orphan declaration. * src/lalr.c (initialize_lookaheads): Set nlookaheads for each state. --- diff --git a/ChangeLog b/ChangeLog index 98b415f7..62a37342 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2001-12-17 Akim Demaille + + * src/state.h (state_t): Rename lookaheads as lookaheadsp. + nlookaheads is a new member. + Adjust all users. + * src/lalr.h (nlookaheads): Remove this orphan declaration. + * src/lalr.c (initialize_lookaheads): Set nlookaheads for each + state. + + 2001-12-17 Akim Demaille * src/files.h, src/files.c (open_files, close_files): Remove. diff --git a/src/conflicts.c b/src/conflicts.c index f10c36b3..3954cc31 100644 --- a/src/conflicts.c +++ b/src/conflicts.c @@ -172,8 +172,8 @@ set_conflicts (int state) /* Loop over all rules which require lookahead in this state. First check for shift-reduce conflict, and try to resolve using precedence */ - for (i = state_table[state]->lookaheads; - i < state_table[state + 1]->lookaheads; + for (i = state_table[state]->lookaheadsp; + i < state_table[state + 1]->lookaheadsp; ++i) if (rule_table[LAruleno[i]].prec) for (j = 0; j < tokensetsize; ++j) @@ -186,8 +186,8 @@ set_conflicts (int state) /* Loop over all rules which require lookahead in this state. Check for conflicts not resolved above. */ - for (i = state_table[state]->lookaheads; - i < state_table[state + 1]->lookaheads; + for (i = state_table[state]->lookaheadsp; + i < state_table[state + 1]->lookaheadsp; ++i) { for (j = 0; j < tokensetsize; ++j) @@ -237,8 +237,8 @@ count_sr_conflicts (int state) if (!SHIFT_IS_DISABLED (shiftp, i)) SETBIT (shiftset, SHIFT_SYMBOL (shiftp, i)); - for (i = state_table[state]->lookaheads; - i < state_table[state + 1]->lookaheads; + for (i = state_table[state]->lookaheadsp; + i < state_table[state + 1]->lookaheadsp; ++i) for (k = 0; k < tokensetsize; ++k) lookaheadset[k] |= LA (i)[k]; @@ -264,8 +264,8 @@ count_rr_conflicts (int state) int i; int rrc_count = 0; - int m = state_table[state]->lookaheads; - int n = state_table[state + 1]->lookaheads; + int m = state_table[state]->lookaheadsp; + int n = state_table[state + 1]->lookaheadsp; if (n - m < 2) return 0; @@ -414,8 +414,8 @@ print_reductions (FILE *out, int state) { int i; int j; - int m = state_table[state]->lookaheads; - int n = state_table[state + 1]->lookaheads; + int m = state_table[state]->lookaheadsp; + int n = state_table[state + 1]->lookaheadsp; shifts *shiftp = state_table[state]->shifts; errs *errp = state_table[state]->errs; int nodefault = 0; diff --git a/src/lalr.c b/src/lalr.c index 150b15e9..a4150cb7 100644 --- a/src/lalr.c +++ b/src/lalr.c @@ -140,7 +140,7 @@ initialize_LA (void) short *np; reductions *rp; - size_t nLA = state_table[nstates]->lookaheads; + size_t nLA = state_table[nstates]->lookaheadsp; if (!nLA) nLA = 1; @@ -314,8 +314,8 @@ add_lookback_edge (int stateno, int ruleno, int gotono) int found; shorts *sp; - i = state_table[stateno]->lookaheads; - k = state_table[stateno + 1]->lookaheads; + i = state_table[stateno]->lookaheadsp; + k = state_table[stateno + 1]->lookaheadsp; found = 0; while (!found && i < k) { @@ -516,7 +516,7 @@ compute_lookaheads (void) int i; shorts *sp; - for (i = 0; i < state_table[nstates]->lookaheads; i++) + for (i = 0; i < state_table[nstates]->lookaheadsp; i++) for (sp = lookback[i]; sp; sp = sp->next) { int size = LA (i + 1) - LA (i); @@ -526,7 +526,7 @@ compute_lookaheads (void) } /* Free LOOKBACK. */ - for (i = 0; i < state_table[nstates]->lookaheads; i++) + for (i = 0; i < state_table[nstates]->lookaheadsp; i++) LIST_FREE (shorts, lookback[i]); XFREE (lookback); @@ -546,14 +546,13 @@ initialize_lookaheads (void) for (i = 0; i < nstates; i++) { int k; + int nlookaheads = 0; reductions *rp = state_table[i]->reductions; shifts *sp = state_table[i]->shifts; - state_table[i]->lookaheads = count; - if (rp && (rp->nreds > 1 || (sp->nshifts && SHIFT_IS_SHIFT (sp, 0)))) - count += rp->nreds; + nlookaheads += rp->nreds; else state_table[i]->consistent = 1; @@ -563,11 +562,15 @@ initialize_lookaheads (void) state_table[i]->consistent = 0; break; } + + state_table[i]->nlookaheads = nlookaheads; + state_table[i]->lookaheadsp = count; + count += nlookaheads; } /* Seems to be needed by conflicts.c. */ state_table[nstates] = STATE_ALLOC (0); - state_table[nstates]->lookaheads = count; + state_table[nstates]->lookaheadsp = count; } void diff --git a/src/lalr.h b/src/lalr.h index fd964b7b..31cf8069 100644 --- a/src/lalr.h +++ b/src/lalr.h @@ -74,6 +74,4 @@ extern state_t **state_table; extern int tokensetsize; -/* The number of lookaheads. */ -extern size_t nlookaheads; #endif /* !LALR_H_ */ diff --git a/src/output.c b/src/output.c index c35fa870..125070ea 100644 --- a/src/output.c +++ b/src/output.c @@ -344,8 +344,8 @@ action_row (int state) int j; /* loop over all the rules available here which require lookahead */ - m = state_table[state]->lookaheads; - n = state_table[state + 1]->lookaheads; + m = state_table[state]->lookaheadsp; + n = state_table[state + 1]->lookaheadsp; for (i = n - 1; i >= m; i--) /* and find each token which the rule finds acceptable diff --git a/src/state.h b/src/state.h index de7ec08c..a31af20b 100644 --- a/src/state.h +++ b/src/state.h @@ -189,7 +189,9 @@ typedef struct state_s char consistent; /* Used in LALR, not LR(0). */ - short lookaheads; + /* Pseudo pointer into LA. */ + short lookaheadsp; + int nlookaheads; /* Its items. */ short nitems;