📄 testwave_app.cpp
字号:
<< "testwave: preprocessing error in '" << flag << "()' directive: " << error << std::endl; return false; } // include this text into the extracted information // only if the result is not zero using namespace std; // some system have atoi in namespace std if (0 != atoi(result.c_str())) { std::string thiscontent(value.substr(p+1)); if (9 == debuglevel) { std::cerr << "extract_special_information: extracted: " << thiscontent << std::endl; } trim_whitespace(thiscontent); content += thiscontent; } } else { std::string thiscontent(value.substr(3, value.size()-5)); if (9 == debuglevel) { std::cerr << "extract_special_information: extracted: " << thiscontent << std::endl; } trim_whitespace(thiscontent); content += thiscontent; } } } else if (T_CPPCOMMENT == id) { std::string value = (*it).get_value().c_str(); if (flag == value[2]) { if (value.size() > 3 && '(' == value[3]) { std::size_t p = value.find_first_of(")"); if (std::string::npos == p) { std::cerr << "testwave: missing closing parenthesis in '" << flag << "()' directive" << std::endl; return false; } std::string source = value.substr(4, p-4); std::string result, error, hooks; bool pp_result = preprocess_file(filename, source, result, error, hooks, true); if (!pp_result) { std::cerr << "testwave: preprocessing error in '" << flag << "()' directive: " << error << std::endl; return false; } // include this text into the extracted information // only if the result is not zero using namespace std; // some system have atoi in namespace std if (0 != atoi(result.c_str())) { std::string thiscontent(value.substr((' ' == value[p+1]) ? p+2 : p+1)); if (9 == debuglevel) { std::cerr << "extract_special_information: extracted: " << thiscontent << std::endl; } trim_whitespace(thiscontent); content += thiscontent; } } else { std::string thiscontent(value.substr((' ' == value[3]) ? 4 : 3)); if (9 == debuglevel) { std::cerr << "extract_special_information: extracted: " << thiscontent; } trim_whitespace(content); content += thiscontent; } } } } } catch (boost::wave::cpplexer::lexing_exception const &e) { // some lexing error std::cerr << e.file_name() << "(" << e.line_no() << "): " << e.description() << std::endl; return false; } if (9 == debuglevel) { std::cerr << "extract_special_information: succeeded extracting special information ('" << flag << "')" << std::endl; } return true;}/////////////////////////////////////////////////////////////////////////////////// Extract the expected output from the given input data//// The expected output has to be provided inside of special comments which// start with a capital 'R'. All such comments are concatenated and returned// through the parameter 'expected'./////////////////////////////////////////////////////////////////////////////////inline bool testwave_app::extract_expected_output(std::string const& filename, std::string const& instr, std::string& expected, std::string& expectedhooks){ return extract_special_information(filename, instr, 'R', expected) && extract_special_information(filename, instr, 'H', expectedhooks);}/////////////////////////////////////////////////////////////////////////////////// Extracts the required preprocessing options from the given input data and// initialises the given Wave context object accordingly. // We allow the same (applicable) options to be used as are valid for the wave // driver executable./////////////////////////////////////////////////////////////////////////////////template <typename Context>bool testwave_app::extract_options(std::string const& filename, std::string const& instr, Context& ctx, bool single_line){ if (9 == debuglevel) { std::cerr << "extract_options: extracting options" << std::endl; }// extract the required information from the comments flagged by a // capital 'O' std::string options; if (!extract_special_information(filename, instr, 'O', options)) return false; try { // parse the configuration information into a program_options_description // object po::variables_map local_vm; cmd_line_utils::read_config_options(debuglevel, options, desc_options, local_vm); initialise_options(ctx, local_vm, single_line); } catch (std::exception const &e) { std::cerr << filename << ": exception caught: " << e.what() << std::endl; return false; } if (9 == debuglevel) { std::cerr << "extract_options: succeeded extracting options" << std::endl; } return true;}template <typename Context>bool testwave_app::initialise_options(Context& ctx, po::variables_map const& vm, bool single_line){ if (9 == debuglevel) { std::cerr << "initialise_options: initializing options" << std::endl; }// initialize the given context from the parsed options#if BOOST_WAVE_SUPPORT_VARIADICS_PLACEMARKERS != 0// enable C99 mode, if appropriate (implies variadics) if (vm.count("c99")) { if (9 == debuglevel) { std::cerr << "initialise_options: option: c99" << std::endl; } ctx.set_language( boost::wave::language_support( boost::wave::support_c99 | boost::wave::support_option_emit_line_directives #if BOOST_WAVE_SUPPORT_PRAGMA_ONCE != 0 | boost::wave::support_option_include_guard_detection#endif#if BOOST_WAVE_EMIT_PRAGMA_DIRECTIVES != 0 | boost::wave::support_option_emit_pragma_directives#endif | boost::wave::support_option_insert_whitespace )); } else if (vm.count("variadics")) { // enable variadics and placemarkers, if appropriate if (9 == debuglevel) { std::cerr << "initialise_options: option: variadics" << std::endl; } ctx.set_language(boost::wave::enable_variadics(ctx.get_language())); }#endif // BOOST_WAVE_SUPPORT_VARIADICS_PLACEMARKERS != 0// enable long_long mode, if appropriate if (vm.count("long_long")) { if (9 == debuglevel) { std::cerr << "initialise_options: option: long_long" << std::endl; } ctx.set_language(boost::wave::enable_long_long(ctx.get_language())); } // enable preserving comments mode, if appropriate if (vm.count("preserve")) { if (9 == debuglevel) { std::cerr << "initialise_options: option: preserve" << std::endl; } ctx.set_language( boost::wave::enable_preserve_comments(ctx.get_language())); } // disable automatic include guard detection if (vm.count("noguard")) { if (9 == debuglevel) { std::cerr << "initialise_options: option: guard" << std::endl; } ctx.set_language( boost::wave::enable_include_guard_detection(ctx.get_language(), false)); } // enable trigraph conversion if (9 == debuglevel) { std::cerr << "initialise_options: option: convert_trigraphs" << std::endl; } ctx.set_language(boost::wave::enable_convert_trigraphs(ctx.get_language()));// enable single_line mode if (single_line) { if (9 == debuglevel) { std::cerr << "initialise_options: option: single_line" << std::endl; } ctx.set_language(boost::wave::enable_single_line(ctx.get_language())); } // add include directories to the system include search paths if (vm.count("sysinclude")) { std::vector<std::string> const& syspaths = variables_map_as(vm["sysinclude"], (std::vector<std::string> *)NULL); std::vector<std::string>::const_iterator end = syspaths.end(); for (std::vector<std::string>::const_iterator cit = syspaths.begin(); cit != end; ++cit) { if (9 == debuglevel) { std::cerr << "initialise_options: option: -S" << *cit << std::endl; } ctx.add_sysinclude_path((*cit).c_str()); } } // add include directories to the user include search paths if (vm.count("include")) { cmd_line_utils::include_paths const &ip = variables_map_as(vm["include"], (cmd_line_utils::include_paths*)NULL); std::vector<std::string>::const_iterator end = ip.paths.end(); for (std::vector<std::string>::const_iterator cit = ip.paths.begin(); cit != end; ++cit) { if (9 == debuglevel) { std::cerr << "initialise_options: option: -I" << *cit << std::endl; } ctx.add_include_path((*cit).c_str()); } // if on the command line was given -I- , this has to be propagated if (ip.seen_separator) { if (9 == debuglevel) { std::cerr << "initialise_options: option: -I-" << std::endl; } ctx.set_sysinclude_delimiter(); } // add system include directories to the include path std::vector<std::string>::const_iterator sysend = ip.syspaths.end(); for (std::vector<std::string>::const_iterator syscit = ip.syspaths.begin(); syscit != sysend; ++syscit) { if (9 == debuglevel) { std::cerr << "initialise_options: option: -S" << *syscit << std::endl; } ctx.add_sysinclude_path((*syscit).c_str()); } }// add additional defined macros if (vm.count("define")) { std::vector<std::string> const ¯os = variables_map_as(vm["define"], (std::vector<std::string>*)NULL); std::vector<std::string>::const_iterator end = macros.end(); for (std::vector<std::string>::const_iterator cit = macros.begin(); cit != end; ++cit) { if (9 == debuglevel) { std::cerr << "initialise_options: option: -D" << *cit << std::endl; } ctx.add_macro_definition(*cit, true); } }// add additional predefined macros if (vm.count("predefine")) { std::vector<std::string> const &predefmacros = variables_map_as(vm["predefine"], (std::vector<std::string>*)NULL); std::vector<std::string>::const_iterator end = predefmacros.end(); for (std::vector<std::string>::const_iterator cit = predefmacros.begin(); cit != end; ++cit) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -