c++: provide control over the stack.hh file name

It was not a good idea to generate the file stack.hh.  It never was.
But now we have to deal with backward compatibility: if we stop
generating it, the build system of some build system will probably
break.

So offer the user a means to (i) decide what the name of the output
file should be, and (ii) not generate this file at all (its content
will be inline where the parser is defined).

* data/lalr1.cc (b4_percent_define_check_file_complain)
(b4_percent_define_check_file): New.
* data/stack.hh: Generate the file only if api.stack.file is not
empty.
In that case, use it as file name.
* data/lalr1.cc: Adjust to include the right file, or to include
the definition of stack.
* tests/calc.at, tests/output.at: Exercise api.stack.file.
This commit is contained in:
Akim Demaille
2018-09-23 17:59:46 +02:00
parent 1a0b3bf83b
commit b122a71c83
6 changed files with 99 additions and 10 deletions

View File

@@ -18,6 +18,14 @@
m4_pushdef([b4_copyright_years],
[2002-2015, 2018])
# b4_stack_file
# -------------
# Name of the file containing the stack class, if we want this file.
b4_percent_define_check_file([b4_stack_file],
[[api.stack.file]],
b4_defines_if([[stack.hh]]))
# b4_stack_define
# ---------------
m4_define([b4_stack_define],
@@ -129,16 +137,17 @@ m4_define([b4_stack_define],
};
]])
b4_defines_if(
[b4_output_begin([b4_dir_prefix[]stack.hh])
b4_copyright([Stack handling for Bison parsers in C++])[
m4_ifdef([b4_stack_file],
[b4_output_begin([b4_dir_prefix[]b4_stack_file])[
]b4_copyright([Stack handling for Bison parsers in C++])[
/**
** \file ]b4_dir_prefix[stack.hh
** \file ]b4_dir_prefix[]b4_stack_file[
** Define the ]b4_namespace_ref[::stack class.
*/
]b4_cpp_guard_open([b4_dir_prefix[]stack.hh])[
]b4_cpp_guard_open([b4_dir_prefix[]b4_stack_file])[
# include <vector>
@@ -148,7 +157,8 @@ b4_copyright([Stack handling for Bison parsers in C++])[
]b4_stack_define[
]b4_namespace_close[
]b4_cpp_guard_close([b4_dir_prefix[]stack.hh])[
]b4_output_end])
]b4_cpp_guard_close([b4_dir_prefix[]b4_stack_file])[
]b4_output_end[
]])
m4_popdef([b4_copyright_years])