Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r62790 - in sandbox/SOC/2010/phoenix3/boost/phoenix: . core
From: thom.heller_at_[hidden]
Date: 2010-06-11 06:32:53


Author: theller
Date: 2010-06-11 06:32:51 EDT (Fri, 11 Jun 2010)
New Revision: 62790
URL: http://svn.boost.org/trac/boost/changeset/62790

Log:
+ added arity calculation for phoenix expressions
+ brought back nullary expressions

Added:
   sandbox/SOC/2010/phoenix3/boost/phoenix/core/arity.hpp (contents, props changed)
Text files modified:
   sandbox/SOC/2010/phoenix3/boost/phoenix/core.hpp | 3
   sandbox/SOC/2010/phoenix3/boost/phoenix/core/actor.hpp | 87 +++++++++++++++++++++++++++++++--------
   sandbox/SOC/2010/phoenix3/boost/phoenix/core/compose.hpp | 3 -
   sandbox/SOC/2010/phoenix3/boost/phoenix/core/domain.hpp | 8 +++
   4 files changed, 77 insertions(+), 24 deletions(-)

Modified: sandbox/SOC/2010/phoenix3/boost/phoenix/core.hpp
==============================================================================
--- sandbox/SOC/2010/phoenix3/boost/phoenix/core.hpp (original)
+++ sandbox/SOC/2010/phoenix3/boost/phoenix/core.hpp 2010-06-11 06:32:51 EDT (Fri, 11 Jun 2010)
@@ -7,8 +7,6 @@
 #ifndef PHOENIX_CORE_HPP
 #define PHOENIX_CORE_HPP
 
-#include <boost/proto/proto.hpp>
-
 #include <boost/phoenix/version.hpp>
 #include <boost/phoenix/core/limits.hpp>
 #include <boost/phoenix/core/actor.hpp>
@@ -18,6 +16,7 @@
 #include <boost/phoenix/core/value.hpp>
 #include <boost/phoenix/core/reference.hpp>
 #include <boost/phoenix/core/nothing.hpp>
+#include <boost/phoenix/core/arity.hpp>
 //#include <boost/phoenix/core/extension.hpp>
 
 #endif

Modified: sandbox/SOC/2010/phoenix3/boost/phoenix/core/actor.hpp
==============================================================================
--- sandbox/SOC/2010/phoenix3/boost/phoenix/core/actor.hpp (original)
+++ sandbox/SOC/2010/phoenix3/boost/phoenix/core/actor.hpp 2010-06-11 06:32:51 EDT (Fri, 11 Jun 2010)
@@ -9,7 +9,9 @@
 #define PHOENIX_CORE_ACTOR_HPP
 
 #include <boost/fusion/container/vector/vector10.hpp>
-#include <boost/phoenix/core/actor_result.hpp>
+#include <boost/mpl/identity.hpp>
+#include <boost/mpl/eval_if.hpp>
+#include <boost/phoenix/core/arity.hpp>
 #include <boost/phoenix/core/domain.hpp>
 #include <boost/phoenix/core/meta_grammar.hpp>
 #include <boost/proto/extends.hpp>
