* 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.
This commit is contained in:
Akim Demaille
2001-11-19 10:33:40 +00:00
parent 300f275f23
commit 2c5f66eda7
5 changed files with 69 additions and 70 deletions

View File

@@ -1,3 +1,15 @@
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.

View File

@@ -198,8 +198,8 @@ new_state (int symbol)
core *p;
#if TRACE
fprintf (stderr, "Entering new_state, symbol = %d, state = %d\n",
symbol, nstates);
fprintf (stderr, "Entering new_state, state = %d, symbol = %d\n",
nstates, symbol);
#endif
if (nstates >= MAXSHORT)
@@ -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];

View File

@@ -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
}

View File

@@ -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

View File

@@ -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)