X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/cff03fb2b92a05f61c142783dd3b2e0103782869..0e16927b48c881317a38132923b6f3150802a7d3:/src/reduce.c?ds=sidebyside diff --git a/src/reduce.c b/src/reduce.c index 2d01255c..5338393c 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. + Copyright (C) 1988-1989, 2000-2003, 2005-2012 Free Software + Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. @@ -29,7 +29,6 @@ #include "system.h" #include -#include #include "complain.h" #include "files.h" @@ -358,10 +357,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 +374,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 +381,16 @@ 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 ")); - + warn (ngettext ("%d nonterminal useless in grammar", + "%d nonterminals useless in grammar", + nuseless_nonterminals), + nuseless_nonterminals); 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"); + warn (ngettext ("%d rule useless in grammar", + "%d rules useless in grammar", + nuseless_productions), + nuseless_productions); } void @@ -506,6 +437,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. |