From 9222837b2743308e4971fc0ad299ca2f73fb20ae Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Sun, 30 Jun 2002 17:31:19 +0000 Subject: [PATCH] * src/gram.h (rule_number_t, RULE_NUMBER_MAX, int_of_rule_number) (item_number_of_rule_number, rule_number_of_item_number): New. * src/LR0.c, src/closure.c, src/derives.c, src/derives.h, * src/gram.c, src/lalr.c, src/nullable.c, src/output.c, src/print.c, * src/print_graph.c, src/reader.c, src/reduce.c, src/reduce.h: Propagate their use. Much remains to be done, in particular wrt `shorts' from types.h. --- ChangeLog | 11 ++++++ src/LR0.c | 3 +- src/closure.c | 20 +++++----- src/derives.c | 32 ++++++++-------- src/derives.h | 2 +- src/gram.c | 93 +++++++++++++++++++++++++++-------------------- src/gram.h | 29 +++++++++++---- src/lalr.c | 4 +- src/nullable.c | 19 +++++----- src/output.c | 22 +++++------ src/print.c | 21 ++++++----- src/print_graph.c | 4 +- src/reader.c | 10 ++--- src/reduce.c | 84 ++++++++++++++++++++++-------------------- src/reduce.h | 4 +- 15 files changed, 202 insertions(+), 156 deletions(-) diff --git a/ChangeLog b/ChangeLog index ba92a1f9..ed8ec2ed 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2002-06-30 Akim Demaille + + * src/gram.h (rule_number_t, RULE_NUMBER_MAX, int_of_rule_number) + (item_number_of_rule_number, rule_number_of_item_number): New. + * src/LR0.c, src/closure.c, src/derives.c, src/derives.h, + * src/gram.c, src/lalr.c, src/nullable.c, src/output.c, src/print.c, + * src/print_graph.c, src/reader.c, src/reduce.c, src/reduce.h: + Propagate their use. + Much remains to be done, in particular wrt `shorts' from types.h. + + 2002-06-30 Akim Demaille * src/symtab.c (symbol_new): Initialize the `printer' member. diff --git a/src/LR0.c b/src/LR0.c index d402d910..9ce53e06 100644 --- a/src/LR0.c +++ b/src/LR0.c @@ -74,7 +74,8 @@ static item_number_t *kernel_items = NULL; static void allocate_itemsets (void) { - int i, r; + symbol_number_t i; + rule_number_t r; item_number_t *rhsp; /* Count the number of occurrences of all the symbols in RITEMS. diff --git a/src/closure.c b/src/closure.c index ea64250e..31b52335 100644 --- a/src/closure.c +++ b/src/closure.c @@ -87,18 +87,19 @@ print_firsts (void) static void print_fderives (void) { - int i, j; + int i; + rule_number_t r; fprintf (stderr, "FDERIVES\n"); for (i = ntokens; i < nsyms; i++) { fprintf (stderr, "\t%s derives\n", symbol_tag_get (symbols[i])); - for (j = 0; j < nrules + 1; j++) - if (bitset_test (FDERIVES (i), j)) + for (r = 0; r < nrules + 1; r++) + if (bitset_test (FDERIVES (i), r)) { - item_number_t *rhsp; - fprintf (stderr, "\t\t%d:", j - 1); - for (rhsp = rules[j].rhs; *rhsp >= 0; ++rhsp) + item_number_t *rhsp = NULL; + fprintf (stderr, "\t\t%d:", r - 1); + for (rhsp = rules[r].rhs; *rhsp >= 0; ++rhsp) fprintf (stderr, " %s", symbol_tag_get (symbols[*rhsp])); fputc ('\n', stderr); } @@ -120,7 +121,7 @@ print_fderives (void) static void set_firsts (void) { - int i, j; + symbol_number_t i, j; firsts = bitsetv_create (nvars, nvars, BITSET_FIXED); @@ -155,7 +156,8 @@ set_firsts (void) static void set_fderives (void) { - int i, j, k; + symbol_number_t i, j; + rule_number_t k; fderives = bitsetv_create (nvars, nrules + 1, BITSET_FIXED); @@ -194,7 +196,7 @@ closure (item_number_t *core, int n) int c; /* A bit index over RULESET. */ - int ruleno; + rule_number_t ruleno; if (trace_flag) print_closure ("input", core, n); diff --git a/src/derives.c b/src/derives.c index d78d5563..6a5681bb 100644 --- a/src/derives.c +++ b/src/derives.c @@ -1,5 +1,5 @@ /* Match rules with nonterminals for bison, - Copyright 1984, 1989, 2000, 2001 Free Software Foundation, Inc. + Copyright 1984, 1989, 2000, 2001, 2002 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. @@ -27,7 +27,7 @@ #include "gram.h" #include "derives.h" -short **derives = NULL; +rule_number_t **derives = NULL; static void print_derives (void) @@ -38,15 +38,16 @@ print_derives (void) for (i = ntokens; i < nsyms; i++) { - short *sp; + rule_number_t *rp; fprintf (stderr, "\t%s derives\n", symbols[i]->tag); - for (sp = derives[i]; *sp > 0; sp++) + for (rp = derives[i]; *rp > 0; rp++) { item_number_t *rhsp; - fprintf (stderr, "\t\t%d:", *sp); - for (rhsp = rules[*sp].rhs; *rhsp >= 0; ++rhsp) - fprintf (stderr, " %s", symbols[*rhsp]->tag); - fprintf (stderr, " (rule %d)\n", -*rhsp - 1); + fprintf (stderr, "\t\t%d:", *rp); + for (rhsp = rules[*rp].rhs; *rhsp >= 0; ++rhsp) + fprintf (stderr, " %s", symbol_tag_get (symbols[*rhsp])); + fprintf (stderr, " (rule %d)\n", + rule_number_of_item_number (*rhsp) - 1); } } @@ -57,9 +58,10 @@ print_derives (void) void set_derives (void) { - int i; + symbol_number_t i; + rule_number_t r; shorts *p; - short *q; + rule_number_t *q; shorts **dset; shorts *delts; @@ -67,17 +69,17 @@ set_derives (void) delts = XCALLOC (shorts, nrules + 1); p = delts; - for (i = nrules; i > 0; i--) + for (r = nrules; r > 0; r--) { - symbol_number_t lhs = rules[i].lhs->number; + symbol_number_t lhs = rules[r].lhs->number; p->next = dset[lhs]; - p->value = i; + p->value = r; dset[lhs] = p; p++; } - derives = XCALLOC (short *, nvars) - ntokens; - q = XCALLOC (short, nvars + nrules); + derives = XCALLOC (rule_number_t *, nvars) - ntokens; + q = XCALLOC (short, nvars + int_of_rule_number (nrules)); for (i = ntokens; i < nsyms; i++) { diff --git a/src/derives.h b/src/derives.h index 96fcc3fc..bcbaa0a7 100644 --- a/src/derives.h +++ b/src/derives.h @@ -23,7 +23,7 @@ /* DERIVES[SYMBOL - NTOKENS] points to a vector of the number of the rules that SYMBOL derives, terminated with -1. */ -extern short **derives; +extern rule_number_t **derives; /* Compute DERIVES. */ diff --git a/src/gram.c b/src/gram.c index 4d88b39b..708922d5 100644 --- a/src/gram.c +++ b/src/gram.c @@ -32,7 +32,7 @@ item_number_t *ritem = NULL; unsigned int nritems = 0; rule_t *rules = NULL; -int nrules = 0; +rule_number_t nrules = 0; symbol_t **symbols = NULL; int nsyms = 0; @@ -121,11 +121,11 @@ size_t ritem_longest_rhs (void) { int max = 0; - int i; + rule_number_t r; - for (i = 1; i < nrules + 1; ++i) + for (r = 1; r < nrules + 1; ++r) { - int length = rule_rhs_length (&rules[i]); + int length = rule_rhs_length (&rules[r]); if (length > max) max = length; } @@ -148,7 +148,7 @@ blanks_print (unsigned n, FILE *out) void grammar_rules_partial_print (FILE *out, const char *title, - int begin, int end) + rule_number_t begin, rule_number_t end) { int r; symbol_t *last_lhs = NULL; @@ -195,49 +195,62 @@ grammar_rules_print (FILE *out) void grammar_dump (FILE *out, const char *title) { - int i; - item_number_t *r; - fprintf (out, "%s\n\n", title); fprintf (out, "ntokens = %d, nvars = %d, nsyms = %d, nrules = %d, nritems = %d\n\n", ntokens, nvars, nsyms, nrules, nritems); + + fprintf (out, "Variables\n---------\n\n"); - fprintf (out, "Value Sprec Sassoc Tag\n"); - for (i = ntokens; i < nsyms; i++) - fprintf (out, "%5d %5d %5d %s\n", - i, - symbols[i]->prec, symbols[i]->assoc, - symbol_tag_get (symbols[i])); - fprintf (out, "\n\n"); + { + symbol_number_t i; + fprintf (out, "Value Sprec Sassoc Tag\n"); + + for (i = ntokens; i < nsyms; i++) + fprintf (out, "%5d %5d %5d %s\n", + i, + symbols[i]->prec, symbols[i]->assoc, + symbol_tag_get (symbols[i])); + fprintf (out, "\n\n"); + } + fprintf (out, "Rules\n-----\n\n"); - fprintf (out, "Num (Prec, Assoc, Useful, Ritem Range) Lhs -> Rhs (Ritem range) [Num]\n"); - for (i = 1; i < nrules + nuseless_productions + 1; i++) - { - int rhs_count = 0; - /* Find the last RHS index in ritems. */ - for (r = rules[i].rhs; *r >= 0; ++r) - ++rhs_count; - fprintf (out, "%3d (%2d, %2d, %2d, %2d-%2d) %2d ->", - i - 1, - rules[i].prec ? rules[i].prec->prec : 0, - rules[i].prec ? rules[i].prec->assoc : 0, - rules[i].useful, - rules[i].rhs - ritem, - rules[i].rhs - ritem + rhs_count - 1, - rules[i].lhs->number); - /* Dumped the RHS. */ - for (r = rules[i].rhs; *r >= 0; r++) - fprintf (out, " %3d", *r); - fprintf (out, " [%d]\n", -(*r) - 1); - } + { + rule_number_t i; + fprintf (out, "Num (Prec, Assoc, Useful, Ritem Range) Lhs -> Rhs (Ritem range) [Num]\n"); + for (i = 1; i < nrules + nuseless_productions + 1; i++) + { + rule_t *rule = &rules[i]; + item_number_t *r = NULL; + int rhs_count = 0; + /* Find the last RHS index in ritems. */ + for (r = rule->rhs; *r >= 0; ++r) + ++rhs_count; + fprintf (out, "%3d (%2d, %2d, %2d, %2d-%2d) %2d ->", + i - 1, + rule->prec ? rule->prec->prec : 0, + rule->prec ? rule->prec->assoc : 0, + rule->useful, + rule->rhs - ritem, + rule->rhs - ritem + rhs_count - 1, + rule->lhs->number); + /* Dumped the RHS. */ + for (r = rule->rhs; *r >= 0; r++) + fprintf (out, " %3d", *r); + fprintf (out, " [%d]\n", -(*r) - 1); + } + } fprintf (out, "\n\n"); + fprintf (out, "Rules interpreted\n-----------------\n\n"); - for (i = 1; i < nrules + nuseless_productions + 1; i++) - { - fprintf (out, "%-5d ", i); - rule_print (&rules[i], out); - } + { + rule_number_t r; + for (r = 1; r < nrules + nuseless_productions + 1; r++) + { + fprintf (out, "%-5d ", r); + rule_print (&rules[r], out); + } + } fprintf (out, "\n\n"); } diff --git a/src/gram.h b/src/gram.h index 3254678f..1aa5cd7d 100644 --- a/src/gram.h +++ b/src/gram.h @@ -107,19 +107,19 @@ # define ISTOKEN(s) ((s) < ntokens) # define ISVAR(s) ((s) >= ntokens) -extern int nrules; extern int nsyms; extern int ntokens; extern int nvars; -# define ITEM_NUMBER_MAX INT_MAX typedef int item_number_t; +# define ITEM_NUMBER_MAX ((item_number_t) INT_MAX) extern item_number_t *ritem; extern unsigned int nritems; -/* There is weird relationship between item_number_t and - symbol_number_t: we store symbol_number_t in item_number_t, but in - the latter we also store, as negative numbers, the rule numbers. +/* There is weird relationship between OT1H item_number_t and OTOH + symbol_number_t and rule_number_t: we store the latter in + item_number_t. symbol_number_t are stored as are, while + the negation of rule_number_t are stored. Therefore, an symbol_number_t must be a valid item_number_t, and we sometimes have to perform the converse transformation. */ @@ -128,16 +128,28 @@ extern unsigned int nritems; extern symbol_number_t start_symbol; +/* Rules numbers. */ +typedef short rule_number_t; +# define RULE_NUMBER_MAX ((rule_number_t) SHRT_MAX) +extern rule_number_t nrules; +# define int_of_rule_number(RNum) ((int) (RNum)) +# define item_number_of_rule_number(RNum) ((item_number_t) (- RNum)) +# define rule_number_of_item_number(INum) ((rule_number_t) (- INum)) + + +/*--------. +| Rules. | +`--------*/ typedef struct rule_s { /* The number of the rule in the source. It is usually the index in RULES too, except if there are useless rules. */ - short user_number; + rule_number_t user_number; /* The index in RULES. Usually the rule number in the source, except if some rules are useless. */ - short number; + rule_number_t number; symbol_t *lhs; item_number_t *rhs; @@ -199,7 +211,8 @@ size_t ritem_longest_rhs PARAMS ((void)); /* Print the grammar's rules numbers from BEGIN (inclusive) to END (exclusive) on OUT under TITLE. */ void grammar_rules_partial_print PARAMS ((FILE *out, const char *title, - int begin, int end)); + rule_number_t begin, + rule_number_t end)); /* Print the grammar's rules on OUT. */ void grammar_rules_print PARAMS ((FILE *out)); diff --git a/src/lalr.c b/src/lalr.c index 8050f9f0..b1f84607 100644 --- a/src/lalr.c +++ b/src/lalr.c @@ -291,7 +291,7 @@ initialize_F (void) static void -add_lookback_edge (state_t *state, int ruleno, int gotono) +add_lookback_edge (state_t *state, rule_number_t ruleno, int gotono) { int i; shorts *sp; @@ -408,7 +408,7 @@ build_relations (void) { int nedges = 0; symbol_number_t symbol1 = states[to_state[i]]->accessing_symbol; - short *rulep; + rule_number_t *rulep; for (rulep = derives[symbol1]; *rulep > 0; rulep++) { diff --git a/src/nullable.c b/src/nullable.c index 42e398b3..b3686646 100644 --- a/src/nullable.c +++ b/src/nullable.c @@ -46,7 +46,7 @@ nullable_print (FILE *out) void set_nullable (void) { - int ruleno; + rule_number_t ruleno; symbol_number_t *s1; symbol_number_t *s2; shorts *p; @@ -71,19 +71,20 @@ set_nullable (void) for (ruleno = 1; ruleno < nrules + 1; ++ruleno) if (rules[ruleno].useful) { - if (rules[ruleno].rhs[0] >= 0) + rule_t *rule = &rules[ruleno]; + if (rule->rhs[0] >= 0) { /* This rule has a non empty RHS. */ - item_number_t *r; + item_number_t *r = NULL; int any_tokens = 0; - for (r = rules[ruleno].rhs; *r >= 0; ++r) + for (r = rule->rhs; *r >= 0; ++r) if (ISTOKEN (*r)) any_tokens = 1; /* This rule has only nonterminals: schedule it for the second pass. */ if (!any_tokens) - for (r = rules[ruleno].rhs; *r >= 0; ++r) + for (r = rule->rhs; *r >= 0; ++r) { rcount[ruleno]++; p->next = rsets[*r]; @@ -95,11 +96,11 @@ set_nullable (void) else { /* This rule has an empty RHS. */ - assert (rules[ruleno].rhs[0] == -ruleno); - if (rules[ruleno].useful && !nullable[rules[ruleno].lhs->number]) + assert (rule_number_of_item_number (rule->rhs[0]) == ruleno); + 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; } } } diff --git a/src/output.c b/src/output.c index daf753e4..30b29fea 100644 --- a/src/output.c +++ b/src/output.c @@ -294,7 +294,7 @@ prepare_tokens (void) static void prepare_rules (void) { - int r; + rule_number_t r; unsigned int i = 0; item_number_t *rhs = XMALLOC (item_number_t, nritems); unsigned int *prhs = XMALLOC (unsigned int, nrules + 1); @@ -306,7 +306,7 @@ prepare_rules (void) for (r = 1; r < nrules + 1; ++r) { - item_number_t *rhsp; + item_number_t *rhsp = NULL; /* Index of rule R in RHS. */ prhs[r] = i; /* RHS of the rule R. */ @@ -428,7 +428,7 @@ static int action_row (state_t *state) { int i; - int default_rule = 0; + rule_number_t default_rule = 0; reductions_t *redp = state->reductions; shifts_t *shiftp = state->shifts; errs_t *errp = state->errs; @@ -504,8 +504,8 @@ action_row (state_t *state) for (i = 0; i < state->nlookaheads; i++) { int count = 0; - int rule = -state->lookaheads_rule[i]->number; - int j; + rule_number_t rule = -state->lookaheads_rule[i]->number; + symbol_number_t j; for (j = 0; j < ntokens; j++) if (actrow[j] == rule) @@ -638,21 +638,21 @@ token_actions (void) void actions_output (FILE *out) { - int rule; + rule_number_t r; fputs ("m4_define([b4_actions], \n[[", out); - for (rule = 1; rule < nrules + 1; ++rule) - if (rules[rule].action) + for (r = 1; r < nrules + 1; ++r) + if (rules[r].action) { - fprintf (out, " case %d:\n", rule); + fprintf (out, " case %d:\n", r); if (!no_lines_flag) fprintf (out, muscle_find ("linef"), - rules[rule].action_location.first_line, + rules[r].action_location.first_line, quotearg_style (c_quoting_style, muscle_find ("filename"))); fprintf (out, " %s\n break;\n\n", - rules[rule].action); + rules[r].action); } fputs ("]])\n\n", out); } diff --git a/src/print.c b/src/print.c index 927d2bee..77895b07 100644 --- a/src/print.c +++ b/src/print.c @@ -354,7 +354,6 @@ static void print_grammar (FILE *out) { symbol_number_t i; - item_number_t *rule; char buffer[90]; int column = 0; @@ -366,7 +365,9 @@ print_grammar (FILE *out) if (token_translations[i] != undeftoken->number) { const char *tag = symbol_tag_get (symbols[token_translations[i]]); - int r; + rule_number_t r; + item_number_t *rhsp; + buffer[0] = 0; column = strlen (tag); fputs (tag, out); @@ -374,8 +375,8 @@ print_grammar (FILE *out) sprintf (buffer, " (%d)", i); for (r = 1; r < nrules + 1; r++) - for (rule = rules[r].rhs; *rule >= 0; rule++) - if (item_number_as_symbol_number (*rule) == token_translations[i]) + for (rhsp = rules[r].rhs; *rhsp >= 0; rhsp++) + if (item_number_as_symbol_number (*rhsp) == token_translations[i]) { END_TEST (65); sprintf (buffer + strlen (buffer), " %d", r - 1); @@ -390,15 +391,16 @@ print_grammar (FILE *out) for (i = ntokens; i < nsyms; i++) { int left_count = 0, right_count = 0; - int r; + rule_number_t r; const char *tag = symbol_tag_get (symbols[i]); for (r = 1; r < nrules + 1; r++) { + item_number_t *rhsp; if (rules[r].lhs->number == i) left_count++; - for (rule = rules[r].rhs; *rule >= 0; rule++) - if (item_number_as_symbol_number (*rule) == i) + for (rhsp = rules[r].rhs; *rhsp >= 0; rhsp++) + if (item_number_as_symbol_number (*rhsp) == i) { right_count++; break; @@ -432,8 +434,9 @@ print_grammar (FILE *out) sprintf (buffer + strlen (buffer), _(" on right:")); for (r = 1; r < nrules + 1; r++) { - for (rule = rules[r].rhs; *rule >= 0; rule++) - if (item_number_as_symbol_number (*rule) == i) + item_number_t *rhsp; + for (rhsp = rules[r].rhs; *rhsp >= 0; rhsp++) + if (item_number_as_symbol_number (*rhsp) == i) { END_TEST (65); sprintf (buffer + strlen (buffer), " %d", r - 1); diff --git a/src/print_graph.c b/src/print_graph.c index 1b83f140..05cb2e6a 100644 --- a/src/print_graph.c +++ b/src/print_graph.c @@ -63,14 +63,14 @@ print_core (struct obstack *oout, state_t *state) { item_number_t *sp; item_number_t *sp1; - int rule; + rule_number_t rule; sp1 = sp = ritem + sitems[i]; while (*sp >= 0) sp++; - rule = -(*sp); + rule = rule_number_of_item_number (*sp); if (i) obstack_1grow (oout, '\n'); diff --git a/src/reader.c b/src/reader.c index 6eda2327..3482d635 100644 --- a/src/reader.c +++ b/src/reader.c @@ -403,17 +403,13 @@ grammar_current_rule_action_append (const char *action, location_t location) static void packgram (void) { - unsigned int itemno; - int ruleno; - symbol_list_t *p; + unsigned int itemno = 0; + rule_number_t ruleno = 1; + symbol_list_t *p = grammar; ritem = XCALLOC (item_number_t, nritems); rules = XCALLOC (rule_t, nrules) - 1; - itemno = 0; - ruleno = 1; - - p = grammar; while (p) { symbol_t *ruleprec = p->ruleprec; diff --git a/src/reduce.c b/src/reduce.c index 35aab2e7..7c3ed15d 100644 --- a/src/reduce.c +++ b/src/reduce.c @@ -50,10 +50,10 @@ static bitset V; `useless', but no warning should be issued). */ static bitset V1; -static int nuseful_productions; -int nuseless_productions; +static rule_number_t nuseful_productions; +rule_number_t nuseless_productions; static int nuseful_nonterminals; -int nuseless_nonterminals; +symbol_number_t nuseless_nonterminals; /*-------------------------------------------------------------------. | Another way to do this would be with a set for each production and | @@ -62,16 +62,15 @@ int nuseless_nonterminals; `-------------------------------------------------------------------*/ static bool -useful_production (int i, bitset N0) +useful_production (rule_number_t r, bitset N0) { - item_number_t *r; - short n; + item_number_t *rhsp; /* A production is useful if all of the nonterminals in its appear in the set of useful nonterminals. */ - for (r = rules[i].rhs; *r >= 0; r++) - if (ISVAR (n = *r) && !bitset_test (N0, n - ntokens)) + for (rhsp = rules[r].rhs; *rhsp >= 0; ++rhsp) + if (ISVAR (*rhsp) && !bitset_test (N0, *rhsp - ntokens)) return FALSE; return TRUE; } @@ -85,7 +84,7 @@ static void useless_nonterminals (void) { bitset Np, Ns; - int i; + rule_number_t r; /* N is set as built. Np is set being built this iteration. P is set of all productions which have a RHS all in N. */ @@ -112,12 +111,12 @@ useless_nonterminals (void) while (1) { bitset_copy (Np, N); - for (i = 1; i < nrules + 1; i++) - if (!bitset_test (P, i) - && useful_production (i, N)) + for (r = 1; r < nrules + 1; r++) + if (!bitset_test (P, r) + && useful_production (r, N)) { - bitset_set (Np, rules[i].lhs->number - ntokens); - bitset_set (P, i); + bitset_set (Np, rules[r].lhs->number - ntokens); + bitset_set (P, r); } if (bitset_equal_p (N, Np)) break; @@ -134,9 +133,6 @@ static void inaccessable_symbols (void) { bitset Vp, Vs, Pp; - int i; - short t; - item_number_t *r; /* Find out which productions are reachable and which symbols are used. Starting with an empty set of productions and a set of @@ -171,17 +167,19 @@ inaccessable_symbols (void) while (1) { + rule_number_t r; bitset_copy (Vp, V); - for (i = 1; i < nrules + 1; i++) + for (r = 1; r < nrules + 1; r++) { - if (!bitset_test (Pp, i) - && bitset_test (P, i) - && bitset_test (V, rules[i].lhs->number)) + if (!bitset_test (Pp, r) + && bitset_test (P, r) + && bitset_test (V, rules[r].lhs->number)) { - for (r = rules[i].rhs; *r >= 0; r++) - if (ISTOKEN (t = *r) || bitset_test (N, t - ntokens)) - bitset_set (Vp, t); - bitset_set (Pp, i); + item_number_t *rhsp; + for (rhsp = rules[r].rhs; *rhsp >= 0; rhsp++) + if (ISTOKEN (*rhsp) || bitset_test (N, *rhsp - ntokens)) + bitset_set (Vp, *rhsp); + bitset_set (Pp, r); } } if (bitset_equal_p (V, Vp)) @@ -207,15 +205,21 @@ inaccessable_symbols (void) nuseless_productions = nrules - nuseful_productions; nuseful_nonterminals = 0; - for (i = ntokens; i < nsyms; i++) - if (bitset_test (V, i)) - nuseful_nonterminals++; + { + symbol_number_t i; + for (i = ntokens; i < nsyms; i++) + if (bitset_test (V, i)) + nuseful_nonterminals++; + } nuseless_nonterminals = nvars - nuseful_nonterminals; /* A token that was used in %prec should not be warned about. */ - for (i = 1; i < nrules + 1; i++) - if (rules[i].precsym != 0) - bitset_set (V1, rules[i].precsym->number); + { + rule_number_t i; + for (i = 1; i < nrules + 1; i++) + if (rules[i].precsym != 0) + bitset_set (V1, rules[i].precsym->number); + } } @@ -229,7 +233,7 @@ reduce_grammar_tables (void) { /* Report and flag useless productions. */ { - int r; + rule_number_t r; for (r = 1; r < nrules + 1; r++) { rules[r].useful = bitset_test (P, r); @@ -248,20 +252,20 @@ reduce_grammar_tables (void) int useful = 1; int useless = nrules + 1 - nuseless_productions; rule_t *rules_sorted = XMALLOC (rule_t, nrules + 1) - 1; - int i; - for (i = 1; i < nrules + 1; ++i) - rules_sorted[rules[i].useful ? useful++ : useless++] = rules[i]; + rule_number_t r; + for (r = 1; r < nrules + 1; ++r) + rules_sorted[rules[r].useful ? useful++ : useless++] = rules[r]; free (rules + 1); rules = rules_sorted; /* Renumber the rules markers in RITEMS. */ - for (i = 1; i < nrules + 1; ++i) + for (r = 1; r < nrules + 1; ++r) { - item_number_t *rhsp = rules[i].rhs; + item_number_t *rhsp = rules[r].rhs; for (/* Nothing. */; *rhsp >= 0; ++rhsp) /* Nothing. */; - *rhsp = -i; - rules[i].number = i; + *rhsp = item_number_of_rule_number (r); + rules[r].number = r; } nrules -= nuseless_productions; } @@ -321,7 +325,7 @@ nonterminals_reduce (void) } { - int r; + rule_number_t r; for (r = 1; r < nrules + 1; ++r) { item_number_t *rhsp; diff --git a/src/reduce.h b/src/reduce.h index c7b3cae8..a1d8aa4c 100644 --- a/src/reduce.h +++ b/src/reduce.h @@ -25,6 +25,6 @@ void reduce_grammar PARAMS ((void)); void reduce_output PARAMS ((FILE *out)); void reduce_free PARAMS ((void)); -extern int nuseless_nonterminals; -extern int nuseless_productions; +extern symbol_number_t nuseless_nonterminals; +extern rule_number_t nuseless_productions; #endif /* !REDUCE_H_ */ -- 2.45.2