Boost logo

Boost-Commit :

From: hartmut.kaiser_at_[hidden]
Date: 2008-04-16 21:56:25


Author: hkaiser
Date: 2008-04-16 21:56:25 EDT (Wed, 16 Apr 2008)
New Revision: 44483
URL: http://svn.boost.org/trac/boost/changeset/44483

Log:
Wave: Fixed slex test
Text files modified:
   trunk/boost/wave/cpplexer/cpp_lex_iterator.hpp | 2
   trunk/boost/wave/cpplexer/re2clex/cpp_re2c_lexer.hpp | 4
   trunk/libs/wave/samples/cpp_tokens/slex/cpp_slex_lexer.hpp | 11 ++--
   trunk/libs/wave/samples/cpp_tokens/slex_iterator.hpp | 100 ++++++++++++++++++++++++++++-----------
   4 files changed, 79 insertions(+), 38 deletions(-)

Modified: trunk/boost/wave/cpplexer/cpp_lex_iterator.hpp
==============================================================================
--- trunk/boost/wave/cpplexer/cpp_lex_iterator.hpp (original)
+++ trunk/boost/wave/cpplexer/cpp_lex_iterator.hpp 2008-04-16 21:56:25 EDT (Wed, 16 Apr 2008)
@@ -79,7 +79,7 @@
     // be released
     template <typename MultiPass>
     static void destroy(MultiPass& mp)
- {
+ {
         delete mp.shared->ftor;
     }
 

Modified: trunk/boost/wave/cpplexer/re2clex/cpp_re2c_lexer.hpp
==============================================================================
--- trunk/boost/wave/cpplexer/re2clex/cpp_re2c_lexer.hpp (original)
+++ trunk/boost/wave/cpplexer/re2clex/cpp_re2c_lexer.hpp 2008-04-16 21:56:25 EDT (Wed, 16 Apr 2008)
@@ -280,11 +280,11 @@
 // std::cerr << boost::wave::get_token_name(id) << ": " << value << std::endl;
 
     // the re2c lexer reports the new line number for newline tokens
-#if BOOST_WAVE_SUPPORT_PRAGMA_ONCE != 0
     result = token_type(id, value, PositionT(filename, actline, scanner.column));
+
+#if BOOST_WAVE_SUPPORT_PRAGMA_ONCE != 0
     return guards.detect_guard(result);
 #else
- result = token_type(id, value, PositionT(filename, actline, scanner.column));
     return result;
 #endif
 }

Modified: trunk/libs/wave/samples/cpp_tokens/slex/cpp_slex_lexer.hpp
==============================================================================
--- trunk/libs/wave/samples/cpp_tokens/slex/cpp_slex_lexer.hpp (original)
+++ trunk/libs/wave/samples/cpp_tokens/slex/cpp_slex_lexer.hpp 2008-04-16 21:56:25 EDT (Wed, 16 Apr 2008)
@@ -578,10 +578,8 @@
     virtual ~slex_functor() {}
 
 // get the next token from the input stream
- token_type get()
+ token_type& get(token_type& result)
     {
- token_type token;
-
         if (!at_eof) {
             do {
             // generate and return the next token
@@ -673,17 +671,18 @@
                         break;
                     }
                     
+ result = token_type(id, token_val, pos);
 #if BOOST_WAVE_SUPPORT_PRAGMA_ONCE != 0
- return guards.detect_guard(token_type(id, token_val, pos));
+ return guards.detect_guard(result);
 #else
- return token_type(id, token_val, pos);
+ return result;
 #endif
                 }
             
             // skip the T_CONTLINE token
             } while (true);
         }
- return token; // return T_EOI
+ return result = token_type(); // return T_EOI
     }
     
     void set_position(PositionT const &pos)

Modified: trunk/libs/wave/samples/cpp_tokens/slex_iterator.hpp
==============================================================================
--- trunk/libs/wave/samples/cpp_tokens/slex_iterator.hpp (original)
+++ trunk/libs/wave/samples/cpp_tokens/slex_iterator.hpp 2008-04-16 21:56:25 EDT (Wed, 16 Apr 2008)
@@ -18,7 +18,7 @@
 
 #include <boost/assert.hpp>
 #include <boost/shared_ptr.hpp>
-#include <boost/spirit/include/classic_multi_pass.hpp>
+#include <boost/spirit/include/support_multi_pass.hpp>
 
 #include <boost/wave/language_support.hpp>
 #include <boost/wave/util/file_position.hpp>
@@ -26,7 +26,7 @@
 
 #include "slex_interface.hpp"
 
-#if 0 != __COMO_VERSION__
+#if 0 != __COMO_VERSION__ || !BOOST_WORKAROUND(BOOST_MSVC, <= 1310)
 #define BOOST_WAVE_EOF_PREFIX static
 #else
 #define BOOST_WAVE_EOF_PREFIX