@@ -19,6 +21,42 @@
 #include <boost/mpl/void.hpp>
 namespace boost { namespace phoenix
 {
+ template <typename Expr>
+ struct actor;
+
+ namespace detail
+ {
+ struct error_expecting_arguments
+ {
+ template <typename T>
+ error_expecting_arguments(T const&) {}
+ };
+ }
+
+ namespace result_of
+ {
+ template <typename Expr, typename A0 = void, typename A1 = void
+ /* ... more ... */
+ , typename Dummy = void>
+ struct actor;
+
+ template <typename Expr>
+ struct actor<Expr>
+ {
+ typedef typename ::boost::phoenix::actor<Expr>::nullary_result type;
+ };
+
+ template <typename Expr, typename A0>
+ struct actor<Expr, A0>
+ : boost::result_of<eval_grammar(::boost::phoenix::actor<Expr>&, fusion::vector1<A0>&)>
+ {};
+
+ template <typename Expr, typename A0, typename A1>
+ struct actor<Expr, A0, A1>
+ : boost::result_of<eval_grammar(::boost::phoenix::actor<Expr>&, fusion::vector2<A0, A1>&)>
+ {};
+ }
+
     ////////////////////////////////////////////////////////////////////////////
     // The actor class. The main thing! In phoenix, everything is an actor
     // This class is responsible for full function evaluation. Partial
@@ -31,30 +69,46 @@
         BOOST_PROTO_EXTENDS_ASSIGN()
         BOOST_PROTO_EXTENDS_SUBSCRIPT()
 
+ static const int arity = result_of::arity<Expr>::type::value;
+
+ typedef typename
+ mpl::eval_if_c<
+ arity == 0 // avoid calling result_of::actor when this is true
+ , boost::result_of<eval_grammar(actor<Expr>&, fusion::vector0<>&)>
+ , mpl::identity<detail::error_expecting_arguments>
+ >::type
+ nullary_result;
+
         template <typename Sig>
- struct result : actor_result<Sig> {};
+ struct result;
 
- typedef actor<Expr> actor_type;
+ template <typename This>
+ struct result<This()>
+ {
+ typedef nullary_result type;
+ };
 
- struct dummy {};
+ template <typename This, typename A0>
+ struct result<This(A0)>
+ : result_of::actor<Expr, A0>
+ {};
+
+ template <typename This, typename A0, typename A1>
+ struct result<This(A0, A1)>
+ : result_of::actor<Expr, A0, A1>
+ {};
 
- //typename boost::result_of<actor_type()>::type
- //typename actor_result<actor_type()>::type
- //typename boost::result_of<eval_grammar(actor_type&, fusion::vector0<>&)>::type
- void
+ nullary_result
         operator()() const
         {
             BOOST_PROTO_ASSERT_MATCHES( *this, eval_grammar );
             fusion::vector0<> args;
 
- eval(*this, args);
- //return eval(*this, args);
+ return eval(*this, args);
         }
 
         template <typename A0>
- //typename boost::result_of<actor_type(A0 const&)>::type
- typename actor_result<actor_type(A0 const&)>::type
- //typename boost::result_of<eval_grammar(actor_type&, fusion::vector1<A0>&)>::type
+ typename result_of::actor<Expr, A0 const &>::type
         operator()(A0 const& a0) const
         {
             BOOST_PROTO_ASSERT_MATCHES(*this, eval_grammar);
@@ -64,9 +118,7 @@
         }
 
         template <typename A0, typename A1>
- //typename boost::result_of<actor_type(A0 const&, A1 const&)>::type
- typename actor_result<actor_type(A0 const&, A1 const&)>::type
- //typename boost::result_of<eval_grammar(actor_type&, fusion::vector1<A0, A1>&)>::type
+ typename result_of::actor<Expr, A0 const &, A1 const &>::type
         operator()(A0 const& a0, A1 const& a1) const
         {
             BOOST_PROTO_ASSERT_MATCHES(*this, eval_grammar);
@@ -84,8 +136,7 @@
     template<typename Expr>
     struct result_of<phoenix::actor<Expr>() >
     {
- typedef phoenix::actor<Expr> F;
- typedef typename F::template result<F()>::type type;
+ typedef typename phoenix::actor<Expr>::nullary_result type;
     };
 
 }

Added: sandbox/SOC/2010/phoenix3/boost/phoenix/core/arity.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2010/phoenix3/boost/phoenix/core/arity.hpp 2010-06-11 06:32:51 EDT (Fri, 11 Jun 2010)
@@ -0,0 +1,111 @@
+/*==============================================================================
+ Copyright (c) 2005-2010 Joel de Guzman
+ Copyright (c) 2010 Thomas Heller
+
+ 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 PHOENIX_CORE_ARITY_HPP
+#define PHOENIX_CORE_ARITY_HPP
+
+#include <boost/mpl/max.hpp>
+#include <boost/mpl/int.hpp>
+#include <boost/proto/proto_fwd.hpp>
+#include <boost/proto/matches.hpp>
+#include <boost/proto/traits.hpp>
+#include <boost/proto/tags.hpp>
+#include <boost/proto/transform/arg.hpp>
+#include <boost/proto/transform/default.hpp>
+#include <boost/proto/transform/when.hpp>
+#include <boost/proto/transform/fold.hpp>
+
+namespace boost { namespace phoenix
+{
+
+ ////////////////////////////////////////////////////////////////////////////
+ // Calculate the arity of an expression using proto transforms
+ ////////////////////////////////////////////////////////////////////////////
+
+ struct argument;
+
+ template <typename F>
+ struct funcwrap;
+
+ struct env;
+
+ namespace detail
+ {
+ struct arity : proto::switch_<struct arity_cases>
+ {};
+
+ typedef proto::fold<
+ proto::_
+ , mpl::int_<0>()
+ , mpl::max<arity, proto::_state>()>
+ arity_fold;
+ typedef proto::when<proto::_, mpl::int_<0>()> arity_default;
+
+ struct arity_cases
+ {
+ template <typename Tag>
+ struct case_
+ : proto::or_<
+ proto::when<
+ proto::nary_expr<proto::_, proto::vararg<arity> >
+ , arity_fold
+ >
+ , arity_default
+ >
+ {};
+ };
+
+ template <>
+ struct arity_cases::case_<proto::tag::function>
+ : proto::or_<
+ proto::when<
+ proto::function<
+ proto::terminal<funcwrap<argument> >
+ , proto::terminal<env>
+ , proto::_ >
+ , mpl::next<proto::_value(proto::_child2)>()>
+ , proto::when<
+ proto::function<
+ proto::terminal<funcwrap<proto::_> >
+ , proto::terminal<env>
+ , proto::vararg<arity>
+ >
+ , arity_fold
+ >
+ , proto::when<
+ proto::function<
+ proto::vararg<arity>
+ >
+ , arity_fold
+ >
+ >
+ {};
+ }
+
+ namespace result_of
+ {
+ template <typename Expr>
+ struct arity
+ : boost::result_of<detail::arity(Expr)>
+ {};
+ }
+
+ template <typename Expr>
+ int arity()
+ {
+ return result_of::arity<Expr>::type::value;
+ }
+
+ template <typename Expr>
+ int arity( Expr const & )
+ {
+ return result_of::arity<Expr>::type::value;
+ }
+
+}}
+
+#endif

Modified: sandbox/SOC/2010/phoenix3/boost/phoenix/core/compose.hpp
==============================================================================
--- sandbox/SOC/2010/phoenix3/boost/phoenix/core/compose.hpp (original)
+++ sandbox/SOC/2010/phoenix3/boost/phoenix/core/compose.hpp 2010-06-11 06:32:51 EDT (Fri, 11 Jun 2010)
@@ -10,9 +10,6 @@
 
 #include <boost/call_traits.hpp>
 #include <boost/fusion/sequence/intrinsic/at.hpp>
-#include <boost/phoenix/core/actor.hpp>
-#include <boost/phoenix/core/domain.hpp>
-#include <boost/phoenix/core/meta_grammar.hpp>
 #include <boost/preprocessor/repetition/enum_binary_params.hpp>
 #include <boost/preprocessor/repetition/enum_trailing_params.hpp>
 #include <boost/preprocessor/iteration/local.hpp>

Modified: sandbox/SOC/2010/phoenix3/boost/phoenix/core/domain.hpp
==============================================================================
--- sandbox/SOC/2010/phoenix3/boost/phoenix/core/domain.hpp (original)
+++ sandbox/SOC/2010/phoenix3/boost/phoenix/core/domain.hpp 2010-06-11 06:32:51 EDT (Fri, 11 Jun 2010)
@@ -22,7 +22,13 @@
       : proto::domain<
         proto::pod_generator<actor>,
         proto::_, proto::default_domain>
- {};
+ {
+ /*
+ template <typename T>
+ struct as_child : as_expr<T>
+ {};
+ */
+ };
 }}
 
 #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