X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/fb9c0b3360928887038a296c338025ced68e2d8c..9b33de72cd2469bedac2b5f0a48a8782571ea9db:/src/gram.c diff --git a/src/gram.c b/src/gram.c index dd77a766..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); } @@ -247,24 +247,23 @@ grammar_dump (FILE *out, const char *title) ntokens, nvars, nsyms, nrules, nritems); - fputs (("Variables\n---------\n\n" - "Value Sprec Sassoc Tag\n"), - out); + fprintf (out, "Variables\n---------\n\n"); { symbol_number 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, symbols[i]->tag); + fprintf (out, "\n\n"); } - fputs ("\n\n", out); - fputs (("Rules\n-----\n\n" - "Num (Prec, Assoc, Useful, Ritem Range) Lhs -> Rhs (Ritem range) [Num]\n"), - out); + fprintf (out, "Rules\n-----\n\n"); { rule_number i; + fprintf (out, "Num (Prec, Assoc, Useful, Ritem Range) Lhs -> Rhs (Ritem range) [Num]\n"); for (i = 0; i < nrules + nuseless_productions; i++) { rule *rule_i = &rules[i]; @@ -288,9 +287,9 @@ grammar_dump (FILE *out, const char *title) fprintf (out, " [%d]\n", item_number_as_rule_number (*rp)); } } - fputs ("\n\n", out); + fprintf (out, "\n\n"); - fputs ("Rules interpreted\n-----------------\n\n", out); + fprintf (out, "Rules interpreted\n-----------------\n\n"); { rule_number r; for (r = 0; r < nrules + nuseless_productions; r++) @@ -299,7 +298,7 @@ grammar_dump (FILE *out, const char *title) rule_print (&rules[r], out); } } - fputs ("\n\n", out); + fprintf (out, "\n\n"); } @@ -318,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); } } @@ -327,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. */