cpp_context.hpp

来自「support vector clustering for vc++」· HPP 代码 · 共 461 行 · 第 1/2 页

HPP
461
字号
/*=============================================================================
    Boost.Wave: A Standard compliant C++ preprocessor library
    Definition of the preprocessor context
    
    http://www.boost.org/

    Copyright (c) 2001-2007 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(CPP_CONTEXT_HPP_907485E2_6649_4A87_911B_7F7225F3E5B8_INCLUDED)
#define CPP_CONTEXT_HPP_907485E2_6649_4A87_911B_7F7225F3E5B8_INCLUDED

#include <string>
#include <vector>
#include <stack>

#include <boost/concept_check.hpp>
#include <boost/noncopyable.hpp>
#include <boost/filesystem/path.hpp>

#include <boost/wave/wave_config.hpp>
#if BOOST_WAVE_SERIALIZATION != 0
#include <boost/serialization/serialization.hpp>
#include <boost/wave/wave_config_constant.hpp>
#endif
#include <boost/wave/token_ids.hpp>

#include <boost/wave/util/unput_queue_iterator.hpp>
#include <boost/wave/util/cpp_ifblock.hpp>
#include <boost/wave/util/cpp_include_paths.hpp>
#include <boost/wave/util/iteration_context.hpp>
#include <boost/wave/util/cpp_iterator.hpp>
#include <boost/wave/util/cpp_macromap.hpp>

#include <boost/wave/preprocessing_hooks.hpp>
#include <boost/wave/whitespace_handling.hpp>
#include <boost/wave/cpp_iteration_context.hpp>
#include <boost/wave/language_support.hpp>

// this must occur after all of the includes and before any code appears
#ifdef BOOST_HAS_ABI_HEADERS
#include BOOST_ABI_PREFIX
#endif

///////////////////////////////////////////////////////////////////////////////
namespace boost {
namespace wave {

///////////////////////////////////////////////////////////////////////////////
// 
//  The C preprocessor context template class
//
//      The boost::wave::context template is the main interface class to 
//      control the behaviour of the preprocessing engine.
//
//      The following template parameters has to be supplied:
//
//      IteratorT       The iterator type of the underlying input stream
//      LexIteratorT    The lexer iterator type to use as the token factory
//      InputPolicyT    The input policy type to use for loading the files
//                      to be included. This template parameter is optional and 
//                      defaults to the 
//                          iteration_context_policies::load_file_to_string
//                      type.
//      HooksT          The hooks policy to use for different notification 
//                      callbacks. This template parameter is optional and
//                      defaults to the
//                          context_policies::default_preprocessing_hooks
//                      type.
//
///////////////////////////////////////////////////////////////////////////////

template <
    typename IteratorT,
    typename LexIteratorT, 
    typename InputPolicyT = iteration_context_policies::load_file_to_string,
    typename HooksT = context_policies::eat_whitespace<typename LexIteratorT::token_type>
>
class context : private boost::noncopyable
{
public:

// concept checks
// the given iterator shall be at least a forward iterator type
    BOOST_CLASS_REQUIRE(IteratorT, boost, ForwardIteratorConcept);
    
// public typedefs
    typedef typename LexIteratorT::token_type       token_type;
    typedef context<IteratorT, LexIteratorT, InputPolicyT, HooksT> 
        self_type;
    
    typedef IteratorT                               target_iterator_type;
    typedef LexIteratorT                            lexer_type;
    typedef pp_iterator<self_type>                  iterator_type;

    typedef InputPolicyT                            input_policy_type;
    typedef typename token_type::position_type      position_type;

    
// type of a token sequence
    typedef std::list<token_type, boost::fast_pool_allocator<token_type> > 
        token_sequence_type;
// types of the policies
    typedef HooksT                                  hook_policy_type;
    
private:
// stack of shared_ptr's to the pending iteration contexts 
    typedef boost::shared_ptr<base_iteration_context<lexer_type> > 
        iteration_ptr_type;
    typedef boost::wave::util::iteration_context_stack<iteration_ptr_type> 
            iteration_context_stack_type;
    typedef typename iteration_context_stack_type::size_type iter_size_type;

    context *this_() { return this; }           // avoid warning in constructor
    
public:
    context(target_iterator_type const &first_, target_iterator_type const &last_, 
            char const *fname = "<Unknown>", HooksT const &hooks_ = HooksT())
    :   first(first_), last(last_), filename(fname)
#if BOOST_WAVE_SUPPORT_PRAGMA_ONCE != 0
        , current_filename(fname)
#endif 
        , macros(*this_())
        , language(language_support(
                      support_cpp 
                    | support_option_convert_trigraphs 
                    | support_option_emit_line_directives 
#if BOOST_WAVE_SUPPORT_PRAGMA_ONCE != 0
                    | support_option_include_guard_detection
#endif
                   ))
        , hooks(hooks_)
    {
        macros.init_predefined_macros(fname);
        includes.init_initial_path();
    }
    
// default copy constructor
// default assignment operator
// default destructor
    
// iterator interface
    iterator_type begin() 
    { 
        std::string fname(filename);
        if (filename != "<Unknown>" && filename != "<stdin>") {
            using namespace boost::filesystem;
            path fpath(complete(path(filename)));
            fname = fpath.string();
            includes.set_current_directory(fname.c_str());
        }
        return iterator_type(*this, first, last, position_type(fname.c_str())); 
    }
    iterator_type begin(
        target_iterator_type const &first_, 
        target_iterator_type const &last_) 
    { 
        std::string fname(filename);
        if (filename != "<Unknown>" && filename != "<stdin>") {
            using namespace boost::filesystem;
            path fpath(complete(path(filename)));
            fname = fpath.string();
            includes.set_current_directory(fname.c_str());
        }
        return iterator_type(*this, first_, last_, position_type(fname.c_str())); 
    }
    iterator_type end() const 
        { return iterator_type(); }

// maintain include paths
    bool add_include_path(char const *path_)
        { return includes.add_include_path(path_, false);}
    bool add_sysinclude_path(char const *path_)
        { return includes.add_include_path(path_, true);}
    void set_sysinclude_delimiter() { includes.set_sys_include_delimiter(); }
    typename iteration_context_stack_type::size_type get_iteration_depth() const 
        { return iter_ctxs.size(); }

// maintain defined macros
#if BOOST_WAVE_ENABLE_COMMANDLINE_MACROS != 0
    bool add_macro_definition(std::string macrostring, 
            bool is_predefined = false)
        { return boost::wave::util::add_macro_definition(*this, macrostring, 
            is_predefined, get_language()); }
#endif 
    bool add_macro_definition(token_type const &name, bool has_params,
            std::vector<token_type> &parameters, token_sequence_type &definition,
            bool is_predefined = false)
        { return macros.add_macro(name, has_params, parameters, definition, 
            is_predefined); }
    template <typename IteratorT2>
    bool is_defined_macro(IteratorT2 const &begin, IteratorT2 const &end) 
        { return macros.is_defined(begin, end); }
    bool get_macro_definition(typename token_type::string_type const &name, 
            bool &has_params, bool &is_predefined, position_type &pos,
            std::vector<token_type> &parameters, token_sequence_type &definition)
        { 
            return macros.get_macro(name, has_params, is_predefined, pos,
                parameters, definition); 
        }
    bool remove_macro_definition(typename token_type::string_type const &name, 
            bool even_predefined = false)
        { 
#if BOOST_WAVE_SUPPORT_PRAGMA_ONCE != 0
            // ensure this gets remove from the list of include guards as well
            includes.remove_pragma_once_header(std::string(name.c_str()));
#endif
            return macros.remove_macro(
                token_type(T_IDENTIFIER, name, macros.get_main_pos()), 
                even_predefined); 
        }
    void reset_macro_definitions() 
        { macros.reset_macromap(); macros.init_predefined_macros(); }

// get the Wave version information 
    static std::string get_version()  
        { return boost::wave::util::predefined_macros::get_fullversion(false); }
    static std::string get_version_string()  
        { return boost::wave::util::predefined_macros::get_versionstr(false); }

// access current language options
    void set_language(boost::wave::language_support language_,
                      bool reset_macros = true) 
    { 
        language = language_; 
        if (reset_macros)
            reset_macro_definitions();
    }
    boost::wave::language_support get_language() const { return language; }

⌨️ 快捷键说明

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