]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/wave/util/cpp_iterator.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / boost / wave / util / cpp_iterator.hpp
1 /*=============================================================================
2 Boost.Wave: A Standard compliant C++ preprocessor library
3
4 Definition of the preprocessor iterator
5
6 http://www.boost.org/
7
8 Copyright (c) 2001-2012 Hartmut Kaiser. Distributed under the Boost
9 Software License, Version 1.0. (See accompanying file
10 LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
11 =============================================================================*/
12
13 #if !defined(CPP_ITERATOR_HPP_175CA88F_7273_43FA_9039_BCF7459E1F29_INCLUDED)
14 #define CPP_ITERATOR_HPP_175CA88F_7273_43FA_9039_BCF7459E1F29_INCLUDED
15
16 #include <string>
17 #include <vector>
18 #include <list>
19 #include <cstdlib>
20 #include <cctype>
21
22 #include <boost/assert.hpp>
23 #include <boost/shared_ptr.hpp>
24 #include <boost/filesystem/path.hpp>
25 #include <boost/filesystem/operations.hpp>
26 #include <boost/spirit/include/classic_multi_pass.hpp>
27 #include <boost/spirit/include/classic_parse_tree_utils.hpp>
28
29 #include <boost/wave/wave_config.hpp>
30 #include <boost/pool/pool_alloc.hpp>
31
32 #include <boost/wave/util/insert_whitespace_detection.hpp>
33 #include <boost/wave/util/macro_helpers.hpp>
34 #include <boost/wave/util/cpp_macromap_utils.hpp>
35 #include <boost/wave/util/interpret_pragma.hpp>
36 #include <boost/wave/util/transform_iterator.hpp>
37 #include <boost/wave/util/functor_input.hpp>
38 #include <boost/wave/util/filesystem_compatibility.hpp>
39
40 #include <boost/wave/grammars/cpp_grammar_gen.hpp>
41 #include <boost/wave/grammars/cpp_expression_grammar_gen.hpp>
42 #if BOOST_WAVE_ENABLE_COMMANDLINE_MACROS != 0
43 #include <boost/wave/grammars/cpp_predef_macros_gen.hpp>
44 #endif
45
46 #include <boost/wave/whitespace_handling.hpp>
47 #include <boost/wave/cpp_iteration_context.hpp>
48 #include <boost/wave/cpp_exceptions.hpp>
49 #include <boost/wave/language_support.hpp>
50
51 // this must occur after all of the includes and before any code appears
52 #ifdef BOOST_HAS_ABI_HEADERS
53 #include BOOST_ABI_PREFIX
54 #endif
55
56 ///////////////////////////////////////////////////////////////////////////////
57 namespace boost {
58 namespace wave {
59 namespace util {
60
61 ///////////////////////////////////////////////////////////////////////////////
62 // retrieve the macro name from the parse tree
63 template <
64 typename ContextT, typename ParseNodeT, typename TokenT,
65 typename PositionT
66 >
67 inline bool
68 retrieve_macroname(ContextT& ctx, ParseNodeT const &node,
69 boost::spirit::classic::parser_id id, TokenT &macroname, PositionT& act_pos,
70 bool update_position)
71 {
72 ParseNodeT const *name_node = 0;
73
74 using boost::spirit::classic::find_node;
75 if (!find_node(node, id, &name_node))
76 {
77 // ill formed define statement (unexpected, should not happen)
78 BOOST_WAVE_THROW_CTX(ctx, preprocess_exception, bad_define_statement,
79 "bad parse tree (unexpected)", act_pos);
80 return false;
81 }
82
83 typename ParseNodeT::children_t const &children = name_node->children;
84
85 if (0 == children.size() ||
86 children.front().value.begin() == children.front().value.end())
87 {
88 // ill formed define statement (unexpected, should not happen)
89 BOOST_WAVE_THROW_CTX(ctx, preprocess_exception, bad_define_statement,
90 "bad parse tree (unexpected)", act_pos);
91 return false;
92 }
93
94 // retrieve the macro name
95 macroname = *children.front().value.begin();
96 if (update_position) {
97 macroname.set_position(act_pos);
98 act_pos.set_column(act_pos.get_column() + macroname.get_value().size());
99 }
100 return true;
101 }
102
103 ///////////////////////////////////////////////////////////////////////////////
104 // retrieve the macro parameters or the macro definition from the parse tree
105 template <typename ParseNodeT, typename ContainerT, typename PositionT>
106 inline bool
107 retrieve_macrodefinition(
108 ParseNodeT const &node, boost::spirit::classic::parser_id id,
109 ContainerT &macrodefinition, PositionT& act_pos, bool update_position)
110 {
111 using namespace boost::wave;
112 typedef typename ParseNodeT::const_tree_iterator const_tree_iterator;
113
114 // find macro parameters/macro definition inside the parse tree
115 std::pair<const_tree_iterator, const_tree_iterator> nodes;
116
117 using boost::spirit::classic::get_node_range;
118 if (get_node_range(node, id, nodes)) {
119 // copy all parameters to the supplied container
120 typename ContainerT::iterator last_nonwhite = macrodefinition.end();
121 const_tree_iterator end = nodes.second;
122
123 for (const_tree_iterator cit = nodes.first; cit != end; ++cit) {
124 if ((*cit).value.begin() != (*cit).value.end()) {
125 typename ContainerT::iterator inserted = macrodefinition.insert(
126 macrodefinition.end(), *(*cit).value.begin());
127
128 if (!IS_CATEGORY(macrodefinition.back(), WhiteSpaceTokenType) &&
129 T_NEWLINE != token_id(macrodefinition.back()) &&
130 T_EOF != token_id(macrodefinition.back()))
131 {
132 last_nonwhite = inserted;
133 }
134
135 if (update_position) {
136 (*inserted).set_position(act_pos);
137 act_pos.set_column(
138 act_pos.get_column() + (*inserted).get_value().size());
139 }
140 }
141 }
142
143 // trim trailing whitespace (leading whitespace is trimmed by the grammar)
144 if (last_nonwhite != macrodefinition.end()) {
145 if (update_position) {
146 act_pos.set_column((*last_nonwhite).get_position().get_column() +
147 (*last_nonwhite).get_value().size());
148 }
149 macrodefinition.erase(++last_nonwhite, macrodefinition.end());
150 }
151 return true;
152 }
153 return false;
154 }
155
156 #if BOOST_WAVE_ENABLE_COMMANDLINE_MACROS != 0
157 ///////////////////////////////////////////////////////////////////////////////
158 // add an additional predefined macro given by a string (MACRO(x)=definition)
159 template <typename ContextT>
160 bool add_macro_definition(ContextT &ctx, std::string macrostring,
161 bool is_predefined, boost::wave::language_support language)
162 {
163 typedef typename ContextT::token_type token_type;
164 typedef typename ContextT::lexer_type lexer_type;
165 typedef typename token_type::position_type position_type;
166 typedef boost::wave::grammars::predefined_macros_grammar_gen<lexer_type>
167 predef_macros_type;
168
169 using namespace boost::wave;
170 using namespace std; // isspace is in std namespace for some systems
171
172 // skip leading whitespace
173 std::string::iterator begin = macrostring.begin();
174 std::string::iterator end = macrostring.end();
175
176 while(begin != end && isspace(*begin))
177 ++begin;
178
179 // parse the macro definition
180 position_type act_pos("<command line>");
181 boost::spirit::classic::tree_parse_info<lexer_type> hit =
182 predef_macros_type::parse_predefined_macro(
183 lexer_type(begin, end, position_type(), language), lexer_type());
184
185 if (!hit.match || (!hit.full && T_EOF != token_id(*hit.stop))) {
186 BOOST_WAVE_THROW_CTX(ctx, preprocess_exception, bad_macro_definition,
187 macrostring.c_str(), act_pos);
188 return false;
189 }
190
191 // retrieve the macro definition from the parse tree
192 token_type macroname;
193 std::vector<token_type> macroparameters;
194 typename ContextT::token_sequence_type macrodefinition;
195 bool has_parameters = false;
196
197 if (!boost::wave::util::retrieve_macroname(ctx, *hit.trees.begin(),
198 BOOST_WAVE_PLAIN_DEFINE_ID, macroname, act_pos, true))
199 return false;
200 has_parameters = boost::wave::util::retrieve_macrodefinition(*hit.trees.begin(),
201 BOOST_WAVE_MACRO_PARAMETERS_ID, macroparameters, act_pos, true);
202 boost::wave::util::retrieve_macrodefinition(*hit.trees.begin(),
203 BOOST_WAVE_MACRO_DEFINITION_ID, macrodefinition, act_pos, true);
204
205 // get rid of trailing T_EOF
206 if (!macrodefinition.empty() && token_id(macrodefinition.back()) == T_EOF)
207 macrodefinition.pop_back();
208
209 // If no macrodefinition is given, and the macro string does not end with a
210 // '=', then the macro should be defined with the value '1'
211 if (macrodefinition.empty() && '=' != macrostring[macrostring.size()-1])
212 macrodefinition.push_back(token_type(T_INTLIT, "1", act_pos));
213
214 // add the new macro to the macromap
215 return ctx.add_macro_definition(macroname, has_parameters, macroparameters,
216 macrodefinition, is_predefined);
217 }
218 #endif // BOOST_WAVE_ENABLE_COMMANDLINE_MACROS != 0
219
220 ///////////////////////////////////////////////////////////////////////////////
221 } // namespace util
222
223 ///////////////////////////////////////////////////////////////////////////////
224 // forward declaration
225 template <typename ContextT> class pp_iterator;
226
227 namespace impl {
228
229 ///////////////////////////////////////////////////////////////////////////////
230 //
231 // pp_iterator_functor
232 //
233 ///////////////////////////////////////////////////////////////////////////////
234 template <typename ContextT>
235 class pp_iterator_functor {
236
237 public:
238 // interface to the boost::spirit::classic::iterator_policies::functor_input policy
239 typedef typename ContextT::token_type result_type;
240
241 // eof token
242 static result_type const eof;
243
244 private:
245 // type of a token sequence
246 typedef typename ContextT::token_sequence_type token_sequence_type;
247
248 typedef typename ContextT::lexer_type lexer_type;
249 typedef typename result_type::string_type string_type;
250 typedef typename result_type::position_type position_type;
251 typedef boost::wave::grammars::cpp_grammar_gen<lexer_type, token_sequence_type>
252 cpp_grammar_type;
253
254 // iteration context related types (an iteration context represents a current
255 // position in an included file)
256 typedef base_iteration_context<ContextT, lexer_type>
257 base_iteration_context_type;
258 typedef iteration_context<ContextT, lexer_type> iteration_context_type;
259
260 // parse tree related types
261 typedef typename cpp_grammar_type::node_factory_type node_factory_type;
262 typedef boost::spirit::classic::tree_parse_info<lexer_type, node_factory_type>
263 tree_parse_info_type;
264 typedef boost::spirit::classic::tree_match<lexer_type, node_factory_type>
265 parse_tree_match_type;
266 typedef typename parse_tree_match_type::node_t parse_node_type; // tree_node<node_val_data<> >
267 typedef typename parse_tree_match_type::parse_node_t parse_node_value_type; // node_val_data<>
268 typedef typename parse_tree_match_type::container_t parse_tree_type; // parse_node_type::children_t
269
270 public:
271 template <typename IteratorT>
272 pp_iterator_functor(ContextT &ctx_, IteratorT const &first_,
273 IteratorT const &last_, typename ContextT::position_type const &pos_)
274 : ctx(ctx_),
275 iter_ctx(new base_iteration_context_type(ctx,
276 lexer_type(first_, last_, pos_,
277 boost::wave::enable_prefer_pp_numbers(ctx.get_language())),
278 lexer_type(),
279 pos_.get_file().c_str()
280 )),
281 seen_newline(true), skipped_newline(false),
282 must_emit_line_directive(false), act_pos(ctx_.get_main_pos()),
283 whitespace(boost::wave::need_insert_whitespace(ctx.get_language()))
284 {
285 act_pos.set_file(pos_.get_file());
286 #if BOOST_WAVE_SUPPORT_PRAGMA_ONCE != 0
287 ctx_.set_current_filename(pos_.get_file().c_str());
288 #endif
289 iter_ctx->emitted_lines = (unsigned int)(-1); // force #line directive
290 }
291
292 // get the next preprocessed token
293 result_type const &operator()();
294
295 // get the last recognized token (for error processing etc.)
296 result_type const &current_token() const { return act_token; }
297
298 protected:
299 friend class pp_iterator<ContextT>;
300 bool on_include_helper(char const *t, char const *s, bool is_system,
301 bool include_next);
302
303 protected:
304 result_type const &get_next_token();
305 result_type const &pp_token();
306
307 template <typename IteratorT>
308 bool extract_identifier(IteratorT &it);
309 template <typename IteratorT>
310 bool ensure_is_last_on_line(IteratorT& it, bool call_hook = true);
311 template <typename IteratorT>
312 bool skip_to_eol_with_check(IteratorT &it, bool call_hook = true);
313
314 bool pp_directive();
315 template <typename IteratorT>
316 bool handle_pp_directive(IteratorT &it);
317 bool dispatch_directive(tree_parse_info_type const &hit,
318 result_type const& found_directive,
319 token_sequence_type const& found_eoltokens);
320 void replace_undefined_identifiers(token_sequence_type &expanded);
321
322 void on_include(string_type const &s, bool is_system, bool include_next);
323 void on_include(typename parse_tree_type::const_iterator const &begin,
324 typename parse_tree_type::const_iterator const &end, bool include_next);
325
326 void on_define(parse_node_type const &node);
327 void on_undefine(lexer_type const &it);
328
329 void on_ifdef(result_type const& found_directive, lexer_type const &it);
330 // typename parse_tree_type::const_iterator const &end);
331 void on_ifndef(result_type const& found_directive, lexer_type const& it);
332 // typename parse_tree_type::const_iterator const &end);
333 void on_else();
334 void on_endif();
335 void on_illformed(typename result_type::string_type s);
336
337 void on_line(typename parse_tree_type::const_iterator const &begin,
338 typename parse_tree_type::const_iterator const &end);
339 void on_if(result_type const& found_directive,
340 typename parse_tree_type::const_iterator const &begin,
341 typename parse_tree_type::const_iterator const &end);
342 void on_elif(result_type const& found_directive,
343 typename parse_tree_type::const_iterator const &begin,
344 typename parse_tree_type::const_iterator const &end);
345 void on_error(typename parse_tree_type::const_iterator const &begin,
346 typename parse_tree_type::const_iterator const &end);
347 #if BOOST_WAVE_SUPPORT_WARNING_DIRECTIVE != 0
348 void on_warning(typename parse_tree_type::const_iterator const &begin,
349 typename parse_tree_type::const_iterator const &end);
350 #endif
351 bool on_pragma(typename parse_tree_type::const_iterator const &begin,
352 typename parse_tree_type::const_iterator const &end);
353
354 bool emit_line_directive();
355 bool returned_from_include();
356
357 bool interpret_pragma(token_sequence_type const &pragma_body,
358 token_sequence_type &result);
359
360 private:
361 ContextT &ctx; // context, this iterator is associated with
362 boost::shared_ptr<base_iteration_context_type> iter_ctx;
363
364 bool seen_newline; // needed for recognizing begin of line
365 bool skipped_newline; // a newline has been skipped since last one
366 bool must_emit_line_directive; // must emit a line directive
367 result_type act_token; // current token
368 typename result_type::position_type &act_pos; // current fileposition (references the macromap)
369
370 token_sequence_type unput_queue; // tokens to be preprocessed again
371 token_sequence_type pending_queue; // tokens already preprocessed
372
373 // detect whether to insert additional whitespace in between two adjacent
374 // tokens, which otherwise would form a different token type, if
375 // re-tokenized
376 boost::wave::util::insert_whitespace_detection whitespace;
377 };
378
379 ///////////////////////////////////////////////////////////////////////////////
380 // eof token
381 template <typename ContextT>
382 typename pp_iterator_functor<ContextT>::result_type const
383 pp_iterator_functor<ContextT>::eof;
384
385 ///////////////////////////////////////////////////////////////////////////////
386 //
387 // returned_from_include()
388 //
389 // Tests if it is necessary to pop the include file context (eof inside
390 // a file was reached). If yes, it pops this context. Preprocessing will
391 // continue with the next outer file scope.
392 //
393 ///////////////////////////////////////////////////////////////////////////////
394 template <typename ContextT>
395 inline bool
396 pp_iterator_functor<ContextT>::returned_from_include()
397 {
398 if (iter_ctx->first == iter_ctx->last && ctx.get_iteration_depth() > 0) {
399 // call the include policy trace function
400 #if BOOST_WAVE_USE_DEPRECIATED_PREPROCESSING_HOOKS != 0
401 ctx.get_hooks().returning_from_include_file();
402 #else
403 ctx.get_hooks().returning_from_include_file(ctx.derived());
404 #endif
405
406 // restore the previous iteration context after finishing the preprocessing
407 // of the included file
408 BOOST_WAVE_STRINGTYPE oldfile = iter_ctx->real_filename;
409 position_type old_pos (act_pos);
410
411 // if this file has include guards handle it as if it had a #pragma once
412 #if BOOST_WAVE_SUPPORT_PRAGMA_ONCE != 0
413 if (need_include_guard_detection(ctx.get_language())) {
414 std::string guard_name;
415 if (iter_ctx->first.has_include_guards(guard_name))
416 ctx.add_pragma_once_header(ctx.get_current_filename(), guard_name);
417 }
418 #endif
419 iter_ctx = ctx.pop_iteration_context();
420
421 must_emit_line_directive = true;
422 iter_ctx->emitted_lines = (unsigned int)(-1); // force #line directive
423 seen_newline = true;
424
425 // restore current file position
426 act_pos.set_file(iter_ctx->filename);
427 act_pos.set_line(iter_ctx->line);
428 act_pos.set_column(0);
429
430 // restore the actual current file and directory
431 #if BOOST_WAVE_SUPPORT_PRAGMA_ONCE != 0
432 namespace fs = boost::filesystem;
433 fs::path rfp(wave::util::create_path(iter_ctx->real_filename.c_str()));
434 std::string real_filename(rfp.string());
435 ctx.set_current_filename(real_filename.c_str());
436 #endif
437 ctx.set_current_directory(iter_ctx->real_filename.c_str());
438 ctx.set_current_relative_filename(iter_ctx->real_relative_filename.c_str());
439
440 // ensure the integrity of the #if/#endif stack
441 // report unbalanced #if/#endif now to make it possible to recover properly
442 if (iter_ctx->if_block_depth != ctx.get_if_block_depth()) {
443 using boost::wave::util::impl::escape_lit;
444 BOOST_WAVE_STRINGTYPE msg(escape_lit(oldfile));
445 BOOST_WAVE_THROW_CTX(ctx, preprocess_exception, unbalanced_if_endif,
446 msg.c_str(), old_pos);
447 }
448 return true;
449 }
450 return false;
451 }
452
453 ///////////////////////////////////////////////////////////////////////////////
454 //
455 // operator()(): get the next preprocessed token
456 //
457 // throws a preprocess_exception, if appropriate
458 //
459 ///////////////////////////////////////////////////////////////////////////////
460 namespace impl {
461
462 // It may be necessary to emit a #line directive either
463 // - when comments need to be preserved: if the current token is not a
464 // whitespace, except comments
465 // - when comments are to be skipped: if the current token is not a
466 // whitespace token.
467 template <typename ContextT>
468 bool consider_emitting_line_directive(ContextT const& ctx, token_id id)
469 {
470 if (need_preserve_comments(ctx.get_language()))
471 {
472 if (!IS_CATEGORY(id, EOLTokenType) && !IS_CATEGORY(id, EOFTokenType))
473 {
474 return true;
475 }
476 }
477 if (!IS_CATEGORY(id, WhiteSpaceTokenType) &&
478 !IS_CATEGORY(id, EOLTokenType) && !IS_CATEGORY(id, EOFTokenType))
479 {
480 return true;
481 }
482 return false;
483 }
484 }
485
486 template <typename ContextT>
487 inline typename pp_iterator_functor<ContextT>::result_type const &
488 pp_iterator_functor<ContextT>::operator()()
489 {
490 using namespace boost::wave;
491
492 // make sure the cwd has been initialized
493 ctx.init_context();
494
495 // loop over skip able whitespace until something significant is found
496 bool was_seen_newline = seen_newline;
497 bool was_skipped_newline = skipped_newline;
498 token_id id = T_UNKNOWN;
499
500 try { // catch lexer exceptions
501 do {
502 if (skipped_newline) {
503 was_skipped_newline = true;
504 skipped_newline = false;
505 }
506
507 // get_next_token assigns result to act_token member
508 get_next_token();
509
510 // if comments shouldn't be preserved replace them with newlines
511 id = token_id(act_token);
512 if (!need_preserve_comments(ctx.get_language()) &&
513 (T_CPPCOMMENT == id || context_policies::util::ccomment_has_newline(act_token)))
514 {
515 act_token.set_token_id(id = T_NEWLINE);
516 act_token.set_value("\n");
517 }
518
519 if (IS_CATEGORY(id, EOLTokenType))
520 seen_newline = true;
521
522 } while (ctx.get_hooks().may_skip_whitespace(ctx.derived(), act_token, skipped_newline));
523 }
524 catch (boost::wave::cpplexer::lexing_exception const& e) {
525 // dispatch any lexer exceptions to the context hook function
526 ctx.get_hooks().throw_exception(ctx.derived(), e);
527 return act_token;
528 }
529
530 // restore the accumulated skipped_newline state for next invocation
531 if (was_skipped_newline)
532 skipped_newline = true;
533
534 // if there were skipped any newlines, we must emit a #line directive
535 if ((must_emit_line_directive || (was_seen_newline && skipped_newline)) &&
536 impl::consider_emitting_line_directive(ctx, id))
537 {
538 // must emit a #line directive
539 if (need_emit_line_directives(ctx.get_language()) && emit_line_directive())
540 {
541 skipped_newline = false;
542 ctx.get_hooks().may_skip_whitespace(ctx.derived(), act_token, skipped_newline); // feed ws eater FSM
543 id = token_id(act_token);
544 }
545 }
546
547 // cleanup of certain tokens required
548 seen_newline = false;
549 switch (id) {
550 case T_NONREPLACABLE_IDENTIFIER:
551 act_token.set_token_id(id = T_IDENTIFIER);
552 break;
553
554 case T_GENERATEDNEWLINE: // was generated by emit_line_directive()
555 act_token.set_token_id(id = T_NEWLINE);
556 ++iter_ctx->emitted_lines;
557 seen_newline = true;
558 break;
559
560 case T_NEWLINE:
561 case T_CPPCOMMENT:
562 seen_newline = true;
563 ++iter_ctx->emitted_lines;
564 break;
565
566 #if BOOST_WAVE_SUPPORT_CPP0X != 0
567 case T_RAWSTRINGLIT:
568 iter_ctx->emitted_lines +=
569 context_policies::util::rawstring_count_newlines(act_token);
570 break;
571 #endif
572
573 case T_CCOMMENT: // will come here only if whitespace is preserved
574 iter_ctx->emitted_lines +=
575 context_policies::util::ccomment_count_newlines(act_token);
576 break;
577
578 case T_PP_NUMBER: // re-tokenize the pp-number
579 {
580 token_sequence_type rescanned;
581
582 std::string pp_number(
583 util::to_string<std::string>(act_token.get_value()));
584
585 lexer_type it = lexer_type(pp_number.begin(),
586 pp_number.end(), act_token.get_position(),
587 ctx.get_language());
588 lexer_type end = lexer_type();
589
590 for (/**/; it != end && T_EOF != token_id(*it); ++it)
591 rescanned.push_back(*it);
592
593 pending_queue.splice(pending_queue.begin(), rescanned);
594 act_token = pending_queue.front();
595 id = token_id(act_token);
596 pending_queue.pop_front();
597 }
598 break;
599
600 case T_EOF:
601 seen_newline = true;
602 break;
603
604 default: // make sure whitespace at line begin keeps seen_newline status
605 if (IS_CATEGORY(id, WhiteSpaceTokenType))
606 seen_newline = was_seen_newline;
607 break;
608 }
609
610 if (token_is_valid(act_token) && whitespace.must_insert(id, act_token.get_value())) {
611 // must insert some whitespace into the output stream to avoid adjacent
612 // tokens, which would form different (and wrong) tokens
613 whitespace.shift_tokens(T_SPACE);
614 pending_queue.push_front(act_token); // push this token back
615 return act_token = result_type(T_SPACE,
616 typename result_type::string_type(" "),
617 act_token.get_position());
618 }
619 whitespace.shift_tokens(id);
620 return ctx.get_hooks().generated_token(ctx.derived(), act_token);
621 }
622
623 ///////////////////////////////////////////////////////////////////////////////
624 template <typename ContextT>
625 inline typename pp_iterator_functor<ContextT>::result_type const &
626 pp_iterator_functor<ContextT>::get_next_token()
627 {
628 using namespace boost::wave;
629
630 // if there is something in the unput_queue, then return the next token from
631 // there (all tokens in the queue are preprocessed already)
632 if (!pending_queue.empty() || !unput_queue.empty())
633 return pp_token(); // return next token
634
635 // test for EOF, if there is a pending input context, pop it back and continue
636 // parsing with it
637 bool returned_from_include_file = returned_from_include();
638
639 // try to generate the next token
640 if (iter_ctx->first != iter_ctx->last) {
641 do {
642 // If there are pending tokens in the queue, we'll have to return
643 // these. This may happen from a #pragma directive, which got replaced
644 // by some token sequence.
645 if (!pending_queue.empty()) {
646 util::on_exit::pop_front<token_sequence_type>
647 pop_front_token(pending_queue);
648
649 return act_token = pending_queue.front();
650 }
651
652 // adjust the current position (line and column)
653 bool was_seen_newline = seen_newline || returned_from_include_file;
654
655 // fetch the current token
656 act_token = *iter_ctx->first;
657 act_pos = act_token.get_position();
658
659 // act accordingly on the current token
660 token_id id = token_id(act_token);
661
662 if (T_EOF == id) {
663 // returned from an include file, continue with the next token
664 whitespace.shift_tokens(T_EOF);
665 ++iter_ctx->first;
666
667 // now make sure this line has a newline
668 if ((!seen_newline || act_pos.get_column() > 1) &&
669 !need_single_line(ctx.get_language()))
670 {
671 if (need_no_newline_at_end_of_file(ctx.get_language()))
672 {
673 seen_newline = true;
674 pending_queue.push_back(
675 result_type(T_NEWLINE, "\n", act_pos)
676 );
677 }
678 else
679 {
680 // warn, if this file does not end with a newline
681 BOOST_WAVE_THROW_CTX(ctx, preprocess_exception,
682 last_line_not_terminated, "", act_pos);
683 }
684 }
685 continue; // if this is the main file, the while loop breaks
686 }
687 else if (T_NEWLINE == id || T_CPPCOMMENT == id) {
688 // a newline is to be returned ASAP, a C++ comment too
689 // (the C++ comment token includes the trailing newline)
690 seen_newline = true;
691 ++iter_ctx->first;
692
693 if (!ctx.get_if_block_status()) {
694 // skip this token because of the disabled #if block
695 whitespace.shift_tokens(id); // whitespace controller
696 util::impl::call_skipped_token_hook(ctx, act_token);
697 continue;
698 }
699 return act_token;
700 }
701 seen_newline = false;
702
703 if (was_seen_newline && pp_directive()) {
704 // a pp directive was found
705 // pending_queue.push_back(result_type(T_NEWLINE, "\n", act_pos));
706 // seen_newline = true;
707 // must_emit_line_directive = true;
708 if (iter_ctx->first == iter_ctx->last)
709 {
710 seen_newline = true;
711 act_token = result_type(T_NEWLINE, "\n", act_pos);
712 }
713
714 // loop to the next token to analyze
715 // simply fall through, since the iterator was already adjusted
716 // correctly
717 }
718 else if (ctx.get_if_block_status()) {
719 // preprocess this token, eat up more, if appropriate, return
720 // the next preprocessed token
721 return pp_token();
722 }
723 else {
724 // compilation condition is false: if the current token is a
725 // newline, account for it, otherwise discard the actual token and
726 // try the next one
727 if (T_NEWLINE == token_id(act_token)) {
728 seen_newline = true;
729 must_emit_line_directive = true;
730 }
731
732 // next token
733 util::impl::call_skipped_token_hook(ctx, act_token);
734 ++iter_ctx->first;
735 }
736
737 } while ((iter_ctx->first != iter_ctx->last) ||
738 (returned_from_include_file = returned_from_include()));
739
740 // overall eof reached
741 if (ctx.get_if_block_depth() > 0 && !need_single_line(ctx.get_language()))
742 {
743 // missing endif directive(s)
744 BOOST_WAVE_THROW_CTX(ctx, preprocess_exception,
745 missing_matching_endif, "", act_pos);
746 }
747 }
748 else {
749 act_token = eof; // this is the last token
750 }
751
752 // whitespace.shift_tokens(T_EOF); // whitespace controller
753 return act_token; // return eof token
754 }
755
756 ///////////////////////////////////////////////////////////////////////////////
757 //
758 // emit_line_directive(): emits a line directive from the act_token data
759 //
760 ///////////////////////////////////////////////////////////////////////////////
761 template <typename ContextT>
762 inline bool
763 pp_iterator_functor<ContextT>::emit_line_directive()
764 {
765 using namespace boost::wave;
766
767 typename ContextT::position_type pos = act_token.get_position();
768
769 // if (must_emit_line_directive &&
770 // iter_ctx->emitted_lines+1 == act_pos.get_line() &&
771 // iter_ctx->filename == act_pos.get_file())
772 // {
773 // must_emit_line_directive = false;
774 // return false;
775 // }
776
777 if (must_emit_line_directive ||
778 iter_ctx->emitted_lines+1 != act_pos.get_line())
779 {
780 // unput the current token
781 pending_queue.push_front(act_token);
782 pos.set_line(act_pos.get_line());
783
784 if (iter_ctx->emitted_lines+2 == act_pos.get_line() && act_pos.get_line() != 1) {
785 // prefer to output a single newline instead of the #line directive
786 // whitespace.shift_tokens(T_NEWLINE);
787 act_token = result_type(T_NEWLINE, "\n", pos);
788 }
789 else {
790 // account for the newline emitted here
791 act_pos.set_line(act_pos.get_line()-1);
792 iter_ctx->emitted_lines = act_pos.get_line()-1;
793
794 token_sequence_type pending;
795
796 if (!ctx.get_hooks().emit_line_directive(ctx, pending, act_token))
797 {
798 unsigned int column = 6;
799
800 // the hook did not generate anything, emit default #line
801 pos.set_column(1);
802 pending.push_back(result_type(T_PP_LINE, "#line", pos));
803
804 pos.set_column(column); // account for '#line'
805 pending.push_back(result_type(T_SPACE, " ", pos));
806
807 // 21 is the max required size for a 64 bit integer represented as a
808 // string
809 char buffer[22];
810
811 using namespace std; // for some systems sprintf is in namespace std
812 sprintf (buffer, "%zd", pos.get_line());
813
814 pos.set_column(++column); // account for ' '
815 pending.push_back(result_type(T_INTLIT, buffer, pos));
816 pos.set_column(column += (unsigned int)strlen(buffer)); // account for <number>
817 pending.push_back(result_type(T_SPACE, " ", pos));
818 pos.set_column(++column); // account for ' '
819
820 std::string file("\"");
821 boost::filesystem::path filename(
822 wave::util::create_path(act_pos.get_file().c_str()));
823
824 using wave::util::impl::escape_lit;
825 file += escape_lit(wave::util::native_file_string(filename)) + "\"";
826
827 pending.push_back(result_type(T_STRINGLIT, file.c_str(), pos));
828 pos.set_column(column += (unsigned int)file.size()); // account for filename
829 pending.push_back(result_type(T_GENERATEDNEWLINE, "\n", pos));
830 }
831
832 // if there is some replacement text, insert it into the pending queue
833 if (!pending.empty()) {
834 pending_queue.splice(pending_queue.begin(), pending);
835 act_token = pending_queue.front();
836 pending_queue.pop_front();
837 }
838 }
839
840 must_emit_line_directive = false; // we are now in sync
841 return true;
842 }
843
844 must_emit_line_directive = false; // we are now in sync
845 return false;
846 }
847
848 ///////////////////////////////////////////////////////////////////////////////
849 //
850 // pptoken(): return the next preprocessed token
851 //
852 ///////////////////////////////////////////////////////////////////////////////
853 template <typename ContextT>
854 inline typename pp_iterator_functor<ContextT>::result_type const &
855 pp_iterator_functor<ContextT>::pp_token()
856 {
857 using namespace boost::wave;
858
859 token_id id = token_id(*iter_ctx->first);
860
861 // eat all T_PLACEHOLDER tokens, eventually slipped through out of the
862 // macro engine
863 do {
864 if (!pending_queue.empty()) {
865 // if there are pending tokens in the queue, return the first one
866 act_token = pending_queue.front();
867 pending_queue.pop_front();
868 act_pos = act_token.get_position();
869 }
870 else if (!unput_queue.empty()
871 || T_IDENTIFIER == id
872 || IS_CATEGORY(id, KeywordTokenType)
873 || IS_EXTCATEGORY(id, OperatorTokenType|AltExtTokenType)
874 || IS_CATEGORY(id, BoolLiteralTokenType))
875 {
876 // call the lexer, preprocess the required number of tokens, put them
877 // into the unput queue
878 act_token = ctx.expand_tokensequence(iter_ctx->first,
879 iter_ctx->last, pending_queue, unput_queue, skipped_newline);
880 }
881 else {
882 // simply return the next token
883 act_token = *iter_ctx->first;
884 ++iter_ctx->first;
885 }
886 id = token_id(act_token);
887
888 } while (T_PLACEHOLDER == id);
889 return act_token;
890 }
891
892 ///////////////////////////////////////////////////////////////////////////////
893 //
894 // pp_directive(): recognize a preprocessor directive
895 //
896 ///////////////////////////////////////////////////////////////////////////////
897 namespace impl {
898
899 // call 'found_directive' preprocessing hook
900 template <typename ContextT>
901 bool call_found_directive_hook(ContextT& ctx,
902 typename ContextT::token_type const& found_directive)
903 {
904 #if BOOST_WAVE_USE_DEPRECIATED_PREPROCESSING_HOOKS != 0
905 ctx.get_hooks().found_directive(found_directive);
906 #else
907 if (ctx.get_hooks().found_directive(ctx.derived(), found_directive))
908 return true; // skip this directive and return newline only
909 #endif
910 return false;
911 }
912
913 // // call 'skipped_token' preprocessing hook
914 // template <typename ContextT>
915 // void call_skipped_token_hook(ContextT& ctx,
916 // typename ContextT::token_type const& skipped)
917 // {
918 // #if BOOST_WAVE_USE_DEPRECIATED_PREPROCESSING_HOOKS != 0
919 // ctx.get_hooks().skipped_token(skipped);
920 // #else
921 // ctx.get_hooks().skipped_token(ctx.derived(), skipped);
922 // #endif
923 // }
924
925 template <typename ContextT, typename IteratorT>
926 bool next_token_is_pp_directive(ContextT &ctx, IteratorT &it, IteratorT const &end)
927 {
928 using namespace boost::wave;
929
930 token_id id = T_UNKNOWN;
931 for (/**/; it != end; ++it) {
932 id = token_id(*it);
933 if (!IS_CATEGORY(id, WhiteSpaceTokenType))
934 break; // skip leading whitespace
935 if (IS_CATEGORY(id, EOLTokenType) || IS_CATEGORY(id, EOFTokenType))
936 break; // do not enter a new line
937 if (T_CPPCOMMENT == id ||
938 context_policies::util::ccomment_has_newline(*it))
939 {
940 break;
941 }
942
943 // this token gets skipped
944 util::impl::call_skipped_token_hook(ctx, *it);
945 }
946 BOOST_ASSERT(it == end || id != T_UNKNOWN);
947 return it != end && IS_CATEGORY(id, PPTokenType);
948 }
949
950 // verify that there isn't anything significant left on the line
951 template <typename ContextT, typename IteratorT>
952 bool pp_is_last_on_line(ContextT &ctx, IteratorT &it, IteratorT const &end,
953 bool call_hook = true)
954 {
955 using namespace boost::wave;
956
957 // this token gets skipped
958 if (call_hook)
959 util::impl::call_skipped_token_hook(ctx, *it);
960
961 for (++it; it != end; ++it) {
962 token_id id = token_id(*it);
963
964 if (T_CPPCOMMENT == id || T_NEWLINE == id ||
965 context_policies::util::ccomment_has_newline(*it))
966 {
967 if (call_hook)
968 util::impl::call_skipped_token_hook(ctx, *it);
969 ++it; // skip eol/C/C++ comment
970 return true; // no more significant tokens on this line
971 }
972
973 if (!IS_CATEGORY(id, WhiteSpaceTokenType))
974 break;
975
976 // this token gets skipped
977 if (call_hook)
978 util::impl::call_skipped_token_hook(ctx, *it);
979 }
980 return need_no_newline_at_end_of_file(ctx.get_language());
981 }
982
983 ///////////////////////////////////////////////////////////////////////////
984 template <typename ContextT, typename IteratorT>
985 bool skip_to_eol(ContextT &ctx, IteratorT &it, IteratorT const &end,
986 bool call_hook = true)
987 {
988 using namespace boost::wave;
989
990 for (/**/; it != end; ++it) {
991 token_id id = token_id(*it);
992
993 if (T_CPPCOMMENT == id || T_NEWLINE == id ||
994 context_policies::util::ccomment_has_newline(*it))
995 {
996 // always call hook for eol
997 util::impl::call_skipped_token_hook(ctx, *it);
998 ++it; // skip eol/C/C++ comment
999 return true; // found eol
1000 }
1001
1002 if (call_hook)
1003 util::impl::call_skipped_token_hook(ctx, *it);
1004 }
1005 return false;
1006 }
1007
1008 ///////////////////////////////////////////////////////////////////////////
1009 template <typename ContextT, typename ContainerT>
1010 inline void
1011 remove_leading_whitespace(ContextT &ctx, ContainerT& c, bool call_hook = true)
1012 {
1013 typename ContainerT::iterator it = c.begin();
1014 while (IS_CATEGORY(*it, WhiteSpaceTokenType)) {
1015 typename ContainerT::iterator save = it++;
1016 if (call_hook)
1017 util::impl::call_skipped_token_hook(ctx, *save);
1018 c.erase(save);
1019 }
1020 }
1021 }
1022
1023 ///////////////////////////////////////////////////////////////////////////////
1024 template <typename ContextT>
1025 template <typename IteratorT>
1026 inline bool
1027 pp_iterator_functor<ContextT>::extract_identifier(IteratorT &it)
1028 {
1029 token_id id = util::impl::skip_whitespace(it, iter_ctx->last);
1030 if (T_IDENTIFIER == id || IS_CATEGORY(id, KeywordTokenType) ||
1031 IS_EXTCATEGORY(id, OperatorTokenType|AltExtTokenType) ||
1032 IS_CATEGORY(id, BoolLiteralTokenType))
1033 {
1034 IteratorT save = it;
1035 if (impl::pp_is_last_on_line(ctx, save, iter_ctx->last, false))
1036 return true;
1037 }
1038
1039 // report the ill formed directive
1040 impl::skip_to_eol(ctx, it, iter_ctx->last);
1041
1042 string_type str(util::impl::as_string<string_type>(iter_ctx->first, it));
1043
1044 seen_newline = true;
1045 iter_ctx->first = it;
1046 on_illformed(str);
1047 return false;
1048 }
1049
1050 ///////////////////////////////////////////////////////////////////////////////
1051 template <typename ContextT>
1052 template <typename IteratorT>
1053 inline bool
1054 pp_iterator_functor<ContextT>::ensure_is_last_on_line(IteratorT& it, bool call_hook)
1055 {
1056 if (!impl::pp_is_last_on_line(ctx, it, iter_ctx->last, call_hook))
1057 {
1058 // enable error recovery (start over with the next line)
1059 impl::skip_to_eol(ctx, it, iter_ctx->last);
1060
1061 string_type str(util::impl::as_string<string_type>(
1062 iter_ctx->first, it));
1063
1064 seen_newline = true;
1065 iter_ctx->first = it;
1066
1067 // report an invalid directive
1068 on_illformed(str);
1069 return false;
1070 }
1071
1072 if (it == iter_ctx->last && !need_single_line(ctx.get_language()))
1073 {
1074 // The line doesn't end with an eol but eof token.
1075 seen_newline = true; // allow to resume after warning
1076 iter_ctx->first = it;
1077
1078 if (!need_no_newline_at_end_of_file(ctx.get_language()))
1079 {
1080 // Trigger a warning that the last line was not terminated with a
1081 // newline.
1082 BOOST_WAVE_THROW_CTX(ctx, preprocess_exception,
1083 last_line_not_terminated, "", act_pos);
1084 }
1085
1086 return false;
1087 }
1088 return true;
1089 }
1090
1091 template <typename ContextT>
1092 template <typename IteratorT>
1093 inline bool
1094 pp_iterator_functor<ContextT>::skip_to_eol_with_check(IteratorT &it, bool call_hook)
1095 {
1096 typename ContextT::string_type value ((*it).get_value());
1097 if (!impl::skip_to_eol(ctx, it, iter_ctx->last, call_hook) &&
1098 !need_single_line(ctx.get_language()))
1099 {
1100 // The line doesn't end with an eol but eof token.
1101 seen_newline = true; // allow to resume after warning
1102 iter_ctx->first = it;
1103
1104 if (!need_no_newline_at_end_of_file(ctx.get_language()))
1105 {
1106 // Trigger a warning, that the last line was not terminated with a
1107 // newline.
1108 BOOST_WAVE_THROW_CTX(ctx, preprocess_exception,
1109 last_line_not_terminated, "", act_pos);
1110 }
1111 return false;
1112 }
1113
1114 // normal line ending reached, adjust iterator and flag
1115 seen_newline = true;
1116 iter_ctx->first = it;
1117 return true;
1118 }
1119
1120 ///////////////////////////////////////////////////////////////////////////////
1121 // handle_pp_directive: handle certain pp_directives
1122 template <typename ContextT>
1123 template <typename IteratorT>
1124 inline bool
1125 pp_iterator_functor<ContextT>::handle_pp_directive(IteratorT &it)
1126 {
1127 token_id id = token_id(*it);
1128 bool can_exit = true;
1129 bool call_hook_in_skip = true;
1130 if (!ctx.get_if_block_status()) {
1131 if (IS_EXTCATEGORY(*it, PPConditionalTokenType)) {
1132 // simulate the if block hierarchy
1133 switch (id) {
1134 case T_PP_IFDEF: // #ifdef
1135 case T_PP_IFNDEF: // #ifndef
1136 case T_PP_IF: // #if
1137 ctx.enter_if_block(false);
1138 break;
1139
1140 case T_PP_ELIF: // #elif
1141 if (!ctx.get_enclosing_if_block_status()) {
1142 if (!ctx.enter_elif_block(false)) {
1143 // #else without matching #if
1144 BOOST_WAVE_THROW_CTX(ctx, preprocess_exception,
1145 missing_matching_if, "#elif", act_pos);
1146 return true; // do not analyze this directive any further
1147 }
1148 }
1149 else {
1150 can_exit = false; // #elif is not always safe to skip
1151 }
1152 break;
1153
1154 case T_PP_ELSE: // #else
1155 case T_PP_ENDIF: // #endif
1156 {
1157 // handle this directive
1158 if (T_PP_ELSE == token_id(*it))
1159 on_else();
1160 else
1161 on_endif();
1162
1163 // make sure, there are no (non-whitespace) tokens left on
1164 // this line
1165 ensure_is_last_on_line(it);
1166
1167 // we skipped to the end of this line already
1168 seen_newline = true;
1169 iter_ctx->first = it;
1170 }
1171 return true;
1172
1173 default: // #something else
1174 on_illformed((*it).get_value());
1175 break;
1176 }
1177 }
1178 else {
1179 util::impl::call_skipped_token_hook(ctx, *it);
1180 ++it;
1181 }
1182 }
1183 else {
1184 // try to handle the simple pp directives without parsing
1185 result_type directive = *it;
1186 bool include_next = false;
1187 switch (id) {
1188 case T_PP_QHEADER: // #include "..."
1189 #if BOOST_WAVE_SUPPORT_INCLUDE_NEXT != 0
1190 case T_PP_QHEADER_NEXT:
1191 #endif
1192 include_next = (T_PP_QHEADER_NEXT == id) ? true : false;
1193 if (!impl::call_found_directive_hook(ctx, *it))
1194 {
1195 string_type dir((*it).get_value());
1196
1197 // make sure, there are no (non-whitespace) tokens left on
1198 // this line
1199 if (ensure_is_last_on_line(it))
1200 {
1201 seen_newline = true;
1202 iter_ctx->first = it;
1203 on_include (dir, false, include_next);
1204 }
1205 return true;
1206 }
1207 break;
1208
1209 case T_PP_HHEADER: // #include <...>
1210 #if BOOST_WAVE_SUPPORT_INCLUDE_NEXT != 0
1211 case T_PP_HHEADER_NEXT:
1212 #endif
1213 include_next = (T_PP_HHEADER_NEXT == id) ? true : false;
1214 if (!impl::call_found_directive_hook(ctx, *it))
1215 {
1216 string_type dir((*it).get_value());
1217
1218 // make sure, there are no (non-whitespace) tokens left on
1219 // this line
1220 if (ensure_is_last_on_line(it))
1221 {
1222 seen_newline = true;
1223 iter_ctx->first = it;
1224 on_include (dir, true, include_next);
1225 }
1226 return true;
1227 }
1228 break;
1229
1230 case T_PP_ELSE: // #else
1231 case T_PP_ENDIF: // #endif
1232 if (!impl::call_found_directive_hook(ctx, *it))
1233 {
1234 // handle this directive
1235 if (T_PP_ELSE == token_id(*it))
1236 on_else();
1237 else
1238 on_endif();
1239
1240 // make sure, there are no (non-whitespace) tokens left on
1241 // this line
1242 ensure_is_last_on_line(it);
1243
1244 // we skipped to the end of this line already
1245 seen_newline = true;
1246 iter_ctx->first = it;
1247 return true;
1248 }
1249 break;
1250
1251 // extract everything on this line as arguments
1252 // case T_PP_IF: // #if
1253 // case T_PP_ELIF: // #elif
1254 // case T_PP_ERROR: // #error
1255 // case T_PP_WARNING: // #warning
1256 // case T_PP_PRAGMA: // #pragma
1257 // case T_PP_LINE: // #line
1258 // break;
1259
1260 // extract first non-whitespace token as argument
1261 case T_PP_UNDEF: // #undef
1262 if (!impl::call_found_directive_hook(ctx, *it) &&
1263 extract_identifier(it))
1264 {
1265 on_undefine(it);
1266 }
1267 call_hook_in_skip = false;
1268 break;
1269
1270 case T_PP_IFDEF: // #ifdef
1271 if (!impl::call_found_directive_hook(ctx, *it) &&
1272 extract_identifier(it))
1273 {
1274 on_ifdef(directive, it);
1275 }
1276 call_hook_in_skip = false;
1277 break;
1278
1279 case T_PP_IFNDEF: // #ifndef
1280 if (!impl::call_found_directive_hook(ctx, *it) &&
1281 extract_identifier(it))
1282 {
1283 on_ifndef(directive, it);
1284 }
1285 call_hook_in_skip = false;
1286 break;
1287
1288 #if BOOST_WAVE_SUPPORT_MS_EXTENSIONS != 0
1289 // case T_MSEXT_PP_REGION: // #region ...
1290 // break;
1291 //
1292 // case T_MSEXT_PP_ENDREGION: // #endregion
1293 // break;
1294 #endif
1295
1296 default:
1297 can_exit = false;
1298 break;
1299 }
1300 }
1301
1302 // start over with the next line, if only possible
1303 if (can_exit) {
1304 skip_to_eol_with_check(it, call_hook_in_skip);
1305 return true; // may be safely ignored
1306 }
1307 return false; // do not ignore this pp directive
1308 }
1309
1310 ///////////////////////////////////////////////////////////////////////////////
1311 // pp_directive(): recognize a preprocessor directive
1312 template <typename ContextT>
1313 inline bool
1314 pp_iterator_functor<ContextT>::pp_directive()
1315 {
1316 using namespace cpplexer;
1317
1318 // test, if the next non-whitespace token is a pp directive
1319 lexer_type it = iter_ctx->first;
1320
1321 if (!impl::next_token_is_pp_directive(ctx, it, iter_ctx->last)) {
1322 // skip null pp directive (no need to do it via the parser)
1323 if (it != iter_ctx->last && T_POUND == BASE_TOKEN(token_id(*it))) {
1324 if (impl::pp_is_last_on_line(ctx, it, iter_ctx->last)) {
1325 // start over with the next line
1326 seen_newline = true;
1327 iter_ctx->first = it;
1328 return true;
1329 }
1330 else if (ctx.get_if_block_status()) {
1331 // report invalid pp directive
1332 impl::skip_to_eol(ctx, it, iter_ctx->last);
1333 seen_newline = true;
1334
1335 string_type str(boost::wave::util::impl::as_string<string_type>(
1336 iter_ctx->first, it));
1337
1338 token_sequence_type faulty_line;
1339
1340 for (/**/; iter_ctx->first != it; ++iter_ctx->first)
1341 faulty_line.push_back(*iter_ctx->first);
1342
1343 token_sequence_type pending;
1344 if (ctx.get_hooks().found_unknown_directive(ctx, faulty_line, pending))
1345 {
1346 // if there is some replacement text, insert it into the pending queue
1347 if (!pending.empty())
1348 pending_queue.splice(pending_queue.begin(), pending);
1349 return true;
1350 }
1351
1352 // default behavior is to throw an exception
1353 on_illformed(str);
1354 }
1355 }
1356
1357 // this line does not contain a pp directive, so simply return
1358 return false;
1359 }
1360
1361 // found eof
1362 if (it == iter_ctx->last)
1363 return false;
1364
1365 // ignore/handle all pp directives not related to conditional compilation while
1366 // if block status is false
1367 if (handle_pp_directive(it)) {
1368 // we may skip pp directives only if the current if block status is
1369 // false or if it was a #include directive we could handle directly
1370 return true; // the pp directive has been handled/skipped
1371 }
1372
1373 // found a pp directive, so try to identify it, start with the pp_token
1374 bool found_eof = false;
1375 result_type found_directive;
1376 token_sequence_type found_eoltokens;
1377
1378 tree_parse_info_type hit = cpp_grammar_type::parse_cpp_grammar(
1379 it, iter_ctx->last, act_pos, found_eof, found_directive, found_eoltokens);
1380
1381 if (hit.match) {
1382 // position the iterator past the matched sequence to allow
1383 // resynchronization, if an error occurs
1384 iter_ctx->first = hit.stop;
1385 seen_newline = true;
1386 must_emit_line_directive = true;
1387
1388 // found a valid pp directive, dispatch to the correct function to handle
1389 // the found pp directive
1390 bool result = dispatch_directive (hit, found_directive, found_eoltokens);
1391
1392 if (found_eof && !need_single_line(ctx.get_language()) &&
1393 !need_no_newline_at_end_of_file(ctx.get_language()))
1394 {
1395 // The line was terminated with an end of file token.
1396 // So trigger a warning, that the last line was not terminated with a
1397 // newline.
1398 BOOST_WAVE_THROW_CTX(ctx, preprocess_exception,
1399 last_line_not_terminated, "", act_pos);
1400 }
1401 return result;
1402 }
1403 else if (token_id(found_directive) != T_EOF) {
1404 // recognized invalid directive
1405 impl::skip_to_eol(ctx, it, iter_ctx->last);
1406 seen_newline = true;
1407
1408 string_type str(boost::wave::util::impl::as_string<string_type>(
1409 iter_ctx->first, it));
1410 iter_ctx->first = it;
1411
1412 // report the ill formed directive
1413 on_illformed(str);
1414 }
1415 return false;
1416 }
1417
1418 ///////////////////////////////////////////////////////////////////////////////
1419 //
1420 // dispatch_directive(): dispatch a recognized preprocessor directive
1421 //
1422 ///////////////////////////////////////////////////////////////////////////////
1423 template <typename ContextT>
1424 inline bool
1425 pp_iterator_functor<ContextT>::dispatch_directive(
1426 tree_parse_info_type const &hit, result_type const& found_directive,
1427 token_sequence_type const& found_eoltokens)
1428 {
1429 using namespace cpplexer;
1430
1431 typedef typename parse_tree_type::const_iterator const_child_iterator_t;
1432
1433 // this iterator points to the root node of the parse tree
1434 const_child_iterator_t begin = hit.trees.begin();
1435
1436 // decide, which preprocessor directive was found
1437 parse_tree_type const &root = (*begin).children;
1438 parse_node_value_type const &nodeval = get_first_leaf(*root.begin()).value;
1439 //long node_id = nodeval.id().to_long();
1440
1441 const_child_iterator_t begin_child_it = (*root.begin()).children.begin();
1442 const_child_iterator_t end_child_it = (*root.begin()).children.end();
1443
1444 token_id id = token_id(found_directive);
1445
1446 // call preprocessing hook
1447 if (impl::call_found_directive_hook(ctx, found_directive))
1448 return true; // skip this directive and return newline only
1449
1450 switch (id) {
1451 // case T_PP_QHEADER: // #include "..."
1452 // #if BOOST_WAVE_SUPPORT_INCLUDE_NEXT != 0
1453 // case T_PP_QHEADER_NEXT: // #include_next "..."
1454 // #endif
1455 // on_include ((*nodeval.begin()).get_value(), false,
1456 // T_PP_QHEADER_NEXT == id);
1457 // break;
1458
1459 // case T_PP_HHEADER: // #include <...>
1460 // #if BOOST_WAVE_SUPPORT_INCLUDE_NEXT != 0
1461 // case T_PP_HHEADER_NEXT: // #include_next <...>
1462 // #endif
1463 // on_include ((*nodeval.begin()).get_value(), true,
1464 // T_PP_HHEADER_NEXT == id);
1465 // break;
1466
1467 case T_PP_INCLUDE: // #include ...
1468 #if BOOST_WAVE_SUPPORT_INCLUDE_NEXT != 0
1469 case T_PP_INCLUDE_NEXT: // #include_next ...
1470 #endif
1471 on_include (begin_child_it, end_child_it, T_PP_INCLUDE_NEXT == id);
1472 break;
1473
1474 case T_PP_DEFINE: // #define
1475 on_define (*begin);
1476 break;
1477
1478 // case T_PP_UNDEF: // #undef
1479 // on_undefine(*nodeval.begin());
1480 // break;
1481 //
1482 // case T_PP_IFDEF: // #ifdef
1483 // on_ifdef(found_directive, begin_child_it, end_child_it);
1484 // break;
1485 //
1486 // case T_PP_IFNDEF: // #ifndef
1487 // on_ifndef(found_directive, begin_child_it, end_child_it);
1488 // break;
1489
1490 case T_PP_IF: // #if
1491 on_if(found_directive, begin_child_it, end_child_it);
1492 break;
1493
1494 case T_PP_ELIF: // #elif
1495 on_elif(found_directive, begin_child_it, end_child_it);
1496 break;
1497
1498 // case T_PP_ELSE: // #else
1499 // on_else();
1500 // break;
1501
1502 // case T_PP_ENDIF: // #endif
1503 // on_endif();
1504 // break;
1505
1506 case T_PP_LINE: // #line
1507 on_line(begin_child_it, end_child_it);
1508 break;
1509
1510 case T_PP_ERROR: // #error
1511 on_error(begin_child_it, end_child_it);
1512 break;
1513
1514 #if BOOST_WAVE_SUPPORT_WARNING_DIRECTIVE != 0
1515 case T_PP_WARNING: // #warning
1516 on_warning(begin_child_it, end_child_it);
1517 break;
1518 #endif
1519
1520 case T_PP_PRAGMA: // #pragma
1521 return on_pragma(begin_child_it, end_child_it);
1522
1523 #if BOOST_WAVE_SUPPORT_MS_EXTENSIONS != 0
1524 case T_MSEXT_PP_REGION:
1525 case T_MSEXT_PP_ENDREGION:
1526 break; // ignore these
1527 #endif
1528
1529 default: // #something else
1530 on_illformed((*nodeval.begin()).get_value());
1531
1532 // if we end up here, we have been instructed to ignore the error, so
1533 // we simply copy the whole construct to the output
1534 {
1535 token_sequence_type expanded;
1536 get_token_value<result_type, parse_node_type> get_value;
1537
1538 std::copy(make_ref_transform_iterator(begin_child_it, get_value),
1539 make_ref_transform_iterator(end_child_it, get_value),
1540 std::inserter(expanded, expanded.end()));
1541 pending_queue.splice(pending_queue.begin(), expanded);
1542 }
1543 break;
1544 }
1545
1546 // properly skip trailing newline for all directives
1547 typename token_sequence_type::const_iterator eol = found_eoltokens.begin();
1548 impl::skip_to_eol(ctx, eol, found_eoltokens.end());
1549 return true; // return newline only
1550 }
1551
1552 ///////////////////////////////////////////////////////////////////////////////
1553 //
1554 // on_include: handle #include <...> or #include "..." directives
1555 //
1556 ///////////////////////////////////////////////////////////////////////////////
1557 template <typename ContextT>
1558 inline void
1559 pp_iterator_functor<ContextT>::on_include (string_type const &s,
1560 bool is_system, bool include_next)
1561 {
1562 BOOST_ASSERT(ctx.get_if_block_status());
1563
1564 // strip quotes first, extract filename
1565 typename string_type::size_type pos_end = s.find_last_of(is_system ? '>' : '\"');
1566
1567 if (string_type::npos == pos_end) {
1568 BOOST_WAVE_THROW_CTX(ctx, preprocess_exception, bad_include_statement,
1569 s.c_str(), act_pos);
1570 return;
1571 }
1572
1573 typename string_type::size_type pos_begin =
1574 s.find_last_of(is_system ? '<' : '\"', pos_end-1);
1575
1576 if (string_type::npos == pos_begin) {
1577 BOOST_WAVE_THROW_CTX(ctx, preprocess_exception, bad_include_statement,
1578 s.c_str(), act_pos);
1579 return;
1580 }
1581
1582 std::string file_token(s.substr(pos_begin, pos_end-pos_begin+1).c_str());
1583 std::string file_path(s.substr(pos_begin+1, pos_end-pos_begin-1).c_str());
1584
1585 // finally include the file
1586 on_include_helper(file_token.c_str(), file_path.c_str(), is_system,
1587 include_next);
1588 }
1589
1590 template <typename ContextT>
1591 inline bool
1592 pp_iterator_functor<ContextT>::on_include_helper (char const *f, char const *s,
1593 bool is_system, bool include_next)
1594 {
1595 namespace fs = boost::filesystem;
1596
1597 // try to locate the given file, searching through the include path lists
1598 std::string file_path(s);
1599 std::string dir_path;
1600 #if BOOST_WAVE_SUPPORT_INCLUDE_NEXT != 0
1601 char const *current_name = include_next ? iter_ctx->real_filename.c_str() : 0;
1602 #else
1603 char const *current_name = 0; // never try to match current file name
1604 #endif
1605
1606 // call the 'found_include_directive' hook function
1607 #if BOOST_WAVE_USE_DEPRECIATED_PREPROCESSING_HOOKS != 0
1608 ctx.get_hooks().found_include_directive(f, include_next);
1609 #else
1610 if (ctx.get_hooks().found_include_directive(ctx.derived(), f, include_next))
1611 return true; // client returned false: skip file to include
1612 #endif
1613
1614 file_path = util::impl::unescape_lit(file_path);
1615 std::string native_path_str;
1616
1617 if (!ctx.get_hooks().locate_include_file(ctx, file_path, is_system,
1618 current_name, dir_path, native_path_str))
1619 {
1620 BOOST_WAVE_THROW_CTX(ctx, preprocess_exception, bad_include_file,
1621 file_path.c_str(), act_pos);
1622 return false;
1623 }
1624
1625 // test, if this file is known through a #pragma once directive
1626 #if BOOST_WAVE_SUPPORT_PRAGMA_ONCE != 0
1627 if (!ctx.has_pragma_once(native_path_str))
1628 #endif
1629 {
1630 // the new include file determines the actual current directory
1631 ctx.set_current_directory(native_path_str.c_str());
1632
1633 // preprocess the opened file
1634 boost::shared_ptr<base_iteration_context_type> new_iter_ctx (
1635 new iteration_context_type(ctx, native_path_str.c_str(), act_pos,
1636 boost::wave::enable_prefer_pp_numbers(ctx.get_language()),
1637 is_system ? base_iteration_context_type::system_header :
1638 base_iteration_context_type::user_header));
1639
1640 // call the include policy trace function
1641 #if BOOST_WAVE_USE_DEPRECIATED_PREPROCESSING_HOOKS != 0
1642 ctx.get_hooks().opened_include_file(dir_path, file_path,
1643 ctx.get_iteration_depth(), is_system);
1644 #else
1645 ctx.get_hooks().opened_include_file(ctx.derived(), dir_path, file_path,
1646 is_system);
1647 #endif
1648
1649 // store current file position
1650 iter_ctx->real_relative_filename = ctx.get_current_relative_filename().c_str();
1651 iter_ctx->filename = act_pos.get_file();
1652 iter_ctx->line = act_pos.get_line();
1653 iter_ctx->if_block_depth = ctx.get_if_block_depth();
1654 iter_ctx->emitted_lines = (unsigned int)(-1); // force #line directive
1655
1656 // push the old iteration context onto the stack and continue with the new
1657 ctx.push_iteration_context(act_pos, iter_ctx);
1658 iter_ctx = new_iter_ctx;
1659 seen_newline = true; // fake a newline to trigger pp_directive
1660 must_emit_line_directive = true;
1661
1662 act_pos.set_file(iter_ctx->filename); // initialize file position
1663 #if BOOST_WAVE_SUPPORT_PRAGMA_ONCE != 0
1664 fs::path rfp(wave::util::create_path(iter_ctx->real_filename.c_str()));
1665 std::string real_filename(rfp.string());
1666 ctx.set_current_filename(real_filename.c_str());
1667 #endif
1668
1669 ctx.set_current_relative_filename(dir_path.c_str());
1670 iter_ctx->real_relative_filename = dir_path.c_str();
1671
1672 act_pos.set_line(iter_ctx->line);
1673 act_pos.set_column(0);
1674 }
1675 return true;
1676 }
1677
1678 ///////////////////////////////////////////////////////////////////////////////
1679 //
1680 // on_include(): handle #include ... directives
1681 //
1682 ///////////////////////////////////////////////////////////////////////////////
1683
1684 namespace impl {
1685
1686 // trim all whitespace from the beginning and the end of the given string
1687 template <typename StringT>
1688 inline StringT
1689 trim_whitespace(StringT const &s)
1690 {
1691 typedef typename StringT::size_type size_type;
1692
1693 size_type first = s.find_first_not_of(" \t\v\f");
1694 if (StringT::npos == first)
1695 return StringT();
1696 size_type last = s.find_last_not_of(" \t\v\f");
1697 return s.substr(first, last-first+1);
1698 }
1699 }
1700
1701 template <typename ContextT>
1702 inline void
1703 pp_iterator_functor<ContextT>::on_include(
1704 typename parse_tree_type::const_iterator const &begin,
1705 typename parse_tree_type::const_iterator const &end, bool include_next)
1706 {
1707 BOOST_ASSERT(ctx.get_if_block_status());
1708
1709 // preprocess the given token sequence (the body of the #include directive)
1710 get_token_value<result_type, parse_node_type> get_value;
1711 token_sequence_type expanded;
1712 token_sequence_type toexpand;
1713
1714 std::copy(make_ref_transform_iterator(begin, get_value),
1715 make_ref_transform_iterator(end, get_value),
1716 std::inserter(toexpand, toexpand.end()));
1717
1718 typename token_sequence_type::iterator begin2 = toexpand.begin();
1719 ctx.expand_whole_tokensequence(begin2, toexpand.end(), expanded,
1720 false);
1721
1722 // now, include the file
1723 string_type s (impl::trim_whitespace(boost::wave::util::impl::as_string(expanded)));
1724 bool is_system = '<' == s[0] && '>' == s[s.size()-1];
1725
1726 if (!is_system && !('\"' == s[0] && '\"' == s[s.size()-1])) {
1727 // should resolve into something like <...> or "..."
1728 BOOST_WAVE_THROW_CTX(ctx, preprocess_exception, bad_include_statement,
1729 s.c_str(), act_pos);
1730 return;
1731 }
1732 on_include(s, is_system, include_next);
1733 }
1734
1735 ///////////////////////////////////////////////////////////////////////////////
1736 //
1737 // on_define(): handle #define directives
1738 //
1739 ///////////////////////////////////////////////////////////////////////////////
1740
1741 template <typename ContextT>
1742 inline void
1743 pp_iterator_functor<ContextT>::on_define (parse_node_type const &node)
1744 {
1745 BOOST_ASSERT(ctx.get_if_block_status());
1746
1747 // retrieve the macro definition from the parse tree
1748 result_type macroname;
1749 std::vector<result_type> macroparameters;
1750 token_sequence_type macrodefinition;
1751 bool has_parameters = false;
1752 position_type pos(act_token.get_position());
1753
1754 if (!boost::wave::util::retrieve_macroname(ctx, node,
1755 BOOST_WAVE_PLAIN_DEFINE_ID, macroname, pos, false))
1756 return;
1757 has_parameters = boost::wave::util::retrieve_macrodefinition(node,
1758 BOOST_WAVE_MACRO_PARAMETERS_ID, macroparameters, pos, false);
1759 boost::wave::util::retrieve_macrodefinition(node,
1760 BOOST_WAVE_MACRO_DEFINITION_ID, macrodefinition, pos, false);
1761
1762 if (has_parameters) {
1763 #if BOOST_WAVE_SUPPORT_VARIADICS_PLACEMARKERS != 0
1764 if (boost::wave::need_variadics(ctx.get_language())) {
1765 // test whether ellipsis are given, and if yes, if these are placed as the
1766 // last argument, test if __VA_ARGS__ is used as a macro parameter name
1767 using namespace cpplexer;
1768 typedef typename std::vector<result_type>::iterator
1769 parameter_iterator_t;
1770
1771 bool seen_ellipses = false;
1772 parameter_iterator_t end = macroparameters.end();
1773 for (parameter_iterator_t pit = macroparameters.begin();
1774 pit != end; ++pit)
1775 {
1776 if (seen_ellipses) {
1777 // ellipses are not the last given formal argument
1778 BOOST_WAVE_THROW_CTX(ctx, preprocess_exception,
1779 bad_define_statement, macroname.get_value().c_str(),
1780 (*pit).get_position());
1781 return;
1782 }
1783 if (T_ELLIPSIS == token_id(*pit))
1784 seen_ellipses = true;
1785
1786 // can't use __VA_ARGS__ as a argument name
1787 if ("__VA_ARGS__" == (*pit).get_value()) {
1788 BOOST_WAVE_THROW_CTX(ctx, preprocess_exception,
1789 bad_define_statement_va_args,
1790 macroname.get_value().c_str(), (*pit).get_position());
1791 return;
1792 }
1793 }
1794
1795 // if there wasn't an ellipsis, then there shouldn't be a __VA_ARGS__
1796 // placeholder in the definition too [C99 Standard 6.10.3.5]
1797 if (!seen_ellipses) {
1798 typedef typename token_sequence_type::iterator definition_iterator_t;
1799
1800 bool seen_va_args = false;
1801 definition_iterator_t pend = macrodefinition.end();
1802 for (definition_iterator_t dit = macrodefinition.begin();
1803 dit != pend; ++dit)
1804 {
1805 if (T_IDENTIFIER == token_id(*dit) &&
1806 "__VA_ARGS__" == (*dit).get_value())
1807 {
1808 seen_va_args = true;
1809 }
1810 }
1811 if (seen_va_args) {
1812 // must not have seen __VA_ARGS__ placeholder
1813 BOOST_WAVE_THROW_CTX(ctx, preprocess_exception,
1814 bad_define_statement_va_args,
1815 macroname.get_value().c_str(), act_token.get_position());
1816 return;
1817 }
1818 }
1819 }
1820 else
1821 #endif // BOOST_WAVE_SUPPORT_VARIADICS_PLACEMARKERS != 0
1822 {
1823 // test, that there is no T_ELLIPSES given
1824 using namespace cpplexer;
1825 typedef typename std::vector<result_type>::iterator
1826 parameter_iterator_t;
1827
1828 parameter_iterator_t end = macroparameters.end();
1829 for (parameter_iterator_t pit = macroparameters.begin();
1830 pit != end; ++pit)
1831 {
1832 if (T_ELLIPSIS == token_id(*pit)) {
1833 // if variadics are disabled, no ellipses should be given
1834 BOOST_WAVE_THROW_CTX(ctx, preprocess_exception,
1835 bad_define_statement, macroname.get_value().c_str(),
1836 (*pit).get_position());
1837 return;
1838 }
1839 }
1840 }
1841 }
1842
1843 // add the new macro to the macromap
1844 ctx.add_macro_definition(macroname, has_parameters, macroparameters,
1845 macrodefinition);
1846 }
1847
1848 ///////////////////////////////////////////////////////////////////////////////
1849 //
1850 // on_undefine(): handle #undef directives
1851 //
1852 ///////////////////////////////////////////////////////////////////////////////
1853 template <typename ContextT>
1854 inline void
1855 pp_iterator_functor<ContextT>::on_undefine (lexer_type const &it)
1856 {
1857 BOOST_ASSERT(ctx.get_if_block_status());
1858
1859 // retrieve the macro name to undefine from the parse tree
1860 ctx.remove_macro_definition((*it).get_value()); // throws for predefined macros
1861 }
1862
1863 ///////////////////////////////////////////////////////////////////////////////
1864 //
1865 // on_ifdef(): handle #ifdef directives
1866 //
1867 ///////////////////////////////////////////////////////////////////////////////
1868 template <typename ContextT>
1869 inline void
1870 pp_iterator_functor<ContextT>::on_ifdef(
1871 result_type const& found_directive, lexer_type const &it)
1872 // typename parse_tree_type::const_iterator const &it)
1873 // typename parse_tree_type::const_iterator const &end)
1874 {
1875 // get_token_value<result_type, parse_node_type> get_value;
1876 // token_sequence_type toexpand;
1877 //
1878 // std::copy(make_ref_transform_iterator((*begin).children.begin(), get_value),
1879 // make_ref_transform_iterator((*begin).children.end(), get_value),
1880 // std::inserter(toexpand, toexpand.end()));
1881
1882 bool is_defined = false;
1883 token_sequence_type directive;
1884
1885 directive.insert(directive.end(), *it);
1886
1887 #if BOOST_WAVE_USE_DEPRECIATED_PREPROCESSING_HOOKS != 0
1888 is_defined = ctx.is_defined_macro((*it).get_value()); // toexpand.begin(), toexpand.end());
1889 ctx.get_hooks().evaluated_conditional_expression(directive, is_defined);
1890 #else
1891 do {
1892 is_defined = ctx.is_defined_macro((*it).get_value()); // toexpand.begin(), toexpand.end());
1893 } while (ctx.get_hooks().evaluated_conditional_expression(ctx.derived(),
1894 found_directive, directive, is_defined));
1895 #endif
1896 ctx.enter_if_block(is_defined);
1897 }
1898
1899 ///////////////////////////////////////////////////////////////////////////////
1900 //
1901 // on_ifndef(): handle #ifndef directives
1902 //
1903 ///////////////////////////////////////////////////////////////////////////////
1904 template <typename ContextT>
1905 inline void
1906 pp_iterator_functor<ContextT>::on_ifndef(
1907 result_type const& found_directive, lexer_type const &it)
1908 // typename parse_tree_type::const_iterator const &it)
1909 // typename parse_tree_type::const_iterator const &end)
1910 {
1911 // get_token_value<result_type, parse_node_type> get_value;
1912 // token_sequence_type toexpand;
1913 //
1914 // std::copy(make_ref_transform_iterator((*begin).children.begin(), get_value),
1915 // make_ref_transform_iterator((*begin).children.end(), get_value),
1916 // std::inserter(toexpand, toexpand.end()));
1917
1918 bool is_defined = false;
1919 token_sequence_type directive;
1920
1921 directive.insert(directive.end(), *it);
1922
1923 #if BOOST_WAVE_USE_DEPRECIATED_PREPROCESSING_HOOKS != 0
1924 is_defined = ctx.is_defined_macro((*it).get_value()); // toexpand.begin(), toexpand.end());
1925 ctx.get_hooks().evaluated_conditional_expression(directive, is_defined);
1926 #else
1927 do {
1928 is_defined = ctx.is_defined_macro((*it).get_value()); // toexpand.begin(), toexpand.end());
1929 } while (ctx.get_hooks().evaluated_conditional_expression(ctx.derived(),
1930 found_directive, directive, is_defined));
1931 #endif
1932 ctx.enter_if_block(!is_defined);
1933 }
1934
1935 ///////////////////////////////////////////////////////////////////////////////
1936 //
1937 // on_else(): handle #else directives
1938 //
1939 ///////////////////////////////////////////////////////////////////////////////
1940 template <typename ContextT>
1941 inline void
1942 pp_iterator_functor<ContextT>::on_else()
1943 {
1944 if (!ctx.enter_else_block()) {
1945 // #else without matching #if
1946 BOOST_WAVE_THROW_CTX(ctx, preprocess_exception, missing_matching_if,
1947 "#else", act_pos);
1948 }
1949 }
1950
1951 ///////////////////////////////////////////////////////////////////////////////
1952 //
1953 // on_endif(): handle #endif directives
1954 //
1955 ///////////////////////////////////////////////////////////////////////////////
1956 template <typename ContextT>
1957 inline void
1958 pp_iterator_functor<ContextT>::on_endif()
1959 {
1960 if (!ctx.exit_if_block()) {
1961 // #endif without matching #if
1962 BOOST_WAVE_THROW_CTX(ctx, preprocess_exception, missing_matching_if,
1963 "#endif", act_pos);
1964 }
1965 }
1966
1967 ///////////////////////////////////////////////////////////////////////////////
1968 // replace all remaining (== undefined) identifiers with an integer literal '0'
1969 template <typename ContextT>
1970 inline void
1971 pp_iterator_functor<ContextT>::replace_undefined_identifiers(
1972 token_sequence_type &expanded)
1973 {
1974 typename token_sequence_type::iterator exp_end = expanded.end();
1975 for (typename token_sequence_type::iterator exp_it = expanded.begin();
1976 exp_it != exp_end; ++exp_it)
1977 {
1978 using namespace boost::wave;
1979
1980 token_id id = token_id(*exp_it);
1981 if (IS_CATEGORY(id, IdentifierTokenType) ||
1982 IS_CATEGORY(id, KeywordTokenType))
1983 {
1984 (*exp_it).set_token_id(T_INTLIT);
1985 (*exp_it).set_value("0");
1986 }
1987 }
1988 }
1989
1990 ///////////////////////////////////////////////////////////////////////////////
1991 //
1992 // on_if(): handle #if directives
1993 //
1994 ///////////////////////////////////////////////////////////////////////////////
1995 template <typename ContextT>
1996 inline void
1997 pp_iterator_functor<ContextT>::on_if(
1998 result_type const& found_directive,
1999 typename parse_tree_type::const_iterator const &begin,
2000 typename parse_tree_type::const_iterator const &end)
2001 {
2002 // preprocess the given sequence into the provided list
2003 get_token_value<result_type, parse_node_type> get_value;
2004 token_sequence_type toexpand;
2005
2006 std::copy(make_ref_transform_iterator(begin, get_value),
2007 make_ref_transform_iterator(end, get_value),
2008 std::inserter(toexpand, toexpand.end()));
2009
2010 impl::remove_leading_whitespace(ctx, toexpand);
2011
2012 bool if_status = false;
2013 grammars::value_error status = grammars::error_noerror;
2014 token_sequence_type expanded;
2015
2016 do {
2017 expanded.clear();
2018
2019 typename token_sequence_type::iterator begin2 = toexpand.begin();
2020 ctx.expand_whole_tokensequence(begin2, toexpand.end(), expanded);
2021
2022 // replace all remaining (== undefined) identifiers with an integer literal '0'
2023 replace_undefined_identifiers(expanded);
2024
2025 #if BOOST_WAVE_DUMP_CONDITIONAL_EXPRESSIONS != 0
2026 {
2027 string_type outstr(boost::wave::util::impl::as_string(toexpand));
2028 outstr += "(" + boost::wave::util::impl::as_string(expanded) + ")";
2029 BOOST_WAVE_DUMP_CONDITIONAL_EXPRESSIONS_OUT << "#if " << outstr
2030 << std::endl;
2031 }
2032 #endif
2033 try {
2034 // parse the expression and enter the #if block
2035 if_status = grammars::expression_grammar_gen<result_type>::
2036 evaluate(expanded.begin(), expanded.end(), act_pos,
2037 ctx.get_if_block_status(), status);
2038 }
2039 catch (boost::wave::preprocess_exception const& e) {
2040 // any errors occurred have to be dispatched to the context hooks
2041 ctx.get_hooks().throw_exception(ctx.derived(), e);
2042 break;
2043 }
2044
2045 #if BOOST_WAVE_USE_DEPRECIATED_PREPROCESSING_HOOKS != 0
2046 ctx.get_hooks().evaluated_conditional_expression(toexpand, if_status);
2047 } while (false);
2048 #else
2049 } while (ctx.get_hooks().evaluated_conditional_expression(ctx.derived(),
2050 found_directive, toexpand, if_status)
2051 && status == grammars::error_noerror);
2052 #endif
2053
2054 ctx.enter_if_block(if_status);
2055 if (grammars::error_noerror != status) {
2056 // division or other error by zero occurred
2057 string_type expression = util::impl::as_string(expanded);
2058 if (0 == expression.size())
2059 expression = "<empty expression>";
2060
2061 if (grammars::error_division_by_zero & status) {
2062 BOOST_WAVE_THROW_CTX(ctx, preprocess_exception, division_by_zero,
2063 expression.c_str(), act_pos);
2064 }
2065 else if (grammars::error_integer_overflow & status) {
2066 BOOST_WAVE_THROW_CTX(ctx, preprocess_exception, integer_overflow,
2067 expression.c_str(), act_pos);
2068 }
2069 else if (grammars::error_character_overflow & status) {
2070 BOOST_WAVE_THROW_CTX(ctx, preprocess_exception,
2071 character_literal_out_of_range, expression.c_str(), act_pos);
2072 }
2073 }
2074 }
2075
2076 ///////////////////////////////////////////////////////////////////////////////
2077 //
2078 // on_elif(): handle #elif directives
2079 //
2080 ///////////////////////////////////////////////////////////////////////////////
2081 template <typename ContextT>
2082 inline void
2083 pp_iterator_functor<ContextT>::on_elif(
2084 result_type const& found_directive,
2085 typename parse_tree_type::const_iterator const &begin,
2086 typename parse_tree_type::const_iterator const &end)
2087 {
2088 // preprocess the given sequence into the provided list
2089 get_token_value<result_type, parse_node_type> get_value;
2090 token_sequence_type toexpand;
2091
2092 std::copy(make_ref_transform_iterator(begin, get_value),
2093 make_ref_transform_iterator(end, get_value),
2094 std::inserter(toexpand, toexpand.end()));
2095
2096 impl::remove_leading_whitespace(ctx, toexpand);
2097
2098 // check current if block status
2099 if (ctx.get_if_block_some_part_status()) {
2100 if (!ctx.enter_elif_block(false)) {
2101 // #else without matching #if
2102 BOOST_WAVE_THROW_CTX(ctx, preprocess_exception,
2103 missing_matching_if, "#elif", act_pos);
2104 // fall through...
2105 }
2106
2107 // skip all the expression and the trailing whitespace
2108 typename token_sequence_type::iterator begin2 = toexpand.begin();
2109
2110 impl::skip_to_eol(ctx, begin2, toexpand.end());
2111 return; // one of previous #if/#elif was true, so don't enter this #elif
2112 }
2113
2114 // preprocess the given sequence into the provided list
2115 bool if_status = false;
2116 grammars::value_error status = grammars::error_noerror;
2117 token_sequence_type expanded;
2118
2119 do {
2120 expanded.clear();
2121
2122 typename token_sequence_type::iterator begin2 = toexpand.begin();
2123 ctx.expand_whole_tokensequence(begin2, toexpand.end(), expanded);
2124
2125 // replace all remaining (== undefined) identifiers with an integer literal '0'
2126 replace_undefined_identifiers(expanded);
2127
2128 #if BOOST_WAVE_DUMP_CONDITIONAL_EXPRESSIONS != 0
2129 {
2130 string_type outstr(boost::wave::util::impl::as_string(toexpand));
2131 outstr += "(" + boost::wave::util::impl::as_string(expanded) + ")";
2132 BOOST_WAVE_DUMP_CONDITIONAL_EXPRESSIONS_OUT << "#elif " << outstr << std::endl;
2133 }
2134 #endif
2135
2136 try {
2137 // parse the expression and enter the #elif block
2138 if_status = grammars::expression_grammar_gen<result_type>::
2139 evaluate(expanded.begin(), expanded.end(), act_pos,
2140 ctx.get_if_block_status(), status);
2141 }
2142 catch (boost::wave::preprocess_exception const& e) {
2143 // any errors occurred have to be dispatched to the context hooks
2144 ctx.get_hooks().throw_exception(ctx.derived(), e);
2145 }
2146
2147 #if BOOST_WAVE_USE_DEPRECIATED_PREPROCESSING_HOOKS != 0
2148 ctx.get_hooks().evaluated_conditional_expression(toexpand, if_status);
2149 } while (false);
2150 #else
2151 } while (ctx.get_hooks().evaluated_conditional_expression(ctx.derived(),
2152 found_directive, toexpand, if_status)
2153 && status == grammars::error_noerror);
2154 #endif
2155
2156 if (!ctx.enter_elif_block(if_status)) {
2157 // #elif without matching #if
2158 BOOST_WAVE_THROW_CTX(ctx, preprocess_exception, missing_matching_if,
2159 "#elif", act_pos);
2160 return;
2161 }
2162
2163 if (grammars::error_noerror != status) {
2164 // division or other error by zero occurred
2165 string_type expression = util::impl::as_string(expanded);
2166 if (0 == expression.size())
2167 expression = "<empty expression>";
2168
2169 if (grammars::error_division_by_zero & status) {
2170 BOOST_WAVE_THROW_CTX(ctx, preprocess_exception, division_by_zero,
2171 expression.c_str(), act_pos);
2172 }
2173 else if (grammars::error_integer_overflow & status) {
2174 BOOST_WAVE_THROW_CTX(ctx, preprocess_exception,
2175 integer_overflow, expression.c_str(), act_pos);
2176 }
2177 else if (grammars::error_character_overflow & status) {
2178 BOOST_WAVE_THROW_CTX(ctx, preprocess_exception,
2179 character_literal_out_of_range, expression.c_str(), act_pos);
2180 }
2181 }
2182 }
2183
2184 ///////////////////////////////////////////////////////////////////////////////
2185 //
2186 // on_illformed(): handles the illegal directive
2187 //
2188 ///////////////////////////////////////////////////////////////////////////////
2189 template <typename ContextT>
2190 inline void
2191 pp_iterator_functor<ContextT>::on_illformed(
2192 typename result_type::string_type s)
2193 {
2194 BOOST_ASSERT(ctx.get_if_block_status());
2195
2196 // some messages have more than one newline at the end
2197 typename string_type::size_type p = s.find_last_not_of('\n');
2198 if (string_type::npos != p)
2199 s = s.substr(0, p+1);
2200
2201 // throw the exception
2202 BOOST_WAVE_THROW_CTX(ctx, preprocess_exception, ill_formed_directive,
2203 s.c_str(), act_pos);
2204 }
2205
2206 ///////////////////////////////////////////////////////////////////////////////
2207 //
2208 // on_line(): handle #line directives
2209 //
2210 ///////////////////////////////////////////////////////////////////////////////
2211
2212 namespace impl {
2213
2214 template <typename IteratorT, typename StringT>
2215 bool retrieve_line_info (IteratorT first, IteratorT const &last,
2216 unsigned int &line, StringT &file,
2217 boost::wave::preprocess_exception::error_code& error)
2218 {
2219 using namespace boost::wave;
2220 token_id id = token_id(*first);
2221 if (T_PP_NUMBER == id || T_INTLIT == id) {
2222 // extract line number
2223 using namespace std; // some systems have atoi in namespace std
2224 line = (unsigned int)atoi((*first).get_value().c_str());
2225 if (0 == line)
2226 error = preprocess_exception::bad_line_number;
2227
2228 // re-extract line number with spirit to diagnose overflow
2229 using namespace boost::spirit::classic;
2230 if (!parse((*first).get_value().c_str(), int_p).full)
2231 error = preprocess_exception::bad_line_number;
2232
2233 // extract file name (if it is given)
2234 while (++first != last && IS_CATEGORY(*first, WhiteSpaceTokenType))
2235 /**/; // skip whitespace
2236
2237 if (first != last) {
2238 if (T_STRINGLIT != token_id(*first)) {
2239 error = preprocess_exception::bad_line_filename;
2240 return false;
2241 }
2242
2243 StringT const &file_lit = (*first).get_value();
2244
2245 if ('L' == file_lit[0]) {
2246 error = preprocess_exception::bad_line_filename;
2247 return false; // shouldn't be a wide character string
2248 }
2249
2250 file = file_lit.substr(1, file_lit.size()-2);
2251
2252 // test if there is other junk on this line
2253 while (++first != last && IS_CATEGORY(*first, WhiteSpaceTokenType))
2254 /**/; // skip whitespace
2255 }
2256 return first == last;
2257 }
2258 error = preprocess_exception::bad_line_statement;
2259 return false;
2260 }
2261 }
2262
2263 template <typename ContextT>
2264 inline void
2265 pp_iterator_functor<ContextT>::on_line(
2266 typename parse_tree_type::const_iterator const &begin,
2267 typename parse_tree_type::const_iterator const &end)
2268 {
2269 BOOST_ASSERT(ctx.get_if_block_status());
2270
2271 // Try to extract the line number and file name from the given token list
2272 // directly. If that fails, preprocess the whole token sequence and try again
2273 // to extract this information.
2274 token_sequence_type expanded;
2275 get_token_value<result_type, parse_node_type> get_value;
2276
2277 typedef typename ref_transform_iterator_generator<
2278 get_token_value<result_type, parse_node_type>,
2279 typename parse_tree_type::const_iterator
2280 >::type const_tree_iterator_t;
2281
2282 const_tree_iterator_t first = make_ref_transform_iterator(begin, get_value);
2283 const_tree_iterator_t last = make_ref_transform_iterator(end, get_value);
2284
2285 // try to interpret the #line body as a number followed by an optional
2286 // string literal
2287 unsigned int line = 0;
2288 preprocess_exception::error_code error = preprocess_exception::no_error;
2289 string_type file_name;
2290 token_sequence_type toexpand;
2291
2292 std::copy(first, last, std::inserter(toexpand, toexpand.end()));
2293 if (!impl::retrieve_line_info(first, last, line, file_name, error)) {
2294 // preprocess the body of this #line message
2295 typename token_sequence_type::iterator begin2 = toexpand.begin();
2296 ctx.expand_whole_tokensequence(begin2, toexpand.end(),
2297 expanded, false);
2298
2299 error = preprocess_exception::no_error;
2300 if (!impl::retrieve_line_info(expanded.begin(), expanded.end(),
2301 line, file_name, error))
2302 {
2303 typename ContextT::string_type msg(
2304 boost::wave::util::impl::as_string(expanded));
2305 BOOST_WAVE_THROW_VAR_CTX(ctx, preprocess_exception, error,
2306 msg.c_str(), act_pos);
2307 return;
2308 }
2309
2310 // call the corresponding pp hook function
2311 ctx.get_hooks().found_line_directive(ctx.derived(), expanded, line,
2312 file_name.c_str());
2313 }
2314 else {
2315 // call the corresponding pp hook function
2316 ctx.get_hooks().found_line_directive(ctx.derived(), toexpand, line,
2317 file_name.c_str());
2318 }
2319
2320 // the queues should be empty at this point
2321 BOOST_ASSERT(unput_queue.empty());
2322 BOOST_ASSERT(pending_queue.empty());
2323
2324 // make sure error recovery starts on the next line
2325 must_emit_line_directive = true;
2326
2327 // diagnose possible error in detected line directive
2328 if (error != preprocess_exception::no_error) {
2329 typename ContextT::string_type msg(
2330 boost::wave::util::impl::as_string(expanded));
2331 BOOST_WAVE_THROW_VAR_CTX(ctx, preprocess_exception, error,
2332 msg.c_str(), act_pos);
2333 return;
2334 }
2335
2336 // set new line number/filename only if ok
2337 if (!file_name.empty()) { // reuse current file name
2338 using boost::wave::util::impl::unescape_lit;
2339 act_pos.set_file(unescape_lit(file_name).c_str());
2340 }
2341 act_pos.set_line(line);
2342 if (iter_ctx->first != iter_ctx->last)
2343 {
2344 iter_ctx->first.set_position(act_pos);
2345 }
2346 }
2347
2348 ///////////////////////////////////////////////////////////////////////////////
2349 //
2350 // on_error(): handle #error directives
2351 //
2352 ///////////////////////////////////////////////////////////////////////////////
2353 template <typename ContextT>
2354 inline void
2355 pp_iterator_functor<ContextT>::on_error(
2356 typename parse_tree_type::const_iterator const &begin,
2357 typename parse_tree_type::const_iterator const &end)
2358 {
2359 BOOST_ASSERT(ctx.get_if_block_status());
2360
2361 // preprocess the given sequence into the provided list
2362 token_sequence_type expanded;
2363 get_token_value<result_type, parse_node_type> get_value;
2364
2365 typename ref_transform_iterator_generator<
2366 get_token_value<result_type, parse_node_type>,
2367 typename parse_tree_type::const_iterator
2368 >::type first = make_ref_transform_iterator(begin, get_value);
2369
2370 #if BOOST_WAVE_PREPROCESS_ERROR_MESSAGE_BODY != 0
2371 // preprocess the body of this #error message
2372 token_sequence_type toexpand;
2373
2374 std::copy(first, make_ref_transform_iterator(end, get_value),
2375 std::inserter(toexpand, toexpand.end()));
2376
2377 typename token_sequence_type::iterator begin2 = toexpand.begin();
2378 ctx.expand_whole_tokensequence(begin2, toexpand.end(), expanded,
2379 false);
2380 if (!ctx.get_hooks().found_error_directive(ctx.derived(), toexpand))
2381 #else
2382 // simply copy the body of this #error message to the issued diagnostic
2383 // message
2384 std::copy(first, make_ref_transform_iterator(end, get_value),
2385 std::inserter(expanded, expanded.end()));
2386 if (!ctx.get_hooks().found_error_directive(ctx.derived(), expanded))
2387 #endif
2388 {
2389 // report the corresponding error
2390 BOOST_WAVE_STRINGTYPE msg(boost::wave::util::impl::as_string(expanded));
2391 BOOST_WAVE_THROW_CTX(ctx, preprocess_exception, error_directive,
2392 msg.c_str(), act_pos);
2393 }
2394 }
2395
2396 #if BOOST_WAVE_SUPPORT_WARNING_DIRECTIVE != 0
2397 ///////////////////////////////////////////////////////////////////////////////
2398 //
2399 // on_warning(): handle #warning directives
2400 //
2401 ///////////////////////////////////////////////////////////////////////////////
2402 template <typename ContextT>
2403 inline void
2404 pp_iterator_functor<ContextT>::on_warning(
2405 typename parse_tree_type::const_iterator const &begin,
2406 typename parse_tree_type::const_iterator const &end)
2407 {
2408 BOOST_ASSERT(ctx.get_if_block_status());
2409
2410 // preprocess the given sequence into the provided list
2411 token_sequence_type expanded;
2412 get_token_value<result_type, parse_node_type> get_value;
2413
2414 typename ref_transform_iterator_generator<
2415 get_token_value<result_type, parse_node_type>,
2416 typename parse_tree_type::const_iterator
2417 >::type first = make_ref_transform_iterator(begin, get_value);
2418
2419 #if BOOST_WAVE_PREPROCESS_ERROR_MESSAGE_BODY != 0
2420 // preprocess the body of this #warning message
2421 token_sequence_type toexpand;
2422
2423 std::copy(first, make_ref_transform_iterator(end, get_value),
2424 std::inserter(toexpand, toexpand.end()));
2425
2426 typename token_sequence_type::iterator begin2 = toexpand.begin();
2427 ctx.expand_whole_tokensequence(begin2, toexpand.end(), expanded,
2428 false);
2429 if (!ctx.get_hooks().found_warning_directive(ctx.derived(), toexpand))
2430 #else
2431 // simply copy the body of this #warning message to the issued diagnostic
2432 // message
2433 std::copy(first, make_ref_transform_iterator(end, get_value),
2434 std::inserter(expanded, expanded.end()));
2435 if (!ctx.get_hooks().found_warning_directive(ctx.derived(), expanded))
2436 #endif
2437 {
2438 // report the corresponding error
2439 BOOST_WAVE_STRINGTYPE msg(boost::wave::util::impl::as_string(expanded));
2440 BOOST_WAVE_THROW_CTX(ctx, preprocess_exception, warning_directive,
2441 msg.c_str(), act_pos);
2442 }
2443 }
2444 #endif // BOOST_WAVE_SUPPORT_WARNING_DIRECTIVE != 0
2445
2446 ///////////////////////////////////////////////////////////////////////////////
2447 //
2448 // on_pragma(): handle #pragma directives
2449 //
2450 ///////////////////////////////////////////////////////////////////////////////
2451 template <typename ContextT>
2452 inline bool
2453 pp_iterator_functor<ContextT>::on_pragma(
2454 typename parse_tree_type::const_iterator const &begin,
2455 typename parse_tree_type::const_iterator const &end)
2456 {
2457 using namespace boost::wave;
2458
2459 BOOST_ASSERT(ctx.get_if_block_status());
2460
2461 // Look at the pragma token sequence and decide, if the first token is STDC
2462 // (see C99 standard [6.10.6.2]), if it is, the sequence must _not_ be
2463 // preprocessed.
2464 token_sequence_type expanded;
2465 get_token_value<result_type, parse_node_type> get_value;
2466
2467 typedef typename ref_transform_iterator_generator<
2468 get_token_value<result_type, parse_node_type>,
2469 typename parse_tree_type::const_iterator
2470 >::type const_tree_iterator_t;
2471
2472 const_tree_iterator_t first = make_ref_transform_iterator(begin, get_value);
2473 const_tree_iterator_t last = make_ref_transform_iterator(end, get_value);
2474
2475 expanded.push_back(result_type(T_PP_PRAGMA, "#pragma", act_token.get_position()));
2476 expanded.push_back(result_type(T_SPACE, " ", act_token.get_position()));
2477
2478 while (++first != last && IS_CATEGORY(*first, WhiteSpaceTokenType))
2479 expanded.push_back(*first); // skip whitespace
2480
2481 if (first != last) {
2482 if (T_IDENTIFIER == token_id(*first) &&
2483 boost::wave::need_c99(ctx.get_language()) &&
2484 (*first).get_value() == "STDC")
2485 {
2486 // do _not_ preprocess the token sequence
2487 std::copy(first, last, std::inserter(expanded, expanded.end()));
2488 }
2489 else {
2490 #if BOOST_WAVE_PREPROCESS_PRAGMA_BODY != 0
2491 // preprocess the given tokensequence
2492 token_sequence_type toexpand;
2493
2494 std::copy(first, last, std::inserter(toexpand, toexpand.end()));
2495
2496 typename token_sequence_type::iterator begin2 = toexpand.begin();
2497 ctx.expand_whole_tokensequence(begin2, toexpand.end(),
2498 expanded, false);
2499 #else
2500 // do _not_ preprocess the token sequence
2501 std::copy(first, last, std::inserter(expanded, expanded.end()));
2502 #endif
2503 }
2504 }
2505 expanded.push_back(result_type(T_NEWLINE, "\n", act_token.get_position()));
2506
2507 // the queues should be empty at this point
2508 BOOST_ASSERT(unput_queue.empty());
2509 BOOST_ASSERT(pending_queue.empty());
2510
2511 // try to interpret the expanded #pragma body
2512 token_sequence_type pending;
2513 if (interpret_pragma(expanded, pending)) {
2514 // if there is some replacement text, insert it into the pending queue
2515 if (!pending.empty())
2516 pending_queue.splice(pending_queue.begin(), pending);
2517 return true; // this #pragma was successfully recognized
2518 }
2519
2520 #if BOOST_WAVE_EMIT_PRAGMA_DIRECTIVES != 0
2521 // Move the resulting token sequence into the pending_queue, so it will be
2522 // returned to the caller.
2523 if (boost::wave::need_emit_pragma_directives(ctx.get_language())) {
2524 pending_queue.splice(pending_queue.begin(), expanded);
2525 return false; // return the whole #pragma directive
2526 }
2527 #endif
2528 return true; // skip the #pragma at all
2529 }
2530
2531 template <typename ContextT>
2532 inline bool
2533 pp_iterator_functor<ContextT>::interpret_pragma(
2534 token_sequence_type const &pragma_body, token_sequence_type &result)
2535 {
2536 using namespace cpplexer;
2537
2538 typename token_sequence_type::const_iterator end = pragma_body.end();
2539 typename token_sequence_type::const_iterator it = pragma_body.begin();
2540 for (++it; it != end && IS_CATEGORY(*it, WhiteSpaceTokenType); ++it)
2541 /**/; // skip whitespace
2542
2543 if (it == end) // eof reached
2544 return false;
2545
2546 return boost::wave::util::interpret_pragma(
2547 ctx.derived(), act_token, it, end, result);
2548 }
2549
2550 ///////////////////////////////////////////////////////////////////////////////
2551 } // namespace impl
2552
2553 ///////////////////////////////////////////////////////////////////////////////
2554 //
2555 // pp_iterator
2556 //
2557 // The boost::wave::pp_iterator template is the iterator, through which
2558 // the resulting preprocessed input stream is accessible.
2559 //
2560 ///////////////////////////////////////////////////////////////////////////////
2561
2562 template <typename ContextT>
2563 class pp_iterator
2564 : public boost::spirit::classic::multi_pass<
2565 boost::wave::impl::pp_iterator_functor<ContextT>,
2566 boost::wave::util::functor_input
2567 >
2568 {
2569 public:
2570 typedef boost::wave::impl::pp_iterator_functor<ContextT> input_policy_type;
2571
2572 private:
2573 typedef
2574 boost::spirit::classic::multi_pass<input_policy_type, boost::wave::util::functor_input>
2575 base_type;
2576 typedef pp_iterator<ContextT> self_type;
2577 typedef boost::wave::util::functor_input functor_input_type;
2578
2579 public:
2580 pp_iterator()
2581 {}
2582
2583 template <typename IteratorT>
2584 pp_iterator(ContextT &ctx, IteratorT const &first, IteratorT const &last,
2585 typename ContextT::position_type const &pos)
2586 : base_type(input_policy_type(ctx, first, last, pos))
2587 {}
2588
2589 bool force_include(char const *path_, bool is_last)
2590 {
2591 bool result = this->get_functor().on_include_helper(path_, path_,
2592 false, false);
2593 if (is_last) {
2594 this->functor_input_type::
2595 template inner<input_policy_type>::advance_input();
2596 }
2597 return result;
2598 }
2599 };
2600
2601 ///////////////////////////////////////////////////////////////////////////////
2602 } // namespace wave
2603 } // namespace boost
2604
2605 // the suffix header occurs after all of the code
2606 #ifdef BOOST_HAS_ABI_HEADERS
2607 #include BOOST_ABI_SUFFIX
2608 #endif
2609
2610 #endif // !defined(CPP_ITERATOR_HPP_175CA88F_7273_43FA_9039_BCF7459E1F29_INCLUDED)