First public contribution.
1 /*=============================================================================
2 Boost.Wave: A Standard compliant C++ preprocessor library
6 Copyright (c) 2001-2007 Hartmut Kaiser. Distributed under the Boost
7 Software License, Version 1.0. (See accompanying file
8 LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9 =============================================================================*/
11 #if !defined(PREPROCESSING_HOOKS_HPP_338DE478_A13C_4B63_9BA9_041C917793B8_INCLUDED)
12 #define PREPROCESSING_HOOKS_HPP_338DE478_A13C_4B63_9BA9_041C917793B8_INCLUDED
14 #include <boost/wave/wave_config.hpp>
17 // this must occur after all of the includes and before any code appears
18 #ifdef BOOST_HAS_ABI_HEADERS
19 #include BOOST_ABI_PREFIX
22 ///////////////////////////////////////////////////////////////////////////////
25 namespace context_policies {
27 ///////////////////////////////////////////////////////////////////////////////
29 // The default_preprocessing_hooks class is a placeholder for all
30 // preprocessing hooks called from inside the preprocessing engine
32 ///////////////////////////////////////////////////////////////////////////////
33 struct default_preprocessing_hooks {
35 ///////////////////////////////////////////////////////////////////////////
37 // The function 'expanding_function_like_macro' is called, whenever a
38 // function-like macro is to be expanded.
40 // The macroname parameter marks the position, where the macro to expand
42 // The formal_args parameter holds the formal arguments used during the
43 // definition of the macro.
44 // The definition parameter holds the macro definition for the macro to
47 // The macro call parameter marks the position, where this macro invoked.
48 // The arguments parameter holds the macro arguments used during the
49 // invocation of the macro
51 ///////////////////////////////////////////////////////////////////////////
52 template <typename TokenT, typename ContainerT>
53 void expanding_function_like_macro(
54 TokenT const ¯odef, std::vector<TokenT> const &formal_args,
55 ContainerT const &definition,
56 TokenT const ¯ocall, std::vector<ContainerT> const &arguments)
59 ///////////////////////////////////////////////////////////////////////////
61 // The function 'expanding_object_like_macro' is called, whenever a
62 // object-like macro is to be expanded .
64 // The macroname parameter marks the position, where the macro to expand
66 // The definition parameter holds the macro definition for the macro to
69 // The macro call parameter marks the position, where this macro invoked.
71 ///////////////////////////////////////////////////////////////////////////
72 template <typename TokenT, typename ContainerT>
73 void expanding_object_like_macro(TokenT const ¯o,
74 ContainerT const &definition, TokenT const ¯ocall)
77 ///////////////////////////////////////////////////////////////////////////
79 // The function 'expanded_macro' is called, whenever the expansion of a
80 // macro is finished but before the rescanning process starts.
82 // The parameter 'result' contains the token sequence generated as the
83 // result of the macro expansion.
85 ///////////////////////////////////////////////////////////////////////////
86 template <typename ContainerT>
87 void expanded_macro(ContainerT const &result)
90 ///////////////////////////////////////////////////////////////////////////
92 // The function 'rescanned_macro' is called, whenever the rescanning of a
95 // The parameter 'result' contains the token sequence generated as the
96 // result of the rescanning.
98 ///////////////////////////////////////////////////////////////////////////
99 template <typename ContainerT>
100 void rescanned_macro(ContainerT const &result)
103 ///////////////////////////////////////////////////////////////////////////
105 // The function 'found_include_directive' is called, whenever a #include
106 // directive was located.
108 // The parameter 'filename' contains the (expanded) file name found after
109 // the #include directive. This has the format '<file>', '"file"' or
111 // The formats '<file>' or '"file"' are used for #include directives found
112 // in the preprocessed token stream, the format 'file' is used for files
113 // specified through the --force_include command line argument.
115 // The parameter 'include_next' is set to true if the found directive was
116 // a #include_next directive and the BOOST_WAVE_SUPPORT_INCLUDE_NEXT
117 // preprocessing constant was defined to something != 0.
119 ///////////////////////////////////////////////////////////////////////////
121 found_include_directive(std::string const &filename, bool include_next)
124 ///////////////////////////////////////////////////////////////////////////
126 // The function 'opened_include_file' is called, whenever a file referred
127 // by an #include directive was successfully located and opened.
129 // The parameter 'filename' contains the file system path of the
130 // opened file (this is relative to the directory of the currently
131 // processed file or a absolute path depending on the paths given as the
132 // include search paths).
134 // The include_depth parameter contains the current include file depth.
136 // The is_system_include parameter denotes, whether the given file was
137 // found as a result of a #include <...> directive.
139 ///////////////////////////////////////////////////////////////////////////
141 opened_include_file(std::string const &relname, std::string const &absname,
142 std::size_t include_depth, bool is_system_include)
145 ///////////////////////////////////////////////////////////////////////////
147 // The function 'returning_from_include_file' is called, whenever an
148 // included file is about to be closed after it's processing is complete.
150 ///////////////////////////////////////////////////////////////////////////
152 returning_from_include_file()
155 ///////////////////////////////////////////////////////////////////////////
157 // The function 'interpret_pragma' is called, whenever a #pragma command
158 // directive is found which isn't known to the core Wave library, where
159 // command is the value defined as the BOOST_WAVE_PRAGMA_KEYWORD constant
160 // which defaults to "wave".
162 // The parameter 'ctx' is a reference to the context object used for
163 // instantiating the preprocessing iterators by the user.
165 // The parameter 'pending' may be used to push tokens back into the input
166 // stream, which are to be used as the replacement text for the whole
167 // #pragma directive.
169 // The parameter 'option' contains the name of the interpreted pragma.
171 // The parameter 'values' holds the values of the parameter provided to
172 // the pragma operator.
174 // The parameter 'act_token' contains the actual #pragma token, which may
175 // be used for error output.
177 // If the return value is 'false', the whole #pragma directive is
178 // interpreted as unknown and a corresponding error message is issued. A
179 // return value of 'true' signs a successful interpretation of the given
182 ///////////////////////////////////////////////////////////////////////////
183 template <typename ContextT, typename ContainerT>
185 interpret_pragma(ContextT const &ctx, ContainerT &pending,
186 typename ContextT::token_type const &option, ContainerT const &values,
187 typename ContextT::token_type const &act_token)
192 ///////////////////////////////////////////////////////////////////////////
194 // The function 'defined_macro' is called, whenever a macro was defined
197 // The parameter 'name' is a reference to the token holding the macro name.
199 // The parameter 'is_functionlike' is set to true, whenever the newly
200 // defined macro is defined as a function like macro.
202 // The parameter 'parameters' holds the parameter tokens for the macro
203 // definition. If the macro has no parameters or if it is a object like
204 // macro, then this container is empty.
206 // The parameter 'definition' contains the token sequence given as the
207 // replacement sequence (definition part) of the newly defined macro.
209 // The parameter 'is_predefined' is set to true for all macros predefined
210 // during the initialisation phase of the library.
212 ///////////////////////////////////////////////////////////////////////////
213 template <typename TokenT, typename ParametersT, typename DefinitionT>
215 defined_macro(TokenT const ¯o_name, bool is_functionlike,
216 ParametersT const ¶meters, DefinitionT const &definition,
220 ///////////////////////////////////////////////////////////////////////////
222 // The function 'undefined_macro' is called, whenever a macro definition
223 // was removed successfully.
225 // The parameter 'name' holds the name of the macro, which definition was
228 ///////////////////////////////////////////////////////////////////////////
229 template <typename TokenT>
231 undefined_macro(TokenT const ¯o_name)
234 ///////////////////////////////////////////////////////////////////////////
236 // The function 'found_directive' is called, whenever a preprocessor
237 // directive was encountered, but before the corresponding action is
240 // The parameter 'directive' is a reference to the token holding the
241 // preprocessing directive.
243 ///////////////////////////////////////////////////////////////////////////
244 template <typename TokenT>
246 found_directive(TokenT const& directive)
249 ///////////////////////////////////////////////////////////////////////////
251 // The function 'evaluated_conditional_expression' is called, whenever a
252 // conditional preprocessing expression was evaluated (the expression
253 // given to a #if, #ifdef or #ifndef directive)
255 // The parameter 'expression' holds the non-expanded token sequence
256 // comprising the evaluated expression.
258 // The parameter expression_value contains the result of the evaluation of
259 // the expression in the current preprocessing context.
261 ///////////////////////////////////////////////////////////////////////////
262 template <typename ContainerT>
264 evaluated_conditional_expression(ContainerT const& expression,
265 bool expression_value)
268 ///////////////////////////////////////////////////////////////////////////
270 // The function 'skipped_token' is called, whenever a token is about to be
271 // skipped due to a false preprocessor condition (code fragments to be
272 // skipped inside the not evaluated conditional #if/#else/#endif branches).
274 // The parameter 'token' refers to the token to be skipped.
277 ///////////////////////////////////////////////////////////////////////////
278 template <typename TokenT>
280 skipped_token(TokenT const& token)
283 ///////////////////////////////////////////////////////////////////////////
285 // The function 'may_skip_whitespace' is called, will be called by the
286 // library, whenever a token is about to be returned to the calling
289 // The parameter 'ctx' is a reference to the context object used for
290 // instantiating the preprocessing iterators by the user.
292 // The 'token' parameter holds a reference to the current token. The policy
293 // is free to change this token if needed.
295 // The 'skipped_newline' parameter holds a reference to a boolean value
296 // which should be set to true by the policy function whenever a newline
297 // is going to be skipped.
299 // If the return value is true, the given token is skipped and the
300 // preprocessing continues to the next token. If the return value is
301 // false, the given token is returned to the calling application.
304 // Caution has to be used, because by returning true the policy function
305 // is able to force skipping even significant tokens, not only whitespace.
307 ///////////////////////////////////////////////////////////////////////////
308 template <typename ContextT, typename TokenT>
310 may_skip_whitespace(ContextT const& ctx, TokenT& token, bool& skipped_newline)
314 ///////////////////////////////////////////////////////////////////////////////
315 } // namespace context_policies
319 // the suffix header occurs after all of the code
320 #ifdef BOOST_HAS_ABI_HEADERS
321 #include BOOST_ABI_SUFFIX
324 #endif // !defined(PREPROCESSING_HOOKS_HPP_338DE478_A13C_4B63_9BA9_041C917793B8_INCLUDED)