options: rename --defines as --header

The name "defines" is incorrect, the generated file contains far more
than just #defines.

* src/getargs.h, src/getargs.c (-H, --header): New option.
With optional argument, just like --defines, --xml, etc.
(defines_flag): Rename as...
(header_flag): this.
Adjust dependencies.
* data/skeletons/bison.m4, data/skeletons/c.m4, data/skeletons/glr.c,
* data/skeletons/glr.cc, data/skeletons/glr2.cc, data/skeletons/lalr1.cc,
* data/skeletons/yacc.c:
Adjust.
* examples, doc/bison.texi: Adjust.
* tests/headers.at, tests/local.at, tests/output.at: Convert most
tests from using --defines to using --header.
This commit is contained in:
Akim Demaille
2020-09-06 13:30:23 +02:00
parent b329f0b5df
commit 75c3746ce2
27 changed files with 78 additions and 63 deletions

7
NEWS
View File

@@ -4,6 +4,13 @@ GNU Bison NEWS
** Changes ** Changes
** New features
*** Option -H, --header
The option -H/--header replaces the option --defines (maintained for
backward compatibility).
*** A C++ native GLR parser *** A C++ native GLR parser
A new version of the generated C++ GLR parser was added as "glr2.cc". It A new version of the generated C++ GLR parser was added as "glr2.cc". It

View File

