mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 20:33:03 +00:00
-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.
(cherry picked from commit 58697c6d89)
This commit is contained in:
committed by
Joel E. Denny
parent
75c21b618d
commit
e14c68313b
11
ChangeLog
11
ChangeLog
@@ -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>
|
||||
|
||||
Initialize the muscle table before parsing the command line.
|
||||
|
||||
@@ -7835,6 +7835,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.
|
||||
@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}
|
||||
@itemx --language=@var{language}
|
||||
Specify the programming language for the generated parser, as if
|
||||
|
||||
@@ -277,7 +277,8 @@ Parser:\n\
|
||||
(this is an experimental feature)\n\
|
||||
-S, --skeleton=FILE specify the skeleton to use\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\
|
||||
-l, --no-lines don't generate `#line' directives\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.
|
||||
Should be computed from long_options. */
|
||||
static char const short_options[] =
|
||||
"D:"
|
||||
"L:"
|
||||
"S:"
|
||||
"T::"
|
||||
@@ -479,6 +481,7 @@ static struct option const long_options[] =
|
||||
|
||||
/* Parser. */
|
||||
{ "debug", no_argument, 0, 't' },
|
||||
{ "define", required_argument, 0, 'D' },
|
||||
{ "locations", no_argument, 0, LOCATIONS_OPTION },
|
||||
{ "no-lines", no_argument, 0, 'l' },
|
||||
{ "raw", no_argument, 0, 0 },
|
||||
@@ -497,6 +500,19 @@ static struct option const long_options[] =
|
||||
# define AS_FILE_NAME(File) (File)
|
||||
#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
|
||||
getargs (int argc, char *argv[])
|
||||
{
|
||||
@@ -506,15 +522,23 @@ getargs (int argc, char *argv[])
|
||||
!= -1)
|
||||
switch (c)
|
||||
{
|
||||
/* ASCII Sorting for short options (i.e., upper case then
|
||||
lower case), and then long-only options. */
|
||||
|
||||
case 0:
|
||||
/* Certain long options cause getopt_long to return 0. */
|
||||
break;
|
||||
|
||||
case 'd':
|
||||
/* Here, the -d and --defines options are differentiated. */
|
||||
defines_flag = true;
|
||||
if (optarg)
|
||||
spec_defines_file = xstrdup (AS_FILE_NAME (optarg));
|
||||
case 'D': /* -DNAME[=VALUE]. */
|
||||
{
|
||||
char* name = optarg;
|
||||
char* value = strchr (optarg, '=');
|
||||
if (value)
|
||||
*value++ = 0;
|
||||
else
|
||||
value = "";
|
||||
muscle_percent_define_insert (name, command_line_location (), value);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'I':
|
||||
@@ -548,6 +572,13 @@ getargs (int argc, char *argv[])
|
||||
spec_file_prefix = AS_FILE_NAME (optarg);
|
||||
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':
|
||||
graph_flag = true;
|
||||
if (optarg)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# 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.
|
||||
|
||||
# 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
|
||||
|
||||
|
||||
## ------------------- ##
|
||||
## %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. ##
|
||||
## --------------------------- ##
|
||||
|
||||
Reference in New Issue
Block a user