File indexing completed on 2025-01-30 10:02:17
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
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
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
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 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; }
0068 #endif
0069
0070
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
0084
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
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
0112
0113
0114 }
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124
0125
0126
0127
0128
0129
0130
0131
0132
0133
0134
0135
0136
0137
0138
0139
0140
0141
0142
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
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
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
0222
0223
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 }
0233 }
0234 }
0235
0236
0237 #ifdef BOOST_HAS_ABI_HEADERS
0238 #include BOOST_ABI_SUFFIX
0239 #endif
0240
0241 #undef BOOST_WAVE_EOF_PREFIX
0242
0243 #endif