63:
public boost::wave::context_policies::default_preprocessing_hooks
68 std::list< token_type > tokens;
70 token_type lastPreprocDirective;
73 std::string includeDirective;
74 token_type includeDirectiveToken;
76 bool updatingLastToken;
77 token_type last_token;
79 : attributeListMap(NULL)
81 , lastPreprocDirective()
85 , updatingLastToken(
false)
120 template <
typename ContextT,
typename TokenT,
typename ContainerT,
typename IteratorT>
121 bool expanding_function_like_macro(ContextT
const&,
122 TokenT
const& macrodef, std::vector<TokenT>
const& formal_args,
123 ContainerT
const& definition,
124 TokenT
const& macrocall, std::vector<ContainerT>
const& arguments,
125 IteratorT
const&, IteratorT
const&)
136 attributeListMap->expanding_function_like_macro(macrodef, formal_args, definition, macrocall, arguments);
155 template <
typename ContextT,
typename TokenT,
typename ContainerT>
156 bool expanding_object_like_macro(ContextT
const& ctx, TokenT
const& macro,
157 ContainerT
const& definition, TokenT
const& macrocall)
159 attributeListMap->expanding_object_like_macro(macro, definition, macrocall);
172 template <
typename ContextT,
typename ContainerT>
173 void expanded_macro(ContextT
const&, ContainerT
const& result)
175 attributeListMap->expanded_macro(result);
187 template <
typename ContextT,
typename ContainerT>
188 void rescanned_macro(ContextT
const&, ContainerT
const& result)
190 attributeListMap->rescanned_macro(result);
211 template <
typename ContextT>
213 found_include_directive(ContextT
const&, std::string
const& filename,
bool )
216 std::cout <<
"Found include directive: " << filename << std::endl;
218 includeDirective = filename;
238 template <
typename ContextT>
240 opened_include_file(ContextT
const&, std::string
const& relname,
241 std::string
const& absname,
bool )
245 std::cout <<
"openend include file relname: " << relname <<
" absname: " << absname << std::endl;
246 std::cout <<
"it is connected to : " << includeDirective << std::endl;
248 attributeListMap->found_include_directive(includeDirectiveToken, relname, absname);
258 template <
typename ContextT>
260 returning_from_include_file(ContextT
const&)
289 template <
typename ContextT,
typename ContainerT>
291 interpret_pragma(ContextT
const&, ContainerT &,
292 typename ContextT::token_type
const &, ContainerT
const &,
293 typename ContextT::token_type
const &)
319 template <
typename ContextT,
typename TokenT,
typename ParametersT,
320 typename DefinitionT>
322 defined_macro(ContextT
const&, TokenT
const& macro_name,
323 bool is_functionlike, ParametersT
const& parameters,
324 DefinitionT
const& definition,
bool is_predefined)
338 if( macro_name.get_position().get_file().size()!=0 )
340 if( (macro_name.get_position().get_file()!=
"<built-in>") )
342 attributeListMap->defined_macro(macro_name, is_functionlike, parameters, definition, is_predefined);
348 attributeListMap->defined_macro(macro_name, is_functionlike, parameters, definition, is_predefined);
352 token_type space = token_type(boost::wave::T_SPACE,
" ", boost::wave::util::file_position_type(BOOST_WAVE_STRINGTYPE(ROSE_WAVE_PSEUDO_FILE), 0, 0));
353 tokens.push_back(space);
354 tokens.push_back(macro_name);
356 boost::wave::util::file_position_type filepos;
358 macro_name.get_position().get_file().find(
"<default>") == std::string::npos &&
359 macro_name.get_position().get_file().find(
"<built-in>") == std::string::npos &&
360 macro_name.get_position().get_file().find(
"<command line>") == std::string::npos &&
361 macro_name.get_position().get_file().find(
"rose_edg_required_macros_and_functions") == std::string::npos)
362 filepos = boost::wave::util::file_position_type(BOOST_WAVE_STRINGTYPE(ROSE_WAVE_PSEUDO_FILE), 0, 0);
364 filepos = boost::wave::util::file_position_type(macro_name.get_position().get_file(), 0, 0);
368 token_type left = token_type(boost::wave::T_LEFTPAREN,
"(", filepos);
369 tokens.push_back(left);
371 for (
typename ParametersT::const_iterator i = parameters.begin(); i != parameters.end(); ++i)
375 token_type comma = token_type(boost::wave::T_COMMA,
",", filepos);
376 tokens.push_back(comma);
378 tokens.push_back(*i);
381 token_type right = token_type(boost::wave::T_RIGHTPAREN,
")", filepos);
382 tokens.push_back(right);
384 token_type space2 = token_type(boost::wave::T_SPACE,
" ", filepos);
385 tokens.push_back(space2);
386 for (
typename DefinitionT::const_iterator i = definition.begin(); i != definition.end(); ++i)
388 token_type space = token_type(boost::wave::T_SPACE,
" ", filepos);
389 tokens.push_back(space);
390 tokens.push_back(*i);
406 template <
typename ContextT,
typename TokenT>
408 found_directive(ContextT
const&, TokenT
const& directive)
411 std::cout <<
"found_directive!" << std::endl;
414 lastPreprocDirective = directive;
416 using namespace boost::wave;
417 token_id
id = token_id(directive);
448 attributeListMap->flush_token_stream();
449 updatingLastToken =
true;
455 case T_PP_DEFINE: std::cout <<
"Directive is: #define\n";
break;
456 case T_PP_IF: std::cout <<
"Directive is: #if\n";
break;
457 case T_PP_IFDEF: std::cout <<
"Directive is: #ifdef\n";
break;
458 case T_PP_IFNDEF: std::cout <<
"Directive is: #ifndef\n";
break;
459 case T_PP_ELSE: std::cout <<
"Directive is: #else\n";
break;
460 case T_PP_ELIF: std::cout <<
"Directive is: #elif\n";
break;
461 case T_PP_ENDIF: std::cout <<
"Directive is: #endif\n";
break;
462 case T_PP_ERROR: std::cout <<
"Directive is: #error\n";
break;
463 case T_PP_LINE: std::cout <<
"Directive is: #line\n";
break;
464 case T_PP_PRAGMA: std::cout <<
"Directive is: #pragma\n";
break;
465 case T_PP_UNDEF: std::cout <<
"Directive is: #undef\n";
break;
466 case T_PP_WARNING: std::cout <<
"Directive is: #warning\n";
break;
467 case T_PP_INCLUDE: std::cout <<
"Directive is: #include \"...\"\n";
break;
468 case T_PP_QHEADER: std::cout <<
"Directive is: #include <...>\n";
break;
469 case T_PP_HHEADER: std::cout <<
"Directive is: #include ...\n";
break;
470 default: std::cout <<
"Directive is: <something else>\n";
break;
474 last_token = directive;
475 tokens.push_back(directive);
485 template <
typename ContextT,
typename TokenT>
486 TokenT
const& generated_token(ContextT
const&, TokenT
const& token)
489 std::cout <<
"Generating token: ";
491 using namespace boost::wave;
492 token_id
id = token_id(token);
498 case T_PP_DEFINE: std::cout <<
"#define: ";
break;
499 case T_PP_IF: std::cout <<
"#if: ";
break;
500 case T_PP_IFDEF: std::cout <<
"#ifdef: ";
break;
501 case T_PP_IFNDEF: std::cout <<
"#ifndef: ";
break;
502 case T_PP_ELSE: std::cout <<
"#else: ";
break;
503 case T_PP_ELIF: std::cout <<
"#elif: ";
break;
504 case T_PP_ENDIF: std::cout <<
"#endif: ";
break;
505 case T_PP_ERROR: std::cout <<
"#error: ";
break;
506 case T_PP_LINE: std::cout <<
"#line: ";
break;
507 case T_PP_PRAGMA: std::cout <<
"#pragma: ";
break;
508 case T_PP_UNDEF: std::cout <<
"#undef: ";
break;
509 case T_PP_WARNING: std::cout <<
"#warning: ";
break;
510 case T_PP_INCLUDE: std::cout <<
"#include \"...\": ";
break;
511 case T_PP_QHEADER: std::cout <<
"#include <...>: ";
break;
512 case T_PP_HHEADER: std::cout <<
"#include ...: ";
break;
513 default: std::cout <<
"<something else (" <<
id <<
")>: ";
break;
516 if (token != token_type())
517 std::cout << token.get_value().c_str() << std::endl;
535 template <
typename ContextT,
typename TokenT,
typename ContainerT>
537 evaluated_conditional_expression(ContextT
const&, TokenT
const& directive, ContainerT
const& expression,
538 bool expression_value)
540 using namespace boost::wave;
541 token_id
id = token_id(directive);
543 ROSE_ASSERT(directive == lastPreprocDirective);
547 std::cout <<
"Conditional: ";
550 case T_PP_DEFINE: std::cout <<
"#define: ";
break;
551 case T_PP_IF: std::cout <<
"#if: ";
break;
552 case T_PP_IFDEF: std::cout <<
"#ifdef: ";
break;
553 case T_PP_IFNDEF: std::cout <<
"#ifndef: ";
break;
554 case T_PP_ELSE: std::cout <<
"#else: ";
break;
555 case T_PP_ELIF: std::cout <<
"#elif: ";
break;
556 case T_PP_ENDIF: std::cout <<
"#endif: ";
break;
557 case T_PP_ERROR: std::cout <<
"#error: ";
break;
558 case T_PP_LINE: std::cout <<
"#line: ";
break;
559 case T_PP_PRAGMA: std::cout <<
"#pragma: ";
break;
560 case T_PP_UNDEF: std::cout <<
"#undef: ";
break;
561 case T_PP_WARNING: std::cout <<
"#warning: ";
break;
562 case T_PP_INCLUDE: std::cout <<
"#include \"...\": ";
break;
563 case T_PP_QHEADER: std::cout <<
"#include <...>: ";
break;
564 case T_PP_HHEADER: std::cout <<
"#include ...: ";
break;
565 default: std::cout <<
"<something else (" <<
id <<
")>: ";
break;
568 std::cout << directive.get_value().c_str() << std::endl;
570 token_type space = token_type(boost::wave::T_SPACE,
" ", boost::wave::util::file_position_type(BOOST_WAVE_STRINGTYPE(ROSE_WAVE_PSEUDO_FILE), 0, 0));
571 token_container whitespace;
572 whitespace.push_back(space);
574 attributeListMap->update_token(lastPreprocDirective, whitespace, expression_value);
575 attributeListMap->update_token(lastPreprocDirective, expression, expression_value);
578 for (
typename ContainerT::const_iterator i = expression.begin(); i != expression.end(); ++i)
580 token_type space = token_type(boost::wave::T_SPACE,
" ", boost::wave::util::file_position_type(BOOST_WAVE_STRINGTYPE(ROSE_WAVE_PSEUDO_FILE), 0, 0));
581 tokens.push_back(space);
582 tokens.push_back(*i);
585 token_type newline = token_type(boost::wave::T_NEWLINE,
"\n", boost::wave::util::file_position_type(BOOST_WAVE_STRINGTYPE(ROSE_WAVE_PSEUDO_FILE), 0, 0));
586 token_container whitespace2;
587 whitespace2.push_back(newline);
588 attributeListMap->update_token(lastPreprocDirective, whitespace2, expression_value);
593 updatingLastToken =
true;
595 last_token = directive;
609 template <
typename ContextT,
typename TokenT>
611 skipped_token(ContextT
const&, TokenT
const& token)
613 using namespace boost::wave;
616 if (token.get_position().get_file().size() == 0)
618 if (token == last_token && token.get_position() == last_token.get_position())
621 token_id
id = token_id(token);
622 token_id lastid = token_id(lastPreprocDirective);
623 if (lastPreprocDirective == token_type())
625 attributeListMap->skipped_token(token);
627 else if (token != lastPreprocDirective)
629 tokens.push_back(token);
632 updatingLastToken =
false;
635 if (updatingLastToken)
640 std::cout <<
"Updating previous token (" << lastPreprocDirective.get_value().c_str() <<
") with token " << token.get_value().c_str() << std::endl;
641 attributeListMap->update_token(lastPreprocDirective, tc,
false);
643 else if (skipping || (lastid != T_PP_IF && lastid != T_PP_IFDEF && lastid != T_PP_IFNDEF && lastid != T_PP_ELIF))
645 attributeListMap->skipped_token(token);
666 lastPreprocDirective = token;
676 case T_PP_DEFINE: std::cout <<
"Skipped: #define\n";
break;
677 case T_PP_IF: std::cout <<
"Skipped: #if\n";
break;
678 case T_PP_IFDEF: std::cout <<
"Skipped: #ifdef\n";
break;
679 case T_PP_IFNDEF: std::cout <<
"Skipped: #ifndef\n";
break;
680 case T_PP_ELSE: std::cout <<
"Skipped: #else\n";
break;
681 case T_PP_ELIF: std::cout <<
"Skipped: #elif\n";
break;
682 case T_PP_ENDIF: std::cout <<
"Skipped: #endif\n";
break;
683 case T_PP_ERROR: std::cout <<
"Skipped: #error\n";
break;
684 case T_PP_LINE: std::cout <<
"Skipped: #line\n";
break;
685 case T_PP_PRAGMA: std::cout <<
"Skipped: #pragma\n";
break;
686 case T_PP_UNDEF: std::cout <<
"Skipped: #undef\n";
break;
687 case T_PP_WARNING: std::cout <<
"Skipped: #warning\n";
break;
688 case T_PP_INCLUDE: std::cout <<
"Skipped: #include \"...\"\n";
break;
689 case T_PP_QHEADER: std::cout <<
"Skipped: #include <...>\n";
break;
690 case T_PP_HHEADER: std::cout <<
"Skipped: #include ...\n";
break;
691 default: std::cout <<
"Skipped: <something else (" << token.get_value().c_str() <<
")>\n";
break;
693 if (lastPreprocDirective != token_type())
694 std::cout <<
"\tskipping is " << skipping <<
"\tupdatingLastToken is " << updatingLastToken <<
"\tlastPreprocDirective is " << lastPreprocDirective.get_value().c_str() << std::endl;
709 template <
typename ContextT,
typename TokenT>
711 undefined_macro(ContextT
const&, TokenT
const& macro_name)
713 token_list_container tokListCont;
714 tokListCont.push_back(macro_name);
715 attributeListMap->
found_directive(lastPreprocDirective,tokListCont,
false);
717 token_type space = token_type(boost::wave::T_SPACE,
" ", boost::wave::util::file_position_type(BOOST_WAVE_STRINGTYPE(ROSE_WAVE_PSEUDO_FILE), 0, 0));
718 tokens.push_back(space);
719 tokens.push_back(macro_name);
723 template <
typename ContainerT>
725 on_warning(ContainerT
const& tokenStream)
727 attributeListMap->
found_directive(lastPreprocDirective,tokenStream,
false);
729 std::cout <<
"ON TOKEN WARNING: " << boost::wave::util::impl::as_string(tokenStream) << std::endl;
745 template <
typename ContextT,
typename ContainerT>
747 found_warning_directive(ContextT
const&, ContainerT
const& message)
749 attributeListMap->
found_directive(lastPreprocDirective,message,
false);
752 std::cout <<
"ON TOKEN WARNING: " << boost::wave::util::impl::as_string(message) << std::endl;
777 template <
typename ContextT,
typename ContainerT>
779 found_line_directive(ContextT
const&, ContainerT
const& arguments,
unsigned int, std::string
const& filename)
781 std::string filenameString(filename.c_str());
784 std::cout <<
"On line found" << std::endl;
791 attributeListMap->
found_directive(lastPreprocDirective,arguments,
false);
793 token_type space = token_type(boost::wave::T_SPACE,
" ", boost::wave::util::file_position_type(BOOST_WAVE_STRINGTYPE(ROSE_WAVE_PSEUDO_FILE), 0, 0));
794 token_container whitespace;
795 whitespace.push_back(space);
797 attributeListMap->update_token(lastPreprocDirective, whitespace,
false);
798 attributeListMap->update_token(lastPreprocDirective, arguments,
false);
801 for (
typename ContainerT::const_iterator i = arguments.begin(); i != arguments.end(); ++i)
803 token_type space = token_type(boost::wave::T_SPACE,
" ", boost::wave::util::file_position_type(BOOST_WAVE_STRINGTYPE(ROSE_WAVE_PSEUDO_FILE), 0, 0));
804 tokens.push_back(space);
805 tokens.push_back(*i);
810 template <
typename ContextT,
typename TokenT>
812 may_skip_whitespace(ContextT
const& ctx, TokenT& token,
bool& skipped_newline)
814 if (token == lastPreprocDirective && token.get_position() == lastPreprocDirective.get_position())
816 if (token == last_token && token.get_position() == last_token.get_position())
819 if (token != TokenT())
820 std::cout <<
"MAX_SKIP_WHITESPACE: " << token.get_value().c_str() << std::endl;
822 using namespace boost::wave;
823 token_id
id = token_id(token);
824 if (
id != T_EOF &&
id != T_EOI)
825 tokens.push_back(token);
826 if (
id != T_EOF &&
id != T_EOI &&
id != T_NEWLINE)
829 std::cout <<
"Normal reported" << std::endl;
830 attributeListMap->may_skip_whitespace(ctx, token, skipped_newline);
835 std::cout <<
"Skip leads to flushing" << std::endl;
836 attributeListMap->flush_token_stream();
841 std::cout <<
"EOF or newline leads to flushing" << std::endl;
842 attributeListMap->flush_token_stream();
847 template <
typename ContextT,
typename ExceptionT>
848 void throw_exception(ContextT
const&, ExceptionT
const&)
851 std::cout <<
"THROW_EXCEPTION" << std::endl;
854 template <
typename ContextT>
855 void detected_include_guard(ContextT
const&, std::string
const& filename, std::string
const& include_guard)
858 std::cout <<
"DETECTED_INCLUDE_GUARD" << include_guard <<
" in file " << filename << std::endl;
861 template <
typename ContextT,
typename TokenT>
862 void detected_pragma_once(ContextT
const&, TokenT
const& pragma_token, std::string
const& filename)
865 std::cout <<
"DETECTED_PRAGMA_ONCE " << pragma_token.get_value() <<
" in file " << filename << std::endl;
868 template <
typename ContextT,
typename ContainerT>
869 bool found_error_directive(ContextT
const&, ContainerT
const&)
872 std::cout <<
"FOUND_ERROR_DIRECTIVE" << std::endl;