X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/fb8ccdcd35fe53e47c6e02cc6ca84c32a9edfdb5..b6e3facf99b007dc0ccb9c615f6d9aba8d14a73f:/src/reduce.c?ds=sidebyside diff --git a/src/reduce.c b/src/reduce.c index 94df548e..1bb40f01 100644 --- a/src/reduce.c +++ b/src/reduce.c @@ -1,6 +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, 2005, 2006 Free + Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. @@ -16,8 +17,8 @@ You should have received a copy of the GNU General Public License along with Bison; see the file COPYING. If not, write to - the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. */ + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. */ /* Reduce the grammar: Find and eliminate unreachable terminals, @@ -26,6 +27,7 @@ /* Don't eliminate unreachable terminals: They may be used by the user's parser. */ +#include #include "system.h" #include @@ -246,7 +248,7 @@ reduce_grammar_tables (void) { int useful = 0; int useless = nrules - nuseless_productions; - rule *rules_sorted = MALLOC (rules_sorted, 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]; @@ -267,7 +269,7 @@ reduce_grammar_tables (void) /* Adjust NRITEMS. */ { - int r; + rule_number r; int length; for (r = nrules; r < nrules + nuseless_productions; ++r) { @@ -290,7 +292,7 @@ nonterminals_reduce (void) /* Map the nonterminals to their new index: useful first, useless afterwards. Kept for later report. */ - symbol_number *nontermmap = CALLOC (nontermmap, nvars); + symbol_number *nontermmap = xnmalloc (nvars, sizeof *nontermmap); n = ntokens; for (i = ntokens; i < nsyms; i++) if (bitset_test (V, i)) @@ -306,7 +308,7 @@ nonterminals_reduce (void) /* Shuffle elements of tables indexed by symbol number. */ { - symbol **symbols_sorted = MALLOC (symbols_sorted, nvars); + symbol **symbols_sorted = xnmalloc (nvars, sizeof *symbols_sorted); for (i = ntokens; i < nsyms; i++) symbols[i]->number = nontermmap[i - ntokens]; @@ -424,7 +426,7 @@ reduce_grammar (void) useless_nonterminals (); inaccessable_symbols (); - reduced = (bool) (nuseless_nonterminals + nuseless_productions > 0); + reduced = (nuseless_nonterminals + nuseless_productions > 0); if (!reduced) return;