From 8a731ca8296e54a6fb31eb42cead791baf6810e7 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Sun, 30 Jun 2002 17:30:46 +0000 Subject: [PATCH] * 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. --- ChangeLog | 9 +++++++++ src/LR0.c | 7 +++---- src/conflicts.c | 2 +- src/lalr.c | 2 +- src/output.c | 4 ++-- src/print.c | 8 ++++---- src/print_graph.c | 4 ++-- src/state.c | 34 +++++++++++++++++++++++----------- src/state.h | 21 ++++++++++++--------- 9 files changed, 57 insertions(+), 34 deletions(-) diff --git a/ChangeLog b/ChangeLog index 673ecece..65776e55 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2002-06-30 Akim Demaille + + * 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 * src/LR0.c (state_list_t, state_list_append): New. diff --git a/src/LR0.c b/src/LR0.c index 27282bd1..d402d910 100644 --- a/src/LR0.c +++ b/src/LR0.c @@ -94,7 +94,7 @@ allocate_itemsets (void) /* See comments before new_itemsets. All the vectors of items live inside KERNEL_ITEMS. The number of active items after 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. */ 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. */ - state->reductions = reductions_new (count); - memcpy (state->reductions->rules, redset, count * sizeof (redset[0])); + state_reductions_set (state, count, redset); } @@ -340,7 +339,7 @@ set_states (void) if (!state->errs) state->errs = errs_new (0); if (!state->reductions) - state->reductions = reductions_new (0); + state_reductions_set (state, 0, 0); states[state->number] = state; diff --git a/src/conflicts.c b/src/conflicts.c index 02876817..aef33e6d 100644 --- a/src/conflicts.c +++ b/src/conflicts.c @@ -179,7 +179,7 @@ resolve_sr_conflict (state_t *state, int lookahead) rule_t *redrule = state->lookaheads_rule[lookahead]; int redprec = redrule->prec->prec; bitset lookaheads = state->lookaheads[lookahead]; - errs *errp = errs_new (ntokens + 1); + errs_t *errp = errs_new (ntokens + 1); errp->nerrs = 0; for (i = 0; i < ntokens; i++) diff --git a/src/lalr.c b/src/lalr.c index 84f32894..8050f9f0 100644 --- a/src/lalr.c +++ b/src/lalr.c @@ -521,7 +521,7 @@ states_lookaheads_count (void) { int k; int nlookaheads = 0; - reductions *rp = states[i]->reductions; + reductions_t *rp = states[i]->reductions; shifts_t *sp = states[i]->shifts; /* We need a lookahead either to distinguish different diff --git a/src/output.c b/src/output.c index ea4186c8..daf753e4 100644 --- a/src/output.c +++ b/src/output.c @@ -429,9 +429,9 @@ action_row (state_t *state) { int i; int default_rule = 0; - reductions *redp = state->reductions; + reductions_t *redp = state->reductions; shifts_t *shiftp = state->shifts; - errs *errp = state->errs; + errs_t *errp = state->errs; /* set nonzero to inhibit having any default reduction */ int nodefault = 0; int conflicted = 0; diff --git a/src/print.c b/src/print.c index b967c73f..927d2bee 100644 --- a/src/print.c +++ b/src/print.c @@ -128,7 +128,7 @@ print_shifts (FILE *out, state_t *state) static void print_errs (FILE *out, state_t *state) { - errs *errp = state->errs; + errs_t *errp = state->errs; int i; for (i = 0; i < errp->nerrs; ++i) @@ -170,8 +170,8 @@ print_reductions (FILE *out, state_t *state) { int i; shifts_t *shiftp = state->shifts; - reductions *redp = state->reductions; - errs *errp = state->errs; + reductions_t *redp = state->reductions; + errs_t *errp = state->errs; int nodefault = 0; if (redp->nreds == 0) @@ -304,7 +304,7 @@ print_reductions (FILE *out, state_t *state) static void print_actions (FILE *out, state_t *state) { - reductions *redp = state->reductions; + reductions_t *redp = state->reductions; shifts_t *shiftp = state->shifts; if (shiftp->nshifts == 0 && redp->nreds == 0) diff --git a/src/print_graph.c b/src/print_graph.c index 7d81e2fe..1b83f140 100644 --- a/src/print_graph.c +++ b/src/print_graph.c @@ -123,8 +123,8 @@ print_actions (state_t *state, const char *node_name) { int i; - shifts_t *shiftp = state->shifts; - reductions *redp = state->reductions; + shifts_t *shiftp = state->shifts; + reductions_t *redp = state->reductions; static char buff[10]; edge_t edge; diff --git a/src/state.c b/src/state.c index 8148702e..dd8ec750 100644 --- a/src/state.c +++ b/src/state.c @@ -61,23 +61,23 @@ shifts_new (int nshifts, state_number_t *shifts) `-------------------------------*/ #define ERRS_ALLOC(Nerrs) \ - (errs *) xcalloc ((unsigned) (sizeof (errs) \ + (errs_t *) xcalloc ((unsigned) (sizeof (errs_t) \ + (Nerrs - 1) * sizeof (short)), 1) -errs * +errs_t * errs_new (int n) { - errs *res = ERRS_ALLOC (n); + errs_t *res = ERRS_ALLOC (n); res->nerrs = n; return res; } -errs * -errs_dup (errs *src) +errs_t * +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])); return res; } @@ -95,14 +95,15 @@ errs_dup (errs *src) `-------------------------------------*/ #define REDUCTIONS_ALLOC(Nreductions) \ - (reductions *) xcalloc ((unsigned) (sizeof (reductions) \ + (reductions_t *) xcalloc ((unsigned) (sizeof (reductions_t) \ + (Nreductions - 1) * sizeof (short)), 1) -reductions * -reductions_new (int n) +static reductions_t * +reductions_new (int nreductions, short *reductions) { - reductions *res = REDUCTIONS_ALLOC (n); - res->nreds = n; + reductions_t *res = REDUCTIONS_ALLOC (nreductions); + res->nreds = nreductions; + memcpy (res->rules, reductions, nreductions * sizeof (reductions[0])); 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 | diff --git a/src/state.h b/src/state.h index 8634b44b..074b1eea 100644 --- a/src/state.h +++ b/src/state.h @@ -144,27 +144,26 @@ typedef struct shifts_s | Errs. | `-------*/ -typedef struct errs +typedef struct errs_s { short nerrs; short errs[1]; -} errs; +} errs_t; -errs *errs_new PARAMS ((int n)); -errs *errs_dup PARAMS ((errs *src)); +errs_t *errs_new PARAMS ((int n)); +errs_t *errs_dup PARAMS ((errs_t *src)); /*-------------. | Reductions. | `-------------*/ -typedef struct reductions +typedef struct reductions_s { short nreds; short rules[1]; -} reductions; +} reductions_t; -reductions *reductions_new PARAMS ((int n)); /*----------. @@ -176,8 +175,8 @@ typedef struct state_s state_number_t number; symbol_number_t accessing_symbol; shifts_t *shifts; - reductions *reductions; - errs *errs; + reductions_t *reductions; + errs_t *errs; /* Nonzero if no lookahead is needed to decide what to do in state S. */ char consistent; @@ -208,6 +207,10 @@ state_t *state_new PARAMS ((symbol_number_t accessing_symbol, void state_shifts_set PARAMS ((state_t *state, 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 reduce this RULE. */ void state_rule_lookaheads_print PARAMS ((state_t *state, rule_t *rule, -- 2.45.2