* src/state.h (reductions_t): Rename member `nreds' as num.

(errs_t): Rename members `nerrs' and `errs' as `num' and `symbols'.
* src/state.c (ERRS_ALLOC, REDUCTIONS_ALLOC): Use the correct types.
This commit is contained in:
Akim Demaille
2002-06-30 17:34:31 +00:00
parent ccaf65bc63
commit d257636504
7 changed files with 42 additions and 34 deletions

View File

@@ -1,3 +1,10 @@
2002-06-30 Akim Demaille <akim@epita.fr>
* src/state.h (reductions_t): Rename member `nreds' as num.
(errs_t): Rename members `nerrs' and `errs' as `num' and `symbols'.
* src/state.c (ERRS_ALLOC, REDUCTIONS_ALLOC): Use the correct types.
2002-06-30 Akim Demaille <akim@epita.fr> 2002-06-30 Akim Demaille <akim@epita.fr>
* src/state.h, src/state.c (shift_t, SHIFT_SYMBOL, SHIFT_IS_SHIFT) * src/state.h, src/state.c (shift_t, SHIFT_SYMBOL, SHIFT_IS_SHIFT)

View File

@@ -58,7 +58,7 @@ enum conflict_resolution_e
`----------------------------------------------------------------*/ `----------------------------------------------------------------*/
static inline void static inline void
log_resolution (rule_t *rule, int token, log_resolution (rule_t *rule, symbol_number_t token,
enum conflict_resolution_e resolution) enum conflict_resolution_e resolution)
{ {
if (report_flag & report_solved_conflicts) if (report_flag & report_solved_conflicts)
@@ -144,7 +144,8 @@ flush_shift (state_t *state, int token)
bitset_reset (lookaheadset, token); bitset_reset (lookaheadset, token);
for (i = 0; i < transitions->num; i++) for (i = 0; i < transitions->num; i++)
if (!TRANSITION_IS_DISABLED (transitions, i) && TRANSITION_SYMBOL (transitions, i) == token) if (!TRANSITION_IS_DISABLED (transitions, i)
&& TRANSITION_SYMBOL (transitions, i) == token)
TRANSITION_DISABLE (transitions, i); TRANSITION_DISABLE (transitions, i);
} }
@@ -174,13 +175,13 @@ flush_reduce (bitset lookaheads, int token)
static void static void
resolve_sr_conflict (state_t *state, int lookahead) resolve_sr_conflict (state_t *state, int lookahead)
{ {
int i; symbol_number_t i;
/* Find the rule to reduce by to get precedence of reduction. */ /* Find the rule to reduce by to get precedence of reduction. */
rule_t *redrule = state->lookaheads_rule[lookahead]; rule_t *redrule = state->lookaheads_rule[lookahead];
int redprec = redrule->prec->prec; int redprec = redrule->prec->prec;
bitset lookaheads = state->lookaheads[lookahead]; bitset lookaheads = state->lookaheads[lookahead];
errs_t *errp = errs_new (ntokens + 1); errs_t *errp = errs_new (ntokens + 1);
errp->nerrs = 0; errp->num = 0;
for (i = 0; i < ntokens; i++) for (i = 0; i < ntokens; i++)
if (bitset_test (lookaheads, i) if (bitset_test (lookaheads, i)
@@ -223,7 +224,7 @@ resolve_sr_conflict (state_t *state, int lookahead)
flush_shift (state, i); flush_shift (state, i);
flush_reduce (lookaheads, i); flush_reduce (lookaheads, i);
/* Record an explicit error for this token. */ /* Record an explicit error for this token. */
errp->errs[errp->nerrs++] = i; errp->symbols[errp->num++] = i;
break; break;
case undef_assoc: case undef_assoc:

View File

@@ -77,7 +77,7 @@ initialize_LA (void)
np = LArule; np = LArule;
for (i = 0; i < nstates; i++) for (i = 0; i < nstates; i++)
if (!states[i]->consistent) if (!states[i]->consistent)
for (j = 0; j < states[i]->reductions->nreds; j++) for (j = 0; j < states[i]->reductions->num; j++)
*np++ = &rules[states[i]->reductions->rules[j]]; *np++ = &rules[states[i]->reductions->rules[j]];
} }
@@ -366,9 +366,9 @@ states_lookaheads_count (void)
reductions (i.e., there are two or more), or to distinguish a reductions (i.e., there are two or more), or to distinguish a
reduction from a shift. Otherwise, it is straightforward, reduction from a shift. Otherwise, it is straightforward,
and the state is `consistent'. */ and the state is `consistent'. */
if (rp->nreds > 1 if (rp->num > 1
|| (rp->nreds == 1 && sp->num && TRANSITION_IS_SHIFT (sp, 0))) || (rp->num == 1 && sp->num && TRANSITION_IS_SHIFT (sp, 0)))
nlookaheads += rp->nreds; nlookaheads += rp->num;
else else
states[i]->consistent = 1; states[i]->consistent = 1;

View File

@@ -439,7 +439,7 @@ action_row (state_t *state)
for (i = 0; i < ntokens; i++) for (i = 0; i < ntokens; i++)
actrow[i] = conflrow[i] = 0; actrow[i] = conflrow[i] = 0;
if (redp->nreds >= 1) if (redp->num >= 1)
{ {
int j; int j;
/* loop over all the rules available here which require /* loop over all the rules available here which require
@@ -478,16 +478,16 @@ action_row (state_t *state)
/* See which tokens are an explicit error in this state (due to /* See which tokens are an explicit error in this state (due to
%nonassoc). For them, record SHRT_MIN as the action. */ %nonassoc). For them, record SHRT_MIN as the action. */
for (i = 0; i < errp->nerrs; i++) for (i = 0; i < errp->num; i++)
{ {
int symbol = errp->errs[i]; symbol_number_t symbol = errp->symbols[i];
actrow[symbol] = SHRT_MIN; actrow[symbol] = SHRT_MIN;
} }
/* Now find the most common reduction and make it the default action /* Now find the most common reduction and make it the default action
for this state. */ for this state. */
if (redp->nreds >= 1 && !nodefault) if (redp->num >= 1 && !nodefault)
{ {
if (state->consistent) if (state->consistent)
default_rule = redp->rules[0]; default_rule = redp->rules[0];

View File

@@ -178,9 +178,9 @@ print_errs (FILE *out, state_t *state)
int i; int i;
/* Compute the width of the lookaheads column. */ /* Compute the width of the lookaheads column. */
for (i = 0; i < errp->nerrs; ++i) for (i = 0; i < errp->num; ++i)
if (errp->errs[i]) if (errp->symbols[i])
max_length (&width, symbol_tag_get (symbols[errp->errs[i]])); max_length (&width, symbol_tag_get (symbols[errp->symbols[i]]));
/* Nothing to report. */ /* Nothing to report. */
if (!width) if (!width)
@@ -190,10 +190,10 @@ print_errs (FILE *out, state_t *state)
width += 2; width += 2;
/* Report lookaheads and errors. */ /* Report lookaheads and errors. */
for (i = 0; i < errp->nerrs; ++i) for (i = 0; i < errp->num; ++i)
if (errp->errs[i]) if (errp->symbols[i])
{ {
const char *tag = symbol_tag_get (symbols[errp->errs[i]]); const char *tag = symbol_tag_get (symbols[errp->symbols[i]]);
int j; int j;
fprintf (out, " %s", tag); fprintf (out, " %s", tag);
for (j = width - strlen (tag); j > 0; --j) for (j = width - strlen (tag); j > 0; --j)
@@ -240,9 +240,9 @@ state_default_rule (state_t *state)
we raise an error (due to %nonassoc). */ we raise an error (due to %nonassoc). */
{ {
errs_t *errp = state->errs; errs_t *errp = state->errs;
for (i = 0; i < errp->nerrs; i++) for (i = 0; i < errp->num; i++)
if (errp->errs[i]) if (errp->symbols[i])
bitset_set (shiftset, errp->errs[i]); bitset_set (shiftset, errp->symbols[i]);
} }
for (i = 0; i < state->nlookaheads; ++i) for (i = 0; i < state->nlookaheads; ++i)
@@ -308,7 +308,7 @@ print_reductions (FILE *out, state_t *state)
size_t width = 0; size_t width = 0;
int i, j; int i, j;
if (redp->nreds == 0) if (redp->num == 0)
return; return;
default_rule = state_default_rule (state); default_rule = state_default_rule (state);
@@ -398,7 +398,7 @@ print_actions (FILE *out, state_t *state)
reductions_t *redp = state->reductions; reductions_t *redp = state->reductions;
transitions_t *transitions = state->shifts; transitions_t *transitions = state->shifts;
if (transitions->num == 0 && redp->nreds == 0) if (transitions->num == 0 && redp->num == 0)
{ {
fputc ('\n', out); fputc ('\n', out);
if (state->number == final_state->number) if (state->number == final_state->number)

View File

@@ -76,14 +76,14 @@ transitions_to (transitions_t *shifts, symbol_number_t s)
#define ERRS_ALLOC(Nerrs) \ #define ERRS_ALLOC(Nerrs) \
(errs_t *) xcalloc ((unsigned) (sizeof (errs_t) \ (errs_t *) xcalloc ((unsigned) (sizeof (errs_t) \
+ (Nerrs - 1) * sizeof (short)), 1) + (Nerrs - 1) * sizeof (symbol_number_t)), 1)
errs_t * errs_t *
errs_new (int n) errs_new (int n)
{ {
errs_t *res = ERRS_ALLOC (n); errs_t *res = ERRS_ALLOC (n);
res->nerrs = n; res->num = n;
return res; return res;
} }
@@ -91,8 +91,8 @@ errs_new (int n)
errs_t * errs_t *
errs_dup (errs_t *src) errs_dup (errs_t *src)
{ {
errs_t *res = errs_new (src->nerrs); errs_t *res = errs_new (src->num);
memcpy (res->errs, src->errs, src->nerrs * sizeof (src->errs[0])); memcpy (res->symbols, src->symbols, src->num * sizeof (src->symbols[0]));
return res; return res;
} }
@@ -110,13 +110,13 @@ errs_dup (errs_t *src)
#define REDUCTIONS_ALLOC(Nreductions) \ #define REDUCTIONS_ALLOC(Nreductions) \
(reductions_t *) xcalloc ((unsigned) (sizeof (reductions_t) \ (reductions_t *) xcalloc ((unsigned) (sizeof (reductions_t) \
+ (Nreductions - 1) * sizeof (short)), 1) + (Nreductions - 1) * sizeof (rule_number_t)), 1)
static reductions_t * static reductions_t *
reductions_new (int nreductions, short *reductions) reductions_new (int nreductions, short *reductions)
{ {
reductions_t *res = REDUCTIONS_ALLOC (nreductions); reductions_t *res = REDUCTIONS_ALLOC (nreductions);
res->nreds = nreductions; res->num = nreductions;
memcpy (res->rules, reductions, nreductions * sizeof (reductions[0])); memcpy (res->rules, reductions, nreductions * sizeof (reductions[0]));
return res; return res;
} }

View File

@@ -152,8 +152,8 @@ struct state_s *transitions_to PARAMS ((transitions_t *state,
typedef struct errs_s typedef struct errs_s
{ {
short nerrs; short num;
short errs[1]; symbol_number_t symbols[1];
} errs_t; } errs_t;
errs_t *errs_new PARAMS ((int n)); errs_t *errs_new PARAMS ((int n));
@@ -166,8 +166,8 @@ errs_t *errs_dup PARAMS ((errs_t *src));
typedef struct reductions_s typedef struct reductions_s
{ {
short nreds; short num;
short rules[1]; rule_number_t rules[1];
} reductions_t; } reductions_t;