From: Akim Demaille Date: Mon, 12 Nov 2001 09:32:51 +0000 (+0000) Subject: * src/reduce.c (print_results): Rename as... X-Git-Tag: before-m4-back-end~318 X-Git-Url: https://git.saurik.com/bison.git/commitdiff_plain/337c5bd13149798e120508d4a250aae8bc78db1c?ds=inline * src/reduce.c (print_results): Rename as... (reduce_output): This. Output to OUT, passed as argument, instead of output_obstack. (dump_grammar): Likewise. (reduce_free): New. Also free V1. (reduce_grammar): No longer call reduce_output, since... * src/print.c (print_results): do it. * src/main.c (main): Call reduce_free; --- diff --git a/ChangeLog b/ChangeLog index b6cd8f83..af61a73d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,10 +1,21 @@ +2001-11-12 Akim Demaille + + * src/reduce.c (print_results): Rename as... + (reduce_output): This. + Output to OUT, passed as argument, instead of output_obstack. + (dump_grammar): Likewise. + (reduce_free): New. + Also free V1. + (reduce_grammar): No longer call reduce_output, since... + * src/print.c (print_results): do it. + * src/main.c (main): Call reduce_free; + 2001-11-12 Akim Demaille * src/conflicts.c (print_reductions): Accept OUT as argument. Output to it, not to output_obstack. * src/print.c (print_actions): Adjust. - 2001-11-12 Akim Demaille * src/conflicts.c (count_sr_conflicts, count_rr_conflicts): Return @@ -24,7 +35,6 @@ * tests/regression.at (Invalid input): Remove, duplicate with ``Invalid input: 1''. - 2001-11-12 Akim Demaille * tests/torture.at (AT_DATA_STACK_TORTURE) diff --git a/src/main.c b/src/main.c index bc9812f2..df66d7c6 100644 --- a/src/main.c +++ b/src/main.c @@ -111,6 +111,7 @@ main (int argc, char *argv[]) /* Close the input files. */ close_files (); + reduce_free (); free_conflicts (); free_nullable (); free_derives (); diff --git a/src/print.c b/src/print.c index d9f38ca9..a5c4aeb6 100644 --- a/src/print.c +++ b/src/print.c @@ -337,6 +337,7 @@ print_results (void) size_t size = obstack_object_size (&output_obstack); fwrite (obstack_finish (&output_obstack), 1, size, out); + reduce_output (out); conflicts_output (out); print_grammar (out); diff --git a/src/reduce.c b/src/reduce.c index b2299b33..991034d1 100644 --- a/src/reduce.c +++ b/src/reduce.c @@ -1,5 +1,5 @@ /* Grammar reduction for Bison. - Copyright 1988, 1989, 2000 Free Software Foundation, Inc. + Copyright 1988, 1989, 2000, 2001 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. @@ -388,21 +388,25 @@ reduce_grammar_tables (void) } } -static void -print_results (void) + +/*-----------------------------------------------------------------. +| Ouput the detailed results of the reductions. For FILE.output. | +`-----------------------------------------------------------------*/ + +void +reduce_output (FILE *out) { int i; -/* short j; JF unused */ rule r; bool b; if (nuseless_nonterminals > 0) { - obstack_sgrow (&output_obstack, _("Useless nonterminals:")); - obstack_sgrow (&output_obstack, "\n\n"); + fprintf (out, _("Useless nonterminals:")); + fprintf (out, "\n\n"); for (i = ntokens; i < nsyms; i++) if (!BITISSET (V, i)) - obstack_fgrow1 (&output_obstack, " %s\n", tags[i]); + fprintf (out, " %s\n", tags[i]); } b = FALSE; for (i = 0; i < ntokens; i++) @@ -411,81 +415,81 @@ print_results (void) { if (!b) { - obstack_sgrow (&output_obstack, "\n\n"); - obstack_sgrow (&output_obstack, - _("Terminals which are not used:")); - obstack_sgrow (&output_obstack, "\n\n"); + fprintf (out, "\n\n"); + fprintf (out, _("Terminals which are not used:")); + fprintf (out, "\n\n"); b = TRUE; } - obstack_fgrow1 (&output_obstack, " %s\n", tags[i]); + fprintf (out, " %s\n", tags[i]); } } if (nuseless_productions > 0) { - obstack_sgrow (&output_obstack, "\n\n"); - obstack_sgrow (&output_obstack, _("Useless rules:")); - obstack_sgrow (&output_obstack, "\n\n"); + fprintf (out, "\n\n"); + fprintf (out, _("Useless rules:")); + fprintf (out, "\n\n"); for (i = 1; i <= nrules; i++) { if (!BITISSET (P, i)) { - obstack_fgrow1 (&output_obstack, "#%-4d ", i); - obstack_fgrow1 (&output_obstack, "%s :\t", tags[rlhs[i]]); + fprintf (out, "#%-4d ", i); + fprintf (out, "%s :\t", tags[rlhs[i]]); for (r = &ritem[rrhs[i]]; *r >= 0; r++) - obstack_fgrow1 (&output_obstack, " %s", tags[*r]); - obstack_sgrow (&output_obstack, ";\n"); + fprintf (out, " %s", tags[*r]); + fprintf (out, ";\n"); } } } if (nuseless_nonterminals > 0 || nuseless_productions > 0 || b) - obstack_sgrow (&output_obstack, "\n\n"); + fprintf (out, "\n\n"); } #if 0 /* XXX currently unused. */ static void -dump_grammar (void) +dump_grammar (FILE *out) { int i; rule r; - obstack_fgrow5 (&output_obstack, + fprintf (out, "ntokens = %d, nvars = %d, nsyms = %d, nrules = %d, nitems = %d\n\n", ntokens, nvars, nsyms, nrules, nitems); - obstack_sgrow (&output_obstack, - _("Variables\n---------\n\n")); - obstack_sgrow (&output_obstack, - _("Value Sprec Sassoc Tag\n")); + fprintf (out, _("Variables\n---------\n\n")); + fprintf (out, _("Value Sprec Sassoc Tag\n")); for (i = ntokens; i < nsyms; i++) - obstack_fgrow4 (&output_obstack, - "%5d %5d %5d %s\n", i, sprec[i], sassoc[i], tags[i]); - obstack_sgrow (&output_obstack, "\n\n"); - obstack_sgrow (&output_obstack, _("Rules\n-----\n\n")); + fprintf (out, "%5d %5d %5d %s\n", i, sprec[i], sassoc[i], tags[i]); + fprintf (out, "\n\n"); + fprintf (out, _("Rules\n-----\n\n")); for (i = 1; i <= nrules; i++) { - obstack_fgrow5 (&output_obstack, "%-5d(%5d%5d)%5d : (@%-5d)", - i, rprec[i], rassoc[i], rlhs[i], rrhs[i]); + fprintf (out, "%-5d(%5d%5d)%5d : (@%-5d)", + i, rprec[i], rassoc[i], rlhs[i], rrhs[i]); for (r = &ritem[rrhs[i]]; *r > 0; r++) - obstack_fgrow1 (&output_obstack, "%5d", *r); - obstack_fgrow1 (&output_obstack, " [%d]\n", -(*r)); + fprintf (out, "%5d", *r); + fprintf (out, " [%d]\n", -(*r)); } - obstack_sgrow (&output_obstack, "\n\n"); - obstack_sgrow (&output_obstack, - _("Rules interpreted\n-----------------\n\n")); + fprintf (out, "\n\n"); + fprintf (out, _("Rules interpreted\n-----------------\n\n")); for (i = 1; i <= nrules; i++) { - obstack_fgrow2 (&output_obstack, "%-5d %s :", i, tags[rlhs[i]]); + fprintf (out, "%-5d %s :", i, tags[rlhs[i]]); for (r = &ritem[rrhs[i]]; *r > 0; r++) - obstack_fgrow1 (&output_obstack, " %s", tags[*r]); - obstack_grow1 (&output_obstack, '\n'); + fprintf (out, " %s", tags[*r]); + fputc ('\n', out); } - obstack_sgrow (&output_obstack, "\n\n"); + fprintf (out, "\n\n"); } #endif + +/*-------------------------------. +| Report the results to STDERR. | +`-------------------------------*/ + static void -print_notices (void) +reduce_print (void) { if (yacc_flag && nuseless_productions) fprintf (stderr, _("%d rules never reduced\n"), nuseless_productions); @@ -527,13 +531,10 @@ reduce_grammar (void) reduced = (bool) (nuseless_nonterminals + nuseless_productions > 0); - if (verbose_flag) - print_results (); - - if (reduced == FALSE) - goto done_reducing; + if (!reduced) + return; - print_notices (); + reduce_print (); if (!BITISSET (N, start_symbol - ntokens)) fatal (_("Start symbol %s does not derive any sentence"), @@ -543,7 +544,7 @@ reduce_grammar (void) #if 0 if (verbose_flag) { - obstack_fgrow1 (&output_obstack, "REDUCED GRAMMAR\n\n"); + fprintf (out, "REDUCED GRAMMAR\n\n"); dump_grammar (); } #endif @@ -558,11 +559,18 @@ reduce_grammar (void) (nvars == 1 ? "" : "s"), nrules, (nrules == 1 ? "" : "s")); +} -done_reducing: - /* Free the global sets used to compute the reduced grammar */ +/*-----------------------------------------------------------. +| Free the global sets used to compute the reduced grammar. | +`-----------------------------------------------------------*/ + +void +reduce_free (void) +{ XFREE (N); XFREE (V); + XFREE (V1); XFREE (P); } diff --git a/src/reduce.h b/src/reduce.h index 6a3031f1..92c118e7 100644 --- a/src/reduce.h +++ b/src/reduce.h @@ -1,5 +1,5 @@ /* Grammar reduction for Bison. - Copyright 2000 Free Software Foundation, Inc. + Copyright 2000, 2001 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. @@ -22,5 +22,6 @@ # define REDUCE_H_ void reduce_grammar PARAMS ((void)); - +void reduce_output PARAMS ((FILE *out)); +void reduce_free PARAMS ((void)); #endif /* !REDUCE_H_ */