diff options
author | Akim Demaille <akim@epita.fr> | 2001-11-19 09:16:24 +0000 |
---|---|---|
committer | Akim Demaille <akim@epita.fr> | 2001-11-19 09:16:24 +0000 |
commit | 8639df64a603c7fedaf8fb3b99284dd617c3b90f (patch) | |
tree | e41b08a2fdf4dc5c39dc69464f41cb50d97fe515 | |
parent | 377bd7c9a243f4fcda8b45b2b7457f4a3090ca9d (diff) | |
download | bison-8639df64a603c7fedaf8fb3b99284dd617c3b90f.tar.gz |
* src/LR0.c (new_state, get_state): Complete TRACE code.
* src/closure.c: Include `reader.h' to get `tags', needed by the
trace code.
Rename the conditional DEBUG as TRACE.
Output consistently TRACEs to stderr, not stdout.
* src/derives.c: Likewise.
* src/reduce.c: (inaccessable_symbols): Using if is better style
than goto.
Use `#if TRACE' instead of `#if 0' for tracing code.
-rw-r--r-- | ChangeLog | 12 | ||||
-rw-r--r-- | src/LR0.c | 3 | ||||
-rw-r--r-- | src/closure.c | 29 | ||||
-rw-r--r-- | src/derives.c | 21 | ||||
-rw-r--r-- | src/reduce.c | 70 |
5 files changed, 67 insertions, 68 deletions
@@ -1,5 +1,17 @@ 2001-11-19 Akim Demaille <akim@epita.fr> + * src/LR0.c (new_state, get_state): Complete TRACE code. + * src/closure.c: Include `reader.h' to get `tags', needed by the + trace code. + Rename the conditional DEBUG as TRACE. + Output consistently TRACEs to stderr, not stdout. + * src/derives.c: Likewise. + * src/reduce.c: (inaccessable_symbols): Using if is better style + than goto. + Use `#if TRACE' instead of `#if 0' for tracing code. + +2001-11-19 Akim Demaille <akim@epita.fr> + * src/system.h (LIST_FREE, shortcpy): New. * src/LR0.c: Use them. * src/output.c (free_itemsets, free_reductions, free_shifts): @@ -242,7 +242,8 @@ get_state (int symbol) int n; #if TRACE - fprintf (stderr, "Entering get_state, symbol = %d\n", symbol); + fprintf (stderr, "Entering get_state, state = %d, symbol = %d\n", + nstates, symbol); #endif isp1 = kernel_base[symbol]; diff --git a/src/closure.c b/src/closure.c index 649d4252..94fa636e 100644 --- a/src/closure.c +++ b/src/closure.c @@ -1,5 +1,5 @@ /* Subroutines for bison - Copyright 1984, 1989, 2000 Free Software Foundation, Inc. + Copyright 1984, 1989, 2000, 2001 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. @@ -20,6 +20,7 @@ #include "system.h" #include "gram.h" +#include "reader.h" #include "closure.h" #include "derives.h" #include "warshall.h" @@ -38,7 +39,7 @@ static int rulesetsize; /* number of words required to hold a bit for each variable */ static int varsetsize; -#if DEBUG +#if TRACE /*-----------------. | Debugging code. | @@ -49,9 +50,9 @@ print_closure (int n) { short *isp; - printf ("\n\nn = %d\n\n", n); + fprintf (stderr, "\n\nn = %d\n\n", n); for (isp = itemset; isp < itemsetend; isp++) - printf (" %d\n", *isp); + fprintf (stderr, " %d\n", *isp); } @@ -62,17 +63,17 @@ print_firsts (void) int j; unsigned *rowp; - printf ("\n\n\nFIRSTS\n\n"); + fprintf (stderr, "\n\n\nFIRSTS\n\n"); for (i = ntokens; i < nsyms; i++) { - printf ("\n\n%s firsts\n\n", tags[i]); + fprintf (stderr, "\n\n%s firsts\n\n", tags[i]); rowp = firsts + ((i - ntokens) * varsetsize); for (j = 0; j < nvars; j++) if (BITISSET (rowp, j)) - printf (" %s\n", tags[j + ntokens]); + fprintf (stderr, " %s\n", tags[j + ntokens]); } } @@ -84,19 +85,17 @@ print_fderives (void) int j; unsigned *rp; - printf ("\n\n\nFDERIVES\n"); + fprintf (stderr, "\n\n\nFDERIVES\n"); for (i = ntokens; i < nsyms; i++) { - printf ("\n\n%s derives\n\n", tags[i]); + fprintf (stderr, "\n\n%s derives\n\n", tags[i]); rp = fderives + i * rulesetsize; for (j = 0; j <= nrules; j++) if (BITISSET (rp, j)) - printf (" %d\n", j); + fprintf (stderr, " %d\n", j); } - - fflush (stdout); } #endif @@ -143,7 +142,7 @@ set_firsts (void) RTC (firsts, nvars); -#ifdef DEBUG +#ifdef TRACE print_firsts (); #endif } @@ -204,7 +203,7 @@ set_fderives (void) rrow += rulesetsize; } -#ifdef DEBUG +#ifdef TRACE print_fderives (); #endif @@ -301,7 +300,7 @@ closure (short *core, int n) while (csp < csend) *itemsetend++ = *csp++; -#if DEBUG +#if TRACE print_closure (n); #endif } diff --git a/src/derives.c b/src/derives.c index a7b86b5b..ec7173d9 100644 --- a/src/derives.c +++ b/src/derives.c @@ -1,5 +1,5 @@ /* Match rules with nonterminals for bison, - Copyright 1984, 1989, 2000 Free Software Foundation, Inc. + Copyright 1984, 1989, 2000, 2001 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. @@ -26,12 +26,13 @@ #include "system.h" #include "types.h" +#include "reader.h" #include "gram.h" #include "derives.h" short **derives; -#if DEBUG +#if TRACE static void print_derives (void) @@ -39,21 +40,17 @@ print_derives (void) int i; short *sp; - fputs ("\n\n\n", stdout); - printf (_("DERIVES")); - fputs ("\n\n", stdout); + fputs ("\n\n\nDERIVES\n\n", stderr); for (i = ntokens; i < nsyms; i++) { - printf (_("%s derives"), tags[i]); + fprintf (stderr, "%s derives", tags[i]); for (sp = derives[i]; *sp > 0; sp++) - { - printf (" %d", *sp); - } - putchar ('\n'); + fprintf (stderr, " %d", *sp); + putc ('\n', stderr); } - putchar ('\n'); + putc ('\n', stderr); } #endif @@ -99,7 +96,7 @@ set_derives (void) *q++ = -1; } -#if DEBUG +#if TRACE print_derives (); #endif diff --git a/src/reduce.c b/src/reduce.c index 1e65eee0..b179f608 100644 --- a/src/reduce.c +++ b/src/reduce.c @@ -200,38 +200,33 @@ inaccessable_symbols (void) Pp = XCALLOC (unsigned, WORDSIZE (nrules + 1)); /* If the start symbol isn't useful, then nothing will be useful. */ - if (!BITISSET (N, start_symbol - ntokens)) - goto end_iteration; - - SETBIT (V, start_symbol); - - while (1) + if (BITISSET (N, start_symbol - ntokens)) { - for (i = WORDSIZE (nsyms) - 1; i >= 0; i--) - Vp[i] = V[i]; - for (i = 1; i <= nrules; i++) + SETBIT (V, start_symbol); + + while (1) { - if (!BITISSET (Pp, i) && BITISSET (P, i) && BITISSET (V, rule_table[i].lhs)) + for (i = WORDSIZE (nsyms) - 1; i >= 0; i--) + Vp[i] = V[i]; + for (i = 1; i <= nrules; i++) { - for (r = &ritem[rule_table[i].rhs]; *r >= 0; r++) + if (!BITISSET (Pp, i) + && BITISSET (P, i) + && BITISSET (V, rule_table[i].lhs)) { - if (ISTOKEN (t = *r) || BITISSET (N, t - ntokens)) - { + for (r = &ritem[rule_table[i].rhs]; *r >= 0; r++) + if (ISTOKEN (t = *r) || BITISSET (N, t - ntokens)) SETBIT (Vp, t); - } + SETBIT (Pp, i); } - SETBIT (Pp, i); } + if (bits_equal (V, Vp, WORDSIZE (nsyms))) + break; + Vs = Vp; + Vp = V; + V = Vs; } - if (bits_equal (V, Vp, WORDSIZE (nsyms))) - { - break; - } - Vs = Vp; - Vp = V; - V = Vs; } -end_iteration: XFREE (V); V = Vp; @@ -430,28 +425,27 @@ reduce_output (FILE *out) fprintf (out, _("Useless rules:")); fprintf (out, "\n\n"); for (i = 1; i <= nrules; i++) - { - if (!BITISSET (P, i)) - { - fprintf (out, "#%-4d ", i); - fprintf (out, "%s :\t", tags[rule_table[i].lhs]); - for (r = &ritem[rule_table[i].rhs]; *r >= 0; r++) - fprintf (out, " %s", tags[*r]); - fprintf (out, ";\n"); - } - } + if (!BITISSET (P, i)) + { + fprintf (out, "#%-4d ", i); + fprintf (out, "%s :\t", tags[rule_table[i].lhs]); + for (r = &ritem[rule_table[i].rhs]; *r >= 0; r++) + fprintf (out, " %s", tags[*r]); + fprintf (out, ";\n"); + } } if (nuseless_nonterminals > 0 || nuseless_productions > 0 || b) fprintf (out, "\n\n"); } -#if 0 /* XXX currently unused. */ +#if TRACE static void dump_grammar (FILE *out) { int i; rule r; + fprintf (out, "REDUCED GRAMMAR\n\n"); fprintf (out, "ntokens = %d, nvars = %d, nsyms = %d, nrules = %d, nitems = %d\n\n", ntokens, nvars, nsyms, nrules, nitems); @@ -545,12 +539,8 @@ reduce_grammar (void) tags[start_symbol]); reduce_grammar_tables (); -#if 0 - if (verbose_flag) - { - fprintf (out, "REDUCED GRAMMAR\n\n"); - dump_grammar (); - } +#if TRACE + dump_grammar (stderr); #endif if (statistics_flag) |