Boost logo

Boost-Commit :

From: eric_at_[hidden]
Date: 2007-12-02 23:53:38


Author: eric_niebler
Date: 2007-12-02 23:53:38 EST (Sun, 02 Dec 2007)
New Revision: 41631
URL: http://svn.boost.org/trac/boost/changeset/41631

Log:
require user disambiguation of call/make transforms
Added:
   branches/proto/v3/boost/xpressive/proto/transform/bind.hpp (contents, props changed)
Text files modified:
   branches/proto/v3/boost/xpressive/detail/static/grammar.hpp | 48 +++++++++++++++----------
   branches/proto/v3/boost/xpressive/proto/proto_fwd.hpp | 4 ++
   branches/proto/v3/boost/xpressive/proto/transform.hpp | 2 +
   branches/proto/v3/boost/xpressive/proto/transform/call.hpp | 73 ++++++++++++++++++++++++++++++++++++++++
   branches/proto/v3/boost/xpressive/proto/transform/when.hpp | 45 ++++++++++++++---------
   5 files changed, 135 insertions(+), 37 deletions(-)

Modified: branches/proto/v3/boost/xpressive/detail/static/grammar.hpp
==============================================================================
--- branches/proto/v3/boost/xpressive/detail/static/grammar.hpp (original)
+++ branches/proto/v3/boost/xpressive/detail/static/grammar.hpp 2007-12-02 23:53:38 EST (Sun, 02 Dec 2007)
@@ -329,7 +329,7 @@
           : or_<
                 when<
                     comma<ListSet<Char>, CharLiteral<Char> >
- , mpl::next<ListSet<Char>(_left)>()
+ , mpl::next<call<ListSet<Char>(_left)> >()
>
               , when<
                     assign<terminal<set_initializer>, CharLiteral<Char> >
@@ -483,12 +483,16 @@
             {};
 
             // Here are some transforms ...
+ struct as_regex
+ : call<Gram>
+ {};
+
             struct as_independent
- : call<Gram(_make_shift_right(_, true_matcher()), no_next())>
+ : call<as_regex(_make_shift_right(_, true_matcher()), no_next())>
             {};
 
             struct as_alternate
- : call<Gram(_make_shift_right(_, alternate_end_matcher()), no_next())>
+ : call<as_regex(_make_shift_right(_, alternate_end_matcher()), no_next())>
             {};
 
             struct as_alternates_list
@@ -582,10 +586,13 @@
               : if_<
                     use_simple_repeat<_arg, Char>()
                   , as_simple_repeat<Greedy>
- , Gram(as_default_repeat<Greedy, tag_of<_> >(_))
+ , as_regex(bind<as_default_repeat<Greedy, tag_of<_> > >)
>
             {};
 
+ struct as_greedy_repeat : as_repeat<greedy_t> {};
+ struct as_non_greedy_repeat : as_repeat<non_greedy_t> {};
+
             template<typename Greedy>
             struct as_optional
               : if_<
@@ -595,10 +602,13 @@
>
             {};
 
+ struct as_greedy_optional : as_optional<greedy_t> {};
+ struct as_non_greedy_optional : as_optional<non_greedy_t> {};
+
             struct as_list_set
               : call<
                     fill_list_set(
- set_matcher<traits(_visitor), ListSet<Char>(_) >()
+ set_matcher<traits(_visitor), call<ListSet<Char> > >()
                       , _
                       , _visitor
                     )
@@ -617,7 +627,7 @@
                           , compound_charset<traits(_visitor)>()
>
>()
- , merge_charset(_state, Gram(_make_shift_right(_, end_matcher()), no_next()), _visitor)
+ , merge_charset(_state, as_regex(_make_shift_right(_, end_matcher()), no_next()), _visitor)
>
             {};
 
@@ -638,7 +648,7 @@
               : when<
                     // _ >> 'a'
                     shift_right<Gram, Gram>
- , reverse_fold_tree<_, _state, in_sequence(Gram, _state)>
+ , reverse_fold_tree<_, _state, in_sequence(as_regex, _state)>
>
             {};
 
@@ -654,38 +664,38 @@
             template<typename Dummy>
             struct case_<tag::dereference, Dummy>
                 // *_