@@ -391,9 +391,9 @@ m4_define([b4_$3_if],
# b4_FLAG_if(IF-TRUE, IF-FALSE) # b4_FLAG_if(IF-TRUE, IF-FALSE)
# ----------------------------- # -----------------------------
# Expand IF-TRUE, if FLAG is true, IF-FALSE otherwise. # Expand IF-TRUE, if FLAG is true, IF-FALSE otherwise.
b4_define_flag_if([defines]) # Whether headers are requested.
b4_define_flag_if([glr]) # Whether a GLR parser is requested. b4_define_flag_if([glr]) # Whether a GLR parser is requested.
b4_define_flag_if([has_translations]) # Whether some tokens are internationalized. b4_define_flag_if([has_translations]) # Whether some tokens are internationalized.
b4_define_flag_if([header]) # Whether a header is requested.
b4_define_flag_if([nondeterministic]) # Whether conflicts should be handled. b4_define_flag_if([nondeterministic]) # Whether conflicts should be handled.
b4_define_flag_if([token_table]) # Whether yytoken_table is demanded. b4_define_flag_if([token_table]) # Whether yytoken_table is demanded.
b4_define_flag_if([yacc]) # Whether POSIX Yacc is emulated. b4_define_flag_if([yacc]) # Whether POSIX Yacc is emulated.

View File

@@ -953,7 +953,7 @@ struct ]b4_api_PREFIX[LTYPE
# b4_declare_yylstype # b4_declare_yylstype
# ------------------- # -------------------
# Declarations that might either go into the header (if --defines) or # Declarations that might either go into the header (if --header) or
# in the parser body. Declare YYSTYPE/YYLTYPE, and yylval/yylloc. # in the parser body. Declare YYSTYPE/YYLTYPE, and yylval/yylloc.
m4_define([b4_declare_yylstype], m4_define([b4_declare_yylstype],
[b4_value_type_define[]b4_locations_if([ [b4_value_type_define[]b4_locations_if([

View File

@@ -151,7 +151,7 @@ m4_define([b4_rhs_location],
# b4_shared_declarations # b4_shared_declarations
# ---------------------- # ----------------------
# Declaration that might either go into the header (if --defines) # Declaration that might either go into the header (if --header)
# or open coded in the parser body. glr.cc has its own definition. # or open coded in the parser body. glr.cc has its own definition.
m4_if(b4_skeleton, ["glr.c"], m4_if(b4_skeleton, ["glr.c"],
[m4_define([b4_shared_declarations], [m4_define([b4_shared_declarations],
@@ -185,7 +185,7 @@ int ]b4_prefix[parse (]m4_ifset([b4_parse_param], [b4_formals(b4_parse_param)],
# glr.cc produces its own header. # glr.cc produces its own header.
b4_glr_cc_if([], b4_glr_cc_if([],
[b4_defines_if( [b4_header_if(
[b4_output_begin([b4_spec_header_file]) [b4_output_begin([b4_spec_header_file])
b4_copyright([Skeleton interface for Bison GLR parsers in C], b4_copyright([Skeleton interface for Bison GLR parsers in C],
[2002-2015, 2018-2020])[ [2002-2015, 2018-2020])[
@@ -228,7 +228,7 @@ b4_copyright([Skeleton implementation for Bison GLR parsers in C],
]b4_cast_define[ ]b4_cast_define[
]b4_null_define[ ]b4_null_define[
]b4_defines_if([[#include "@basename(]b4_spec_header_file[@)"]], ]b4_header_if([[#include "@basename(]b4_spec_header_file[@)"]],
[b4_shared_declarations])[ [b4_shared_declarations])[
]b4_glr_cc_if([b4_glr_cc_setup], ]b4_glr_cc_if([b4_glr_cc_setup],

View File

@@ -281,7 +281,7 @@ b4_symbol_foreach([b4_undef_symbol_kind])dnl
# b4_shared_declarations(hh|cc) # b4_shared_declarations(hh|cc)
# ----------------------------- # -----------------------------
# Declaration that might either go into the header (if --defines, $1 = hh) # Declaration that might either go into the header (if --header, $1 = hh)
# or in the implementation file. # or in the implementation file.
m4_define([b4_shared_declarations], m4_define([b4_shared_declarations],
[m4_pushdef([b4_parse_param], m4_defn([b4_parse_param_orig]))dnl [m4_pushdef([b4_parse_param], m4_defn([b4_parse_param_orig]))dnl
@@ -378,7 +378,7 @@ b4_percent_code_get([[requires]])[
]m4_popdef([b4_parse_param])dnl ]m4_popdef([b4_parse_param])dnl
])[ ])[
]b4_defines_if( ]b4_header_if(
[b4_output_begin([b4_spec_header_file]) [b4_output_begin([b4_spec_header_file])
b4_copyright([Skeleton interface for Bison GLR parsers in C++], b4_copyright([Skeleton interface for Bison GLR parsers in C++],
[2002-2015, 2018-2020])[ [2002-2015, 2018-2020])[

View File

@@ -101,7 +101,7 @@ m4_define([b4_glr_cc_cleanup],
# b4_shared_declarations(hh|cc) # b4_shared_declarations(hh|cc)
# ----------------------------- # -----------------------------
# Declaration that might either go into the header (if --defines, $1 = hh) # Declaration that might either go into the header (if --header, $1 = hh)
# or in the implementation file. # or in the implementation file.
m4_define([b4_shared_declarations], m4_define([b4_shared_declarations],
[m4_pushdef([b4_parse_param], m4_defn([b4_parse_param_orig]))dnl [m4_pushdef([b4_parse_param], m4_defn([b4_parse_param_orig]))dnl
@@ -317,7 +317,7 @@ const std::ptrdiff_t strong_index_alias<T>::INVALID_INDEX =
]m4_popdef([b4_parse_param])dnl ]m4_popdef([b4_parse_param])dnl
])[ ])[
]b4_defines_if( ]b4_header_if(
[b4_output_begin([b4_spec_header_file]) [b4_output_begin([b4_spec_header_file])
b4_copyright([Skeleton interface for Bison GLR parsers in C++], b4_copyright([Skeleton interface for Bison GLR parsers in C++],
[2002-2015, 2018-2020])[ [2002-2015, 2018-2020])[
@@ -491,7 +491,7 @@ b4_copyright([Skeleton implementation for Bison GLR parsers in C],
]b4_null_define[ ]b4_null_define[
]b4_defines_if([[#include "@basename(]b4_spec_header_file[@)"]], ]b4_header_if([[#include "@basename(]b4_spec_header_file[@)"]],
[b4_shared_declarations])[ [b4_shared_declarations])[
]b4_glr_cc_setup[ ]b4_glr_cc_setup[

View File

@@ -174,7 +174,7 @@ b4_variant_if([m4_include(b4_skeletonsdir/[variant.hh])])
# b4_shared_declarations(hh|cc) # b4_shared_declarations(hh|cc)
# ----------------------------- # -----------------------------
# Declaration that might either go into the header (if --defines, $1 = hh) # Declaration that might either go into the header (if --header, $1 = hh)
# or in the implementation file. # or in the implementation file.
m4_define([b4_shared_declarations], m4_define([b4_shared_declarations],
[b4_percent_code_get([[requires]])[ [b4_percent_code_get([[requires]])[
@@ -500,7 +500,7 @@ m4_define([b4_shared_declarations],
## Output files. ## ## Output files. ##
## -------------- ## ## -------------- ##
b4_defines_if( b4_header_if(
[b4_output_begin([b4_spec_header_file]) [b4_output_begin([b4_spec_header_file])
b4_copyright([Skeleton interface for Bison LALR(1) parsers in C++]) b4_copyright([Skeleton interface for Bison LALR(1) parsers in C++])
[ [
@@ -530,7 +530,7 @@ m4_if(b4_prefix, [yy], [],
]b4_user_pre_prologue[ ]b4_user_pre_prologue[
]b4_defines_if([[#include "@basename(]b4_spec_header_file[@)"]], ]b4_header_if([[#include "@basename(]b4_spec_header_file[@)"]],
[b4_shared_declarations([cc])])[ [b4_shared_declarations([cc])])[
]b4_user_post_prologue[ ]b4_user_post_prologue[

View File

@@ -17,7 +17,7 @@
m4_include(b4_skeletonsdir/[java.m4]) m4_include(b4_skeletonsdir/[java.m4])
b4_defines_if([b4_complain([%defines does not make sense in Java])]) b4_header_if([b4_complain([%defines does not make sense in Java])])
m4_define([b4_symbol_no_destructor_assert], m4_define([b4_symbol_no_destructor_assert],
[b4_symbol_if([$1], [has_destructor], [b4_symbol_if([$1], [has_destructor],

View File

@@ -22,7 +22,7 @@ m4_pushdef([b4_copyright_years],
# b4_position_file # b4_position_file
# ---------------- # ----------------
# Name of the file containing the position class, if we want this file. # Name of the file containing the position class, if we want this file.
b4_defines_if([b4_required_version_if([302], [], b4_header_if([b4_required_version_if([302], [],
[m4_define([b4_position_file], [position.hh])])])]) [m4_define([b4_position_file], [position.hh])])])])
@@ -32,7 +32,7 @@ b4_defines_if([b4_required_version_if([302], [],
# if we want this file. # if we want this file.
b4_percent_define_check_file([b4_location_file], b4_percent_define_check_file([b4_location_file],
[[api.location.file]], [[api.location.file]],
b4_defines_if([[location.hh]])) b4_header_if([[location.hh]]))
# b4_location_include # b4_location_include
# ------------------- # -------------------

View File

@@ -19,7 +19,7 @@
# b4_stack_file # b4_stack_file
# ------------- # -------------
# Name of the file containing the stack class, if we want this file. # Name of the file containing the stack class, if we want this file.
b4_defines_if([b4_required_version_if([302], [], b4_header_if([b4_required_version_if([302], [],
[m4_define([b4_stack_file], [stack.hh])])]) [m4_define([b4_stack_file], [stack.hh])])])

View File

@@ -293,7 +293,7 @@ m4_define([b4_declare_yyparse],
# b4_shared_declarations # b4_shared_declarations
# ---------------------- # ----------------------
# Declaration that might either go into the header (if --defines) # Declaration that might either go into the header (if --header)
# or open coded in the parser body. # or open coded in the parser body.
m4_define([b4_shared_declarations], m4_define([b4_shared_declarations],
[b4_cpp_guard_open([b4_spec_mapped_header_file])[ [b4_cpp_guard_open([b4_spec_mapped_header_file])[
@@ -330,13 +330,13 @@ m4_if(b4_spec_header_file, [y.tab.h], [],
## -------------- ## ## -------------- ##
b4_defines_if([[ b4_header_if([[
]b4_output_begin([b4_spec_header_file])[ ]b4_output_begin([b4_spec_header_file])[
]b4_copyright([Bison interface for Yacc-like parsers in C])[ ]b4_copyright([Bison interface for Yacc-like parsers in C])[
]b4_disclaimer[ ]b4_disclaimer[
]b4_shared_declarations[ ]b4_shared_declarations[
]b4_output_end[ ]b4_output_end[
]])# b4_defines_if ]])# b4_header_if
b4_output_begin([b4_parser_file_name])[ b4_output_begin([b4_parser_file_name])[
]b4_copyright([Bison implementation for Yacc-like parsers in C])[ ]b4_copyright([Bison implementation for Yacc-like parsers in C])[

View File

@@ -6092,7 +6092,7 @@ std::string} as default).
@item Purpose: Specify how the generated parser should include the generated header. @item Purpose: Specify how the generated parser should include the generated header.
Historically, when option @option{-D}/@option{--defines} was used, Historically, when option @option{-d} or @option{--header} was used,
@command{bison} generated a header and pasted an exact copy of it into the @command{bison} generated a header and pasted an exact copy of it into the
generated parser implementation file. Since Bison 3.6, it is generated parser implementation file. Since Bison 3.6, it is
@code{#include}d as @samp{"@var{basename}.h"}, instead of duplicated, unless @code{#include}d as @samp{"@var{basename}.h"}, instead of duplicated, unless
@@ -11798,15 +11798,19 @@ Options controlling the output.
@c Please, keep this ordered as in 'bison --help'. @c Please, keep this ordered as in 'bison --help'.
@table @option @table @option
@item --defines[=@var{file}] @item -H [@var{file}]
@itemx --header=[@var{file}]
Pretend that @code{%defines} was specified, i.e., write an extra output file Pretend that @code{%defines} was specified, i.e., write an extra output file
containing definitions for the token kind names defined in the grammar, as containing definitions for the token kind names defined in the grammar, as
well as a few other declarations. @xref{Decl Summary}. well as a few other declarations. @xref{Decl Summary}.
@item --defines[=@var{file}]
Historical name for option @option{--header}.
@item -d @item -d
This is the same as @option{--defines} except @option{-d} does not accept a This is the same as @option{--header} except @option{-d} does not accept a
@var{file} argument since POSIX Yacc requires that @option{-d} can be bundled @var{file} argument since POSIX Yacc requires that @option{-d} can be
with other short options. bundled with other short options.
@item -b @var{file-prefix} @item -b @var{file-prefix}
@itemx --file-prefix=@var{prefix} @itemx --file-prefix=@var{prefix}
@@ -13794,7 +13798,8 @@ GLR parsers are currently unsupported in Java. Do not use the
@code{glr-parser} directive. @code{glr-parser} directive.
No header file can be generated for Java parsers. Do not use the No header file can be generated for Java parsers. Do not use the
@code{%defines} directive or the @option{-d}/@option{--defines} options. @code{%defines} directive or the @option{-d}/@option{-H}/@option{--header}
options.
@c FIXME: Possible code change. @c FIXME: Possible code change.
Currently, support for tracing is always compiled in. Thus the Currently, support for tracing is always compiled in. Thus the

View File

@@ -19,7 +19,7 @@ LIBS = -lreadline -lm # In some environments, -lintl is needed.
all: $(BASE) all: $(BASE)
%.c %.h %.xml %.gv: %.y %.c %.h %.xml %.gv: %.y
$(BISON) $(BISONFLAGS) --defines --xml --graph=$*.gv -o $*.c $< $(BISON) $(BISONFLAGS) --header --xml --graph=$*.gv -o $*.c $<
$(BASE): parse.o $(BASE): parse.o
$(CC) $(CPPFLAGS) $(CFLAGS) -o $@ $^ $(LDFLAGS) $(LIBS) $(CC) $(CPPFLAGS) $(CFLAGS) -o $@ $^ $(LDFLAGS) $(LIBS)

View File

@@ -8,7 +8,7 @@ XSLTPROC = xsltproc
all: $(BASE) all: $(BASE)
%.c %.h %.xml %.gv: %.y %.c %.h %.xml %.gv: %.y
$(BISON) $(BISONFLAGS) --defines --xml --graph=$*.gv -o $*.c $< $(BISON) $(BISONFLAGS) --header --xml --graph=$*.gv -o $*.c $<
$(BASE): $(BASE).o $(BASE): $(BASE).o
$(CC) $(CFLAGS) -o $@ $^ $(CC) $(CFLAGS) -o $@ $^

View File

@@ -9,7 +9,7 @@ XSLTPROC = xsltproc
all: $(BASE) all: $(BASE)
%.c %.h %.xml %.gv: %.y %.c %.h %.xml %.gv: %.y
$(BISON) $(BISONFLAGS) --defines --xml --graph=$*.gv -o $*.c $< $(BISON) $(BISONFLAGS) --header --xml --graph=$*.gv -o $*.c $<
%.c: %.l %.c: %.l
$(FLEX) $(FLEXFLAGS) -o$@ $< $(FLEX) $(FLEXFLAGS) -o$@ $<

View File

@@ -8,7 +8,7 @@ XSLTPROC = xsltproc
all: $(BASE) all: $(BASE)
%.c %.h %.xml %.gv: %.y %.c %.h %.xml %.gv: %.y
$(BISON) $(BISONFLAGS) --defines --xml --graph=$*.gv -o $*.c $< $(BISON) $(BISONFLAGS) --header --xml --graph=$*.gv -o $*.c $<
$(BASE): $(BASE).o $(BASE): $(BASE).o
$(CC) $(CFLAGS) -o $@ $^ $(CC) $(CFLAGS) -o $@ $^

View File

@@ -9,7 +9,7 @@ XSLTPROC = xsltproc
all: $(BASE) all: $(BASE)
%.c %.h %.xml %.gv: %.y %.c %.h %.xml %.gv: %.y
$(BISON) $(BISONFLAGS) --defines --xml --graph=$*.gv -o $*.c $< $(BISON) $(BISONFLAGS) --header --xml --graph=$*.gv -o $*.c $<
%.c %.h: %.l %.c %.h: %.l
$(FLEX) $(FLEXFLAGS) -o$*.c --header=$*.h $< $(FLEX) $(FLEXFLAGS) -o$*.c --header=$*.h $<

View File

@@ -56,7 +56,7 @@ location spec_name_prefix_loc = EMPTY_LOCATION_INIT;
char *spec_verbose_file = NULL; /* for --verbose. */ char *spec_verbose_file = NULL; /* for --verbose. */
char *spec_graph_file = NULL; /* for -g. */ char *spec_graph_file = NULL; /* for -g. */
char *spec_xml_file = NULL; /* for -x. */ char *spec_xml_file = NULL; /* for -x. */
char *spec_header_file = NULL; /* for --defines. */ char *spec_header_file = NULL; /* for --header. */
char *spec_mapped_header_file = NULL; char *spec_mapped_header_file = NULL;
char *parser_file_name; char *parser_file_name;
@@ -411,7 +411,7 @@ compute_output_file_names (void)
? xstrdup (spec_outfile) ? xstrdup (spec_outfile)
: concat2 (all_but_ext, src_extension)); : concat2 (all_but_ext, src_extension));
if (defines_flag) if (header_flag)
{ {
if (! spec_header_file) if (! spec_header_file)
spec_header_file = concat2 (all_but_ext, header_extension); spec_header_file = concat2 (all_but_ext, header_extension);

View File

@@ -47,10 +47,10 @@ extern char *spec_graph_file;
/* File name specified for the xml output. */ /* File name specified for the xml output. */
extern char *spec_xml_file; extern char *spec_xml_file;
/* File name specified with --defines. */ /* File name specified with --header. */
extern char *spec_header_file; extern char *spec_header_file;
/* File name specified with --defines, adjusted for mapped prefixes. */ /* File name specified with --header, adjusted for mapped prefixes. */
extern char *spec_mapped_header_file; extern char *spec_mapped_header_file;
/* Directory prefix of output file names. */ /* Directory prefix of output file names. */

View File

@@ -38,7 +38,7 @@
#include "output.h" #include "output.h"
#include "uniqstr.h" #include "uniqstr.h"
bool defines_flag = false; bool header_flag = false;
bool graph_flag = false; bool graph_flag = false;
bool xml_flag = false; bool xml_flag = false;
bool no_lines_flag = false; bool no_lines_flag = false;
@@ -422,11 +422,9 @@ Tuning the Parser:\n\
"), stdout); "), stdout);
putc ('\n', stdout); putc ('\n', stdout);
/* Keep -d and --defines separate so that ../build-aux/cross-options.pl
* won't assume that -d also takes an argument. */
fputs (_("\ fputs (_("\
Output Files:\n\ Output Files:\n\
--defines[=FILE] also produce a header file\n\ -H, --header=[FILE] also produce a header file\n\
-d likewise but cannot specify FILE (for POSIX Yacc)\n\ -d likewise but cannot specify FILE (for POSIX Yacc)\n\
-r, --report=THINGS also produce details on the automaton\n\ -r, --report=THINGS also produce details on the automaton\n\
--report-file=FILE write report to FILE\n\ --report-file=FILE write report to FILE\n\
@@ -545,6 +543,7 @@ language_argmatch (char const *arg, int prio, location loc)
static char const short_options[] = static char const short_options[] =
"D:" "D:"
"F:" "F:"
"H::"
"L:" "L:"
"S:" "S:"
"T::" "T::"
@@ -609,6 +608,7 @@ static struct option const long_options[] =
{ "yacc", no_argument, 0, 'y' }, { "yacc", no_argument, 0, 'y' },
/* Output Files. */ /* Output Files. */
{ "header", optional_argument, 0, 'H' },
{ "defines", optional_argument, 0, 'd' }, { "defines", optional_argument, 0, 'd' },
{ "report", required_argument, 0, 'r' }, { "report", required_argument, 0, 'r' },
{ "report-file", required_argument, 0, REPORT_FILE_OPTION }, { "report-file", required_argument, 0, REPORT_FILE_OPTION },
@@ -719,6 +719,16 @@ getargs (int argc, char *argv[])
} }
break; break;
case 'H':
case 'd':
header_flag = true;
if (optarg)
{
free (spec_header_file);
spec_header_file = xstrdup (optarg);
}
break;
case 'L': case 'L':
language_argmatch (optarg, command_line_prio, loc); language_argmatch (optarg, command_line_prio, loc);
break; break;
@@ -763,16 +773,6 @@ getargs (int argc, char *argv[])
spec_file_prefix = optarg; spec_file_prefix = optarg;
break; break;
case 'd':
/* Here, the -d and --defines options are differentiated. */
defines_flag = true;
if (optarg)
{
free (spec_header_file);
spec_header_file = xstrdup (optarg);
}
break;
case 'g': case 'g':
graph_flag = true; graph_flag = true;
if (optarg) if (optarg)

View File

@@ -34,7 +34,7 @@ extern int skeleton_prio;
/* for -I */ /* for -I */
extern char const *include; extern char const *include;
extern bool defines_flag; /* for -d */ extern bool header_flag; /* for -d/-H */
extern bool graph_flag; /* for -g */ extern bool graph_flag; /* for -g */
extern bool xml_flag; /* for -x */ extern bool xml_flag; /* for -x */
extern bool no_lines_flag; /* for -l */ extern bool no_lines_flag; /* for -l */

View File

@@ -810,7 +810,7 @@ prepare (void)
MUSCLE_INSERT_INT ("required_version", required_version); MUSCLE_INSERT_INT ("required_version", required_version);
/* Flags. */ /* Flags. */
MUSCLE_INSERT_BOOL ("defines_flag", defines_flag); MUSCLE_INSERT_BOOL ("header_flag", header_flag);
MUSCLE_INSERT_BOOL ("glr_flag", glr_parser); MUSCLE_INSERT_BOOL ("glr_flag", glr_parser);
MUSCLE_INSERT_BOOL ("nondeterministic_flag", nondeterministic_parser); MUSCLE_INSERT_BOOL ("nondeterministic_flag", nondeterministic_parser);
MUSCLE_INSERT_BOOL ("synclines_flag", !no_lines_flag); MUSCLE_INSERT_BOOL ("synclines_flag", !no_lines_flag);

View File

@@ -2075,7 +2075,7 @@ yyreduce:
break; break;
case 9: /* prologue_declaration: "%defines" */ case 9: /* prologue_declaration: "%defines" */
{ defines_flag = true; } { header_flag = true; }
break; break;
case 10: /* prologue_declaration: "%defines" "string" */ case 10: /* prologue_declaration: "%defines" "string" */
@@ -2938,7 +2938,7 @@ add_param (param_type type, char *decl, location loc)
static void static void
handle_defines (char const *value) handle_defines (char const *value)
{ {
defines_flag = true; header_flag = true;
char *file = unquote (value); char *file = unquote (value);
spec_header_file = xstrdup (file); spec_header_file = xstrdup (file);
gram_scanner_last_string_free (); gram_scanner_last_string_free ();

View File

@@ -339,7 +339,7 @@ prologue_declaration:
muscle_percent_define_insert ($2, @$, $3.kind, $3.chars, muscle_percent_define_insert ($2, @$, $3.kind, $3.chars,
MUSCLE_PERCENT_DEFINE_GRAMMAR_FILE); MUSCLE_PERCENT_DEFINE_GRAMMAR_FILE);
} }
| "%defines" { defines_flag = true; } | "%defines" { header_flag = true; }
| "%defines" STRING { handle_defines ($2); } | "%defines" STRING { handle_defines ($2); }
| "%error-verbose" { handle_error_verbose (&@$, $1); } | "%error-verbose" { handle_error_verbose (&@$, $1); }
| "%expect" INT_LITERAL { expected_sr_conflicts = $2; } | "%expect" INT_LITERAL { expected_sr_conflicts = $2; }
@@ -949,7 +949,7 @@ add_param (param_type type, char *decl, location loc)
static void static void
handle_defines (char const *value) handle_defines (char const *value)
{ {
defines_flag = true; header_flag = true;
char *file = unquote (value); char *file = unquote (value);
spec_header_file = xstrdup (file); spec_header_file = xstrdup (file);
gram_scanner_last_string_free (); gram_scanner_last_string_free ();

View File

@@ -47,7 +47,6 @@ dummy: %empty;
]) ])
AT_BISON_CHECK([--defines=$1.h --output=$1.c $1.y]) AT_BISON_CHECK([--defines=$1.h --output=$1.c $1.y])
AT_COMPILE([$1.o], [-I. -c $1.c]) AT_COMPILE([$1.o], [-I. -c $1.c])
AT_BISON_OPTION_POPDEFS AT_BISON_OPTION_POPDEFS
@@ -83,7 +82,7 @@ AT_DATA_GRAMMAR([input.y],
exp: %empty; exp: %empty;
]]) ]])
AT_BISON_CHECK([--defines -o input.c input.y], [], [], AT_BISON_CHECK([--header -o input.c input.y], [], [],
[[input.y:11.1-18: warning: deprecated directive: '%name-prefix "my_"', use '%define api.prefix {my_}' [-Wdeprecated] [[input.y:11.1-18: warning: deprecated directive: '%name-prefix "my_"', use '%define api.prefix {my_}' [-Wdeprecated]
input.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother] input.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother]
]]) ]])

View File

@@ -1506,7 +1506,7 @@ m4_define([AT_PARSER_CHECK],
# #
# If TEST-SPEC contains the attribute no-xml, then invoke bison using # If TEST-SPEC contains the attribute no-xml, then invoke bison using
# AT_BISON_CHECK_NO_XML. Otherwise, invoke bison using AT_BISON_CHECK. # AT_BISON_CHECK_NO_XML. Otherwise, invoke bison using AT_BISON_CHECK.
# On the bison command-line, specify `--report=all --defines'. Check # On the bison command-line, specify `--report=all --header'. Check
# that Bison exits with value 0, has no stdout, and has stderr # that Bison exits with value 0, has no stdout, and has stderr
# BISON-STDERR. # BISON-STDERR.
# #
@@ -1600,7 +1600,7 @@ yylex (void)
m4_if(m4_index(m4_quote($3), [no-xml]), -1, m4_if(m4_index(m4_quote($3), [no-xml]), -1,
[AT_BISON_CHECK], [AT_BISON_CHECK],
[AT_BISON_CHECK_NO_XML])([[-Wall --report=all,no-cex --defines -o input.c input.y]], [AT_BISON_CHECK_NO_XML])([[-Wall --report=all,no-cex --header -o input.c input.y]],
[0], [], m4_dquote($7)) [0], [], m4_dquote($7))
m4_if(m4_index(m4_quote($3), [last-state]), -1, m4_if(m4_index(m4_quote($3), [last-state]), -1,

View File

@@ -132,6 +132,10 @@ AT_CHECK_OUTPUT([foo.yy], [%defines %verbose], [],
AT_CHECK_OUTPUT([foo.yy], [%defines %verbose ], [-o foo.c], AT_CHECK_OUTPUT([foo.yy], [%defines %verbose ], [-o foo.c],
[foo.c foo.h foo.output]) [foo.c foo.h foo.output])
AT_CHECK_OUTPUT([foo.yy], [],
[--header=foo.hpp -o foo.c++],
[foo.c++ foo.hpp])
AT_CHECK_OUTPUT([foo.yy], [], AT_CHECK_OUTPUT([foo.yy], [],
[--defines=foo.hpp -o foo.c++], [--defines=foo.hpp -o foo.c++],
[foo.c++ foo.hpp]) [foo.c++ foo.hpp])
@@ -147,14 +151,14 @@ AT_CHECK_OUTPUT([foo.yy], [],
# Do not generate code when there are early errors (even warnings as # Do not generate code when there are early errors (even warnings as
# errors). # errors).
AT_CHECK_OUTPUT([foo.y], [%type <foo> useless], AT_CHECK_OUTPUT([foo.y], [%type <foo> useless],
[--defines --graph --xml --report=all -Wall -Werror], [--header --graph --xml --report=all -Wall -Werror],
[foo.dot foo.output foo.xml], [foo.dot foo.output foo.xml],
[1]) [1])
# Do not generate code when there are late errors (even warnings as # Do not generate code when there are late errors (even warnings as
# errors). # errors).
AT_CHECK_OUTPUT([foo.y], [%define useless], AT_CHECK_OUTPUT([foo.y], [%define useless],
[--defines --graph --xml --report=all -Wall -Werror], [--header --graph --xml --report=all -Wall -Werror],
[foo.dot foo.output foo.xml], [foo.dot foo.output foo.xml],
[1]) [1])
@@ -284,7 +288,7 @@ AT_DATA_GRAMMAR([glr.y],
%% %%
start: {}; start: {};
]]) ]])
AT_BISON_CHECK([-o "AS_ESCAPE([$1.c])" --defines="AS_ESCAPE([$1.h])" glr.y]) AT_BISON_CHECK([-o "AS_ESCAPE([$1.c])" --header="AS_ESCAPE([$1.h])" glr.y])
AT_CHECK([ls "AS_ESCAPE([$1.c])" "AS_ESCAPE([$1.h])"], [], [ignore]) AT_CHECK([ls "AS_ESCAPE([$1.c])" "AS_ESCAPE([$1.h])"], [], [ignore])
AT_COMPILE([glr.o], [-c "AS_ESCAPE([$1.c])"]) AT_COMPILE([glr.o], [-c "AS_ESCAPE([$1.c])"])
$2 $2
@@ -295,7 +299,7 @@ AT_DATA_GRAMMAR([cxx.y],
%% %%
start: {}; start: {};
]]) ]])
AT_BISON_CHECK([-o "AS_ESCAPE([$1.cc])" --defines="AS_ESCAPE([$1.hh])" cxx.y]) AT_BISON_CHECK([-o "AS_ESCAPE([$1.cc])" --header="AS_ESCAPE([$1.hh])" cxx.y])
AT_CHECK([ls "AS_ESCAPE([$1.cc])" "AS_ESCAPE([$1.hh])"], [], [ignore]) AT_CHECK([ls "AS_ESCAPE([$1.cc])" "AS_ESCAPE([$1.hh])"], [], [ignore])
AT_COMPILE_CXX([cxx.o], [-c "AS_ESCAPE([$1.cc])"]) AT_COMPILE_CXX([cxx.o], [-c "AS_ESCAPE([$1.cc])"])
$2 $2