[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
01-argmatch-trace.patch
From: |
Akim Demaille |
Subject: |
01-argmatch-trace.patch |
Date: |
Thu, 01 Aug 2002 11:00:25 +0200 |
Index: ChangeLog
from Akim Demaille <address@hidden>
Let --trace have arguments.
* src/getargs.h (enum trace_e): New.
* src/getargs.c (trace_args, trace_types, trace_argmatch): New.
(long_options, short_options): --trace/-T takes an optional
argument.
Change all the uses of trace_flag to reflect the new flags.
* tests/sets.at (Firsts, Nullable, Broken Closure): Use --trace=sets.
Strengthen `stage' portability.
* m4/stage.m4 (BISON_PREREQ_STAGE): New.
* configure.in: Use it.
Don't check for malloc.h and sys/times.h.
* src/system.h: Include them when appropriate.
* src/main.c (stage): Compile only when mallinfo, struct mallinfo,
times and struct tms are available.
Index: configure.in
--- configure.in Tue, 30 Jul 2002 09:41:14 +0200 akim
+++ configure.in Wed, 31 Jul 2002 19:49:18 +0200 akim
@@ -78,9 +78,7 @@
# Checks for header files.
AC_HEADER_STDC
-AC_CHECK_HEADERS([ctype.h locale.h malloc.h memory.h stdlib.h string.h \
- sys/times.h unistd.h])
-
+AC_CHECK_HEADERS([ctype.h locale.h memory.h stdlib.h string.h unistd.h])
# Checks for compiler characteristics.
AC_C_CONST
@@ -102,6 +100,7 @@
jm_PREREQ_QUOTEARG
jm_PREREQ_ERROR
AM_WITH_DMALLOC
+BISON_PREREQ_STAGE
# Gettext.
GETTEXT_VERSION=0.11.2
Index: m4/Makefile.am
--- m4/Makefile.am Sat, 16 Mar 2002 13:01:57 +0100 akim
+++ m4/Makefile.am Wed, 31 Jul 2002 20:13:10 +0200 akim
@@ -17,5 +17,6 @@
prereq.m4 \
progtest.m4 \
realloc.m4 \
+stage.m4 \
strerror_r.m4 \
warning.m4
Index: m4/warning.m4
--- m4/warning.m4 Sat, 30 Sep 2000 10:32:09 +0200 akim
+++ m4/warning.m4 Wed, 31 Jul 2002 19:46:56 +0200 akim
@@ -1,4 +1,25 @@
-AC_DEFUN(BISON_WARNING,
+# Finding valid warning flags for the C Compiler. -*-Autoconf-*-
+#
+# Copyright (C) 2001, 2002 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+# 02111-1307 USA
+
+# serial 1
+
+AC_DEFUN([BISON_WARNING],
[AC_MSG_CHECKING(whether compiler accepts $1)
AC_SUBST(WARNING_CFLAGS)
ac_save_CFLAGS="$CFLAGS"
Index: src/LR0.c
--- src/LR0.c Tue, 30 Jul 2002 12:36:46 +0200 akim
+++ src/LR0.c Wed, 31 Jul 2002 19:29:53 +0200 akim
@@ -59,7 +59,7 @@
state_list_t *node = XMALLOC (state_list_t, 1);
state_t *state = state_new (symbol, core_size, core);
- if (trace_flag)
+ if (trace_flag & trace_automaton)
fprintf (stderr, "state_list_append (state = %d, symbol = %d (%s))\n",
nstates, symbol, symbols[symbol]->tag);
@@ -177,7 +177,7 @@
{
int i;
- if (trace_flag)
+ if (trace_flag & trace_automaton)
fprintf (stderr, "Entering new_itemsets, state = %d\n",
state->number);
@@ -215,7 +215,7 @@
{
state_t *sp;
- if (trace_flag)
+ if (trace_flag & trace_automaton)
fprintf (stderr, "Entering get_state, symbol = %d (%s)\n",
symbol, symbols[symbol]->tag);
@@ -223,7 +223,7 @@
if (!sp)
sp = state_list_append (symbol, core_size, core);
- if (trace_flag)
+ if (trace_flag & trace_automaton)
fprintf (stderr, "Exiting get_state => %d\n", sp->number);
return sp;
@@ -243,7 +243,7 @@
int j;
symbol_number_t symbol;
- if (trace_flag)
+ if (trace_flag & trace_automaton)
fprintf (stderr, "Entering append_states, state = %d\n",
state->number);
@@ -351,7 +351,7 @@
while (list)
{
state_t *state = list->state;
- if (trace_flag)
+ if (trace_flag & trace_automaton)
fprintf (stderr, "Processing state %d (reached by %s)\n",
state->number,
symbols[state->accessing_symbol]->tag);
Index: src/closure.c
--- src/closure.c Thu, 25 Jul 2002 23:18:58 +0200 akim
+++ src/closure.c Wed, 31 Jul 2002 19:29:53 +0200 akim
@@ -132,13 +132,13 @@
bitset_set (FIRSTS (i), symbol - ntokens);
}
- if (trace_flag)
+ if (trace_flag & trace_sets)
bitsetv_matrix_dump (stderr, "RTC: Firsts Input", firsts);
bitsetv_reflexive_transitive_closure (firsts);
- if (trace_flag)
+ if (trace_flag & trace_sets)
bitsetv_matrix_dump (stderr, "RTC: Firsts Output", firsts);
- if (trace_flag)
+ if (trace_flag & trace_sets)
print_firsts ();
}
@@ -168,7 +168,7 @@
for (k = 0; derives[j][k] >= 0; ++k)
bitset_set (FDERIVES (i), derives[j][k]);
- if (trace_flag)
+ if (trace_flag & trace_sets)
print_fderives ();
bitsetv_free (firsts);
@@ -199,7 +199,7 @@
bitset_iterator iter;
- if (trace_flag)
+ if (trace_flag & trace_sets)
print_closure ("input", core, n);
bitset_zero (ruleset);
@@ -230,7 +230,7 @@
c++;
}
- if (trace_flag)
+ if (trace_flag & trace_sets)
print_closure ("output", itemset, nritemset);
}
Index: src/derives.c
--- src/derives.c Thu, 25 Jul 2002 23:18:58 +0200 akim
+++ src/derives.c Wed, 31 Jul 2002 19:29:53 +0200 akim
@@ -101,7 +101,7 @@
*q++ = -1;
}
- if (trace_flag)
+ if (trace_flag & trace_sets)
print_derives ();
free (dset + ntokens);
Index: src/getargs.c
--- src/getargs.c Fri, 28 Jun 2002 21:50:19 +0200 akim
+++ src/getargs.c Wed, 31 Jul 2002 19:40:06 +0200 akim
@@ -31,17 +31,73 @@
int locations_flag = 0;
int no_lines_flag = 0;
int no_parser_flag = 0;
-int report_flag = 0;
+int report_flag = report_none;
int token_table_flag = 0;
int yacc_flag = 0; /* for -y */
int graph_flag = 0;
-int trace_flag = 0;
+int trace_flag = trace_none;
const char *skeleton = NULL;
const char *include = NULL;
extern char *program_name;
+
+/*---------------------.
+| --trace's handling. |
+`---------------------*/
+
+static const char * const trace_args[] =
+{
+ /* In a series of synonyms, present the most meaningful first, so
+ that argmatch_valid be more readable. */
+ "none - no report",
+ "automaton - contruction of the automaton",
+ "bitsets - use of bitsets",
+ "grammar - reading, reducing of the grammar",
+ "resource - time and memory (where available)",
+ "sets - grammar sets: firsts, nullable etc.",
+ "tools - m4 invocation and preserve the temporary file",
+ "all - all of the above",
+ 0
+};
+
+static const int trace_types[] =
+{
+ trace_none,
+ trace_automaton,
+ trace_bitsets,
+ trace_grammar,
+ trace_resource,
+ trace_sets,
+ trace_tools,
+ trace_all
+};
+
+
+static void
+trace_argmatch (char *args)
+{
+ ARGMATCH_ASSERT (trace_args, trace_types);
+ if (args)
+ {
+ args = strtok (args, ",");
+ do
+ {
+ int trace = XARGMATCH ("--trace", args,
+ trace_args, trace_types);
+ if (trace == trace_none)
+ trace_flag = trace_none;
+ else
+ trace_flag |= trace;
+ }
+ while ((args = strtok (NULL, ",")));
+ }
+ else
+ trace_flag = trace_all;
+}
+
+
/*----------------------.
| --report's handling. |
`----------------------*/
@@ -186,7 +242,7 @@ Output:\n\
`----------------------*/
/* Shorts options. */
-const char *short_options = "yvegdhr:ltknVo:b:p:S:";
+const char *short_options = "yvegdhr:ltknVo:b:p:S:T::";
static struct option const long_options[] =
{
@@ -207,7 +263,7 @@ Output:\n\
{ "verbose", no_argument, 0, 'v' },
/* Hidden. */
- { "trace", no_argument, &trace_flag, 1 },
+ { "trace", optional_argument, 0, 'T' },
/* FIXME: semantic parsers will output an `include' of an
output file: be sure that the naem included is indeed the name of
@@ -327,6 +383,10 @@ Output:\n\
case 'r':
report_argmatch (optarg);
+ break;
+
+ case 'T':
+ trace_argmatch (optarg);
break;
default:
Index: src/getargs.h
--- src/getargs.h Thu, 06 Jun 2002 20:45:16 +0200 akim
+++ src/getargs.h Wed, 31 Jul 2002 20:26:56 +0200 akim
@@ -34,19 +34,31 @@
extern int token_table_flag; /* for -k */
extern int graph_flag; /* for -g */
extern int yacc_flag; /* for -y */
+
+/* --trace. */
+enum trace_e
+ {
+ trace_none = 0,
+ trace_resource = 1 << 0,
+ trace_sets = 1 << 1,
+ trace_bitsets = 1 << 2,
+ trace_tools = 1 << 3,
+ trace_automaton = 1 << 4,
+ trace_grammar = 1 << 5,
+ trace_all = ~0
+ };
extern int trace_flag;
/* --report. */
-enum
+enum report_e
{
- report_none = 0,
- report_states = 1 << 0,
- report_itemsets = 1 << 1,
- report_lookaheads = 1 << 2,
+ report_none = 0,
+ report_states = 1 << 0,
+ report_itemsets = 1 << 1,
+ report_lookaheads = 1 << 2,
report_solved_conflicts = 1 << 3,
- report_all = ~0
+ report_all = ~0
};
-
extern int report_flag;
void getargs PARAMS ((int argc, char *argv[]));
Index: src/injections.c
--- src/injections.c Sat, 15 Jun 2002 20:33:14 +0200 akim
+++ src/injections.c Wed, 31 Jul 2002 19:29:53 +0200 akim
@@ -100,10 +100,10 @@
bitset_set (INJECTS (i), symbol - ntokens);
}
- if (trace_flag)
+ if (trace_flag & trace_sets)
injections_print ("syntactic direct injections");
bitsetv_transitive_closure (injects);
- if (trace_flag)
+ if (trace_flag & trace_sets)
injections_print ("syntactic injections");
}
Index: src/lalr.c
--- src/lalr.c Mon, 29 Jul 2002 19:31:35 +0200 akim
+++ src/lalr.c Wed, 31 Jul 2002 19:29:53 +0200 akim
@@ -457,6 +457,6 @@
compute_FOLLOWS ();
compute_lookaheads ();
- if (trace_flag)
+ if (trace_flag & trace_sets)
lookaheads_print (stderr);
}
Index: src/main.c
--- src/main.c Tue, 30 Jul 2002 09:41:14 +0200 akim
+++ src/main.c Wed, 31 Jul 2002 19:57:07 +0200 akim
@@ -48,16 +48,11 @@
| Tracking space and time. |
`--------------------------*/
-#if HAVE_MALLOC_H & HAVE_SYS_TIMES_H
-# include <malloc.h>
-# include <sys/times.h>
-#endif
-
static void
stage (const char *title)
{
-#if HAVE_MALLOC_H & HAVE_SYS_TIMES_H
- if (trace_flag)
+#if HAVE_MALLINFO && HAVE_STRUCT_MALLINFO & HAVE_TIMES & HAVE_STRUCT_TMS
+ if (trace_flag & trace_resource)
{
struct mallinfo minfo = mallinfo ();
struct tms tinfo;
@@ -81,7 +76,7 @@
getargs (argc, argv);
- if (trace_flag)
+ if (trace_flag & trace_bitsets)
bitset_stats_enable ();
muscle_init ();
@@ -171,7 +166,7 @@
alloca (0);
#endif
- if (trace_flag)
+ if (trace_flag & trace_bitsets)
bitset_stats_dump (stderr);
return complain_message_count ? EXIT_FAILURE : EXIT_SUCCESS;
Index: src/nullable.c
--- src/nullable.c Thu, 25 Jul 2002 23:18:58 +0200 akim
+++ src/nullable.c Wed, 31 Jul 2002 19:29:53 +0200 akim
@@ -66,9 +66,6 @@
Supposedly NRITEMS - NRULES is enough. But why take the risk? */
rule_list_t *relts = XCALLOC (rule_list_t, nritems + nvars + 1);
- if (trace_flag)
- fprintf (stderr, "Entering set_nullable\n");
-
nullable = XCALLOC (char, nvars) - ntokens;
s1 = s2 = squeue;
@@ -128,7 +125,7 @@
XFREE (rsets + ntokens);
XFREE (relts);
- if (trace_flag)
+ if (trace_flag & trace_sets)
nullable_print (stderr);
}
Index: src/output.c
--- src/output.c Tue, 30 Jul 2002 12:36:46 +0200 akim
+++ src/output.c Wed, 31 Jul 2002 19:43:41 +0200 akim
@@ -183,10 +183,10 @@
static int conflict_list_cnt;
static int conflict_list_free;
-/* TABLE_SIZE is the allocated size of both TABLE and CHECK.
- We start with the original hard-coded value: SHRT_MAX
- (yes, not USHRT_MAX). */
-static size_t table_size = SHRT_MAX;
+/* TABLE_SIZE is the allocated size of both TABLE and CHECK. We start
+ with more or less the original hard-coded value (which was
+ SHRT_MAX). */
+static size_t table_size = 32768;
static base_t *table = NULL;
static base_t *check = NULL;
/* The value used in TABLE to denote explicit parse errors
@@ -216,7 +216,7 @@
while (table_size <= desired)
table_size *= 2;
- if (trace_flag)
+ if (trace_flag & trace_resource)
fprintf (stderr, "growing table and check from: %d to %d\n",
old_size, table_size);
@@ -1381,7 +1381,7 @@
m4_invoke (tempfile);
/* If `debugging', keep this file alive. */
- if (!trace_flag)
+ if (!(trace_flag & trace_tools))
unlink (tempfile);
free (tempfile);
Index: src/reader.c
--- src/reader.c Sun, 28 Jul 2002 16:59:35 +0200 akim
+++ src/reader.c Wed, 31 Jul 2002 19:29:53 +0200 akim
@@ -456,7 +456,7 @@
assert (itemno == nritems);
- if (trace_flag)
+ if (trace_flag & trace_sets)
ritem_print (stderr);
}
Index: src/reduce.c
--- src/reduce.c Sun, 28 Jul 2002 16:59:35 +0200 akim
+++ src/reduce.c Wed, 31 Jul 2002 19:29:53 +0200 akim
@@ -451,7 +451,7 @@
if (nuseless_productions > 0)
reduce_grammar_tables ();
- if (trace_flag)
+ if (trace_flag & trace_grammar)
{
grammar_dump (stderr, "Reduced Grammar");
Index: src/relation.c
--- src/relation.c Sat, 29 Jun 2002 19:01:05 +0200 akim
+++ src/relation.c Wed, 31 Jul 2002 19:41:05 +0200 akim
@@ -132,7 +132,7 @@
int *nedges = XCALLOC (int, n);
int i, j;
- if (trace_flag)
+ if (trace_flag & trace_sets)
{
fputs ("relation_transpose: input\n", stderr);
relation_print (*R_arg, n, stderr);
@@ -171,7 +171,7 @@
XFREE ((*R_arg)[i]);
free (*R_arg);
- if (trace_flag)
+ if (trace_flag & trace_sets)
{
fputs ("relation_transpose: output\n", stderr);
relation_print (new_R, n, stderr);
Index: src/system.h
--- src/system.h Tue, 11 Jun 2002 13:08:50 +0200 akim
+++ src/system.h Wed, 31 Jul 2002 19:55:50 +0200 akim
@@ -104,6 +104,18 @@
/* From xstrndup.c. */
char *xstrndup PARAMS ((const char *s, size_t n));
+/* Finding `mallinfo' where available. */
+#if HAVE_MALLOC_H
+# include <malloc.h>
+#endif
+
+
+/* Find `times' where available. */
+#if HAVE_SYS_TIMES_H
+# include <sys/times.h>
+#endif
+
+
/*---------------------.
| Missing prototypes. |
`---------------------*/
Index: tests/sets.at
--- tests/sets.at Sun, 28 Jul 2002 16:59:35 +0200 akim
+++ tests/sets.at Wed, 31 Jul 2002 20:03:15 +0200 akim
@@ -78,7 +78,7 @@ m4_define([AT_EXTRACT_SETS],
e: 'e' | /* Nothing */;
]])
-AT_CHECK([[bison --trace input.y]], [], [], [stderr])
+AT_CHECK([[bison --trace=sets input.y]], [], [], [stderr])
AT_EXTRACT_SETS([stderr], [sets])
AT_CHECK([[cat sets]], [],
[[DERIVES
@@ -162,7 +162,7 @@ g: h;
h: 'h';
]])
-AT_CHECK([[bison --trace input.y]], [], [], [stderr])
+AT_CHECK([[bison --trace=sets input.y]], [], [], [stderr])
AT_CHECK([[sed -n 's/[ ]*$//;/^RTC: Firsts Output BEGIN/,/^RTC: Firsts Output
END/p' stderr]], [],
[[RTC: Firsts Output BEGIN
@@ -208,7 +208,7 @@ exp:
;
]])
-AT_CHECK([[bison --trace input.y]], [], [], [stderr])
+AT_CHECK([[bison --trace=sets input.y]], [], [], [stderr])
AT_EXTRACT_SETS([stderr], [sets])
AT_CHECK([[cat sets]], [],
[[DERIVES
Index: .project
--- .project Wed, 31 Jul 2002 20:27:02 +0200 akim
+++ .project Sun, 07 Apr 2002 19:29:13 +0200 akim
@@ -0,0 +1 @@
+patch_list='Bison Patches <address@hidden>'
Index: m4/stage.m4
--- m4/stage.m4 Wed, 31 Jul 2002 20:27:02 +0200 akim
+++ m4/stage.m4 Wed, 31 Jul 2002 19:57:44 +0200 akim
@@ -0,0 +1,40 @@
+# -*-Autoconf-*-
+# Checks required to run `stage', a nonportable memory/time tracker.
+#
+# Copyright (C) 2002 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+# 02111-1307 USA
+
+# serial 1
+
+AC_DEFUN([BISON_PREREQ_STAGE],
+[AC_CHECK_HEADERS([malloc.h sys/times.h])
+AC_CHECK_FUNCS([mallinfo times])
+
+AC_CHECK_TYPES([struct mallinfo], [], [],
+[$ac_includes_default
+#if HAVE_MALLOC_H
+# include <malloc.h>
+#endif
+])
+
+AC_CHECK_TYPES([struct tms], [], [],
+[$ac_includes_default
+#if HAVE_SYS_TIMES_H
+# include <sys/times.h>
+#endif
+])
+])
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- 01-argmatch-trace.patch,
Akim Demaille <=