X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/0fb669f9d648dfdd7a39478a6b658511455ae966..276f48df88293dc0a67237d1124a26e0f9ee82fb:/src/gram.c?ds=sidebyside diff --git a/src/gram.c b/src/gram.c index e394478d..28666b0c 100644 --- a/src/gram.c +++ b/src/gram.c @@ -1,7 +1,7 @@ /* Allocate input grammar variables for Bison. - Copyright (C) 1984, 1986, 1989, 2001, 2002, 2003 Free Software - Foundation, Inc. + Copyright (C) 1984, 1986, 1989, 2001, 2002, 2003, 2005, 2006 Free + Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. @@ -20,7 +20,7 @@ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - +#include #include "system.h" #include @@ -65,7 +65,7 @@ rule_useful_p (rule *r) bool rule_useless_p (rule *r) { - return r->number >= nrules; + return !rule_useful_p (r); } @@ -77,7 +77,7 @@ rule_useless_p (rule *r) bool rule_never_reduced_p (rule *r) { - return !r->useful && r->number < nrules; + return !r->useful && rule_useful_p (r); } @@ -269,7 +269,7 @@ grammar_dump (FILE *out, const char *title) rule *rule_i = &rules[i]; item_number *rp = NULL; unsigned int rhs_itemno = rule_i->rhs - ritem; - unsigned int rhs_count = 0; + unsigned int rhs_count = 0; /* Find the last RHS index in ritems. */ for (rp = rule_i->rhs; *rp >= 0; ++rp) ++rhs_count; @@ -317,8 +317,7 @@ grammar_rules_never_reduced_report (const char *message) if (!rules[r].useful) { location_print (stderr, rules[r].location); - fprintf (stderr, ": %s: %s: ", - _("warning"), message); + fprintf (stderr, ": %s: %s: ", _("warning"), message); rule_print (&rules[r], stderr); } } @@ -326,7 +325,8 @@ grammar_rules_never_reduced_report (const char *message) void grammar_free (void) { - free (ritem); + if (ritem) + free (ritem - 1); free (rules); free (token_translations); /* Free the symbol table data structure. */