From: Akim Demaille Date: Wed, 5 Dec 2001 09:32:23 +0000 (+0000) Subject: * src/state.h (SHIFT_DISABLE, SHIFT_IS_DISABLED): New. X-Git-Tag: before-m4-back-end~196 X-Git-Url: https://git.saurik.com/bison.git/commitdiff_plain/9839bbe557af2c1c3a8160a157d713fb2fc9145a * src/state.h (SHIFT_DISABLE, SHIFT_IS_DISABLED): New. * src/conflicts.c: Use it. Restore a few missing `if (!SHIFT_IS_DISABLED)' which were incorrectly ``simplified''. --- diff --git a/ChangeLog b/ChangeLog index 316fd5b9..eb53eab6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2001-12-05 Akim Demaille + + * src/state.h (SHIFT_DISABLE, SHIFT_IS_DISABLED): New. + * src/conflicts.c: Use it. + Restore a few missing `if (!SHIFT_IS_DISABLED)' which were + incorrectly ``simplified''. + + 2001-12-05 Akim Demaille * src/conflicts.c (flush_shift, resolve_sr_conflict): De-obfuscate diff --git a/src/conflicts.c b/src/conflicts.c index b8689dad..a9bf9519 100644 --- a/src/conflicts.c +++ b/src/conflicts.c @@ -62,8 +62,8 @@ flush_shift (int state, int token) if (shiftp) for (i = 0; i < shiftp->nshifts; i++) - if (shiftp->shifts[i] && SHIFT_SYMBOL (shiftp, i) == token) - shiftp->shifts[i] = 0; + if (!SHIFT_IS_DISABLED (shiftp, i) && SHIFT_SYMBOL (shiftp, i) == token) + SHIFT_DISABLE (shiftp, i); } @@ -176,7 +176,8 @@ set_conflicts (int state) shiftp = state_table[state].shift_table; if (shiftp) for (i = 0; i < shiftp->nshifts && SHIFT_IS_SHIFT (shiftp, i); i++) - SETBIT (lookaheadset, SHIFT_SYMBOL (shiftp, i)); + if (!SHIFT_IS_DISABLED (shiftp, i)) + SETBIT (lookaheadset, SHIFT_SYMBOL (shiftp, i)); /* Loop over all rules which require lookahead in this state. First check for shift-reduce conflict, and try to resolve using @@ -245,7 +246,8 @@ count_sr_conflicts (int state) } for (i = 0; i < shiftp->nshifts && SHIFT_IS_SHIFT (shiftp, i); i++) - SETBIT (shiftset, SHIFT_SYMBOL (shiftp, i)); + if (!SHIFT_IS_DISABLED (shiftp, i)) + SETBIT (shiftset, SHIFT_SYMBOL (shiftp, i)); for (i = state_table[state].lookaheads; i < state_table[state + 1].lookaheads; @@ -436,13 +438,14 @@ print_reductions (FILE *out, int state) shiftp = state_table[state].shift_table; if (shiftp) for (i = 0; i < shiftp->nshifts && SHIFT_IS_SHIFT (shiftp, i); i++) - { - /* if this state has a shift for the error token, don't use a - default rule. */ - if (SHIFT_IS_ERROR (shiftp, i)) - nodefault = 1; - SETBIT (shiftset, SHIFT_SYMBOL (shiftp, i)); - } + if (!SHIFT_IS_DISABLED (shiftp, i)) + { + /* if this state has a shift for the error token, don't use a + default rule. */ + if (SHIFT_IS_ERROR (shiftp, i)) + nodefault = 1; + SETBIT (shiftset, SHIFT_SYMBOL (shiftp, i)); + } errp = err_table[state]; if (errp) @@ -506,7 +509,8 @@ print_reductions (FILE *out, int state) if (shiftp) for (i = 0; i < shiftp->nshifts && SHIFT_IS_SHIFT (shiftp, i); i++) - SETBIT (shiftset, SHIFT_SYMBOL (shiftp, i)); + if (!SHIFT_IS_DISABLED (shiftp, i)) + SETBIT (shiftset, SHIFT_SYMBOL (shiftp, i)); for (i = 0; i < ntokens; i++) { diff --git a/src/state.h b/src/state.h index 53574297..3bf9022f 100644 --- a/src/state.h +++ b/src/state.h @@ -146,6 +146,15 @@ typedef struct shifts #define SHIFT_IS_ERROR(Shifts, Shift) \ (SHIFT_SYMBOL (Shifts, Shift) == error_token_number) +/* When resolving a SR conflicts, if the reduction wins, the shift is + disabled. */ + +#define SHIFT_DISABLE(Shifts, Shift) \ + (Shifts->shifts[Shift] = 0) + +#define SHIFT_IS_DISABLED(Shifts, Shift) \ + (Shifts->shifts[Shift] == 0) + /*-------. | Errs. |