mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-22 10:43:02 +00:00
Implement --warnings/-W.
* src/getargs.c (report_argmatch, trace_argmatch): Remove, replaced by... (flags_argmatch, FLAGS_ARGMATCH): this new function and macro. Adjust callers. * src/getargs.h, src/getargs.c (warnings, warnings_flags) (warnings_args, warnings_types): New. (getargs, short_options, long_options): Accept -W/--warnings. Sort the options by alphabetical order, upper case letter right before its lower case.
This commit is contained in:
13
ChangeLog
13
ChangeLog
@@ -1,3 +1,16 @@
|
|||||||
|
2006-07-09 Akim Demaille <akim@lrde.epita.fr>
|
||||||
|
|
||||||
|
Implement --warnings/-W.
|
||||||
|
* src/getargs.c (report_argmatch, trace_argmatch): Remove,
|
||||||
|
replaced by...
|
||||||
|
(flags_argmatch, FLAGS_ARGMATCH): this new function and macro.
|
||||||
|
Adjust callers.
|
||||||
|
* src/getargs.h, src/getargs.c (warnings, warnings_flags)
|
||||||
|
(warnings_args, warnings_types): New.
|
||||||
|
(getargs, short_options, long_options): Accept -W/--warnings.
|
||||||
|
Sort the options by alphabetical order, upper case letter right
|
||||||
|
before its lower case.
|
||||||
|
|
||||||
2006-07-09 Joel E. Denny <jdenny@ces.clemson.edu>
|
2006-07-09 Joel E. Denny <jdenny@ces.clemson.edu>
|
||||||
|
|
||||||
Change %merge result type clash warnings to errors. Discussed at
|
Change %merge result type clash warnings to errors. Discussed at
|
||||||
|
|||||||
190
src/getargs.c
190
src/getargs.c
@@ -62,6 +62,7 @@ bool pure_parser = false;
|
|||||||
|
|
||||||
int report_flag = report_none;
|
int report_flag = report_none;
|
||||||
int trace_flag = trace_none;
|
int trace_flag = trace_none;
|
||||||
|
int warnings_flag = warnings_none;
|
||||||
|
|
||||||
const char *skeleton = NULL;
|
const char *skeleton = NULL;
|
||||||
const char *include = NULL;
|
const char *include = NULL;
|
||||||
@@ -69,6 +70,53 @@ const char *include = NULL;
|
|||||||
extern char *program_name;
|
extern char *program_name;
|
||||||
|
|
||||||
|
|
||||||
|
/** Decode an option's set of keys.
|
||||||
|
*
|
||||||
|
* \param option option being decoded.
|
||||||
|
* \paran keys array of valid subarguments.
|
||||||
|
* \param values array of corresponding (int) values.
|
||||||
|
* \param flag the flags to update
|
||||||
|
* \param args colon separated list of effective subarguments to decode.
|
||||||
|
* If 0, then activate all the flags.
|
||||||
|
*
|
||||||
|
* The special value 0 resets the flags to 0.
|
||||||
|
*/
|
||||||
|
static int
|
||||||
|
flags_argmatch (const char *option,
|
||||||
|
const char * const keys[], const int values[],
|
||||||
|
int *flags, char *args)
|
||||||
|
{
|
||||||
|
if (args)
|
||||||
|
{
|
||||||
|
args = strtok (args, ",");
|
||||||
|
do
|
||||||
|
{
|
||||||
|
int value = XARGMATCH (option, args, keys, values);
|
||||||
|
if (value == 0)
|
||||||
|
*flags = 0;
|
||||||
|
else
|
||||||
|
*flags |= value;
|
||||||
|
}
|
||||||
|
while ((args = strtok (NULL, ",")));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
*flags = ~0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Decode a set of sub arguments.
|
||||||
|
*
|
||||||
|
* \param FlagName the flag familly to update.
|
||||||
|
* \param args the effective sub arguments to decode.
|
||||||
|
*
|
||||||
|
* \arg FlagName_args the list of keys.
|
||||||
|
* \arg FlagName_types the list of values.
|
||||||
|
* \arg FlagName_flag the flag to update.
|
||||||
|
*/
|
||||||
|
#define FLAGS_ARGMATCH(FlagName, Args) \
|
||||||
|
flags_argmatch ("--" #FlagName, FlagName ## _args, FlagName ## _types, \
|
||||||
|
&FlagName ## _flag, Args)
|
||||||
|
|
||||||
|
|
||||||
/*----------------------.
|
/*----------------------.
|
||||||
| --report's handling. |
|
| --report's handling. |
|
||||||
`----------------------*/
|
`----------------------*/
|
||||||
@@ -100,22 +148,6 @@ static const int report_types[] =
|
|||||||
|
|
||||||
ARGMATCH_VERIFY (report_args, report_types);
|
ARGMATCH_VERIFY (report_args, report_types);
|
||||||
|
|
||||||
static void
|
|
||||||
report_argmatch (char *args)
|
|
||||||
{
|
|
||||||
args = strtok (args, ",");
|
|
||||||
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, ",")));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*---------------------.
|
/*---------------------.
|
||||||
| --trace's handling. |
|
| --trace's handling. |
|
||||||
@@ -160,26 +192,31 @@ static const int trace_types[] =
|
|||||||
|
|
||||||
ARGMATCH_VERIFY (trace_args, trace_types);
|
ARGMATCH_VERIFY (trace_args, trace_types);
|
||||||
|
|
||||||
static void
|
|
||||||
trace_argmatch (char *args)
|
/*------------------------.
|
||||||
|
| --warnings's handling. |
|
||||||
|
`------------------------*/
|
||||||
|
|
||||||
|
static const char * const warnings_args[] =
|
||||||
{
|
{
|
||||||
if (args)
|
/* In a series of synonyms, present the most meaningful first, so
|
||||||
{
|
that argmatch_valid be more readable. */
|
||||||
args = strtok (args, ",");
|
"none - no warnings",
|
||||||
do
|
"error - warnings are errors",
|
||||||
{
|
"yacc - incompatibilities with POSIX YACC",
|
||||||
int trace = XARGMATCH ("--trace", args,
|
"all - all of the above",
|
||||||
trace_args, trace_types);
|
0
|
||||||
if (trace == trace_none)
|
};
|
||||||
trace_flag = trace_none;
|
|
||||||
else
|
static const int warnings_types[] =
|
||||||
trace_flag |= trace;
|
{
|
||||||
}
|
warnings_none,
|
||||||
while ((args = strtok (NULL, ",")));
|
warnings_error,
|
||||||
}
|
warnings_yacc,
|
||||||
else
|
warnings_all
|
||||||
trace_flag = trace_all;
|
};
|
||||||
}
|
|
||||||
|
ARGMATCH_VERIFY (warnings_args, warnings_types);
|
||||||
|
|
||||||
|
|
||||||
/*-------------------------------------------.
|
/*-------------------------------------------.
|
||||||
@@ -255,7 +292,7 @@ THINGS is a list of comma separated words that can include:\n\
|
|||||||
putc ('\n', stdout);
|
putc ('\n', stdout);
|
||||||
|
|
||||||
fputs (_("\
|
fputs (_("\
|
||||||
Report bugs to <bug-bison@gnu.org>.\n"), stdout);
|
Report bugs to <" PACKAGE_BUGREPORT ">.\n"), stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
exit (status);
|
exit (status);
|
||||||
@@ -293,7 +330,7 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\
|
|||||||
`----------------------*/
|
`----------------------*/
|
||||||
|
|
||||||
/* Shorts options. */
|
/* Shorts options. */
|
||||||
static char const short_options[] = "yvegdhr:ltknVo:b:p:S:T::";
|
static char const short_options[] = "yvegdhr:ltknVo:b:p:S:T::W";
|
||||||
|
|
||||||
/* Values for long options that do not have single-letter equivalents. */
|
/* Values for long options that do not have single-letter equivalents. */
|
||||||
enum
|
enum
|
||||||
@@ -305,9 +342,10 @@ enum
|
|||||||
static struct option const long_options[] =
|
static struct option const long_options[] =
|
||||||
{
|
{
|
||||||
/* Operation modes. */
|
/* Operation modes. */
|
||||||
{ "help", no_argument, 0, 'h' },
|
{ "help", no_argument, 0, 'h' },
|
||||||
{ "version", no_argument, 0, 'V' },
|
{ "version", no_argument, 0, 'V' },
|
||||||
{ "print-localedir", no_argument, 0, PRINT_LOCALEDIR_OPTION },
|
{ "print-localedir", no_argument, 0, PRINT_LOCALEDIR_OPTION },
|
||||||
|
{ "warnings", optional_argument, 0, 'W' },
|
||||||
|
|
||||||
/* Parser. */
|
/* Parser. */
|
||||||
{ "name-prefix", required_argument, 0, 'p' },
|
{ "name-prefix", required_argument, 0, 'p' },
|
||||||
@@ -364,21 +402,10 @@ getargs (int argc, char *argv[])
|
|||||||
/* Certain long options cause getopt_long to return 0. */
|
/* Certain long options cause getopt_long to return 0. */
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'y':
|
case 'b':
|
||||||
yacc_flag = true;
|
spec_file_prefix = AS_FILE_NAME (optarg);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'h':
|
|
||||||
usage (EXIT_SUCCESS);
|
|
||||||
|
|
||||||
case 'V':
|
|
||||||
version ();
|
|
||||||
exit (EXIT_SUCCESS);
|
|
||||||
|
|
||||||
case PRINT_LOCALEDIR_OPTION:
|
|
||||||
printf ("%s\n", LOCALEDIR);
|
|
||||||
exit (EXIT_SUCCESS);
|
|
||||||
|
|
||||||
case 'g':
|
case 'g':
|
||||||
/* Here, the -g and --graph=FILE options are differentiated. */
|
/* Here, the -g and --graph=FILE options are differentiated. */
|
||||||
graph_flag = true;
|
graph_flag = true;
|
||||||
@@ -386,9 +413,8 @@ getargs (int argc, char *argv[])
|
|||||||
spec_graph_file = AS_FILE_NAME (optarg);
|
spec_graph_file = AS_FILE_NAME (optarg);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'v':
|
case 'h':
|
||||||
report_flag |= report_states;
|
usage (EXIT_SUCCESS);
|
||||||
break;
|
|
||||||
|
|
||||||
case 'S':
|
case 'S':
|
||||||
skeleton = AS_FILE_NAME (optarg);
|
skeleton = AS_FILE_NAME (optarg);
|
||||||
@@ -405,46 +431,62 @@ getargs (int argc, char *argv[])
|
|||||||
spec_defines_file = AS_FILE_NAME (optarg);
|
spec_defines_file = AS_FILE_NAME (optarg);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'l':
|
|
||||||
no_lines_flag = true;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case LOCATIONS_OPTION:
|
|
||||||
locations_flag = true;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'k':
|
case 'k':
|
||||||
token_table_flag = true;
|
token_table_flag = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'l':
|
||||||
|
no_lines_flag = true;
|
||||||
|
break;
|
||||||
|
|
||||||
case 'n':
|
case 'n':
|
||||||
no_parser_flag = true;
|
no_parser_flag = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 't':
|
|
||||||
debug_flag = true;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'o':
|
case 'o':
|
||||||
spec_outfile = AS_FILE_NAME (optarg);
|
spec_outfile = AS_FILE_NAME (optarg);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'b':
|
|
||||||
spec_file_prefix = AS_FILE_NAME (optarg);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'p':
|
case 'p':
|
||||||
spec_name_prefix = optarg;
|
spec_name_prefix = optarg;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'r':
|
case 'r':
|
||||||
report_argmatch (optarg);
|
FLAGS_ARGMATCH (report, optarg);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'T':
|
case 'T':
|
||||||
trace_argmatch (optarg);
|
FLAGS_ARGMATCH (trace, optarg);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 't':
|
||||||
|
debug_flag = true;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'V':
|
||||||
|
version ();
|
||||||
|
exit (EXIT_SUCCESS);
|
||||||
|
|
||||||
|
case 'v':
|
||||||
|
report_flag |= report_states;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'y':
|
||||||
|
yacc_flag = true;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'W':
|
||||||
|
FLAGS_ARGMATCH (warnings, optarg);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case LOCATIONS_OPTION:
|
||||||
|
locations_flag = true;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PRINT_LOCALEDIR_OPTION:
|
||||||
|
printf ("%s\n", LOCALEDIR);
|
||||||
|
exit (EXIT_SUCCESS);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
usage (EXIT_FAILURE);
|
usage (EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,7 +59,11 @@ extern bool pure_parser;
|
|||||||
|
|
||||||
extern bool nondeterministic_parser;
|
extern bool nondeterministic_parser;
|
||||||
|
|
||||||
/* --report. */
|
|
||||||
|
/*-----------.
|
||||||
|
| --report. |
|
||||||
|
`-----------*/
|
||||||
|
|
||||||
enum report
|
enum report
|
||||||
{
|
{
|
||||||
report_none = 0,
|
report_none = 0,
|
||||||
@@ -72,7 +76,9 @@ enum report
|
|||||||
/** What appears in the *.output file. */
|
/** What appears in the *.output file. */
|
||||||
extern int report_flag;
|
extern int report_flag;
|
||||||
|
|
||||||
/* --trace. */
|
/*----------.
|
||||||
|
| --trace. |
|
||||||
|
`----------*/
|
||||||
enum trace
|
enum trace
|
||||||
{
|
{
|
||||||
trace_none = 0, /**< No traces. */
|
trace_none = 0, /**< No traces. */
|
||||||
@@ -92,6 +98,26 @@ enum trace
|
|||||||
/** What debug items bison displays during its run. */
|
/** What debug items bison displays during its run. */
|
||||||
extern int trace_flag;
|
extern int trace_flag;
|
||||||
|
|
||||||
|
/*-------------.
|
||||||
|
| --warnings. |
|
||||||
|
`-------------*/
|
||||||
|
|
||||||
|
enum warnings
|
||||||
|
{
|
||||||
|
warnings_none = 0, /**< Issue no warnings. */
|
||||||
|
warnings_error = 1 << 0, /**< Warnings are treated as errors. */
|
||||||
|
warnings_yacc = 1 << 1, /**< POSIXME. */
|
||||||
|
warnings_all = ~0 /**< All of the above. */
|
||||||
|
};
|
||||||
|
/** What warnings are issued. */
|
||||||
|
extern int warnings_flag;
|
||||||
|
|
||||||
|
|
||||||
|
/** Process the command line arguments.
|
||||||
|
*
|
||||||
|
* \param argc size of \a argv
|
||||||
|
* \param argv list of arguments.
|
||||||
|
*/
|
||||||
void getargs (int argc, char *argv[]);
|
void getargs (int argc, char *argv[]);
|
||||||
|
|
||||||
#endif /* !GETARGS_H_ */
|
#endif /* !GETARGS_H_ */
|
||||||
|
|||||||
Reference in New Issue
Block a user