-D, --define.

* src/getargs.c (usage): Document -D.
	Fix help string for --locations.
	(command_line_location): New.
	(short_options, long_options, getargs): Support -D, --define.
	(getargs): Move -d support at the right place.
	* doc/bison.texinfo (Bison Options): Update.
	* tests/input.at (%define, --define): New.
This commit is contained in:
Akim Demaille
2008-07-29 12:52:19 +02:00
parent 9fe5a4571e
commit 58697c6d89
4 changed files with 80 additions and 7 deletions

View File

@@ -1,3 +1,14 @@
2008-11-07 Akim Demaille <demaille@gostai.com>
-D, --define.
* src/getargs.c (usage): Document -D.
Fix help string for --locations.
(command_line_location): New.
(short_options, long_options, getargs): Support -D, --define.
(getargs): Move -d support at the right place.
* doc/bison.texinfo (Bison Options): Update.
* tests/input.at (%define, --define): New.
2008-11-07 Akim Demaille <demaille@gostai.com> 2008-11-07 Akim Demaille <demaille@gostai.com>
Initialize the muscle table before parsing the command line. Initialize the muscle table before parsing the command line.

View File

@@ -7833,6 +7833,11 @@ In the parser file, define the macro @code{YYDEBUG} to 1 if it is not
already defined, so that the debugging facilities are compiled. already defined, so that the debugging facilities are compiled.
@xref{Tracing, ,Tracing Your Parser}. @xref{Tracing, ,Tracing Your Parser}.
@item -D @var{name}[=@var{value}]
@itemx --define=@var{name}[=@var{value}]
Same as running @samp{%define @var{name} "@var{value}"} (@pxref{Decl
Summary, ,%define}).
@item -L @var{language} @item -L @var{language}
@itemx --language=@var{language} @itemx --language=@var{language}
Specify the programming language for the generated parser, as if Specify the programming language for the generated parser, as if

View File

@@ -277,7 +277,8 @@ Parser:\n\
(this is an experimental feature)\n\ (this is an experimental feature)\n\
-S, --skeleton=FILE specify the skeleton to use\n\ -S, --skeleton=FILE specify the skeleton to use\n\
-t, --debug instrument the parser for debugging\n\ -t, --debug instrument the parser for debugging\n\
--locations enable locations computation\n\ --locations enable location support\n\
-D, --define=NAME[=VALUE] same as `%define NAME \"VALUE\"'\n\
-p, --name-prefix=PREFIX prepend PREFIX to the external symbols\n\ -p, --name-prefix=PREFIX prepend PREFIX to the external symbols\n\
-l, --no-lines don't generate `#line' directives\n\ -l, --no-lines don't generate `#line' directives\n\
-k, --token-table include a table of token names\n\ -k, --token-table include a table of token names\n\
@@ -413,6 +414,7 @@ language_argmatch (char const *arg, int prio, location const *loc)
/* Shorts options. /* Shorts options.
Should be computed from long_options. */ Should be computed from long_options. */
static char const short_options[] = static char const short_options[] =
"D:"
"L:" "L:"
"S:" "S:"
"T::" "T::"
@@ -479,6 +481,7 @@ static struct option const long_options[] =
/* Parser. */ /* Parser. */
{ "debug", no_argument, 0, 't' }, { "debug", no_argument, 0, 't' },
{ "define", required_argument, 0, 'D' },
{ "locations", no_argument, 0, LOCATIONS_OPTION }, { "locations", no_argument, 0, LOCATIONS_OPTION },
{ "no-lines", no_argument, 0, 'l' }, { "no-lines", no_argument, 0, 'l' },
{ "raw", no_argument, 0, 0 }, { "raw", no_argument, 0, 0 },
@@ -497,6 +500,19 @@ static struct option const long_options[] =
# define AS_FILE_NAME(File) (File) # define AS_FILE_NAME(File) (File)
#endif #endif
/* Build a location for the current command line argument. */
static
location
command_line_location()
{
location res;
/* "<command line>" is used in GCC's messages about -D. */
boundary_set (&res.start, uniqstr_new ("<command line>"), optind, -1);
res.end = res.start;
return res;
}
void void
getargs (int argc, char *argv[]) getargs (int argc, char *argv[])
{ {
@@ -506,15 +522,23 @@ getargs (int argc, char *argv[])
!= -1) != -1)
switch (c) switch (c)
{ {
/* ASCII Sorting for short options (i.e., upper case then
lower case), and then long-only options. */
case 0: case 0:
/* Certain long options cause getopt_long to return 0. */ /* Certain long options cause getopt_long to return 0. */
break; break;
case 'd': case 'D': /* -DNAME[=VALUE]. */
/* Here, the -d and --defines options are differentiated. */ {
defines_flag = true; char* name = optarg;
if (optarg) char* value = strchr (optarg, '=');
spec_defines_file = xstrdup (AS_FILE_NAME (optarg)); if (value)
*value++ = 0;
else
value = "";
muscle_percent_define_insert (name, command_line_location (), value);
}
break; break;
case 'I': case 'I':
@@ -548,6 +572,13 @@ getargs (int argc, char *argv[])
spec_file_prefix = AS_FILE_NAME (optarg); spec_file_prefix = AS_FILE_NAME (optarg);
break; break;
case 'd':
/* Here, the -d and --defines options are differentiated. */
defines_flag = true;
if (optarg)
spec_defines_file = xstrdup (AS_FILE_NAME (optarg));
break;
case 'g': case 'g':
graph_flag = true; graph_flag = true;
if (optarg) if (optarg)

View File

@@ -1,5 +1,5 @@
# Checking the Bison scanner. -*- Autotest -*- # Checking the Bison scanner. -*- Autotest -*-
# Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 Free Software Foundation, # Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation,
# Inc. # Inc.
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
@@ -821,6 +821,32 @@ input.y:5.9-16: warning: %define variable `special2' is not used
AT_CLEANUP AT_CLEANUP
## ------------------- ##
## %define, --define. ##
## ------------------- ##
AT_SETUP([%define, --define])
AT_DATA([input.y],
[[%define var "value1"
%%
start: ;
]])
AT_BISON_CHECK([[input.y -DFOO -DFOO -Dvar=value]], [0], [],
[[<command line>:4: warning: %define variable `FOO' redefined
<command line>:3: warning: previous definition
input.y:1.9-11: warning: %define variable `var' redefined
<command line>:5: warning: previous definition
<command line>:3: warning: %define variable `FOO' is not used
<command line>:4: warning: %define variable `FOO' is not used
<command line>:5: warning: %define variable `var' is not used
input.y:1.9-11: warning: %define variable `var' is not used
]])
AT_CLEANUP
## --------------------------- ## ## --------------------------- ##
## %define Boolean variables. ## ## %define Boolean variables. ##
## --------------------------- ## ## --------------------------- ##