* doc/bison.texinfo (Debugging): Split into...

(Tracing): this new section, its former contents, and...
(Understanding): this new section.
* src/getargs.h, src/getargs.c (verbose_flag): Remove, replaced
by...
(report_flag): this.
Adjust all dependencies.
(report_args, report_types, report_argmatch): New.
(usage, getargs): Report/support -r, --report.
* src/options.h
(struct option_table_struct): Rename as..,
(struct option_table_s): this.
Rename the `set_flag' member to `flag' to match with getopt_long's
struct.
* src/options.c (option_table): Split verbose into an entry for
%verbose, and another for --verbose.
Support --report/-r, so remove -r from the obsolete --raw.
* src/print.c: Attach full item sets and lookaheads reports to
report_flag instead of trace_flag.
* lib/argmatch.h, lib/argmatch.c: New, from Fileutils 4.1.
This commit is contained in:
Akim Demaille
2002-05-25 16:12:40 +00:00
parent 78df825093
commit ec3bc3961d
25 changed files with 735 additions and 304 deletions

View File

@@ -43,7 +43,7 @@ static bitset lookaheadset;
static inline void
log_resolution (state_t *state, int LAno, int token, const char *resolution)
{
if (verbose_flag)
if (report_flag & report_states)
obstack_fgrow4 (&output_obstack,
_("\
Conflict in state %d between rule %d and token %s resolved as %s.\n"),

View File

@@ -19,22 +19,21 @@
Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA. */
#include <stdio.h>
#include "getopt.h"
#include "system.h"
#include "files.h"
#include "getopt.h"
#include "argmatch.h"
#include "complain.h"
#include "getargs.h"
#include "xalloc.h"
#include "options.h"
#include "files.h"
int debug_flag = 0;
int defines_flag = 0;
int locations_flag = 0;
int no_lines_flag = 0;
int no_parser_flag = 0;
int report_flag = 0;
int token_table_flag = 0;
int verbose_flag = 0;
int yacc_flag = 0; /* for -y */
int graph_flag = 0;
int trace_flag = 0;
@@ -44,6 +43,48 @@ const char *include = NULL;
extern char *program_name;
/*----------------------.
| --report's handling. |
`----------------------*/
static const char * const report_args[] =
{
/* In a series of synonyms, present the most meaningful first, so
that argmatch_valid be more readable. */
"none",
"state", "states",
"itemset", "itemsets",
"lookahead", "lookaheads",
"all",
0
};
static const int report_types[] =
{
report_none,
report_states, report_states,
report_states | report_itemsets, report_states | report_itemsets,
report_states | report_lookaheads, report_states | report_lookaheads,
report_all
};
static void
report_argmatch (char *args)
{
ARGMATCH_ASSERT (report_args, report_types);
do
{
int report = XARGMATCH ("--report", args,
report_args, report_types);
if (report == report_none)
report_flag = report_none;
else
report_flag |= report;
}
while ((args = strtok (NULL, ",")));
}
/*---------------------------.
| Display the help message. |
`---------------------------*/
@@ -89,10 +130,18 @@ Parser:\n\
fputs (_("\
Output:\n\
-d, --defines also produce a header file\n\
-v, --verbose also produce an explanation of the automaton\n\
-r, --report=THINGS also produce details on the automaton\n\
-v, --verbose same as `--report=state'\n\
-b, --file-prefix=PREFIX specify a PREFIX for output files\n\
-o, --output=FILE leave output to FILE\n\
-g, --graph also produce a VCG description of the automaton\n\
\n\
THINGS is a list of comma separated words that can include:\n\
`state' describe the states\n\
`itemset' complete the core item sets with their closure\n\
`lookahead' explicitly associate lookaheads to items\n\
`all' include all the above information\n\
`none' disable the report\n\
"), stream);
putc ('\n', stream);
@@ -170,7 +219,7 @@ getargs (int argc, char *argv[])
break;
case 'v':
verbose_flag = 1;
report_flag |= report_states;
break;
case 'S':
@@ -196,10 +245,6 @@ getargs (int argc, char *argv[])
token_table_flag = 1;
break;
case 'r':
fatal (_("`%s' is no longer supported"), "--raw");
break;
case 'n':
no_parser_flag = 1;
break;
@@ -220,6 +265,10 @@ getargs (int argc, char *argv[])
spec_name_prefix = optarg;
break;
case 'r':
report_argmatch (optarg);
break;
default:
fprintf (stderr, _("Try `%s --help' for more information.\n"),
program_name);

View File

@@ -1,5 +1,6 @@
/* Parse command line arguments for bison.
Copyright 1984, 1986, 1989, 1992, 2000, 2001 Free Software Foundation, Inc.
Copyright 1984, 1986, 1989, 1992, 2000, 2001, 2002
Free Software Foundation, Inc.
This file is part of Bison, the GNU Compiler Compiler.
@@ -31,11 +32,22 @@ extern int locations_flag;
extern int no_lines_flag; /* for -l */
extern int no_parser_flag; /* for -n */
extern int token_table_flag; /* for -k */
extern int verbose_flag; /* for -v */
extern int graph_flag; /* for -g */
extern int yacc_flag; /* for -y */
extern int trace_flag;
/* --report. */
enum
{
report_none = 0,
report_states = 1 << 0,
report_itemsets = 1 << 1,
report_lookaheads = 1 << 2,
report_all = ~0
};
extern int report_flag;
void getargs PARAMS ((int argc, char *argv[]));
#endif /* !GETARGS_H_ */

View File

@@ -484,7 +484,7 @@ option_strcmp (const char *left, const char *right)
token_t
parse_percent_token (void)
{
const struct option_table_struct *tx = NULL;
const struct option_table_s *tx = NULL;
const char *arg = NULL;
/* Where the ARG was found in token_buffer. */
size_t arg_offset = 0;
@@ -578,15 +578,16 @@ parse_percent_token (void)
switch (tx->ret_val)
{
case tok_stropt:
assert (tx->set_flag);
assert (tx->flag);
if (arg)
{
char **flag = (char **) tx->flag;
/* Keep only the first assignment: command line options have
already been processed, and we want them to have
precedence. Side effect: if this %-option is used
several times, only the first is honored. Bah. */
if (!*((char **) (tx->set_flag)))
*((char **) (tx->set_flag)) = xstrdup (arg);
if (!*flag)
*flag = xstrdup (arg);
}
else
fatal (_("`%s' requires an argument"), token_buffer);
@@ -594,8 +595,8 @@ parse_percent_token (void)
break;
case tok_intopt:
assert (tx->set_flag);
*((int *) (tx->set_flag)) = 1;
assert (tx->flag);
*((int *) (tx->flag)) = 1;
return tok_noop;
break;

View File

@@ -50,7 +50,10 @@ typedef enum token_e
tok_define,
tok_skel,
tok_noop,
/* A directive that sets to true its associated variable. */
tok_intopt,
/* A directive that sets its associated variable to the string
argument. */
tok_stropt,
tok_illegal,
tok_obsolete

View File

@@ -91,7 +91,7 @@ main (int argc, char *argv[])
compute_output_file_names ();
/* Output the detailed report on the grammar. */
if (verbose_flag)
if (report_flag)
print_results ();
/* Stop if there were errors, to avoid trashing previous output

View File

@@ -29,7 +29,7 @@
#include "options.h"
/* Shorts options. */
const char *shortopts = "yvegdhrltknVo:b:p:S:";
const char *shortopts = "yvegdhr:ltknVo:b:p:S:";
/* A CLI option only.
Arguments is the policy: `no', `optional', `required'.
@@ -52,7 +52,7 @@ const char *shortopts = "yvegdhrltknVo:b:p:S:";
(String), (Arguments##_argument), (Var), (Token), (OptionChar) },
const struct option_table_struct option_table[] =
const struct option_table_s option_table[] =
{
/*
* Command line.
@@ -71,6 +71,8 @@ const struct option_table_struct option_table[] =
OPTN ("output", required, 0, 0, 'o')
OPTN ("output-file", required, 0, 0, 'o')
OPTN ("graph", optional, 0, 0, 'g')
OPTN ("report", required, 0, 0, 'r')
OPTN ("verbose", no, 0, 0, 'v')
/* Hidden. */
OPTN ("trace", no, &trace_flag, 0, 1)
@@ -92,6 +94,7 @@ const struct option_table_struct option_table[] =
DRTV ("nonassoc", no, NULL, tok_nonassoc)
DRTV ("binary", no, NULL, tok_nonassoc)
DRTV ("prec", no, NULL, tok_prec)
DRTV ("verbose", no, &report_flag, tok_intopt)
DRTV ("error-verbose",no, &error_verbose, tok_intopt)
/* FIXME: semantic parsers will output an `include' of an
@@ -111,7 +114,6 @@ const struct option_table_struct option_table[] =
/* Output. */
BOTH ("defines", optional, &defines_flag, tok_intopt, 'd')
BOTH ("verbose", no, &verbose_flag, tok_intopt, 'v')
/* Operation modes. */
BOTH ("fixed-output-files", no, &yacc_flag, tok_intopt, 'y')
@@ -122,7 +124,7 @@ const struct option_table_struct option_table[] =
BOTH ("locations", no, &locations_flag, tok_intopt, 1)
BOTH ("no-lines", no, &no_lines_flag, tok_intopt, 'l')
BOTH ("no-parser", no, &no_parser_flag, tok_intopt, 'n')
BOTH ("raw", no, 0, tok_obsolete, 'r')
BOTH ("raw", no, 0, tok_obsolete, 0)
BOTH ("skeleton", required, 0, tok_skel, 'S')
BOTH ("token-table", no, &token_table_flag, tok_intopt, 'k')
@@ -153,17 +155,16 @@ long_option_table_new ()
if (option_table[i].access == opt_cmd_line
|| option_table[i].access == opt_both)
{
/* Copy the struct information in the longoptions. */
res[j].name = option_table[i].name;
res[j].has_arg = option_table[i].has_arg;
/* When an options is declared having 'optional_argument' and
a flag is specified to be set, the option is skipped on
command line. So we never use a flag when a command line
option is declared 'optional_argument. */
/* When a getopt_long option has an associated variable
(member FLAG), then it is set of the VAL member value. In
other words, we cannot expect getopt_long to store the
argument if we also want a short option. */
if (res[j].has_arg == optional_argument)
res[j].flag = NULL;
else
res[j].flag = option_table[i].set_flag;
res[j].flag = option_table[i].flag;
res[j++].val = option_table[i].val;
}
res[number_options].name = NULL;

View File

@@ -1,5 +1,5 @@
/* Concentrate all options use in bison,
Copyright 2001 Free Software Foundation, Inc.
Copyright 2001, 2002 Free Software Foundation, Inc.
This file is part of Bison, the GNU Compiler Compiler.
@@ -34,7 +34,7 @@ typedef enum opt_access_e
/* This is the general struct, which contains user's options from
command line or in grammar with percent flag. */
struct option_table_struct
struct option_table_s
{
/* Set the accessibility. */
opt_access_t access;
@@ -42,8 +42,8 @@ struct option_table_struct
const char *name;
/* Use for command line. */
int has_arg;
/* A set_flag value causes the named flag to be set. */
void *set_flag;
/* An optional lvalue to be set. */
void *flag;
/* A retval action returns the code. */
int ret_val;
/* The short option value, frequently a letter. */
@@ -53,9 +53,9 @@ struct option_table_struct
extern const char *shortopts;
/* Table which contain all options. */
extern const struct option_table_struct option_table[];
extern const struct option_table_s option_table[];
/* Set the longopts variable from option_table. */
/* Return a malloc'd list of the options for getopt_long. */
struct option *long_option_table_new PARAMS ((void));
#endif /* !OPTIONS_H_ */

View File

@@ -72,9 +72,8 @@ print_core (FILE *out, state_t *state)
item_number_t *sitems = state->items;
int snritems = state->nitems;
/* New experimental feature: if TRACE_FLAGS output all the items of
a state, not only its kernel. */
if (trace_flag)
/* Output all the items of a state, not only its kernel. */
if (report_flag & report_itemsets)
{
closure (sitems, snritems);
sitems = itemset;
@@ -105,8 +104,8 @@ print_core (FILE *out, state_t *state)
for (/* Nothing */; *sp >= 0; ++sp)
fprintf (out, " %s", escape (symbols[*sp]->tag));
/* Experimental feature: display the lookaheads. */
if (trace_flag && state->nlookaheads)
/* Display the lookaheads? */
if (report_flag & report_lookaheads)
{
int j, k;
int nlookaheads = 0;
@@ -513,10 +512,9 @@ print_results (void)
print_grammar (out);
/* New experimental feature: output all the items of a state, not
only its kernel. Requires to run closure, which need memory
allocation/deallocation. */
if (trace_flag)
/* If the whole state item sets, not only the kernels, are wanted,
`closure' will be run, which needs memory allocation/deallocation. */
if (report_flag & report_itemsets)
new_closure (nritems);
/* Storage for print_reductions. */
shiftset = bitset_create (ntokens, BITSET_FIXED);
@@ -525,7 +523,7 @@ print_results (void)
print_state (out, states[i]);
bitset_free (shiftset);
bitset_free (lookaheadset);
if (trace_flag)
if (report_flag & report_itemsets)
free_closure ();
xfclose (out);