Boost logo

Boost-Commit :

From: eric_at_[hidden]
Date: 2007-12-08 20:46:12


Author: eric_niebler
Date: 2007-12-08 20:46:11 EST (Sat, 08 Dec 2007)
New Revision: 41914
URL: http://svn.boost.org/trac/boost/changeset/41914

Log:
stricter adherence to result_of protocol (still working on it)
Text files modified:
   branches/proto/v3/boost/xpressive/detail/core/matcher/action_matcher.hpp | 12 +++++---
   branches/proto/v3/boost/xpressive/detail/core/matcher/predicate_matcher.hpp | 2
   branches/proto/v3/boost/xpressive/detail/static/compile.hpp | 10 ++++++
   branches/proto/v3/boost/xpressive/detail/static/is_pure.hpp | 22 ++++++++--------
   branches/proto/v3/boost/xpressive/detail/static/width_of.hpp | 55 ++++++++++++++++++++++-----------------
   branches/proto/v3/boost/xpressive/match_results.hpp | 16 +++++++----
   branches/proto/v3/boost/xpressive/proto/context/default.hpp | 42 +++++++++++++++++++++++++++--
   branches/proto/v3/boost/xpressive/proto/traits.hpp | 5 +++
   branches/proto/v3/libs/xpressive/test/test_actions.cpp | 2 -
   9 files changed, 112 insertions(+), 54 deletions(-)

Modified: branches/proto/v3/boost/xpressive/detail/core/matcher/action_matcher.hpp
==============================================================================
--- branches/proto/v3/boost/xpressive/detail/core/matcher/action_matcher.hpp (original)
+++ branches/proto/v3/boost/xpressive/detail/core/matcher/action_matcher.hpp 2007-12-08 20:46:11 EST (Sat, 08 Dec 2007)
@@ -65,8 +65,9 @@
         typedef typename child_<Expr, 1>::type right_type;
 
         typedef
- typename proto::result_of::arg<
+ typename proto::result_of::value_at_c<
                 typename proto::result_of::arg_c<right_type, 0>::type
+ , 0
>::type
         function_type;
 
@@ -110,7 +111,7 @@
         typedef typename child_<Expr, 1>::type right_type;
 
         typedef
- typename proto::result_of::arg<right_type>::type
+ typename proto::result_of::value_at_c<right_type, 0>::type
         function_type;
 
         typedef typename boost::result_of<
@@ -200,7 +201,7 @@
 
         template<typename Expr>
         struct eval<Expr, proto::tag::terminal>
- : eval_terminal<Expr, typename proto::result_of::arg<Expr>::type>
+ : eval_terminal<Expr, typename unref_arg_c<Expr, 0>::type>
         {};
 
         // Evaluate attributes like a1|42
