Compile Time Configuration |
Library compile time configuration
The C++ preprocessor iterator library may be configured at compile time by specifying different preprocessor constants to include different additional features. The possible preprocessor constants are described in the following table.
Summary of possible preprocessor constants
for library configuration |
|
BOOST_WAVE_SUPPORT_WARNING_DIRECTIVE |
Support the #warning directive |
|
Support several MS specific language extensions (i.e. __int8 et.al.) |
|
Enable the preprocessing of the message bodies of #error and #warning directives. |
|
If defined, then the #pragma directives are returned as a token sequence to the caller, if not defined, the whole #pragma directive is skipped. |
|
Enable the preprocessing of the bodies of
#pragma directives. |
|
Enable the functionality required to define macros with the command line syntax (-DMACRO(x)=definition) |
|
The tokens generated by the Wave library
contain the token data and the file position, where this token was found
in the input stream. |
|
If defined, then the preprocessor library supports variadics and placemarkers. Note, to support C99 mode, this constant must be defined too. |
|
If defined, it will determine the initial maximal possible include file nesting depth supported. It defaults to 1024. |
|
If defined, then the |
BOOST_ WAVE_SUPPORT_INCLUDE_NEXT |
If defined, then the |
Using a different token type or lexer type in conjunction with Wave
It is possible to use the Wave library while using your own token and/or lexer types. This may be achieved by providing your lexer type as the second template parameter while instantiating the boost::wave::context<> object. The token type used by the library is derived from the token_type typedef to be provided by the lexer type. If you want to provide your own token type only, you may use the boost::wave::lex_iterator<> type contained with the library. This type needs to be parametrized with the token type to use.
To show, how this may be done, the Wave library contains several samples illustrating this possibility. The cpp_tokens sample shows the usage of a custom lexer and a custom token types. The lexer type used is functionally fully compatible to the re2c [3] based lexer used by default. It is implemented based on the SLex [5] lexer example written by Dan Nuffer. The token type used therein is functionally equivalent to the default token type except for an additional operator<< used for dumping the information carried by the token.
Separation and inclusion compilation models
The Wave C++ preprocessor iterator library is build almost completely as a header only library (except for the re2c based lexer). If you're trying to include all required files at once you will mention, that the resulting compilation times are very large (up to an hour - depending on your system configuration). This straightforward method we'll call the inclusion compilation model. If you do not pay attention to compilation times, that's the way to go, no special handling is needed.
If you're interested in decreasing compilation times, the following method is to be used. This we will call it the separation compilation model. The trick is to separate the different objects such, that they are compilable separately. The function, which instantiates the templated object in question is factored out such, that its definition is visible to only one translation unit. To simplify this further this creation function is packaged into a small generator template structure.
There are two levels of separation implemented: the separation of the compilation of the C++ lexer and the separation of the compilation of the different Spirit grammars used. To use these separations you will have to define two preprocessor constants while compiling the whole application and you will have to explicitely instantiate some helper templates. The following tables shows these constants in detail.
Summary of possible compilation constants
required to enable the separation compilation model |
|
Separate |
|
C++ lexer |
|
Spirit grammars |
|
The following table shows the explicit template instantiations required,
if you want to use the separation compilation model. The TokenT placeholder
type has to be replaced with your token type to use and the LexIteratorT
placeholder type has to be replaced with your lex iterator type you've used while instantiation of the boost::wave::context<> object. You will achieve the best
results, if you place these into separate compilation units each. The IteratorT
placeholder should be replaced by the iterator type, which was used to instantiate
the boost::wave::context<> object.
Summary of required explicit template
instantiations required when using the separation compilation model |
|
Separate |
|
C++ lexer |
template
cpplexer::re2clex::new_lexer_gen<IteratorT>; |
Spirit grammars |
|
To see an example of this you can look at the Wave driver program included as an acompanion sample to the C++ preprocessor iterator library. The corresponding files are named obviously "instantiate_...something.cpp", where the '...somthing' is a hint, which grammars are explicitely instantiated inside. By using the separation model the compilation times required to build the Wave example are dropped by up to 90%.
Copyright © 2003-2005 Hartmut Kaiser
Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
Last updated: Sunday, May 15, 2005 12:23