@@ -48,39 +48,48 @@
 template <typename TokenT>
 class slex_iterator_functor_shim
 {
+ typedef typename TokenT::position_type position_type;
+
 public:
- template <typename IteratorT>
- slex_iterator_functor_shim(IteratorT const &first, IteratorT const &last,
- typename TokenT::position_type const &pos,
- boost::wave::language_support language)
- : functor_ptr(slex_input_interface<TokenT>
- ::new_lexer(first, last, pos, language))
+ slex_iterator_functor_shim()
 #if 0 != __DECCXX_VER || BOOST_INTEL_CXX_VERSION > 900 || defined(__PGI)
- , eof()
+ : eof()
 #endif // 0 != __DECCXX_VER
     {}
 
 // interface to the boost::spirit::classic::multi_pass_policies::functor_input
 // policy
     typedef TokenT result_type;
+ typedef slex_iterator_functor_shim unique;
+ typedef lex_input_interface<TokenT>* shared;
 
     BOOST_WAVE_EOF_PREFIX result_type const eof;
     
- result_type operator()()
+ template <typename MultiPass>
+ static result_type& get_next(MultiPass& mp, result_type& result)
     {
- BOOST_ASSERT(0 != functor_ptr.get());
- return functor_ptr->get();
+ return mp.shared->ftor->get(result);
     }
- void set_position(typename TokenT::position_type const &pos)
+
+ // this will be called whenever the last reference to a multi_pass will
+ // be released
+ template <typename MultiPass>
+ static void destroy(MultiPass& mp)
+ {
+ delete mp.shared->ftor;
+ }
+
+ template <typename MultiPass>
+ static void set_position(MultiPass& mp, position_type const &pos)
     {
- BOOST_ASSERT(0 != functor_ptr.get());
- functor_ptr->set_position(pos);
+ mp.shared->ftor->set_position(pos);
     }
     
 #if BOOST_WAVE_SUPPORT_PRAGMA_ONCE != 0
- bool has_include_guards(std::string& guard_name) const
+ template <typename MultiPass>
+ static bool has_include_guards(MultiPass& mp, std::string& guard_name)
     {
- return functor_ptr->has_include_guards(guard_name);
+ return mp.shared->ftor->has_include_guards(guard_name);
     }
 #endif
 
@@ -88,7 +97,7 @@
     boost::shared_ptr<lex_input_interface<TokenT> > functor_ptr;
 };
 
-#if 0 != __COMO_VERSION__
+#if 0 != __COMO_VERSION__ || !BOOST_WORKAROUND(BOOST_MSVC, <= 1310)
 ///////////////////////////////////////////////////////////////////////////////
 // eof token
 template <typename TokenT>
@@ -121,18 +130,45 @@
 //
 ///////////////////////////////////////////////////////////////////////////////
 
+///////////////////////////////////////////////////////////////////////////////
+// Divide the given functor type into its components (unique and shared)
+// and build a std::pair from these parts
+template <typename FunctorData>
+struct make_multi_pass
+{
+ typedef
+ std::pair<typename FunctorData::unique, typename FunctorData::shared>
+ functor_data_type;
+ typedef typename FunctorData::result_type result_type;
+
+ typedef boost::spirit::multi_pass_policies::split_functor_input input_policy;
+ typedef boost::spirit::multi_pass_policies::ref_counted ownership_policy;
+#if defined(BOOST_WAVE_DEBUG)
+ typedef boost::spirit::multi_pass_policies::buf_id_check check_policy;
+#else
+ typedef boost::spirit::multi_pass_policies::no_check check_policy;
+#endif
+ typedef boost::spirit::multi_pass_policies::split_std_deque storage_policy;
+
+ typedef boost::spirit::multi_pass_policies::default_policy<
+ input_policy, ownership_policy, check_policy, storage_policy>
+ policy_type;
+ typedef boost::spirit::multi_pass<functor_data_type, policy_type> type;
+};
+
+///////////////////////////////////////////////////////////////////////////////
 template <typename TokenT>
 class slex_iterator
-: public boost::spirit::classic::multi_pass<
- impl::slex_iterator_functor_shim<TokenT>,
- boost::wave::util::functor_input
- >
+: public make_multi_pass<impl::slex_iterator_functor_shim<TokenT> >::type
 {
     typedef impl::slex_iterator_functor_shim<TokenT> input_policy_type;
- typedef
- boost::spirit::classic::multi_pass<input_policy_type,
- boost::wave::util::functor_input>
- base_type;
+
+ typedef typename make_multi_pass<input_policy_type>::type base_type;
+ typedef typename make_multi_pass<input_policy_type>::functor_data_type
+ functor_data_type;
+
+ typedef typename input_policy_type::unique unique_functor_type;
+ typedef typename input_policy_type::shared shared_functor_type;
     
 public:
     typedef TokenT token_type;
@@ -144,7 +180,13 @@
     slex_iterator(IteratorT const &first, IteratorT const &last,
             typename TokenT::position_type const &pos,
             boost::wave::language_support language)
- : base_type(input_policy_type(first, last, pos, language))
+ : base_type(
+ functor_data_type(
+ unique_functor_type(),
+ slex_input_interface<TokenT>
+ ::new_lexer(first, last, pos, language)
+ )
+ )
     {}
 
     void set_position(typename TokenT::position_type const &pos)
@@ -165,7 +207,7 @@
         {
             currpos.set_line(pos.get_line() + 1);
         }
- base_type::get_functor().set_position(currpos);
+ unique_functor_type::get_functor().set_position(currpos);
     }
 
 #if BOOST_WAVE_SUPPORT_PRAGMA_ONCE != 0
@@ -174,7 +216,7 @@
     // completely
     bool has_include_guards(std::string& guard_name) const
     {
- return base_type::get_functor().has_include_guards(guard_name);
+ return unique_functor_type::has_include_guards(guard_name);
     }
 #endif
 };


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk