X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/cff03fb2b92a05f61c142783dd3b2e0103782869..5523ac79a0e46820d9a947b8cf0f7149da0f0165:/src/reduce.c?ds=sidebyside diff --git a/src/reduce.c b/src/reduce.c index 2d01255c..596a26bc 100644 --- a/src/reduce.c +++ b/src/reduce.c @@ -1,7 +1,7 @@ /* Grammar reduction for Bison. Copyright (C) 1988, 1989, 2000, 2001, 2002, 2003, 2005, 2006, - 2007 Free Software Foundation, Inc. + 2007, 2008 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. @@ -358,10 +358,10 @@ reduce_output (FILE *out) bool b = false; int i; for (i = 0; i < ntokens; i++) - if (!bitset_test (V, i) && !bitset_test (V1, i)) + if (reduce_token_unused_in_grammar (i)) { if (!b) - fprintf (out, "%s\n\n", _("Terminals which are not used")); + fprintf (out, "%s\n\n", _("Terminals unused in grammar")); b = true; fprintf (out, " %s\n", symbols[i]->tag); } @@ -375,64 +375,6 @@ reduce_output (FILE *out) } -/*--------------------------------------------------------------. -| Output the detailed results of the reductions. For FILE.xml. | -`---------------------------------------------------------------*/ - -void -reduce_xml (FILE *out, int level) -{ - fputc ('\n', out); - xml_puts (out, level, ""); - xml_puts (out, level + 1, ""); - - if (nuseless_nonterminals > 0) - { - int i; - xml_puts (out, level + 2, ""); - for (i = 0; i < nuseless_nonterminals; ++i) - xml_printf (out, level + 3, - "%s", - symbols[nsyms + i]->tag); - xml_puts (out, level + 2, ""); - } - else - xml_puts (out, level + 2, ""); - - if (nuseless_productions > 0) - grammar_rules_partial_print_xml (out, level + 1, true, - rule_useless_in_grammar_p); - else - xml_puts (out, level + 2, ""); - - xml_puts (out, level + 1, ""); - xml_puts (out, level + 1, ""); - - { - bool b = false; - int i; - for (i = 0; i < ntokens; i++) - if (!bitset_test (V, i) && !bitset_test (V1, i)) - { - if (!b) - xml_puts (out, level + 2, ""); - b = true; - xml_printf (out, level + 3, - "%s", - xml_escape (symbols[i]->tag)); - } - if (b) - xml_puts (out, level + 2, ""); - else - xml_puts (out, level + 2, ""); - } - - xml_puts (out, level + 1, ""); - xml_puts (out, level, ""); - fputc ('\n', out); -} - - /*-------------------------------. | Report the results to STDERR. | `-------------------------------*/ @@ -440,26 +382,24 @@ reduce_xml (FILE *out, int level) static void reduce_print (void) { - fprintf (stderr, "%s: %s: ", grammar_file, _("warning")); - if (nuseless_nonterminals > 0) - fprintf (stderr, ngettext ("%d nonterminal", - "%d nonterminals", - nuseless_nonterminals), - nuseless_nonterminals); - - if (nuseless_nonterminals > 0 && nuseless_productions > 0) - fprintf (stderr, _(" and ")); - + { + fprintf (stderr, "%s: %s: ", grammar_file, _("warning")); + fprintf (stderr, ngettext ("%d nonterminal useless in grammar", + "%d nonterminals useless in grammar", + nuseless_nonterminals), + nuseless_nonterminals); + fprintf (stderr, "\n"); + } if (nuseless_productions > 0) - fprintf (stderr, ngettext ("%d rule", - "%d rules", - nuseless_productions), - nuseless_productions); - - if (nuseless_nonterminals > 0 || nuseless_productions > 0) - fprintf (stderr, _(" useless in grammar")); - fprintf (stderr, "\n"); + { + fprintf (stderr, "%s: %s: ", grammar_file, _("warning")); + fprintf (stderr, ngettext ("%d rule useless in grammar", + "%d rules useless in grammar", + nuseless_productions), + nuseless_productions); + fprintf (stderr, "\n"); + } } void @@ -506,6 +446,19 @@ reduce_grammar (void) } } +bool +reduce_token_unused_in_grammar (symbol_number i) +{ + aver (i < ntokens); + return !bitset_test (V, i) && !bitset_test (V1, i); +} + +bool +reduce_nonterminal_useless_in_grammar (symbol_number i) +{ + aver (ntokens <= i && i < nsyms + nuseless_nonterminals); + return nsyms <= i; +} /*-----------------------------------------------------------. | Free the global sets used to compute the reduced grammar. |