Пример #1
0
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 
    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;
    }