* src/LR0.c (save_reductions): Remove, replaced by...

* src/state.h, src/state.c (state_reductions_set): New.
(reductions, errs): Rename as...
(reductions_t, errs_t): these.
Adjust all dependencies.
This commit is contained in:
Akim Demaille
2002-06-30 17:30:46 +00:00
parent 32e1e0a486
commit 8a731ca829
9 changed files with 57 additions and 34 deletions

View File

@@ -1,3 +1,12 @@
2002-06-30 Akim Demaille <akim@epita.fr>
* src/LR0.c (save_reductions): Remove, replaced by...
* src/state.h, src/state.c (state_reductions_set): New.
(reductions, errs): Rename as...
(reductions_t, errs_t): these.
Adjust all dependencies.
2002-06-30 Akim Demaille <akim@epita.fr> 2002-06-30 Akim Demaille <akim@epita.fr>
* src/LR0.c (state_list_t, state_list_append): New. * src/LR0.c (state_list_t, state_list_append): New.

View File

@@ -94,7 +94,7 @@ allocate_itemsets (void)
/* See comments before new_itemsets. All the vectors of items /* See comments before new_itemsets. All the vectors of items
live inside KERNEL_ITEMS. The number of active items after live inside KERNEL_ITEMS. The number of active items after
some symbol cannot be more than the number of times that symbol some symbol cannot be more than the number of times that symbol
appears as an item, which is symbol_count[symbol]. appears as an item, which is SYMBOL_COUNT[SYMBOL].
We allocate that much space for each symbol. */ We allocate that much space for each symbol. */
kernel_base = XCALLOC (item_number_t *, nsyms); kernel_base = XCALLOC (item_number_t *, nsyms);
@@ -313,8 +313,7 @@ save_reductions (state_t *state)
} }
/* Make a reductions structure and copy the data into it. */ /* Make a reductions structure and copy the data into it. */
state->reductions = reductions_new (count); state_reductions_set (state, count, redset);
memcpy (state->reductions->rules, redset, count * sizeof (redset[0]));
} }
@@ -340,7 +339,7 @@ set_states (void)
if (!state->errs) if (!state->errs)
state->errs = errs_new (0); state->errs = errs_new (0);
if (!state->reductions) if (!state->reductions)
state->reductions = reductions_new (0); state_reductions_set (state, 0, 0);
states[state->number] = state; states[state->number] = state;

View File

@@ -179,7 +179,7 @@ resolve_sr_conflict (state_t *state, int lookahead)
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 *errp = errs_new (ntokens + 1); errs_t *errp = errs_new (ntokens + 1);
errp->nerrs = 0; errp->nerrs = 0;
for (i = 0; i < ntokens; i++) for (i = 0; i < ntokens; i++)

View File

