Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ jobs:
compiler_version: [g++-10, g++-11]
cxx_std: [17, 20]
os: [ubuntu-22.04]
disable_trace: [false]
include:
# Test with trace disabled
- compiler_version: g++-11
cxx_std: 20
os: ubuntu-22.04
disable_trace: true

runs-on: ${{ matrix.os }}

Expand All @@ -30,7 +37,11 @@ jobs:
run: |
mkdir build
cd build
cmake .. -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} -DCMAKE_CXX_COMPILER=${{ matrix.compiler_version }} -DCXX_STD=${{ matrix.cxx_std }}
if [ "${{ matrix.disable_trace }}" = "true" ]; then
cmake .. -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} -DCMAKE_CXX_COMPILER=${{ matrix.compiler_version }} -DCXX_STD=${{ matrix.cxx_std }} -DDISABLE_TRACE=true
else
cmake .. -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} -DCMAKE_CXX_COMPILER=${{ matrix.compiler_version }} -DCXX_STD=${{ matrix.cxx_std }}
fi

- name: Build
run: cd build ; make -j4
Expand Down
14 changes: 13 additions & 1 deletion .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ jobs:
matrix:
cxx_std: [17, 20, 23]
os: [windows-2022]
disable_trace: [false]
include:
# Test with trace disabled
- cxx_std: 20
os: windows-2022
disable_trace: true

runs-on: ${{ matrix.os }}

Expand All @@ -26,7 +32,13 @@ jobs:
- name: Configure CMake
# Configure CMake in a 'build' subdirectory. Visual Studio is a multi-config generator, so we don't use CMAKE_BUILD_TYPE.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: cmake -B build -DCXX_STD=${{ matrix.cxx_std }}
run: |
if ("${{ matrix.disable_trace }}" -eq "true") {
cmake -B build -DCXX_STD=${{ matrix.cxx_std }} -DDISABLE_TRACE=true
} else {
cmake -B build -DCXX_STD=${{ matrix.cxx_std }}
}
shell: pwsh

- name: Build
working-directory: build
Expand Down
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ if (BUILD_WITH_HANA)
add_definitions(-DBOOST_PARSER_USE_HANA_TUPLE)
endif()

set(DISABLE_TRACE false CACHE BOOL
"Disable parser trace functionality (defines BOOST_PARSER_DISABLE_TRACE).")
if (DISABLE_TRACE)
add_definitions(-DBOOST_PARSER_DISABLE_TRACE)
endif()


##################################################
# Dependencies
Expand Down
1 change: 1 addition & 0 deletions doc/parser.qbk
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@
[def _RULES_ [macroref BOOST_PARSER_DEFINE_RULES `BOOST_PARSER_DEFINE_RULES`]]
[def _AGGR_SIZE_ [macroref BOOST_PARSER_MAX_AGGREGATE_SIZE `BOOST_PARSER_MAX_AGGREGATE_SIZE`]]
[def _SUBRNG_ [macroref BOOST_PARSER_SUBRANGE `BOOST_PARSER_SUBRANGE`]]
[def _DISABLE_TRACE_ [macroref BOOST_PARSER_DISABLE_TRACE `BOOST_PARSER_DISABLE_TRACE`]]

[def __p_ [globalref boost::parser::_p `_p`]]

Expand Down
19 changes: 18 additions & 1 deletion doc/tutorial.qbk
Original file line number Diff line number Diff line change
Expand Up @@ -3766,6 +3766,22 @@ Some things to be aware of when looking at _Parser_ trace output:
produces that value. In these cases, you'll see the resolved value of the
parse argument.

[heading Compile-time trace disabling]

While trace mode is very useful for debugging, it does have some overhead.
Most parser templates are instantiated twice: Once with tracing enabled,
once with tracing disabled.
If you want to completely disable trace functionality at compile time, you can define
`BOOST_PARSER_DISABLE_TRACE` before including any Boost.Parser headers:

[teletype]``
#define BOOST_PARSER_DISABLE_TRACE
#include <boost/parser/parser.hpp>
``

When this define is set, all trace-related code is compiled out,
reducing the compile time.

[endsect]

[section Memory Allocation]
Expand Down Expand Up @@ -3983,7 +3999,8 @@ This defines a RAII trace object that will produce the verbose trace requested
by the user if they passed `_trace_::on` to the top-level parse. It only has
effect if `detail::enable_trace(flags)` is `true`. If trace is enabled, it
will show the state of the parse at the point at which it is defined, and then
again when it goes out of scope.
again when it goes out of scope. By defining `BOOST_PARSER_DISABLE_TRACE`,
the trace feature can be disabled globally at compile time.

[important For the tracing code to work, you must define an overload of
`detail::print_parser` for your new parser type/template. See
Expand Down
10 changes: 10 additions & 0 deletions include/boost/parser/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
disable the use of concepts, define this macro. */
# define BOOST_PARSER_DISABLE_CONCEPTS

/** Boost.Parser will generate code to trace the execution of each and every
parser by default. To disable all trace code, define this macro. */
# define BOOST_PARSER_DISABLE_TRACE

/** Define this macro to use `boost::hana::tuple` instead of `std::tuple`
throughout Boost.Parser. */
# define BOOST_PARSER_USE_HANA_TUPLE
Expand Down Expand Up @@ -92,6 +96,12 @@
# define BOOST_PARSER_USE_CONCEPTS 0
#endif

#if defined(BOOST_PARSER_DISABLE_TRACE)
# define BOOST_PARSER_DO_TRACE 0
#else
# define BOOST_PARSER_DO_TRACE 1
#endif

#if defined(__cpp_lib_ranges) && BOOST_PARSER_USE_CONCEPTS
# define BOOST_PARSER_SUBRANGE std::ranges::subrange
#else
Expand Down
11 changes: 11 additions & 0 deletions include/boost/parser/detail/printing.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,9 @@ namespace boost { namespace parser { namespace detail {
template<typename Context>
auto resolve(Context const &, nope n);

template<typename DependentType, bool DoTraceMacro>
constexpr bool trace_disabled = !DoTraceMacro;

template<
bool DoTrace,
typename Iter,
Expand All @@ -606,6 +609,8 @@ namespace boost { namespace parser { namespace detail {
typename Attribute>
struct scoped_trace_t
{
static_assert(!trace_disabled<Iter, BOOST_PARSER_DO_TRACE>);

scoped_trace_t(
std::ostream & os,
Iter & first,
Expand Down Expand Up @@ -681,6 +686,9 @@ namespace boost { namespace parser { namespace detail {
flags f,
Attribute const & attr)
{
if constexpr (!BOOST_PARSER_DO_TRACE)
return;

if constexpr (Context::do_trace) {
std::stringstream oss;
detail::print_parser(context, parser, oss);
Expand All @@ -695,6 +703,9 @@ namespace boost { namespace parser { namespace detail {
template<typename Context, typename Attribute>
auto final_trace(Context const & context, flags f, Attribute const & attr)
{
if constexpr (!BOOST_PARSER_DO_TRACE)
return;

if (!detail::do_trace(f))
return;

Expand Down
Loading