@@ -208,12 +209,13 @@
         struct eval<Expr, attr_with_default_tag>
         {
             typedef
- typename proto::result_of::arg<
+ typename proto::result_of::value_at_c<
                     typename proto::result_of::left<
                         typename proto::result_of::arg<
                             Expr
>::type
>::type
+ , 0
>::type
             temp_type;
 
@@ -331,7 +333,7 @@
     template<typename Expr>
     struct const_reference
     {
- typedef typename proto::result_of::arg<Expr>::type type;
+ typedef typename proto::result_of::arg<Expr const>::type type;
     };
 
     using grammar_detail::mark_number;

Modified: branches/proto/v3/boost/xpressive/detail/core/matcher/predicate_matcher.hpp
==============================================================================
--- branches/proto/v3/boost/xpressive/detail/core/matcher/predicate_matcher.hpp (original)
+++ branches/proto/v3/boost/xpressive/detail/core/matcher/predicate_matcher.hpp 2007-12-08 20:46:11 EST (Sat, 08 Dec 2007)
@@ -78,7 +78,7 @@
 
         template<typename Expr>
         struct eval<Expr, proto::tag::terminal>
- : eval_terminal<Expr, typename proto::result_of::arg<Expr>::type>
+ : eval_terminal<Expr, typename unref_arg_c<Expr, 0>::type>
         {};
 
         #if BOOST_VERSION >= 103500

Modified: branches/proto/v3/boost/xpressive/detail/static/compile.hpp
==============================================================================
--- branches/proto/v3/boost/xpressive/detail/static/compile.hpp (original)
+++ branches/proto/v3/boost/xpressive/detail/static/compile.hpp 2007-12-08 20:46:11 EST (Sat, 08 Dec 2007)
@@ -81,8 +81,16 @@
     static_compile_impl1(Xpr const &xpr, shared_ptr<regex_impl<BidiIter> > const &impl)
     {
         // use specified traits
- typedef typename proto::result_of::arg<typename proto::result_of::left<Xpr>::type>::type::locale_type locale_type;
+ typedef
+ typename remove_reference<
+ typename proto::result_of::arg<
+ typename proto::result_of::left<Xpr>::type
+ >::type
+ >::type::locale_type
+ locale_type;
+
         typedef typename regex_traits_type<locale_type, BidiIter>::type traits_type;
+
         static_compile_impl2(proto::right(xpr), impl, traits_type(proto::arg(proto::left(xpr)).getloc()));
     }
 

Modified: branches/proto/v3/boost/xpressive/detail/static/is_pure.hpp
==============================================================================
--- branches/proto/v3/boost/xpressive/detail/static/is_pure.hpp (original)
+++ branches/proto/v3/boost/xpressive/detail/static/is_pure.hpp 2007-12-08 20:46:11 EST (Sat, 08 Dec 2007)
@@ -63,14 +63,14 @@
 
     template<typename Expr, typename Char>
     struct use_simple_repeat_<Expr, Char, proto::tag::terminal>
- : use_simple_repeat_terminal<typename proto::result_of::arg<Expr>::type, Char>
+ : use_simple_repeat_terminal<typename unref_arg_c<Expr, 0>::type, Char>
     {};
 
     template<typename Expr, typename Char>
     struct use_simple_repeat_<Expr, Char, proto::tag::shift_right>
       : mpl::and_<
- use_simple_repeat_<typename proto::result_of::arg_c<Expr, 0>::type, Char>
- , use_simple_repeat_<typename proto::result_of::arg_c<Expr, 1>::type, Char>
+ use_simple_repeat_<typename unref_arg_c<Expr, 0>::type, Char>
+ , use_simple_repeat_<typename unref_arg_c<Expr, 1>::type, Char>
>
     {};
 
@@ -78,8 +78,8 @@
     struct use_simple_repeat_<Expr, Char, proto::tag::bitwise_or>
       : mpl::and_<
             mpl::not_equal_to<unknown_width, width_of<Expr, Char> >
- , use_simple_repeat_<typename proto::result_of::arg_c<Expr, 0>::type, Char>
- , use_simple_repeat_<typename proto::result_of::arg_c<Expr, 1>::type, Char>
+ , use_simple_repeat_<typename unref_arg_c<Expr, 0>::type, Char>
+ , use_simple_repeat_<typename unref_arg_c<Expr, 1>::type, Char>
>
     {};
 
@@ -105,12 +105,12 @@
     // either (s1 = ...) or (a1 = ...) or (set = ...)
     template<typename Expr, typename Char>
     struct use_simple_repeat_<Expr, Char, proto::tag::assign>
- : use_simple_repeat_assign<typename proto::result_of::arg<typename proto::result_of::arg_c<Expr, 0>::type>::type>
+ : use_simple_repeat_assign<typename unref_arg_c<typename unref_arg_c<Expr, 0>::type, 0>::type>
     {};
 
     template<typename Expr, typename Char>
     struct use_simple_repeat_<Expr, Char, modifier_tag>
- : use_simple_repeat_<typename proto::result_of::arg_c<Expr, 0>::type, Char>
+ : use_simple_repeat_<typename unref_arg_c<Expr, 0>::type, Char>
     {};
 
     template<typename Expr, typename Char>
@@ -131,7 +131,7 @@
     // when complementing a set or an assertion, the purity is that of the set (true) or the assertion
     template<typename Expr, typename Char>
     struct use_simple_repeat_<Expr, Char, proto::tag::complement>
- : use_simple_repeat_<typename proto::result_of::arg_c<Expr, 0>::type, Char>
+ : use_simple_repeat_<typename unref_arg_c<Expr, 0>::type, Char>
     {};
 
     // The comma is used in list-initialized sets, which are pure
@@ -154,7 +154,7 @@
 
     template<typename Expr, typename Char>
     struct use_simple_repeat_<Expr, Char, proto::tag::subscript>
- : use_simple_repeat_subscript<Expr, Char, typename proto::result_of::arg_c<Expr, 0>::type>
+ : use_simple_repeat_subscript<Expr, Char, typename unref_arg_c<Expr, 0>::type>
     {};
 
     // Quantified expressions are variable-width and cannot use the simple quantifier
@@ -180,12 +180,12 @@
 
     template<typename Expr, typename Char, uint_t Count>
     struct use_simple_repeat_<Expr, Char, generic_quant_tag<Count, Count> >
- : use_simple_repeat_<typename proto::result_of::arg_c<Expr, 0>::type, Char>
+ : use_simple_repeat_<typename unref_arg_c<Expr, 0>::type, Char>
     {};
 
     template<typename Expr, typename Char>
     struct use_simple_repeat_<Expr, Char, proto::tag::negate>
- : use_simple_repeat_<typename proto::result_of::arg_c<Expr, 0>::type, Char>
+ : use_simple_repeat_<typename unref_arg_c<Expr, 0>::type, Char>
     {};
 
     ///////////////////////////////////////////////////////////////////////////////

Modified: branches/proto/v3/boost/xpressive/detail/static/width_of.hpp
==============================================================================
--- branches/proto/v3/boost/xpressive/detail/static/width_of.hpp (original)
+++ branches/proto/v3/boost/xpressive/detail/static/width_of.hpp 2007-12-08 20:46:11 EST (Sat, 08 Dec 2007)
@@ -27,6 +27,13 @@
 
 namespace boost { namespace xpressive { namespace detail
 {
+ template<typename E, long N>
+ struct unref_arg_c
+ : remove_const<typename remove_reference<
+ typename proto::result_of::value_at_c<E, N>::type
+ >::type>
+ {};
+
     ///////////////////////////////////////////////////////////////////////////////
     // is_char
     //
@@ -74,14 +81,14 @@
     {};
 
     template<typename Elem, std::size_t N, typename Char>
- struct width_of_terminal<Elem (&) [N], Char, false>
+ struct width_of_terminal<Elem [N], Char, false>
       : mpl::size_t<N-is_char<Elem>::value> // string literals
     {};
 
- template<typename Elem, std::size_t N, typename Char>
- struct width_of_terminal<Elem const (&) [N], Char, false>
- : mpl::size_t<N-is_char<Elem>::value> // string literals
- {};
+ //template<typename Elem, std::size_t N, typename Char>
+ //struct width_of_terminal<Elem const [N], Char, false>
+ // : mpl::size_t<N-is_char<Elem>::value> // string literals
+ //{};
 
     ///////////////////////////////////////////////////////////////////////////////
     // width_of
@@ -92,20 +99,20 @@
 
     template<typename Expr, typename Char>
     struct width_of<Expr, Char, proto::tag::terminal>
- : width_of_terminal<typename proto::result_of::arg<Expr>::type, Char>
+ : width_of_terminal<typename unref_arg_c<Expr, 0>::type, Char>
     {};
 
     template<typename Expr, typename Char>
     struct width_of<Expr, Char, proto::tag::shift_right>
       : mpl::if_<
             mpl::or_<
- mpl::equal_to<unknown_width, width_of<typename proto::result_of::arg_c<Expr, 0>::type, Char> >
- , mpl::equal_to<unknown_width, width_of<typename proto::result_of::arg_c<Expr, 1>::type, Char> >
+ mpl::equal_to<unknown_width, width_of<typename unref_arg_c<Expr, 0>::type, Char> >
+ , mpl::equal_to<unknown_width, width_of<typename unref_arg_c<Expr, 1>::type, Char> >
>
           , unknown_width
           , mpl::plus<
- width_of<typename proto::result_of::arg_c<Expr, 0>::type, Char>
- , width_of<typename proto::result_of::arg_c<Expr, 1>::type, Char>
+ width_of<typename unref_arg_c<Expr, 0>::type, Char>
+ , width_of<typename unref_arg_c<Expr, 1>::type, Char>
>
>::type
     {};
@@ -114,14 +121,14 @@
     struct width_of<Expr, Char, proto::tag::bitwise_or>
       : mpl::if_<
             mpl::or_<
- mpl::equal_to<unknown_width, width_of<typename proto::result_of::arg_c<Expr, 0>::type, Char> >
+ mpl::equal_to<unknown_width, width_of<typename unref_arg_c<Expr, 0>::type, Char> >
               , mpl::not_equal_to<
- width_of<typename proto::result_of::arg_c<Expr, 0>::type, Char>
- , width_of<typename proto::result_of::arg_c<Expr, 1>::type, Char>
+ width_of<typename unref_arg_c<Expr, 0>::type, Char>
+ , width_of<typename unref_arg_c<Expr, 1>::type, Char>
>
>
           , unknown_width
- , width_of<typename proto::result_of::arg_c<Expr, 0>::type, Char>
+ , width_of<typename unref_arg_c<Expr, 0>::type, Char>
>::type
     {};
 
@@ -131,7 +138,7 @@
 
     template<typename Expr, typename Char>
     struct width_of_assign<Expr, Char, mark_placeholder>
- : width_of<typename proto::result_of::arg_c<Expr, 1>::type, Char>
+ : width_of<typename unref_arg_c<Expr, 1>::type, Char>
     {};
 
     template<typename Expr, typename Char>
@@ -147,12 +154,12 @@
     // either (s1 = ...) or (a1 = ...) or (set = ...)
     template<typename Expr, typename Char>
     struct width_of<Expr, Char, proto::tag::assign>
- : width_of_assign<Expr, Char, typename proto::result_of::arg<typename proto::result_of::arg_c<Expr, 0>::type>::type>
+ : width_of_assign<Expr, Char, typename unref_arg_c<typename unref_arg_c<Expr, 0>::type, 0>::type>
     {};
 
     template<typename Expr, typename Char>
     struct width_of<Expr, Char, modifier_tag>
- : width_of<typename proto::result_of::arg_c<Expr, 1>::type, Char>
+ : width_of<typename unref_arg_c<Expr, 1>::type, Char>
     {};
 
     template<typename Expr, typename Char>
@@ -174,7 +181,7 @@
         // If this assert fires, you put something that doesn't require backtracking
         // in a keep(). In that case, the keep() is not necessary and you should just
         // remove it.
- BOOST_MPL_ASSERT_RELATION((width_of<typename proto::result_of::arg_c<Expr, 0>::type, Char>::value), ==, unknown_width::value);
+ BOOST_MPL_ASSERT_RELATION((width_of<typename unref_arg_c<Expr, 0>::type, Char>::value), ==, unknown_width::value);
     };
 
     template<typename Expr, typename Char>
@@ -200,10 +207,10 @@
     template<typename Expr, typename Char, uint_t Count>
     struct width_of<Expr, Char, generic_quant_tag<Count, Count> >
       : mpl::if_<
- mpl::equal_to<unknown_width, width_of<typename proto::result_of::arg_c<Expr, 0>::type, Char> >
+ mpl::equal_to<unknown_width, width_of<typename unref_arg_c<Expr, 0>::type, Char> >
           , unknown_width
           , mpl::times<
- width_of<typename proto::result_of::arg_c<Expr, 0>::type, Char>
+ width_of<typename unref_arg_c<Expr, 0>::type, Char>
               , mpl::size_t<Count>
>
>::type
@@ -211,13 +218,13 @@
 
     template<typename Expr, typename Char>
     struct width_of<Expr, Char, proto::tag::negate>
- : width_of<typename proto::result_of::arg_c<Expr, 0>::type, Char>
+ : width_of<typename unref_arg_c<Expr, 0>::type, Char>
     {};
 
     // when complementing a set or an assertion, the width is that of the set (1) or the assertion (0)
     template<typename Expr, typename Char>
     struct width_of<Expr, Char, proto::tag::complement>
- : width_of<typename proto::result_of::arg_c<Expr, 0>::type, Char>
+ : width_of<typename unref_arg_c<Expr, 0>::type, Char>
     {};
 
     // The comma is used in list-initialized sets, and the width of sets are 1
@@ -238,12 +245,12 @@
       : mpl::size_t<1>
     {
         // If Left is "set" then make sure that Right has a width_of 1
- BOOST_MPL_ASSERT_RELATION(1, ==, (width_of<typename proto::result_of::arg_c<Expr, 1>::type, Char>::value));
+ BOOST_MPL_ASSERT_RELATION(1, ==, (width_of<typename unref_arg_c<Expr, 1>::type, Char>::value));
     };
 
     template<typename Expr, typename Char>
     struct width_of<Expr, Char, proto::tag::subscript>
- : width_of_subscript<Expr, Char, typename proto::result_of::arg_c<Expr, 0>::type>
+ : width_of_subscript<Expr, Char, typename unref_arg_c<Expr, 0>::type>
     {};
 
 }}} // namespace boost::xpressive::detail

