1 /*=============================================================================
2 Boost.Wave: A Standard compliant C++ preprocessor library
5 Copyright (c) 2001-2010 Hartmut Kaiser. Distributed under the Boost
6 Software License, Version 1.0. (See accompanying file
7 LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
8 =============================================================================*/
10 #if !defined(BOOST_WAVE_ADVANCED_PREPROCESSING_HOOKS_INCLUDED)
11 #define BOOST_WAVE_ADVANCED_PREPROCESSING_HOOKS_INCLUDED
17 #include <boost/assert.hpp>
18 #include <boost/config.hpp>
20 #include <boost/wave/token_ids.hpp>
21 #include <boost/wave/util/macro_helpers.hpp>
22 #include <boost/wave/preprocessing_hooks.hpp>
24 ///////////////////////////////////////////////////////////////////////////////
26 // The advanced_preprocessing_hooks policy class is used to register some
27 // of the more advanced (and probably more rarely used hooks with the Wave
30 // This policy type is used as a template parameter to the boost::wave::context<>
33 ///////////////////////////////////////////////////////////////////////////////
34 class advanced_preprocessing_hooks
35 : public boost::wave::context_policies::default_preprocessing_hooks
38 advanced_preprocessing_hooks() : need_comment(true) {}
40 ///////////////////////////////////////////////////////////////////////////
42 // The function 'found_directive' is called, whenever a preprocessor
43 // directive was encountered, but before the corresponding action is
46 // The parameter 'ctx' is a reference to the context object used for
47 // instantiating the preprocessing iterators by the user.
49 // The parameter 'directive' is a reference to the token holding the
50 // preprocessing directive.
52 ///////////////////////////////////////////////////////////////////////////
53 template <typename ContextT, typename TokenT>
55 found_directive(ContextT const& ctx, TokenT const& directive)
57 // print the commented conditional directives
58 using namespace boost::wave;
59 token_id id = token_id(directive);
65 std::cout << "// " << directive.get_value() << " ";
71 std::cout << "// " << directive.get_value() << std::endl;
82 ///////////////////////////////////////////////////////////////////////////
84 // The function 'evaluated_conditional_expression' is called, whenever a
85 // conditional preprocessing expression was evaluated (the expression
86 // given to a #if, #elif, #ifdef or #ifndef directive)
88 // The parameter 'ctx' is a reference to the context object used for
89 // instantiating the preprocessing iterators by the user.
91 // The parameter 'expression' holds the non-expanded token sequence
92 // comprising the evaluated expression.
94 // The parameter expression_value contains the result of the evaluation of
95 // the expression in the current preprocessing context.
97 // The return value defines, whether the given expression has to be
98 // evaluated again, allowing to decide which of the conditional branches
99 // should be expanded. You need to return 'true' from this hook function
100 // to force the expression to be re-evaluated.
102 ///////////////////////////////////////////////////////////////////////////
103 template <typename ContextT, typename TokenT, typename ContainerT>
105 evaluated_conditional_expression(ContextT const &ctx,
106 TokenT const& directive, ContainerT const& expression,
107 bool expression_value)
109 // print the conditional expressions
110 std::cout << boost::wave::util::impl::as_string(expression) << std::endl;
112 return false; // ok to continue, do not re-evaluate expression
115 ///////////////////////////////////////////////////////////////////////////
117 // The function 'skipped_token' is called, whenever a token is about to be
118 // skipped due to a false preprocessor condition (code fragments to be
119 // skipped inside the not evaluated conditional #if/#else/#endif branches).
121 // The parameter 'ctx' is a reference to the context object used for
122 // instantiating the preprocessing iterators by the user.
124 // The parameter 'token' refers to the token to be skipped.
126 ///////////////////////////////////////////////////////////////////////////
127 template <typename ContextT, typename TokenT>
129 skipped_token(ContextT const& ctx, TokenT const& token)
131 // prepend a comment at the beginning of all skipped lines
132 using namespace boost::wave;
133 if (need_comment && token_id(token) != T_SPACE) {
135 need_comment = false;
137 std::cout << token.get_value();
138 if (token_id(token) == T_NEWLINE || token_id(token) == T_CPPCOMMENT)
146 #endif // !defined(BOOST_WAVE_ADVANCED_PREPROCESSING_HOOKS_INCLUDED)