@@ -521,7 +521,7 @@ states_lookaheads_count (void)
{ {
int k; int k;
int nlookaheads = 0; int nlookaheads = 0;
reductions *rp = states[i]->reductions; reductions_t *rp = states[i]->reductions;
shifts_t *sp = states[i]->shifts; shifts_t *sp = states[i]->shifts;
/* We need a lookahead either to distinguish different /* We need a lookahead either to distinguish different

View File

@@ -429,9 +429,9 @@ action_row (state_t *state)
{ {
int i; int i;
int default_rule = 0; int default_rule = 0;
reductions *redp = state->reductions; reductions_t *redp = state->reductions;
shifts_t *shiftp = state->shifts; shifts_t *shiftp = state->shifts;
errs *errp = state->errs; errs_t *errp = state->errs;
/* set nonzero to inhibit having any default reduction */ /* set nonzero to inhibit having any default reduction */
int nodefault = 0; int nodefault = 0;
int conflicted = 0; int conflicted = 0;

View File

@@ -128,7 +128,7 @@ print_shifts (FILE *out, state_t *state)
static void static void
print_errs (FILE *out, state_t *state) print_errs (FILE *out, state_t *state)
{ {
errs *errp = state->errs; errs_t *errp = state->errs;
int i; int i;
for (i = 0; i < errp->nerrs; ++i) for (i = 0; i < errp->nerrs; ++i)
@@ -170,8 +170,8 @@ print_reductions (FILE *out, state_t *state)
{ {
int i; int i;
shifts_t *shiftp = state->shifts; shifts_t *shiftp = state->shifts;
reductions *redp = state->reductions; reductions_t *redp = state->reductions;
errs *errp = state->errs; errs_t *errp = state->errs;
int nodefault = 0; int nodefault = 0;
if (redp->nreds == 0) if (redp->nreds == 0)
@@ -304,7 +304,7 @@ print_reductions (FILE *out, state_t *state)
static void static void
print_actions (FILE *out, state_t *state) print_actions (FILE *out, state_t *state)
{ {
reductions *redp = state->reductions; reductions_t *redp = state->reductions;
shifts_t *shiftp = state->shifts; shifts_t *shiftp = state->shifts;
if (shiftp->nshifts == 0 && redp->nreds == 0) if (shiftp->nshifts == 0 && redp->nreds == 0)

View File

@@ -123,8 +123,8 @@ print_actions (state_t *state, const char *node_name)
{ {
int i; int i;
shifts_t *shiftp = state->shifts; shifts_t *shiftp = state->shifts;
reductions *redp = state->reductions; reductions_t *redp = state->reductions;
static char buff[10]; static char buff[10];
edge_t edge; edge_t edge;

View File

@@ -61,23 +61,23 @@ shifts_new (int nshifts, state_number_t *shifts)
`-------------------------------*/ `-------------------------------*/
#define ERRS_ALLOC(Nerrs) \ #define ERRS_ALLOC(Nerrs) \
(errs *) xcalloc ((unsigned) (sizeof (errs) \ (errs_t *) xcalloc ((unsigned) (sizeof (errs_t) \
+ (Nerrs - 1) * sizeof (short)), 1) + (Nerrs - 1) * sizeof (short)), 1)
errs * errs_t *
errs_new (int n) errs_new (int n)
{ {
errs *res = ERRS_ALLOC (n); errs_t *res = ERRS_ALLOC (n);
res->nerrs = n; res->nerrs = n;
return res; return res;
} }
errs * errs_t *
errs_dup (errs *src) errs_dup (errs_t *src)
{ {
errs *res = errs_new (src->nerrs); errs_t *res = errs_new (src->nerrs);
memcpy (res->errs, src->errs, src->nerrs * sizeof (src->errs[0])); memcpy (res->errs, src->errs, src->nerrs * sizeof (src->errs[0]));
return res; return res;
} }
@@ -95,14 +95,15 @@ errs_dup (errs *src)
`-------------------------------------*/ `-------------------------------------*/
#define REDUCTIONS_ALLOC(Nreductions) \ #define REDUCTIONS_ALLOC(Nreductions) \
(reductions *) xcalloc ((unsigned) (sizeof (reductions) \ (reductions_t *) xcalloc ((unsigned) (sizeof (reductions_t) \
+ (Nreductions - 1) * sizeof (short)), 1) + (Nreductions - 1) * sizeof (short)), 1)
reductions * static reductions_t *
reductions_new (int n) reductions_new (int nreductions, short *reductions)
{ {
reductions *res = REDUCTIONS_ALLOC (n); reductions_t *res = REDUCTIONS_ALLOC (nreductions);
res->nreds = n; res->nreds = nreductions;
memcpy (res->rules, reductions, nreductions * sizeof (reductions[0]));
return res; return res;
} }
@@ -159,6 +160,17 @@ state_shifts_set (state_t *state, int nshifts, state_number_t *shifts)
} }
/*------------------------------.
| Set the reductions of STATE. |
`------------------------------*/
void
state_reductions_set (state_t *state, int nreductions, short *reductions)
{
state->reductions = reductions_new (nreductions, reductions);
}
/*--------------------------------------------------------------. /*--------------------------------------------------------------.
| Print on OUT all the lookaheads such that this STATE wants to | | Print on OUT all the lookaheads such that this STATE wants to |

View File

@@ -144,27 +144,26 @@ typedef struct shifts_s
| Errs. | | Errs. |
`-------*/ `-------*/
typedef struct errs typedef struct errs_s
{ {
short nerrs; short nerrs;
short errs[1]; short errs[1];
} errs; } errs_t;
errs *errs_new PARAMS ((int n)); errs_t *errs_new PARAMS ((int n));
errs *errs_dup PARAMS ((errs *src)); errs_t *errs_dup PARAMS ((errs_t *src));
/*-------------. /*-------------.
| Reductions. | | Reductions. |
`-------------*/ `-------------*/
typedef struct reductions typedef struct reductions_s
{ {
short nreds; short nreds;
short rules[1]; short rules[1];
} reductions; } reductions_t;
reductions *reductions_new PARAMS ((int n));
/*----------. /*----------.
@@ -176,8 +175,8 @@ typedef struct state_s
state_number_t number; state_number_t number;
symbol_number_t accessing_symbol; symbol_number_t accessing_symbol;
shifts_t *shifts; shifts_t *shifts;
reductions *reductions; reductions_t *reductions;
errs *errs; errs_t *errs;
/* Nonzero if no lookahead is needed to decide what to do in state S. */ /* Nonzero if no lookahead is needed to decide what to do in state S. */
char consistent; char consistent;
@@ -208,6 +207,10 @@ state_t *state_new PARAMS ((symbol_number_t accessing_symbol,
void state_shifts_set PARAMS ((state_t *state, void state_shifts_set PARAMS ((state_t *state,
int nshifts, state_number_t *shifts)); int nshifts, state_number_t *shifts));
/* Set the reductions of STATE. */
void state_reductions_set PARAMS ((state_t *state,
int nreductions, short *reductions));
/* Print on OUT all the lookaheads such that this STATE wants to /* Print on OUT all the lookaheads such that this STATE wants to
reduce this RULE. */ reduce this RULE. */
void state_rule_lookaheads_print PARAMS ((state_t *state, rule_t *rule, void state_rule_lookaheads_print PARAMS ((state_t *state, rule_t *rule,