Modified: branches/proto/v3/boost/xpressive/match_results.hpp
==============================================================================
--- branches/proto/v3/boost/xpressive/match_results.hpp (original)
+++ branches/proto/v3/boost/xpressive/match_results.hpp 2007-12-08 20:46:11 EST (Sat, 08 Dec 2007)
@@ -503,13 +503,8 @@
     template<typename Arg>
     match_results<BidiIter> &let(Arg const &arg)
     {
- typedef typename proto::result_of::left<Arg>::type left_type;
- typedef typename proto::result_of::right<Arg>::type right_type;
- typedef typename proto::result_of::arg<left_type>::type arg_left_type;
- typedef typename proto::result_of::arg<right_type>::type arg_right_type;
         BOOST_MPL_ASSERT((proto::matches<Arg, detail::ActionArgBinding>));
- BOOST_MPL_ASSERT((is_same<typename arg_left_type::type, arg_right_type>));
- this->args_[&typeid(proto::arg(proto::left(arg)))] = &proto::arg(proto::right(arg));
+ this->let_(proto::arg(proto::left(arg)), proto::arg(proto::right(arg)));
         return *this;
     }
 
@@ -1045,6 +1040,15 @@
         return out;
     }
 
+ /// INTERNAL ONLY
+ ///
+ template<typename Left, typename Right>
+ void let_(Left const &, Right &right)
+ {
+ BOOST_MPL_ASSERT((is_same<typename Left::type, Right>));
+ this->args_[&typeid(Left)] = &right;
+ }
+
     regex_id_type regex_id_;
     detail::sub_match_vector<BidiIter> sub_matches_;
     BidiIter base_;