- : when<dereference<Gram>, as_repeat<greedy_t> >
+ : when<dereference<Gram>, as_greedy_repeat>
             {};
 
             template<typename Dummy>
             struct case_<tag::posit, Dummy>
                 // +_
- : when<posit<Gram>, as_repeat<greedy_t> >
+ : when<posit<Gram>, as_greedy_repeat>
             {};
 
             template<uint_t Min, uint_t Max, typename Dummy>
             struct case_<generic_quant_tag<Min, Max>, Dummy>
                 // repeat<0,42>(_)
- : when<unary_expr<generic_quant_tag<Min, Max>, Gram>, as_repeat<greedy_t> >
+ : when<unary_expr<generic_quant_tag<Min, Max>, Gram>, as_greedy_repeat>
             {};
 
             template<typename Dummy>
             struct case_<tag::logical_not, Dummy>
                 // !_
- : when<logical_not<Gram>, as_optional<greedy_t>(_arg)>
+ : when<logical_not<Gram>, as_greedy_optional(_arg)>
             {};
 
             template<typename Dummy>
             struct case_<tag::negate, Dummy>
               : or_<
                     // -*_
- when<negate<dereference<Gram> > , as_repeat<non_greedy_t>(_arg)>
+ when<negate<dereference<Gram> > , as_non_greedy_repeat(_arg)>
                     // -+_
- , when<negate<posit<Gram> > , as_repeat<non_greedy_t>(_arg)>
+ , when<negate<posit<Gram> > , as_non_greedy_repeat(_arg)>
                     // -repeat<0,42>(_)
- , when<negate<GenericQuant> , as_repeat<non_greedy_t>(_arg)>
+ , when<negate<GenericQuant> , as_non_greedy_repeat(_arg)>
                     // -!_
- , when<negate<logical_not<Gram> > , as_optional<non_greedy_t>(_arg(_arg))>
+ , when<negate<logical_not<Gram> > , as_non_greedy_optional(_arg(_arg))>
>
             {};
 
@@ -693,7 +703,7 @@
             struct case_<tag::assign, Dummy>
               : or_<
                     // (s1= ...)
- when<assign<terminal<mark_placeholder>, Gram>, Gram(as_marker)>
+ when<assign<terminal<mark_placeholder>, Gram>, as_regex(as_marker)>
                     // (set= 'a')
                   , when<ListSet<Char>, as_matcher(_arg(_right), _visitor)>
>
@@ -787,7 +797,7 @@
                             complement<subscript<terminal<set_initializer>, terminal<_> > >
                           , complement<assign<terminal<set_initializer>, terminal<_> > >
>
- , Gram(_make_complement(_right(_arg)))
+ , as_regex(_make_complement(_right(_arg)))
>
                     // ~set['a' | alpha | ... ] or ~(set='a','b','c')
                   , when<
@@ -795,7 +805,7 @@
                             complement<subscript<terminal<set_initializer>, bitwise_or<Gram, Gram> > >
                           , complement<ListSet<Char> >
>
- , invert(Gram(_arg))
+ , invert(as_regex(_arg))
>
>
             {};
@@ -820,7 +830,7 @@
             struct case_<modifier_tag, Dummy>
               : when<
                     binary_expr<modifier_tag, terminal<_>, Gram>
- , Gram(_right, _state, modify(_arg(_left), _visitor))
+ , as_regex(_right, _state, modify(_arg(_left), _visitor))
>
             {};
         };

Modified: branches/proto/v3/boost/xpressive/proto/proto_fwd.hpp
==============================================================================
--- branches/proto/v3/boost/xpressive/proto/proto_fwd.hpp (original)
+++ branches/proto/v3/boost/xpressive/proto/proto_fwd.hpp 2007-12-02 23:53:38 EST (Sun, 02 Dec 2007)
@@ -349,6 +349,9 @@
         template<typename Fun, typename... Args>
         struct make;
 
+ template<typename Fun, typename... Args>
+ struct bind;
+
         template<typename Sequence, typename State, typename Fun>
         struct fold;
 
@@ -408,6 +411,7 @@
     using transform::_arg_c;
     using transform::call;
     using transform::make;
+ using transform::bind;
     using transform::fold;
     using transform::always;
     using transform::reverse_fold;

Modified: branches/proto/v3/boost/xpressive/proto/transform.hpp
==============================================================================
--- branches/proto/v3/boost/xpressive/proto/transform.hpp (original)
+++ branches/proto/v3/boost/xpressive/proto/transform.hpp 2007-12-02 23:53:38 EST (Sun, 02 Dec 2007)
@@ -10,7 +10,9 @@
 #define BOOST_PROTO_TRANSFORM_HPP_EAN_10_29_2007
 
 #include <boost/xpressive/proto/transform/arg.hpp>
+#include <boost/xpressive/proto/transform/bind.hpp>
 #include <boost/xpressive/proto/transform/call.hpp>
+#include <boost/xpressive/proto/transform/make.hpp>
 #include <boost/xpressive/proto/transform/fold.hpp>
 #include <boost/xpressive/proto/transform/fold_tree.hpp>
 #include <boost/xpressive/proto/transform/when.hpp>

Added: branches/proto/v3/boost/xpressive/proto/transform/bind.hpp
==============================================================================
--- (empty file)
+++ branches/proto/v3/boost/xpressive/proto/transform/bind.hpp 2007-12-02 23:53:38 EST (Sun, 02 Dec 2007)
@@ -0,0 +1,63 @@
+///////////////////////////////////////////////////////////////////////////////
+/// \file bind.hpp
+/// Contains definition of the bind<> transform.
+//
+// Copyright 2007 Eric Niebler. 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)
+
+#ifndef BOOST_PROTO_TRANSFORM_BIND_HPP_EAN_12_02_2007
+#define BOOST_PROTO_TRANSFORM_BIND_HPP_EAN_12_02_2007
+
+#include <boost/utility/result_of.hpp>
+#include <boost/xpressive/proto/proto_fwd.hpp>
+#include <boost/xpressive/proto/transform/make.hpp>
+#include <boost/xpressive/proto/transform/call.hpp>
+
+namespace boost { namespace proto
+{
+
+ namespace transform
+ {
+ template<typename Return, typename... Args>
+ struct bind : transform_base
+ {
+ template<typename Sig>
+ struct result;
+
+ template<typename This, typename Expr, typename State, typename Visitor>
+ struct result<This(Expr, State, Visitor)>
+ : boost::result_of<
+ call<
+ typename boost::result_of<make<Return>(Expr, State, Visitor)>::type
+ , Args...
+ >(Expr, State, Visitor)
+ >
+ {};
+
+ template<typename Expr, typename State, typename Visitor>
+ typename result<bind(Expr, State, Visitor)>::type
+ operator()(Expr const &expr, State const &state, Visitor &visitor) const
+ {
+ return call<
+ typename boost::result_of<make<Return>(Expr, State, Visitor)>::type
+ , Args...
+ >()(expr, state, visitor);
+ }
+ };
+
+ template<typename Fun, typename... Args>
+ struct bind<Fun(Args...)>
+ : bind<Fun, Args...>
+ {};
+
+ }
+
+ template<typename Fun, typename... Args>
+ struct is_transform<transform::bind<Fun, Args...> >
+ : mpl::true_
+ {};
+
+}}
+
+#endif

Modified: branches/proto/v3/boost/xpressive/proto/transform/call.hpp
==============================================================================
--- branches/proto/v3/boost/xpressive/proto/transform/call.hpp (original)
+++ branches/proto/v3/boost/xpressive/proto/transform/call.hpp 2007-12-02 23:53:38 EST (Sun, 02 Dec 2007)
@@ -13,6 +13,13 @@
 #include <boost/xpressive/proto/proto_fwd.hpp>
 #include <boost/xpressive/proto/traits.hpp>
 
+// BUGBUG these are not the same:
+// as_foo< transform(_arg) >(_)
+// call<as_foo< transform(_arg) >(_)>
+//
+// The problem is that in the second, the inner transform is
+// evaluated, but in the first it isn't.
+
 namespace boost { namespace proto
 {
 
@@ -42,6 +49,14 @@
             no_type check_fun_arity(private_type_ const &);
 
             template<typename Fun>
+ struct callable0_wrap : Fun
+ {
+ callable0_wrap();
+ typedef private_type_ const &(*pfun0)();
+ operator pfun0() const;
+ };
+
+ template<typename Fun>
             struct callable1_wrap : Fun
             {
                 callable1_wrap();
@@ -58,6 +73,17 @@
             };
 
             template<typename Fun, typename A0>
+ struct arity0
+ {
+ static callable0_wrap<Fun> &fun;
+
+ static int const value =
+ sizeof(yes_type) == sizeof(check_fun_arity((fun(), 0)))
+ ? 0
+ : 3;
+ };
+
+ template<typename Fun, typename A0>
             struct arity1
             {
                 static callable1_wrap<Fun> &fun;
@@ -96,6 +122,25 @@
             };
 
             template<typename Fun, typename Expr, typename State, typename Visitor
+ , int Arity = arity0<Fun, Expr>::value>
+ struct call0
+ : call3<Fun, Expr, State, Visitor>
+ {};
+
+ template<typename Fun, typename Expr, typename State, typename Visitor>
+ struct call0<Fun, Expr, State, Visitor, 0>
+ {
+ typedef typename boost::result_of<Fun()>::type type;
+
+ template<typename A, typename B, typename C>
+ static type call(A &&, B &&, C &&)
+ {
+ Fun f;
+ return f();
+ }
+ };
+
+ template<typename Fun, typename Expr, typename State, typename Visitor
               , int Arity = arity1<Fun, Expr>::value>
             struct call1
               : call3<Fun, Expr, State, Visitor>
@@ -156,6 +201,34 @@
             }
         };
 
+ template<typename Fun>
+ struct call<Fun> : transform_base
+ {
+ template<typename Sig>
+ struct result;
+
+ template<typename This, typename Expr, typename State, typename Visitor>
+ struct result<This(Expr, State, Visitor)>
+ : detail::call0<
+ Fun
+ , Expr
+ , State
+ , Visitor
+ >
+ {};
+
+ template<typename Expr, typename State, typename Visitor>
+ typename result<call(Expr, State, Visitor)>::type
+ operator()(Expr const &expr, State const &state, Visitor &visitor) const
+ {
+ return result<call(Expr, State, Visitor)>::call(
+ expr
+ , state
+ , visitor
+ );
+ }
+ };
+
         template<typename Fun, typename Arg0>
         struct call<Fun, Arg0> : transform_base
         {

Modified: branches/proto/v3/boost/xpressive/proto/transform/when.hpp
==============================================================================
--- branches/proto/v3/boost/xpressive/proto/transform/when.hpp (original)
+++ branches/proto/v3/boost/xpressive/proto/transform/when.hpp 2007-12-02 23:53:38 EST (Sun, 02 Dec 2007)
@@ -78,28 +78,37 @@
>
             struct apply
             {
- typedef
- typename boost::result_of<
- transform::make<Return, Args...>(Expr, State, Visitor)
- >::type
- lambda_type;
-
- // If the result of applying the lambda on the return type is a transform,
- // apply the transform rather than trying to construct it.
- typedef
- typename mpl::if_<
- proto::detail::is_transform2_<lambda_type>
- , transform::call<lambda_type, Args...>
- , transform::make<Return, Args...>
- >::type
- transform_type;
-
- typedef typename boost::result_of<transform_type(Expr, State, Visitor)>::type type;
+ typedef typename boost::result_of<
+ transform::make<Return, Args...>(Expr, State, Visitor)
+ >::type type;
 
                 static type call(Expr const &expr, State const &state, Visitor &visitor)
                 {
- return transform_type()(expr, state, visitor);
+ return transform::make<Return, Args...>()(expr, state, visitor);
                 }
+
+ //typedef
+ // typename boost::result_of<
+ // transform::make<Return, Args...>(Expr, State, Visitor)
+ // >::type
+ //lambda_type;
+
+ //// If the result of applying the lambda on the return type is a transform,
+ //// apply the transform rather than trying to construct it.
+ //typedef
+ // typename mpl::if_<
+ // proto::detail::is_transform2_<lambda_type>
+ // , transform::call<lambda_type, Args...>
+ // , transform::make<Return, Args...>
+ // >::type
+ //transform_type;
+
+ //typedef typename boost::result_of<transform_type(Expr, State, Visitor)>::type type;
+
+ //static type call(Expr const &expr, State const &state, Visitor &visitor)
+ //{
+ // return transform_type()(expr, state, visitor);
+ //}
             };
 
             template<


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