X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/17ee7397a87c4c4ccd45f956e0b88b824a3689f9..e62f1a899168bdf1658dd6d934dea407491a80ff:/src/reduce.c diff --git a/src/reduce.c b/src/reduce.c index fa09b497..b53948f9 100644 --- a/src/reduce.c +++ b/src/reduce.c @@ -1,5 +1,7 @@ /* Grammar reduction for Bison. - Copyright (C) 1988, 1989, 2000, 2001, 2002 Free Software Foundation, Inc. + + Copyright (C) 1988, 1989, 2000, 2001, 2002, 2003 Free Software + Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. @@ -245,7 +247,7 @@ reduce_grammar_tables (void) { int useful = 0; int useless = nrules - nuseless_productions; - rule *rules_sorted = XMALLOC (rule, nrules); + rule *rules_sorted = xnmalloc (nrules, sizeof *rules_sorted); rule_number r; for (r = 0; r < nrules; ++r) rules_sorted[rules[r].useful ? useful++ : useless++] = rules[r]; @@ -266,7 +268,7 @@ reduce_grammar_tables (void) /* Adjust NRITEMS. */ { - int r; + rule_number r; int length; for (r = nrules; r < nrules + nuseless_productions; ++r) { @@ -289,15 +291,15 @@ nonterminals_reduce (void) /* Map the nonterminals to their new index: useful first, useless afterwards. Kept for later report. */ - symbol_number *nontermmap = XCALLOC (symbol_number, nvars) - ntokens; + symbol_number *nontermmap = xnmalloc (nvars, sizeof *nontermmap); n = ntokens; for (i = ntokens; i < nsyms; i++) if (bitset_test (V, i)) - nontermmap[i] = n++; + nontermmap[i - ntokens] = n++; for (i = ntokens; i < nsyms; i++) if (!bitset_test (V, i)) { - nontermmap[i] = n++; + nontermmap[i - ntokens] = n++; warn_at (symbols[i]->location, _("useless nonterminal: %s"), symbols[i]->tag); } @@ -305,15 +307,15 @@ nonterminals_reduce (void) /* Shuffle elements of tables indexed by symbol number. */ { - symbol **symbols_sorted = XMALLOC (symbol *, nvars) - ntokens; + symbol **symbols_sorted = xnmalloc (nvars, sizeof *symbols_sorted); for (i = ntokens; i < nsyms; i++) - symbols[i]->number = nontermmap[i]; + symbols[i]->number = nontermmap[i - ntokens]; for (i = ntokens; i < nsyms; i++) - symbols_sorted[nontermmap[i]] = symbols[i]; + symbols_sorted[nontermmap[i - ntokens] - ntokens] = symbols[i]; for (i = ntokens; i < nsyms; i++) - symbols[i] = symbols_sorted[i]; - free (symbols_sorted + ntokens); + symbols[i] = symbols_sorted[i - ntokens]; + free (symbols_sorted); } { @@ -323,15 +325,16 @@ nonterminals_reduce (void) item_number *rhsp; for (rhsp = rules[r].rhs; *rhsp >= 0; ++rhsp) if (ISVAR (*rhsp)) - *rhsp = symbol_number_as_item_number (nontermmap[*rhsp]); + *rhsp = symbol_number_as_item_number (nontermmap[*rhsp + - ntokens]); } - accept->number = nontermmap[accept->number]; + accept->number = nontermmap[accept->number - ntokens]; } nsyms -= nuseless_nonterminals; nvars -= nuseless_nonterminals; - free (nontermmap + ntokens); + free (nontermmap); } @@ -405,7 +408,6 @@ reduce_print (void) nuseless_productions), nuseless_productions); fprintf (stderr, "\n"); - fflush (stderr); } void