Modified: branches/proto/v3/boost/xpressive/proto/context/default.hpp
==============================================================================
--- branches/proto/v3/boost/xpressive/proto/context/default.hpp (original)
+++ branches/proto/v3/boost/xpressive/proto/context/default.hpp 2007-12-08 20:46:11 EST (Sat, 08 Dec 2007)
@@ -23,6 +23,24 @@
 #include <boost/xpressive/proto/traits.hpp> // for proto::arg_c()
 #include <boost/xpressive/proto/detail/indices.hpp>
 
+#define CV(T)\
+ typename add_const<T>::type
+
+#define REF(T)\
+ typename add_reference<T>::type
+
+#define CVREF(T)\
+ REF(CV(T))
+
+#define UNCV(T)\
+ typename remove_cv<T>::type
+
+#define UNREF(T)\
+ typename remove_reference<T>::type
+
+#define UNCVREF(T)\
+ UNCV(UNREF(T))
+
 // If we're generating doxygen documentation, hide all the nasty
 // Boost.Typeof gunk.
 #ifndef BOOST_PROTO_DOXYGEN_INVOKED
@@ -134,7 +152,7 @@
             typedef
                 typename proto::detail::result_of_fixup<
                     typename proto::result_of::eval<
- typename proto::result_of::arg_c<Expr, 0>::type
+ typename remove_reference<typename proto::result_of::arg_c<Expr, 0>::type>::type
                       , Context
