⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 collect_hooks_information.hpp

📁 Boost provides free peer-reviewed portable C++ source libraries. We emphasize libraries that work
💻 HPP
📖 第 1 页 / 共 2 页
字号:
/*=============================================================================    Boost.Wave: A Standard compliant C++ preprocessor library    http://www.boost.org/    Copyright (c) 2001-2008 Hartmut Kaiser. Distributed under the Boost    Software License, Version 1.0. (See accompanying file    LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)=============================================================================*/#if !defined(BOOST_WAVE_LIBS_WAVE_TEST_COLLECT_HOOKS_INFORMATION_HPP)#define BOOST_WAVE_LIBS_WAVE_TEST_COLLECT_HOOKS_INFORMATION_HPP#include <boost/lexical_cast.hpp>#include <boost/filesystem/path.hpp>#include <boost/filesystem/operations.hpp>///////////////////////////////////////////////////////////////////////////////// workaround for missing ostringstream#ifdef BOOST_NO_STRINGSTREAM#include <strstream>#define BOOST_WAVETEST_OSSTREAM std::ostrstreamstd::string BOOST_WAVETEST_GETSTRING(std::ostrstream& ss){    ss << ends;    std::string rval = ss.str();    ss.freeze(false);    return rval;}#else#include <sstream>#define BOOST_WAVETEST_GETSTRING(ss) ss.str()#define BOOST_WAVETEST_OSSTREAM std::ostringstream#endif///////////////////////////////////////////////////////////////////////////////template <typename String>String handle_filepath(String const &name){    using boost::wave::util::impl::unescape_lit;        String unesc_name (unescape_lit(name));    typename String::size_type p = unesc_name.find_last_of("/\\");    if (p != unesc_name.npos)        unesc_name = unesc_name.substr(p+1);    return unesc_name;}///////////////////////////////////////////////////////////////////////////////template <typename String>inline String repr(boost::wave::util::file_position<String> const& pos){    std::string linenum = boost::lexical_cast<std::string>(pos.get_line());    return handle_filepath(pos.get_file()) + String("(") + linenum.c_str() + ")";}///////////////////////////////////////////////////////////////////////////////template <typename Token>class collect_hooks_information   : public boost::wave::context_policies::eat_whitespace<Token>{    typedef boost::wave::context_policies::eat_whitespace<Token> base_type;public:    collect_hooks_information(std::string& trace)      : hooks_trace(trace)    {}    ///////////////////////////////////////////////////////////////////////////    //      //  The function 'expanding_function_like_macro' is called, whenever a     //  function-like macro is to be expanded.    //    //  The parameter 'macrodef' marks the position, where the macro to expand     //  is defined.    //    //  The parameter 'formal_args' holds the formal arguments used during the    //  definition of the macro.    //    //  The parameter 'definition' holds the macro definition for the macro to     //  trace.    //    //  The parameter 'macro_call' marks the position, where this macro invoked.    //    //  The parameter 'arguments' holds the macro arguments used during the     //  invocation of the macro    //    //  The parameters 'seqstart' and 'seqend' point into the input token     //  stream allowing to access the whole token sequence comprising the macro    //  invocation (starting with the opening parenthesis and ending after the    //  closing one).    //    //  The return value defines, whether the corresponding macro will be     //  expanded (return false) or will be copied to the output (return true).    //  Note: the whole argument list is copied unchanged to the output as well    //        without any further processing.    //    ///////////////////////////////////////////////////////////////////////////    template <typename Context, typename Container, typename Iterator>    bool     expanding_function_like_macro(Context const& ctx,        Token const& macro, std::vector<Token> const& formal_args,         Container const& definition,        Token const& macrocall, std::vector<Container> const& arguments,        Iterator const& seqstart, Iterator const& seqend)     {         BOOST_WAVETEST_OSSTREAM strm;        // trace real macro call        strm << "00: " << repr(macrocall.get_position()) << ": "              << macrocall.get_value() << "(";         for (typename std::vector<Token>::size_type i = 0;             i < arguments.size(); ++i)         {            strm << boost::wave::util::impl::as_string(arguments[i]);            if (i < arguments.size()-1)                strm << ",";        }        strm << "), ";                // trace macro definition        strm << "[" << repr(macro.get_position()) << ": "             << macro.get_value() << "(";         for (typename std::vector<Token>::size_type i = 0;             i < formal_args.size(); ++i)         {            strm << formal_args[i].get_value();            if (i < formal_args.size()-1)                strm << ", ";        }        strm << ")=" << boost::wave::util::impl::as_string(definition) << "]"              << std::endl;        hooks_trace += BOOST_WAVETEST_GETSTRING(strm);        return false;     // default is to normally expand the macro    }    ///////////////////////////////////////////////////////////////////////////    //      //  The function 'expanding_object_like_macro' is called, whenever a     //  object-like macro is to be expanded .    //    //  The parameter 'ctx' is a reference to the context object used for     //  instantiating the preprocessing iterators by the user.    //    //  The parameter 'macro' marks the position, where the macro to expand     //  is defined.    //    //  The definition 'definition' holds the macro definition for the macro to     //  trace.    //    //  The parameter 'macrocall' marks the position, where this macro invoked.    //    //  The return value defines, whether the corresponding macro will be     //  expanded (return false) or will be copied to the output (return true).    //    ///////////////////////////////////////////////////////////////////////////    template <typename Context, typename Container>    bool     expanding_object_like_macro(Context const& ctx, Token const& macro,         Container const& definition, Token const& macrocall)    {         BOOST_WAVETEST_OSSTREAM strm;        strm << "01: " << repr(macro.get_position()) << ": "              << macro.get_value() << std::endl;        hooks_trace += BOOST_WAVETEST_GETSTRING(strm);        return false;   // default is to normally expand the macro    }    ///////////////////////////////////////////////////////////////////////////    //      //  The function 'expanded_macro' is called, whenever the expansion of a     //  macro is finished but before the rescanning process starts.    //    //  The parameter 'ctx' is a reference to the context object used for     //  instantiating the preprocessing iterators by the user.    //    //  The parameter 'result' contains the token sequence generated as the     //  result of the macro expansion.    //    ///////////////////////////////////////////////////////////////////////////    template <typename Context, typename Container>    void expanded_macro(Context const& ctx, Container const& result)    {        BOOST_WAVETEST_OSSTREAM strm;        strm << "02: " << boost::wave::util::impl::as_string(result) << std::endl;        hooks_trace += BOOST_WAVETEST_GETSTRING(strm);    }    ///////////////////////////////////////////////////////////////////////////    //      //  The function 'rescanned_macro' is called, whenever the rescanning of a     //  macro is finished.    //    //  The parameter 'ctx' is a reference to the context object used for     //  instantiating the preprocessing iterators by the user.    //    //  The parameter 'result' contains the token sequence generated as the     //  result of the rescanning.    //    ///////////////////////////////////////////////////////////////////////////    template <typename Context, typename Container>    void rescanned_macro(Context const& ctx, Container const& result)    {        BOOST_WAVETEST_OSSTREAM strm;        strm << "03: " << boost::wave::util::impl::as_string(result) << std::endl;        hooks_trace += BOOST_WAVETEST_GETSTRING(strm);    }    ///////////////////////////////////////////////////////////////////////////    //      //  The function 'found_include_directive' is called, whenever a #include    //  directive was located.    //    //  The parameter 'ctx' is a reference to the context object used for     //  instantiating the preprocessing iterators by the user.    //    //  The parameter 'filename' contains the (expanded) file name found after     //  the #include directive. This has the format '<file>', '"file"' or     //  'file'.    //  The formats '<file>' or '"file"' are used for #include directives found     //  in the preprocessed token stream, the format 'file' is used for files    //  specified through the --force_include command line argument.    //    //  The parameter 'include_next' is set to true if the found directive was    //  a #include_next directive and the BOOST_WAVE_SUPPORT_INCLUDE_NEXT    //  preprocessing constant was defined to something != 0.    //    //  The return value defines, whether the found file will be included     //  (return false) or will be skipped (return true).    //    ///////////////////////////////////////////////////////////////////////////    template <typename Context>    bool     found_include_directive(Context const& ctx, std::string const& filename,         bool include_next)     {        BOOST_WAVETEST_OSSTREAM strm;        strm << "04: " << filename;        if (include_next)            strm << " (include_next)";        strm << std::endl;        hooks_trace += BOOST_WAVETEST_GETSTRING(strm);        return false;    // ok to include this file    }        ///////////////////////////////////////////////////////////////////////////    //      //  The function 'opened_include_file' is called, whenever a file referred     //  by an #include directive was successfully located and opened.    //    //  The parameter 'ctx' is a reference to the context object used for     //  instantiating the preprocessing iterators by the user.    //    //  The parameter 'filename' contains the file system path of the     //  opened file (this is relative to the directory of the currently     //  processed file or a absolute path depending on the paths given as the    //  include search paths).    //    //  The include_depth parameter contains the current include file depth.    //    //  The is_system_include parameter denotes, whether the given file was     //  found as a result of a #include <...> directive.    //      ///////////////////////////////////////////////////////////////////////////    template <typename Context>    void     opened_include_file(Context const& ctx, std::string const& relname,         std::string const& absname, bool is_system_include)     {        BOOST_WAVETEST_OSSTREAM strm;        strm << "05: " << relname << " (" << absname << ")" << std::endl;        hooks_trace += BOOST_WAVETEST_GETSTRING(strm);    }        ///////////////////////////////////////////////////////////////////////////    //      //  The function 'returning_from_include_file' is called, whenever an    //  included file is about to be closed after it's processing is complete.    //    //  The parameter 'ctx' is a reference to the context object used for     //  instantiating the preprocessing iterators by the user.    //    ///////////////////////////////////////////////////////////////////////////    template <typename Context>    void    returning_from_include_file(Context const& ctx)     {        BOOST_WAVETEST_OSSTREAM strm;        strm << "06: " << std::endl;        hooks_trace += BOOST_WAVETEST_GETSTRING(strm);    }    ///////////////////////////////////////////////////////////////////////////    //      //  The function 'interpret_pragma' is called, whenever a #pragma command     //  directive is found which isn't known to the core Wave library, where    //  command is the value defined as the BOOST_WAVE_PRAGMA_KEYWORD constant    //  which defaults to "wave".    //    //  The parameter 'ctx' is a reference to the context object used for     //  instantiating the preprocessing iterators by the user.    //    //  The parameter 'pending' may be used to push tokens back into the input     //  stream, which are to be used as the replacement text for the whole     //  #pragma directive.    //    //  The parameter 'option' contains the name of the interpreted pragma.    //    //  The parameter 'values' holds the values of the parameter provided to     //  the pragma operator.    //    //  The parameter 'act_token' contains the actual #pragma token, which may     //  be used for error output.    //    //  If the return value is 'false', the whole #pragma directive is     //  interpreted as unknown and a corresponding error message is issued. A    //  return value of 'true' signs a successful interpretation of the given     //  #pragma.    //    ///////////////////////////////////////////////////////////////////////////    template <typename Context, typename Container>    bool     interpret_pragma(Context const& ctx, Container &pending,         Token const& option, Container const& values, Token const& act_token)    {        BOOST_WAVETEST_OSSTREAM strm;        strm << "07: " << std::endl;        hooks_trace += BOOST_WAVETEST_GETSTRING(strm);        return false;    }    ///////////////////////////////////////////////////////////////////////////    //    //  The function 'defined_macro' is called, whenever a macro was defined    //  successfully.    //    //  The parameter 'ctx' is a reference to the context object used for     //  instantiating the preprocessing iterators by the user.    //    //  The parameter 'name' is a reference to the token holding the macro name.    //

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -