bool CPreProcessor::emit_line_directive(ContextT const& ctx, ContainerT&pending, typename ContextT::token_type const& act_token) { //std::cout << "in emit_line_directive" << std::endl; // emit a #line directive showing the relative filename instead typename ContextT::position_type pos = act_token.get_position(); unsigned int column = 1; typedef typename ContextT::token_type result_type; pos.set_column(column); std::string comments = "// From file: "; pending.push_back(result_type(wave::T_STRINGLIT, comments.c_str(), pos)); pos.set_column(column += (unsigned int)comments.size()); // account for comments std::string file(""); boost::filesystem::path filename(wave::util::create_path(ctx.get_current_filename().c_str())); file += boost::wave::util::impl::escape_lit(wave::util::native_file_string(filename)) + ""; pending.push_back(result_type(wave::T_STRINGLIT, file.c_str(), pos)); pos.set_column(column += (unsigned int)file.size()); // account for filename pending.push_back(result_type(wave::T_GENERATEDNEWLINE, "\n", pos)); return true; }
bool interpret_pragma(ContextT &ctx, ContainerT &pending, typename ContextT::token_type const &option, ContainerT const &valuetokens, typename ContextT::token_type const &act_token) { typedef typename ContextT::token_type token_type; ContainerT values(valuetokens); boost::wave::util::impl::trim_sequence(values); // trim whitespace if (option.get_value() == "timer") { // #pragma wave timer(value) if (0 == values.size()) { // no value means '1' using namespace boost::wave; timer(token_type(T_INTLIT, "1", act_token.get_position())); } else { timer(values.front()); } return true; } if (option.get_value() == "trace") { // enable/disable tracing option return interpret_pragma_trace(ctx, values, act_token); } if (option.get_value() == "system") { if (!enable_system_command) { // if the #pragma wave system() directive is not enabled, throw // a corresponding error (actually its a remark), BOOST_WAVE_THROW_CTX(ctx, bad_pragma_exception, pragma_system_not_enabled, boost::wave::util::impl::as_string(values).c_str(), act_token.get_position()); return false; } // try to spawn the given argument as a system command and return the // std::cout of this process as the replacement of this _Pragma return interpret_pragma_system(ctx, pending, values, act_token); } if (option.get_value() == "stop") { // stop the execution and output the argument BOOST_WAVE_THROW_CTX(ctx, preprocess_exception, error_directive, boost::wave::util::impl::as_string(values).c_str(), act_token.get_position()); return false; } if (option.get_value() == "option") { // handle different options return interpret_pragma_option(ctx, values, act_token); } return false; }
bool emit_line_directive(ContextT const& ctx, ContainerT &pending, typename ContextT::token_type const& act_token) { if (!need_emit_line_directives(ctx.get_language()) || !enable_relative_names_in_line_directives()) { return false; } // emit a #line directive showing the relative filename instead typename ContextT::position_type pos = act_token.get_position(); unsigned int column = 6; typedef typename ContextT::token_type result_type; using namespace boost::wave; pos.set_column(1); pending.push_back(result_type(T_PP_LINE, "#line", pos)); pos.set_column(column); // account for '#line' pending.push_back(result_type(T_SPACE, " ", pos)); // 21 is the max required size for a 64 bit integer represented as a // string char buffer[22]; using namespace std; // for some systems sprintf is in namespace std sprintf (buffer, "%d", pos.get_line()); pos.set_column(++column); // account for ' ' pending.push_back(result_type(T_INTLIT, buffer, pos)); pos.set_column(column += (unsigned int)strlen(buffer)); // account for <number> pending.push_back(result_type(T_SPACE, " ", pos)); pos.set_column(++column); // account for ' ' std::string file("\""); boost::filesystem::path filename( boost::wave::util::create_path(ctx.get_current_relative_filename().c_str())); using boost::wave::util::impl::escape_lit; file += escape_lit(boost::wave::util::native_file_string(filename)) + "\""; pending.push_back(result_type(T_STRINGLIT, file.c_str(), pos)); pos.set_column(column += (unsigned int)file.size()); // account for filename pending.push_back(result_type(T_GENERATEDNEWLINE, "\n", pos)); return true; }