>::type
>::type
@@ -144,7 +162,7 @@
                 typename boost::result_of<
                     function_type(
                         typename proto::result_of::eval<
- typename proto::result_of::arg_c<Expr, Indices>::type
+ typename remove_reference<typename proto::result_of::arg_c<Expr, Indices>::type>::type
                           , Context
>::type...
                     )
@@ -326,9 +344,18 @@
         template<typename Expr, typename Context>
         struct default_eval<Expr, Context, proto::tag::comma>
         {
- typedef typename proto::result_of::eval<typename proto::result_of::arg_c<Expr, 0>::type, Context>::type proto_arg0;
- typedef typename proto::result_of::eval<typename proto::result_of::arg_c<Expr, 1>::type, Context>::type proto_arg1;
+ typedef typename proto::result_of::eval<
+ typename remove_reference<typename proto::result_of::arg_c<Expr, 0>::type>::type
+ , Context
+ >::type proto_arg0;
+
+ typedef typename proto::result_of::eval<
+ typename remove_reference<typename proto::result_of::arg_c<Expr, 1>::type>::type
+ , Context
+ >::type proto_arg1;
+
             typedef typename proto::detail::comma_result<proto_arg0, proto_arg1>::type result_type;
+
             result_type operator()(Expr &expr, Context &ctx) const
             {
                 return proto::eval(proto::arg_c<0>(expr), ctx), proto::eval(proto::arg_c<1>(expr), ctx);
@@ -361,4 +388,11 @@
 
 }} // namespace boost::proto
 
