Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r61416 - in trunk/libs/spirit/example/scheme: output qi utree/detail
From: hartmut.kaiser_at_[hidden]
Date: 2010-04-19 19:14:24


Author: hkaiser
Date: 2010-04-19 19:14:23 EDT (Mon, 19 Apr 2010)
New Revision: 61416
URL: http://svn.boost.org/trac/boost/changeset/61416

Log:
Spirit: replaced implementation of boost::get(utree)
Removed:
   trunk/libs/spirit/example/scheme/utree/detail/utree_detail3.hpp
Text files modified:
   trunk/libs/spirit/example/scheme/output/sexpr.hpp | 15 ++++++--
   trunk/libs/spirit/example/scheme/output/utree_traits.hpp | 63 ++++++++++++++++++++++++---------------
   trunk/libs/spirit/example/scheme/qi/qiexpr_generator.hpp | 2
   trunk/libs/spirit/example/scheme/qi/qiexpr_parser.hpp | 1
   trunk/libs/spirit/example/scheme/utree/detail/utree_detail2.hpp | 18 ++++++++++
   5 files changed, 68 insertions(+), 31 deletions(-)

Modified: trunk/libs/spirit/example/scheme/output/sexpr.hpp
==============================================================================
--- trunk/libs/spirit/example/scheme/output/sexpr.hpp (original)
+++ trunk/libs/spirit/example/scheme/output/sexpr.hpp 2010-04-19 19:14:23 EDT (Mon, 19 Apr 2010)
@@ -7,7 +7,6 @@
 #define SCHEME_OUTPUT_SEXPR_MAR_8_2010_829AM
 
 #include <utree/utree.hpp>
-#include <utree/detail/utree_detail3.hpp>
 #include <output/utree_traits.hpp>
 
 #include <string>
@@ -49,7 +48,7 @@
                       | symbol
                       | byte_str
                       | list
- | nil_
+ | nil
                       | ref_
                       ;
 
@@ -58,8 +57,16 @@
             string_ = '"' << string << '"';
             symbol = string;
             byte_str = '#' << *right_align(2, '0')[hex2] << '#';
- nil_ = eps << "<nil>";
+ nil = eps << "<nil>";
             ref_ = start;
+
+ start.name("start");
+ list.name("list");
+ string_.name("string_");
+ symbol.name("symbol");
+ byte_str.name("byte_str");
+ nil.name("nil");
+ ref_.name("ref_");
         }
 
         typedef boost::iterator_range<utree::const_iterator> utree_list;
@@ -69,7 +76,7 @@
         rule<OutputIterator, utf8_symbol_range()> symbol;
         rule<OutputIterator, utf8_string_range()> string_;
         rule<OutputIterator, binary_range()> byte_str;
- rule<OutputIterator, nil()> nil_;
+ rule<OutputIterator, nil()> nil;
         rule<OutputIterator, space_type, utree()> ref_;
     };
 }}

Modified: trunk/libs/spirit/example/scheme/output/utree_traits.hpp
==============================================================================
--- trunk/libs/spirit/example/scheme/output/utree_traits.hpp (original)
+++ trunk/libs/spirit/example/scheme/output/utree_traits.hpp 2010-04-19 19:14:23 EDT (Mon, 19 Apr 2010)
@@ -28,7 +28,7 @@
     // type is compatible with a given variant type
     template <>
     struct compute_compatible_component_variant<
