X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/34cdeddfa54df8c85b20bf013a0b82053a5148f2..041308d0c03783c51ef362f888c957cd2a0e129a:/src/reduce.c?ds=sidebyside diff --git a/src/reduce.c b/src/reduce.c index 2e309a44..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" @@ -239,7 +238,7 @@ reduce_grammar_tables (void) rule_number r; for (r = 0; r < nrules; r++) rules[r].useful = bitset_test (P, r); - grammar_rules_never_reduced_report (_("useless rule")); + grammar_rules_useless_report (_("rule useless in grammar")); } /* Map the nonterminals to their new index: useful first, useless @@ -300,7 +299,7 @@ nonterminals_reduce (void) if (!bitset_test (V, i)) { nontermmap[i - ntokens] = n++; - warn_at (symbols[i]->location, _("useless nonterminal: %s"), + warn_at (symbols[i]->location, _("nonterminal useless in grammar: %s"), symbols[i]->tag); } @@ -348,7 +347,7 @@ reduce_output (FILE *out) if (nuseless_nonterminals > 0) { int i; - fprintf (out, "%s\n\n", _("Useless nonterminals")); + fprintf (out, "%s\n\n", _("Nonterminals useless in grammar")); for (i = 0; i < nuseless_nonterminals; ++i) fprintf (out, " %s\n", symbols[nsyms + i]->tag); fputs ("\n\n", out); @@ -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); } @@ -370,65 +369,8 @@ reduce_output (FILE *out) } if (nuseless_productions > 0) - grammar_rules_partial_print (out, _("Useless rules"), - rule_useless_p); -} - - -/*--------------------------------------------------------------. -| 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_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); + grammar_rules_partial_print (out, _("Rules useless in grammar"), + rule_useless_in_grammar_p); } @@ -439,29 +381,16 @@ reduce_xml (FILE *out, int level) static void reduce_print (void) { - if (yacc_flag && nuseless_productions) - fprintf (stderr, ngettext ("%d rule never reduced\n", - "%d rules never reduced\n", - nuseless_productions), - nuseless_productions); - - fprintf (stderr, "%s: %s: ", grammar_file, _("warning")); - if (nuseless_nonterminals > 0) - fprintf (stderr, ngettext ("%d useless nonterminal", - "%d useless 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 useless rule", - "%d useless rules", - nuseless_productions), - nuseless_productions); - fprintf (stderr, "\n"); + warn (ngettext ("%d rule useless in grammar", + "%d rules useless in grammar", + nuseless_productions), + nuseless_productions); } void @@ -508,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. |