Skip to content

Commit 399eb5b

Browse files
author
Andreas Buhr
committed
Add define BOOST_PARSER_DISABLE_TRACE to disable trace mode at compile time.
The trace feature doubles the compile time, even if never used. This patch introduces the preprocessor define BOOST_PARSER_DISABLE_TRACE to deactivate this feature at compile time.
1 parent 41d939b commit 399eb5b

9 files changed

Lines changed: 221 additions & 15 deletions

File tree

.github/workflows/ubuntu.yml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ jobs:
1818
compiler_version: [g++-10, g++-11]
1919
cxx_std: [17, 20]
2020
os: [ubuntu-22.04]
21+
disable_trace: [false]
22+
include:
23+
# Test with trace disabled
24+
- compiler_version: g++-11
25+
cxx_std: 20
26+
os: ubuntu-22.04
27+
disable_trace: true
2128

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

@@ -30,7 +37,11 @@ jobs:
3037
run: |
3138
mkdir build
3239
cd build
33-
cmake .. -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} -DCMAKE_CXX_COMPILER=${{ matrix.compiler_version }} -DCXX_STD=${{ matrix.cxx_std }}
40+
if [ "${{ matrix.disable_trace }}" = "true" ]; then
41+
cmake .. -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} -DCMAKE_CXX_COMPILER=${{ matrix.compiler_version }} -DCXX_STD=${{ matrix.cxx_std }} -DDISABLE_TRACE=true
42+
else
43+
cmake .. -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} -DCMAKE_CXX_COMPILER=${{ matrix.compiler_version }} -DCXX_STD=${{ matrix.cxx_std }}
44+
fi
3445
3546
- name: Build
3647
run: cd build ; make -j4

.github/workflows/windows.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ jobs:
1717
matrix:
1818
cxx_std: [17, 20, 23]
1919
os: [windows-2022]
20+
disable_trace: [false]
21+
include:
22+
# Test with trace disabled
23+
- cxx_std: 20
24+
os: windows-2022
25+
disable_trace: true
2026

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

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

3143
- name: Build
3244
working-directory: build

CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ if (BUILD_WITH_HANA)
6464
add_definitions(-DBOOST_PARSER_USE_HANA_TUPLE)
6565
endif()
6666

67+
set(DISABLE_TRACE false CACHE BOOL
68+
"Disable parser trace functionality (defines BOOST_PARSER_DISABLE_TRACE).")
69+
if (DISABLE_TRACE)
70+
add_definitions(-DBOOST_PARSER_DISABLE_TRACE)
71+
endif()
72+
6773

6874
##################################################
6975
# Dependencies

doc/parser.qbk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@
148148
[def _RULES_ [macroref BOOST_PARSER_DEFINE_RULES `BOOST_PARSER_DEFINE_RULES`]]
149149
[def _AGGR_SIZE_ [macroref BOOST_PARSER_MAX_AGGREGATE_SIZE `BOOST_PARSER_MAX_AGGREGATE_SIZE`]]
150150
[def _SUBRNG_ [macroref BOOST_PARSER_SUBRANGE `BOOST_PARSER_SUBRANGE`]]
151+
[def _DISABLE_TRACE_ [macroref BOOST_PARSER_DISABLE_TRACE `BOOST_PARSER_DISABLE_TRACE`]]
151152

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

doc/tutorial.qbk

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3766,6 +3766,22 @@ Some things to be aware of when looking at _Parser_ trace output:
37663766
produces that value. In these cases, you'll see the resolved value of the
37673767
parse argument.
37683768

3769+
[heading Compile-time trace disabling]
3770+
3771+
While trace mode is very useful for debugging, it does have some overhead.
3772+
Most parser templates are instantiated twice: Once with tracing enabled,
3773+
once with tracing disabled.
3774+
If you want to completely disable trace functionality at compile time, you can define
3775+
`BOOST_PARSER_DISABLE_TRACE` before including any Boost.Parser headers:
3776+
3777+
[teletype]``
3778+
#define BOOST_PARSER_DISABLE_TRACE
3779+
#include <boost/parser/parser.hpp>
3780+
``
3781+
3782+
When this define is set, all trace-related code is compiled out,
3783+
reducing the compile time.
3784+
37693785
[endsect]
37703786

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

39884005
[important For the tracing code to work, you must define an overload of
39894006
`detail::print_parser` for your new parser type/template. See

include/boost/parser/detail/printing.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,7 @@ namespace boost { namespace parser { namespace detail {
598598
template<typename Context>
599599
auto resolve(Context const &, nope n);
600600

601+
#ifndef BOOST_PARSER_DISABLE_TRACE
601602
template<
602603
bool DoTrace,
603604
typename Iter,
@@ -708,6 +709,7 @@ namespace boost { namespace parser { namespace detail {
708709
}
709710
os << "--------------------" << std::endl;
710711
}
712+
#endif // BOOST_PARSER_DISABLE_TRACE
711713

712714
}}}
713715

0 commit comments

Comments
 (0)