Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 10:02:17

0001 /*=============================================================================
0002     Boost.Wave: A Standard compliant C++ preprocessor library
0003 
0004     Definition of the lexer iterator
0005 
0006     http://www.boost.org/
0007 
0008     Copyright (c) 2001-2012 Hartmut Kaiser. Distributed under the Boost
0009     Software License, Version 1.0. (See accompanying file
0010     LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0011 =============================================================================*/
0012 
0013 #if !defined(BOOST_CPP_LEX_ITERATOR_HPP_AF0C37E3_CBD8_4F33_A225_51CF576FA61F_INCLUDED)
0014 #define BOOST_CPP_LEX_ITERATOR_HPP_AF0C37E3_CBD8_4F33_A225_51CF576FA61F_INCLUDED
0015 
0016 #include <string>
0017 
0018 #include <boost/assert.hpp>
0019 #include <boost/intrusive_ptr.hpp>
0020 
0021 #include <boost/wave/wave_config.hpp>
0022 #include <boost/spirit/include/support_multi_pass.hpp>
0023 
0024 #include <boost/wave/util/file_position.hpp>
0025 #include <boost/wave/util/functor_input.hpp>
0026 #include <boost/wave/cpplexer/cpp_lex_interface_generator.hpp>
0027 
0028 #include <boost/wave/language_support.hpp>
0029 
0030 // this must occur after all of the includes and before any code appears
0031 #ifdef BOOST_HAS_ABI_HEADERS
0032 #include BOOST_ABI_PREFIX
0033 #endif
0034 
0035 #if 0 != __COMO_VERSION__ || !BOOST_WORKAROUND(BOOST_MSVC, <= 1310)
0036 #define BOOST_WAVE_EOF_PREFIX static
0037 #else
0038 #define BOOST_WAVE_EOF_PREFIX
0039 #endif
0040 
0041 ///////////////////////////////////////////////////////////////////////////////
0042 namespace boost {
0043 namespace wave {
0044 namespace cpplexer {
0045 namespace impl {
0046 
0047 ///////////////////////////////////////////////////////////////////////////////
0048 //
0049 //  lex_iterator_functor_shim
0050 //
0051 ///////////////////////////////////////////////////////////////////////////////
0052 
0053 template <typename TokenT>
0054 class lex_iterator_functor_shim
0055 {
0056     typedef typename TokenT::position_type  position_type;
0057 
0058 public:
0059     lex_iterator_functor_shim()
0060 #if /*0 != __DECCXX_VER || */defined(__PGI)
0061       : eof()
0062 #endif
0063     {}
0064 
0065 #if BOOST_WORKAROUND(BOOST_MSVC, <= 1310)
0066     lex_iterator_functor_shim& operator= (lex_iterator_functor_shim const& rhs)
0067         { return *this; }   // nothing to do here
0068 #endif
0069 
0070     // interface to the iterator_policies::split_functor_input policy
0071     typedef TokenT result_type;
0072     typedef lex_iterator_functor_shim unique;
0073     typedef lex_input_interface<TokenT>* shared;
0074 
0075     BOOST_WAVE_EOF_PREFIX result_type const eof;
0076 
0077     template <typename MultiPass>
0078     static result_type& get_next(MultiPass& mp, result_type& result)
0079     {
0080         return mp.shared()->ftor->get(result);
0081     }
0082 
0083     // this will be called whenever the last reference to a multi_pass will
0084     // be released
0085     template <typename MultiPass>
0086     static void destroy(MultiPass& mp)
0087     {
0088         delete mp.shared()->ftor;
0089     }
0090 
0091     template <typename MultiPass>
0092     static void set_position(MultiPass& mp, position_type const &pos)
0093     {
0094         mp.shared()->ftor->set_position(pos);
0095     }
0096 #if BOOST_WAVE_SUPPORT_PRAGMA_ONCE != 0
0097     template <typename MultiPass>
0098     static bool has_include_guards(MultiPass& mp, std::string& guard_name)
0099     {
0100         return mp.shared()->ftor->has_include_guards(guard_name);
0101     }
0102 #endif
0103 };
0104 
0105 ///////////////////////////////////////////////////////////////////////////////
0106 //  eof token
0107 #if 0 != __COMO_VERSION__ || !BOOST_WORKAROUND(BOOST_MSVC, <= 1310)
0108 template <typename TokenT>
0109 typename lex_iterator_functor_shim<TokenT>::result_type const
0110     lex_iterator_functor_shim<TokenT>::eof;
0111 #endif // 0 != __COMO_VERSION__
0112 
0113 ///////////////////////////////////////////////////////////////////////////////
0114 }   // namespace impl
0115 
0116 ///////////////////////////////////////////////////////////////////////////////
0117 //
0118 //  lex_iterator
0119 //
0120 //      A generic C++ lexer interface class, which allows to plug in different
0121 //      lexer implementations. The interface between the lexer type used and
0122 //      the preprocessor component depends on the token type only (template
0123 //      parameter TokenT).
0124 //      Additionally, the following requirements apply:
0125 //
0126 //          - the lexer type should have a function implemented, which returnes
0127 //            the next lexed token from the input stream:
0128 //                typename TokenT get();
0129 //          - at the end of the input stream this function should return the
0130 //            eof token equivalent
0131 //          - the lexer should implement a constructor taking two iterators
0132 //            pointing to the beginning and the end of the input stream,
0133 //            a third parameter containing the name of the parsed input file
0134 //            and a 4th parameter of the type boost::wave::language_support
0135 //            which specifies, which language subset should be supported (C++,
0136 //            C99, C++11 etc.).
0137 //
0138 ///////////////////////////////////////////////////////////////////////////////
0139 
0140 ///////////////////////////////////////////////////////////////////////////////
0141 //  Divide the given functor type into its components (unique and shared)
0142 //  and build a std::pair from these parts
0143 template <typename FunctorData>
0144 struct make_multi_pass
0145 {
0146     typedef
0147         std::pair<typename FunctorData::unique, typename FunctorData::shared>
0148     functor_data_type;
0149     typedef typename FunctorData::result_type result_type;
0150 
0151     typedef boost::spirit::iterator_policies::split_functor_input input_policy;
0152     typedef boost::spirit::iterator_policies::ref_counted ownership_policy;
0153 #if defined(BOOST_WAVE_DEBUG)
0154     typedef boost::spirit::iterator_policies::buf_id_check check_policy;
0155 #else
0156     typedef boost::spirit::iterator_policies::no_check check_policy;
0157 #endif
0158     typedef boost::spirit::iterator_policies::split_std_deque storage_policy;
0159 
0160     typedef boost::spirit::iterator_policies::default_policy<
0161             ownership_policy, check_policy, input_policy, storage_policy>
0162         policy_type;
0163     typedef boost::spirit::multi_pass<functor_data_type, policy_type> type;
0164 };
0165 
0166 ///////////////////////////////////////////////////////////////////////////////
0167 template <typename TokenT>
0168 class lex_iterator
0169 :   public make_multi_pass<impl::lex_iterator_functor_shim<TokenT> >::type
0170 {
0171     typedef impl::lex_iterator_functor_shim<TokenT> input_policy_type;
0172 
0173     typedef typename make_multi_pass<input_policy_type>::type base_type;
0174     typedef typename make_multi_pass<input_policy_type>::functor_data_type
0175         functor_data_type;
0176 
0177     typedef typename input_policy_type::unique unique_functor_type;
0178     typedef typename input_policy_type::shared shared_functor_type;
0179 
0180 public:
0181     typedef TokenT token_type;
0182 
0183     lex_iterator()
0184     {}
0185 
0186     template <typename IteratorT>
0187     lex_iterator(IteratorT const &first, IteratorT const &last,
0188             typename TokenT::position_type const &pos,
0189             boost::wave::language_support language)
0190     :   base_type(
0191             functor_data_type(
0192                 unique_functor_type(),
0193                 lex_input_interface_generator<TokenT>
0194                     ::new_lexer(first, last, pos, language)
0195             )
0196         )
0197     {}
0198 
0199     void set_position(typename TokenT::position_type const &pos)
0200     {
0201         typedef typename TokenT::position_type position_type;
0202 
0203         // set the new position in the current token
0204         token_type const& currtoken = this->base_type::dereference(*this);
0205         position_type currpos = currtoken.get_position();
0206 
0207         currpos.set_file(pos.get_file());
0208         currpos.set_line(pos.get_line());
0209         const_cast<token_type&>(currtoken).set_position(currpos);
0210 
0211         // set the new position for future tokens as well
0212         if (token_type::string_type::npos !=
0213             currtoken.get_value().find_first_of('\n'))
0214         {
0215             currpos.set_line(pos.get_line() + 1);
0216         }
0217         unique_functor_type::set_position(*this, currpos);
0218     }
0219 
0220 #if BOOST_WAVE_SUPPORT_PRAGMA_ONCE != 0
0221     // return, whether the current file has include guards
0222     // this function returns meaningful results only if the file was scanned
0223     // completely
0224     bool has_include_guards(std::string& guard_name) const
0225     {
0226         return unique_functor_type::has_include_guards(*this, guard_name);
0227     }
0228 #endif
0229 };
0230 
0231 ///////////////////////////////////////////////////////////////////////////////
0232 }   // namespace cpplexer
0233 }   // namespace wave
0234 }   // namespace boost
0235 
0236 // the suffix header occurs after all of the code
0237 #ifdef BOOST_HAS_ABI_HEADERS
0238 #include BOOST_ABI_SUFFIX
0239 #endif
0240 
0241 #undef BOOST_WAVE_EOF_PREFIX
0242 
0243 #endif // !defined(BOOST_CPP_LEX_ITERATOR_HPP_AF0C37E3_CBD8_4F33_A225_51CF576FA61F_INCLUDED)