+#undef CV
+#undef REF
+#undef CVREF
+#undef UNCV
+#undef UNREF
+#undef UNCVREF
+
 #endif

Modified: branches/proto/v3/boost/xpressive/proto/traits.hpp
==============================================================================
--- branches/proto/v3/boost/xpressive/proto/traits.hpp (original)
+++ branches/proto/v3/boost/xpressive/proto/traits.hpp 2007-12-08 20:46:11 EST (Sat, 08 Dec 2007)
@@ -376,6 +376,11 @@
         {};
 
         template<typename Expr, long N>
+ struct value_at_c<Expr &, N>
+ : detail::value_at_c<typename Expr::proto_args::cons_type, N>
+ {};
+
+ template<typename Expr, long N>
         struct arg_c
           : detail::arg_c<typename Expr::proto_args::cons_type, N>
         {};

Modified: branches/proto/v3/libs/xpressive/test/test_actions.cpp
==============================================================================
--- branches/proto/v3/libs/xpressive/test/test_actions.cpp (original)
+++ branches/proto/v3/libs/xpressive/test/test_actions.cpp 2007-12-08 20:46:11 EST (Sat, 08 Dec 2007)
@@ -5,8 +5,6 @@
 // Software License, Version 1.0. (See accompanying file
 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
 
-//#define BOOST_XPRESSIVE_BETTER_ERRORS
-
 #include <map>
 #include <list>
 #include <stack>


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