- iterator_range<scheme::utree::iterator>, scheme::utree>
+ scheme::utree, iterator_range<scheme::utree::iterator> >
       : mpl::true_
     {
         typedef iterator_range<scheme::utree::iterator> compatible_type;
@@ -39,7 +39,7 @@
 
     template <>
     struct compute_compatible_component_variant<
- iterator_range<scheme::utree::const_iterator>, scheme::utree>
+ scheme::utree, iterator_range<scheme::utree::const_iterator> >
       : mpl::true_
     {
         typedef iterator_range<scheme::utree::const_iterator> compatible_type;
@@ -49,7 +49,7 @@
     };
 
     template <>
- struct compute_compatible_component_variant<scheme::nil, scheme::utree>
+ struct compute_compatible_component_variant<scheme::utree, scheme::nil>
       : mpl::true_
     {
         typedef scheme::nil compatible_type;
@@ -59,7 +59,7 @@
     };
 
     template <>
- struct compute_compatible_component_variant<bool, scheme::utree>
+ struct compute_compatible_component_variant<scheme::utree, bool>
       : mpl::true_
     {
         typedef bool compatible_type;
@@ -69,7 +69,7 @@
     };
 
     template <>
- struct compute_compatible_component_variant<int, scheme::utree>
+ struct compute_compatible_component_variant<scheme::utree, int>
       : mpl::true_
     {
         typedef int compatible_type;
@@ -79,7 +79,7 @@
     };
 
     template <>
- struct compute_compatible_component_variant<double, scheme::utree>
+ struct compute_compatible_component_variant<scheme::utree, double>
       : mpl::true_
     {
         typedef double compatible_type;
@@ -90,7 +90,7 @@
 
     template <>
     struct compute_compatible_component_variant<
- scheme::utf8_string_range, scheme::utree>
+ scheme::utree, scheme::utf8_string_range>
       : mpl::true_
     {
         typedef scheme::utf8_string_range compatible_type;
@@ -101,7 +101,7 @@
 
     template <>
     struct compute_compatible_component_variant<
- scheme::utf8_string, scheme::utree>
+ scheme::utree, scheme::utf8_string>
       : mpl::true_
     {
         typedef scheme::utf8_string compatible_type;
@@ -112,7 +112,7 @@
 
     template <>
     struct compute_compatible_component_variant<
- scheme::utf8_symbol_range, scheme::utree>
+ scheme::utree, scheme::utf8_symbol_range>
       : mpl::true_
     {
         typedef scheme::utf8_symbol_range compatible_type;
@@ -123,7 +123,7 @@
 
     template <>
     struct compute_compatible_component_variant<
- scheme::utf8_symbol, scheme::utree>
+ scheme::utree, scheme::utf8_symbol>
       : mpl::true_
     {
         typedef scheme::utf8_symbol compatible_type;
@@ -134,7 +134,7 @@
 
     template <>
     struct compute_compatible_component_variant<
- scheme::binary_range, scheme::utree>
+ scheme::utree, scheme::binary_range>
       : mpl::true_
     {
         typedef scheme::binary_range compatible_type;
@@ -145,7 +145,7 @@
 
     template <>
     struct compute_compatible_component_variant<
- scheme::binary_string, scheme::utree>
+ scheme::utree, scheme::binary_string>
       : mpl::true_
     {
         typedef scheme::binary_string compatible_type;
@@ -158,7 +158,7 @@
     struct compute_compatible_component_variant<scheme::utree, scheme::utree>
       : mpl::true_
     {
- typedef iterator_range<scheme::utree::const_iterator> compatible_type;
+ typedef scheme::utree compatible_type;
         typedef mpl::int_<scheme::utree_type::reference_type> distance;
 
         static bool is_compatible(int d)
@@ -169,7 +169,7 @@
     };
 
     template <typename Sequence>
- struct compute_compatible_component_variant<Sequence, scheme::utree
+ struct compute_compatible_component_variant<scheme::utree, Sequence
           , mpl::false_
           , typename enable_if<fusion::traits::is_sequence<Sequence> >::type>
       : mpl::true_
@@ -182,13 +182,14 @@
 
     ///////////////////////////////////////////////////////////////////////////
     template <>
- struct symbols_lookup<scheme::utf8_symbol, scheme::utree>
+ struct symbols_lookup<scheme::utree, scheme::utf8_symbol>
     {
         typedef std::string type;
 
         static type call(scheme::utree const& t)
         {
- return boost::get<scheme::utf8_symbol>(t);
+ scheme::utf8_symbol_range r = boost::get<scheme::utf8_symbol_range>(t);
+ return std::string(r.begin(), r.end());
         }
     };
 
@@ -199,9 +200,10 @@
         typedef std::string type;
 
         template <typename Context>
- static type call(scheme::utree const& attr, Context&)
+ static type call(scheme::utree const& t, Context&)
         {
- return boost::get<scheme::utf8_symbol>(attr);
+ scheme::utf8_symbol_range r = boost::get<scheme::utf8_symbol_range>(t);
+ return std::string(r.begin(), r.end());
         }
     };
 
@@ -211,9 +213,10 @@
         typedef std::string type;
 
         template <typename Context>
- static type call(scheme::utree const& attr, Context&)
+ static type call(scheme::utree const& t, Context&)
         {
- return boost::get<scheme::utf8_string>(attr);
+ scheme::utf8_string_range r = boost::get<scheme::utf8_string_range>(t);
+ return std::string(r.begin(), r.end());
         }
     };
 
@@ -223,9 +226,10 @@
     {
         typedef std::string type;
 
- static type pre(scheme::utree const& val)
+ static type pre(scheme::utree const& t)
         {
- return boost::get<scheme::utf8_string>(val);
+ scheme::utf8_string_range r = boost::get<scheme::utf8_string_range>(t);
+ return std::string(r.begin(), r.end());
         }
     };
 
@@ -234,11 +238,22 @@
     {
         typedef std::string type;
 
- static type pre(scheme::utree const& val)
+ static type pre(scheme::utree const& t)
         {
- return boost::get<scheme::utf8_symbol>(val);
+ scheme::utf8_symbol_range r = boost::get<scheme::utf8_symbol_range>(t);
+ return std::string(r.begin(), r.end());
         }
     };
 }}}
 
+///////////////////////////////////////////////////////////////////////////////
+namespace boost
+{
+ template <typename T>
+ inline T get(scheme::utree const& x)
+ {
+ return x.as<T>();
+ }
+}
+
 #endif

Modified: trunk/libs/spirit/example/scheme/qi/qiexpr_generator.hpp
==============================================================================
--- trunk/libs/spirit/example/scheme/qi/qiexpr_generator.hpp (original)
+++ trunk/libs/spirit/example/scheme/qi/qiexpr_generator.hpp 2010-04-19 19:14:23 EDT (Mon, 19 Apr 2010)
@@ -12,7 +12,6 @@
 #include <boost/spirit/include/karma.hpp>
 
 #include <utree/utree.hpp>
-#include <utree/detail/utree_detail3.hpp>
 #include <utree/operators.hpp>
 #include <output/utree_traits.hpp>
 #include <qi/component_names.hpp>
@@ -62,6 +61,7 @@
                 | primitive2 << '(' << literal << ',' << literal << ')'
                 | primitive1 << '(' << literal << ')'
                 | primitive0 << -omit[node]
+ | repeat(1)[alternative]
                 ;
 
             symbol = string(_r1);

Modified: trunk/libs/spirit/example/scheme/qi/qiexpr_parser.hpp
==============================================================================
--- trunk/libs/spirit/example/scheme/qi/qiexpr_parser.hpp (original)
+++ trunk/libs/spirit/example/scheme/qi/qiexpr_parser.hpp 2010-04-19 19:14:23 EDT (Mon, 19 Apr 2010)
@@ -17,7 +17,6 @@
 #include <boost/spirit/include/phoenix_operator.hpp>
 
 #include <utree/utree.hpp>
-#include <utree/detail/utree_detail3.hpp>
 #include <utree/operators.hpp>
 #include <input/string.hpp>
 #include <qi/component_names.hpp>

Modified: trunk/libs/spirit/example/scheme/utree/detail/utree_detail2.hpp
==============================================================================
--- trunk/libs/spirit/example/scheme/utree/detail/utree_detail2.hpp (original)
+++ trunk/libs/spirit/example/scheme/utree/detail/utree_detail2.hpp 2010-04-19 19:14:23 EDT (Mon, 19 Apr 2010)
@@ -1043,6 +1043,16 @@
         }
     }
 
+ template <typename T>
+ struct is_iterator_range
+ : boost::mpl::false_
+ {};
+
+ template <typename Iterator>
+ struct is_iterator_range<boost::iterator_range<Iterator> >
+ : boost::mpl::true_
+ {};
+
     template <typename To>
     struct utree_cast
     {
@@ -1065,7 +1075,13 @@
         template <typename From>
         To operator()(From const& val) const
         {
- return dispatch(val, boost::is_convertible<From, To>());
+ // boost::iterator_range has a templated constructor, accepting
+ // any argument and hence any type is 'convertible' to it.
+ typedef typename boost::mpl::eval_if<
+ is_iterator_range<To>
+ , boost::is_same<From, To>, boost::is_convertible<From, To>
+ >::type is_convertible;
+ return dispatch(val, is_convertible());
         }
     };
 

Deleted: trunk/libs/spirit/example/scheme/utree/detail/utree_detail3.hpp
==============================================================================
--- trunk/libs/spirit/example/scheme/utree/detail/utree_detail3.hpp 2010-04-19 19:14:23 EDT (Mon, 19 Apr 2010)
+++ (empty file)
@@ -1,177 +0,0 @@
-/*=============================================================================
- Copyright (c) 2001-2010 Joel de Guzman
- Copyright (c) 2001-2010 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_SPIRIT_UTREE_DETAIL3)
-#define BOOST_SPIRIT_UTREE_DETAIL3
-
-#include <boost/variant/get.hpp> // boost::bad_get
-
-namespace scheme
-{
- namespace detail
- {
- ///////////////////////////////////////////////////////////////////////
- template <typename T>
- struct get_utree_type;
-
-#define SCHEME_GET_UTREE_TYPE(t, v) \
- template <> struct get_utree_type<t> { enum { value = v }; } \
- /**/
-
- SCHEME_GET_UTREE_TYPE(nil, utree_type::nil_type);
- SCHEME_GET_UTREE_TYPE(bool, utree_type::bool_type);
- SCHEME_GET_UTREE_TYPE(int, utree_type::int_type);
- SCHEME_GET_UTREE_TYPE(double, utree_type::double_type);
- SCHEME_GET_UTREE_TYPE(utf8_string_range, utree_type::string_type);
- SCHEME_GET_UTREE_TYPE(utf8_string, utree_type::string_type);
- SCHEME_GET_UTREE_TYPE(utf8_symbol_range, utree_type::symbol_type);
- SCHEME_GET_UTREE_TYPE(utf8_symbol, utree_type::symbol_type);
- SCHEME_GET_UTREE_TYPE(binary_range, utree_type::binary_type);
- SCHEME_GET_UTREE_TYPE(boost::iterator_range<utree::iterator>,
- utree_type::list_type);
- SCHEME_GET_UTREE_TYPE(boost::iterator_range<utree::const_iterator>,
- utree_type::list_type);
- SCHEME_GET_UTREE_TYPE(utree, utree_type::reference_type);
-
-#undef SCHEME_GET_UTREE_TYPE
-
- ///////////////////////////////////////////////////////////////////////
- template <typename T>
- struct get_impl;
-
- template <>
- struct get_impl<nil>
- {
- typedef nil type;
- static type call(utree const&) { return nil(); }
- };
-
- template <>
- struct get_impl<bool>
- {
- typedef bool type;
- static type call(utree const& x) { return x.b; }
- };
-
- template <>
- struct get_impl<int>
- {
- typedef int type;
- static type call(utree const& x) { return x.i; }
- };
-
- template <>
- struct get_impl<double>
- {
- typedef double type;
- static type call(utree const& x) { return x.d; }
- };
-
- template <>
- struct get_impl<boost::iterator_range<utree::iterator> >
- {
- typedef boost::iterator_range<utree::iterator> type;
- static type call(utree const& x)
- {
- return type(utree::iterator(x.l.first)
- , utree::iterator(0, x.l.last));
- }
- };
-
- template <>
- struct get_impl<boost::iterator_range<utree::const_iterator> >
- {
- typedef boost::iterator_range<utree::const_iterator> type;
- static type call(utree const& x)
- {
- return type(utree::const_iterator(x.l.first)
- , utree::const_iterator(0, x.l.last));
- }
- };
-
- template <>
- struct get_impl<utf8_string_range>
- {
- typedef utf8_string_range type;
- static type call(utree const& x)
- {
- return type(x.s.str(), x.s.size());
- }
- };
-
- template <>
- struct get_impl<utf8_string>
- {
- typedef utf8_string type;
- static type call(utree const& x)
- {
- return type(x.s.str(), x.s.size());
- }
- };
-
- template <>
- struct get_impl<utf8_symbol_range>
- {
- typedef utf8_symbol_range type;
- static type call(utree const& x)
- {
- return type(x.s.str(), x.s.size());
- }
- };
-
- template <>
- struct get_impl<utf8_symbol>
- {
- typedef utf8_symbol type;
- static type call(utree const& x)
- {
- return type(x.s.str(), x.s.size());
- }
- };
-
- template <>
- struct get_impl<binary_range>
- {
- typedef binary_range type;
- static type call(utree const& x)
- {
- return type(x.s.str(), x.s.size());
- }
- };
-
- template <>
- struct get_impl<utree>
- {
- typedef utree const& type;
- static type call(utree const& x)
- {
- return x.which() == utree_type::reference_type ? *x.p : x;
- }
- };
- }
-}
-
-///////////////////////////////////////////////////////////////////////////////
-namespace boost
-{
- template <typename T>
- typename scheme::detail::get_impl<T>::type
- get(scheme::utree const& x)
- {
- if (x.which() == scheme::utree_type::reference_type)
- return get<T>(x.deref());
-
- if (x.which() !=
- (scheme::utree_type::info)scheme::detail::get_utree_type<T>::value)
- {
- throw boost::bad_get();
- }
- return scheme::detail::get_impl<T>::call(x);
- }
-}
-
-#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