From: Akim Demaille Date: Thu, 1 Aug 2002 18:13:29 +0000 (+0000) Subject: * src/derives.h, src/derives.c (derives): A `rule_t***' instead of X-Git-Tag: BISON-1_49b~54 X-Git-Url: https://git.saurik.com/bison.git/commitdiff_plain/bb0027a9aca454a80f737e0c49df0a231c50b996 * src/derives.h, src/derives.c (derives): A `rule_t***' instead of `rule_number_t**'. (set_derives, free_derives): Rename as... (derives_compute, derives_free): this. Adjust all dependencies. * src/nullable.c (set_nullable, free_nullable): Rename as... (nullable_compute, nullable_free): these. (rule_list_t): Store rule_t *, not rule_number_t. * src/state.c (state_rule_lookaheads_print): Directly compare rule pointers, instead of their numbers. * src/main.c (main): Call nullable_free, and derives_free earlier, as they were lo longer used. --- diff --git a/ChangeLog b/ChangeLog index bfa1ed26..da461eea 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2002-08-01 Akim Demaille + + * src/derives.h, src/derives.c (derives): A `rule_t***' instead of + `rule_number_t**'. + (set_derives, free_derives): Rename as... + (derives_compute, derives_free): this. + Adjust all dependencies. + * src/nullable.c (set_nullable, free_nullable): Rename as... + (nullable_compute, nullable_free): these. + (rule_list_t): Store rule_t *, not rule_number_t. + * src/state.c (state_rule_lookaheads_print): Directly compare rule + pointers, instead of their numbers. + * src/main.c (main): Call nullable_free, and derives_free earlier, + as they were lo longer used. + 2002-08-01 Akim Demaille * lib/timevar.c (get_time): Include children time. diff --git a/src/closure.c b/src/closure.c index 994634c0..3d5ac28d 100644 --- a/src/closure.c +++ b/src/closure.c @@ -125,9 +125,9 @@ set_firsts (void) firsts = bitsetv_create (nvars, nvars, BITSET_FIXED); for (i = ntokens; i < nsyms; i++) - for (j = 0; derives[i][j] >= 0; ++j) + for (j = 0; derives[i][j]; ++j) { - int symbol = rules[derives[i][j]].rhs[0]; + int symbol = derives[i][j]->rhs[0]; if (ISVAR (symbol)) bitset_set (FIRSTS (i), symbol - ntokens); } @@ -165,8 +165,8 @@ set_fderives (void) for (i = ntokens; i < nsyms; ++i) for (j = ntokens; j < nsyms; ++j) if (bitset_test (FIRSTS (i), j - ntokens)) - for (k = 0; derives[j][k] >= 0; ++k) - bitset_set (FDERIVES (i), derives[j][k]); + for (k = 0; derives[j][k]; ++k) + bitset_set (FDERIVES (i), derives[j][k]->number); if (trace_flag & trace_sets) print_fderives (); diff --git a/src/derives.c b/src/derives.c index c5b67104..74692975 100644 --- a/src/derives.c +++ b/src/derives.c @@ -1,5 +1,5 @@ /* Match rules with nonterminals for bison, - Copyright 1984, 1989, 2000, 2001, 2002 Free Software Foundation, Inc. + Copyright (C) 1984, 1989, 2000, 2001, 2002 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. @@ -30,10 +30,10 @@ typedef struct rule_list_s { struct rule_list_s *next; - rule_number_t value; + rule_t *value; } rule_list_t; -rule_number_t **derives = NULL; +rule_t ***derives = NULL; static void print_derives (void) @@ -44,12 +44,12 @@ print_derives (void) for (i = ntokens; i < nsyms; i++) { - rule_number_t *rp; + rule_t **rp; fprintf (stderr, "\t%s derives\n", symbols[i]->tag); - for (rp = derives[i]; *rp >= 0; rp++) + for (rp = derives[i]; *rp; ++rp) { - fprintf (stderr, "\t\t%3d ", *rp); - rule_rhs_print (&rules[*rp], stderr); + fprintf (stderr, "\t\t%3d ", (*rp)->user_number); + rule_rhs_print (*rp, stderr); } } @@ -58,11 +58,11 @@ print_derives (void) void -set_derives (void) +derives_compute (void) { symbol_number_t i; int r; - rule_number_t *q; + rule_t **q; /* DSET[NTERM] -- A linked list of the numbers of the rules whose LHS is NTERM. */ @@ -79,15 +79,15 @@ set_derives (void) rule_list_t *p = &delts[r]; /* A new LHS is found. */ p->next = dset[lhs]; - p->value = r; + p->value = &rules[r]; dset[lhs] = p; } /* DSET contains what we need under the form of a linked list. Make it a single array. */ - derives = XCALLOC (rule_number_t *, nvars) - ntokens; - q = XCALLOC (rule_number_t, nvars + int_of_rule_number (nrules)); + derives = XCALLOC (rule_t **, nvars) - ntokens; + q = XCALLOC (rule_t *, nvars + int_of_rule_number (nrules)); for (i = ntokens; i < nsyms; i++) { @@ -98,7 +98,7 @@ set_derives (void) *q++ = p->value; p = p->next; } - *q++ = -1; + *q++ = NULL; } if (trace_flag & trace_sets) @@ -110,7 +110,7 @@ set_derives (void) void -free_derives (void) +derives_free (void) { XFREE (derives[ntokens]); XFREE (derives + ntokens); diff --git a/src/derives.h b/src/derives.h index bcbaa0a7..c5581243 100644 --- a/src/derives.h +++ b/src/derives.h @@ -1,5 +1,5 @@ /* Match rules with nonterminals for bison, - Copyright 1984, 1989, 2000, 2001 Free Software Foundation, Inc. + Copyright (C) 1984, 1989, 2000, 2001, 2002 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. @@ -21,13 +21,13 @@ #ifndef DERIVES_H_ # define DERIVES_H_ -/* DERIVES[SYMBOL - NTOKENS] points to a vector of the number of the - rules that SYMBOL derives, terminated with -1. */ -extern rule_number_t **derives; +/* DERIVES[SYMBOL - NTOKENS] points to a vector of the rules that + SYMBOL derives, terminated with NULL. */ +extern rule_t ***derives; /* Compute DERIVES. */ -void set_derives PARAMS((void)); -void free_derives PARAMS((void)); +void derives_compute PARAMS((void)); +void derives_free PARAMS((void)); #endif /* !DERIVES_H_ */ diff --git a/src/lalr.c b/src/lalr.c index 275c6ab7..832f1fcf 100644 --- a/src/lalr.c +++ b/src/lalr.c @@ -244,16 +244,16 @@ initialize_F (void) static void -add_lookback_edge (state_t *state, rule_number_t ruleno, int gotono) +add_lookback_edge (state_t *state, rule_t *rule, int gotono) { int i; goto_list_t *sp; for (i = 0; i < state->nlookaheads; ++i) - if (state->lookaheads_rule[i]->number == ruleno) + if (state->lookaheads_rule[i] == rule) break; - assert (state->lookaheads_rule[i]->number == ruleno); + assert (state->lookaheads_rule[i] == rule); sp = XCALLOC (goto_list_t, 1); sp->next = lookback[(state->lookaheads - LA) + i]; @@ -276,9 +276,9 @@ build_relations (void) { int nedges = 0; symbol_number_t symbol1 = states[to_state[i]]->accessing_symbol; - rule_number_t *rulep; + rule_t **rulep; - for (rulep = derives[symbol1]; *rulep >= 0; rulep++) + for (rulep = derives[symbol1]; *rulep; rulep++) { int done; int length = 1; @@ -286,7 +286,7 @@ build_relations (void) state_t *state = states[from_state[i]]; states1[0] = state->number; - for (rp = rules[*rulep].rhs; *rp >= 0; rp++) + for (rp = (*rulep)->rhs; *rp >= 0; rp++) { state = transitions_to (state->transitions, item_number_as_symbol_number (*rp)); diff --git a/src/main.c b/src/main.c index b59e2978..c695ae5f 100644 --- a/src/main.c +++ b/src/main.c @@ -1,5 +1,5 @@ /* Top level entry point of bison, - Copyright 1984, 1986, 1989, 1992, 1995, 2000, 2001, 2002 + Copyright (C) 1984, 1986, 1989, 1992, 1995, 2000, 2001, 2002 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. @@ -84,8 +84,8 @@ main (int argc, char *argv[]) /* Record other info about the grammar. In files derives and nullable. */ timevar_push (TV_SETS); - set_derives (); - set_nullable (); + derives_compute (); + nullable_compute (); timevar_pop (TV_SETS); /* Convert to nondeterministic finite state machine. In file LR0. @@ -99,6 +99,11 @@ main (int argc, char *argv[]) lalr (); timevar_pop (TV_LALR); + timevar_push (TV_FREE); + nullable_free (); + derives_free (); + timevar_pop (TV_FREE); + /* Find and record any conflicts: places where one token of lookahead is not enough to disambiguate the parsing. In file conflicts. Also resolve s/r conflicts based on precedence @@ -152,8 +157,6 @@ main (int argc, char *argv[]) states_free (); reduce_free (); conflicts_free (); - free_nullable (); - free_derives (); grammar_free (); /* The scanner memory cannot be released right after parsing, as it diff --git a/src/nullable.c b/src/nullable.c index 9f61fa87..c0b60f64 100644 --- a/src/nullable.c +++ b/src/nullable.c @@ -30,14 +30,14 @@ #include "reduce.h" #include "nullable.h" -/* Linked list of rule numbers. */ +/* Linked list of rules. */ typedef struct rule_list_s { struct rule_list_s *next; - rule_number_t value; + rule_t *value; } rule_list_t; -char *nullable = NULL; +bool *nullable = NULL; static void nullable_print (FILE *out) @@ -50,7 +50,7 @@ nullable_print (FILE *out) } void -set_nullable (void) +nullable_compute (void) { rule_number_t ruleno; symbol_number_t *s1; @@ -66,7 +66,7 @@ set_nullable (void) Supposedly NRITEMS - NRULES is enough. But why take the risk? */ rule_list_t *relts = XCALLOC (rule_list_t, nritems + nvars + 1); - nullable = XCALLOC (char, nvars) - ntokens; + nullable = XCALLOC (bool, nvars) - ntokens; s1 = s2 = squeue; p = relts; @@ -91,7 +91,7 @@ set_nullable (void) { rcount[ruleno]++; p->next = rsets[*r]; - p->value = ruleno; + p->value = rule; rsets[*r] = p; p++; } @@ -111,12 +111,12 @@ set_nullable (void) while (s1 < s2) for (p = rsets[*s1++]; p; p = p->next) { - ruleno = p->value; - if (--rcount[ruleno] == 0) - if (rules[ruleno].useful && !nullable[rules[ruleno].lhs->number]) + rule_t *rule = p->value; + if (--rcount[rule->number] == 0) + if (rule->useful && !nullable[rule->lhs->number]) { - nullable[rules[ruleno].lhs->number] = 1; - *s2++ = rules[ruleno].lhs->number; + nullable[rule->lhs->number] = 1; + *s2++ = rule->lhs->number; } } @@ -131,7 +131,7 @@ set_nullable (void) void -free_nullable (void) +nullable_free (void) { XFREE (nullable + ntokens); } diff --git a/src/nullable.h b/src/nullable.h index a2d9b4b8..af46c9c6 100644 --- a/src/nullable.h +++ b/src/nullable.h @@ -1,5 +1,5 @@ /* Part of the bison parser generator, - Copyright 2000 Free Software Foundation, Inc. + Copyright (C) 2000, 2002 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. @@ -23,11 +23,11 @@ /* A vector saying which nonterminals can expand into the null string. NULLABLE[I - NTOKENS] is nonzero if symbol I can do so. */ -extern char *nullable; +extern bool *nullable; /* Set up NULLABLE. */ -extern void set_nullable PARAMS((void)); +extern void nullable_compute PARAMS((void)); /* Free NULLABLE. */ -extern void free_nullable PARAMS((void)); +extern void nullable_free PARAMS((void)); #endif /* !NULLABLE_H_ */ diff --git a/src/state.c b/src/state.c index 77307126..eb244e28 100644 --- a/src/state.c +++ b/src/state.c @@ -223,7 +223,7 @@ state_rule_lookaheads_print (state_t *state, rule_t *rule, FILE *out) /* Count the number of lookaheads corresponding to this rule. */ for (j = 0; j < state->nlookaheads; ++j) BITSET_FOR_EACH (biter, state->lookaheads[j], k, 0) - if (state->lookaheads_rule[j]->number == rule->number) + if (state->lookaheads_rule[j] == rule) nlookaheads++; /* Print them if there are. */ @@ -232,7 +232,7 @@ state_rule_lookaheads_print (state_t *state, rule_t *rule, FILE *out) fprintf (out, " ["); for (j = 0; j < state->nlookaheads; ++j) BITSET_FOR_EACH (biter, state->lookaheads[j], k, 0) - if (state->lookaheads_rule[j]->number == rule->number) + if (state->lookaheads_rule[j] == rule) fprintf (out, "%s%s", symbols[k]->tag, --nlookaheads ? ", " : "");