mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-16 07:43:03 +00:00
* src/conflicts.c (flush_shift, resolve_sr_conflict): De-obfuscate
using the good o' techniques: arrays not pointers, variable locality, BITISSET, RESETBIT etc.
This commit is contained in:
@@ -1,3 +1,10 @@
|
|||||||
|
2001-12-05 Akim Demaille <akim@epita.fr>
|
||||||
|
|
||||||
|
* src/conflicts.c (flush_shift, resolve_sr_conflict): De-obfuscate
|
||||||
|
using the good o' techniques: arrays not pointers, variable
|
||||||
|
locality, BITISSET, RESETBIT etc.
|
||||||
|
|
||||||
|
|
||||||
2001-12-05 Akim Demaille <akim@epita.fr>
|
2001-12-05 Akim Demaille <akim@epita.fr>
|
||||||
|
|
||||||
* src/state.h (SHIFT_SYMBOL): New.
|
* src/state.h (SHIFT_SYMBOL): New.
|
||||||
|
|||||||
@@ -57,21 +57,13 @@ Conflict in state %d between rule %d and token %s resolved as %s.\n"),
|
|||||||
static void
|
static void
|
||||||
flush_shift (int state, int token)
|
flush_shift (int state, int token)
|
||||||
{
|
{
|
||||||
shifts *shiftp;
|
shifts *shiftp = state_table[state].shift_table;
|
||||||
int k, i;
|
int i;
|
||||||
|
|
||||||
shiftp = state_table[state].shift_table;
|
|
||||||
|
|
||||||
if (shiftp)
|
if (shiftp)
|
||||||
{
|
for (i = 0; i < shiftp->nshifts; i++)
|
||||||
k = shiftp->nshifts;
|
if (shiftp->shifts[i] && SHIFT_SYMBOL (shiftp, i) == token)
|
||||||
for (i = 0; i < k; i++)
|
shiftp->shifts[i] = 0;
|
||||||
{
|
|
||||||
if (shiftp->shifts[i]
|
|
||||||
&& token == state_table[shiftp->shifts[i]].accessing_symbol)
|
|
||||||
(shiftp->shifts[i]) = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -86,22 +78,16 @@ static void
|
|||||||
resolve_sr_conflict (int state, int lookaheadnum)
|
resolve_sr_conflict (int state, int lookaheadnum)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int mask;
|
/* find the rule to reduce by to get precedence of reduction */
|
||||||
unsigned *fp1;
|
int redprec = rule_table[LAruleno[lookaheadnum]].prec;
|
||||||
unsigned *fp2;
|
|
||||||
int redprec;
|
|
||||||
errs *errp = ERRS_ALLOC (ntokens + 1);
|
errs *errp = ERRS_ALLOC (ntokens + 1);
|
||||||
short *errtokens = errp->errs;
|
short *errtokens = errp->errs;
|
||||||
|
|
||||||
/* find the rule to reduce by to get precedence of reduction */
|
|
||||||
redprec = rule_table[LAruleno[lookaheadnum]].prec;
|
|
||||||
|
|
||||||
mask = 1;
|
|
||||||
fp1 = LA (lookaheadnum);
|
|
||||||
fp2 = lookaheadset;
|
|
||||||
for (i = 0; i < ntokens; i++)
|
for (i = 0; i < ntokens; i++)
|
||||||
{
|
{
|
||||||
if ((mask & *fp2 & *fp1) && sprec[i])
|
if (BITISSET (LA (lookaheadnum), i)
|
||||||
|
&& BITISSET (lookaheadset, i)
|
||||||
|
&& sprec[i])
|
||||||
/* Shift-reduce conflict occurs for token number i
|
/* Shift-reduce conflict occurs for token number i
|
||||||
and it has a precedence.
|
and it has a precedence.
|
||||||
The precedence of shifting is that of token i. */
|
The precedence of shifting is that of token i. */
|
||||||
@@ -109,13 +95,15 @@ resolve_sr_conflict (int state, int lookaheadnum)
|
|||||||
if (sprec[i] < redprec)
|
if (sprec[i] < redprec)
|
||||||
{
|
{
|
||||||
log_resolution (state, lookaheadnum, i, _("reduce"));
|
log_resolution (state, lookaheadnum, i, _("reduce"));
|
||||||
*fp2 &= ~mask; /* flush the shift for this token */
|
/* flush the shift for this token */
|
||||||
|
RESETBIT (lookaheadset, i);
|
||||||
flush_shift (state, i);
|
flush_shift (state, i);
|
||||||
}
|
}
|
||||||
else if (sprec[i] > redprec)
|
else if (sprec[i] > redprec)
|
||||||
{
|
{
|
||||||
log_resolution (state, lookaheadnum, i, _("shift"));
|
log_resolution (state, lookaheadnum, i, _("shift"));
|
||||||
*fp1 &= ~mask; /* flush the reduce for this token */
|
/* flush the reduce for this token */
|
||||||
|
RESETBIT (LA (lookaheadnum), i);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -141,12 +129,14 @@ resolve_sr_conflict (int state, int lookaheadnum)
|
|||||||
|
|
||||||
if (sassoc[i] != right_assoc)
|
if (sassoc[i] != right_assoc)
|
||||||
{
|
{
|
||||||
*fp2 &= ~mask; /* flush the shift for this token */
|
/* flush the shift for this token */
|
||||||
|
RESETBIT (lookaheadset, i);
|
||||||
flush_shift (state, i);
|
flush_shift (state, i);
|
||||||
}
|
}
|
||||||
if (sassoc[i] != left_assoc)
|
if (sassoc[i] != left_assoc)
|
||||||
{
|
{
|
||||||
*fp1 &= ~mask; /* flush the reduce for this token */
|
/* flush the reduce for this token */
|
||||||
|
RESETBIT (LA (lookaheadnum), i);
|
||||||
}
|
}
|
||||||
if (sassoc[i] == non_assoc)
|
if (sassoc[i] == non_assoc)
|
||||||
{
|
{
|
||||||
@@ -155,14 +145,6 @@ resolve_sr_conflict (int state, int lookaheadnum)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mask <<= 1;
|
|
||||||
if (mask == 0)
|
|
||||||
{
|
|
||||||
mask = 1;
|
|
||||||
fp2++;
|
|
||||||
fp1++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
errp->nerrs = errtokens - errp->errs;
|
errp->nerrs = errtokens - errp->errs;
|
||||||
if (errp->nerrs)
|
if (errp->nerrs)
|
||||||
|
|||||||
Reference in New Issue
Block a user