Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r66634 - in sandbox/SOC/2010/phoenix3: boost/phoenix boost/phoenix/core boost/phoenix/object boost/phoenix/object/detail libs/phoenix/test/object
From: thom.heller_at_[hidden]
Date: 2010-11-18 11:09:37


Author: theller
Date: 2010-11-18 11:09:32 EST (Thu, 18 Nov 2010)
New Revision: 66634
URL: http://svn.boost.org/trac/boost/changeset/66634

Log:
refactored casts
Added:
   sandbox/SOC/2010/phoenix3/boost/phoenix/object/detail/cast_target.hpp (contents, props changed)
Text files modified:
   sandbox/SOC/2010/phoenix3/boost/phoenix/core/expression.hpp | 78 +++++++++++++++++++++++++++++++--------
   sandbox/SOC/2010/phoenix3/boost/phoenix/object.hpp | 6 +-
   sandbox/SOC/2010/phoenix3/boost/phoenix/object/const_cast.hpp | 52 ++++++++++++++++++++------
   sandbox/SOC/2010/phoenix3/boost/phoenix/object/dynamic_cast.hpp | 50 ++++++++++++++----------
   sandbox/SOC/2010/phoenix3/boost/phoenix/object/reinterpret_cast.hpp | 52 ++++++++++++++++++++------
   sandbox/SOC/2010/phoenix3/boost/phoenix/object/static_cast.hpp | 52 ++++++++++++++++++++------
   sandbox/SOC/2010/phoenix3/libs/phoenix/test/object/cast_tests.cpp | 12 +----
   7 files changed, 214 insertions(+), 88 deletions(-)

Modified: sandbox/SOC/2010/phoenix3/boost/phoenix/core/expression.hpp
==============================================================================
--- sandbox/SOC/2010/phoenix3/boost/phoenix/core/expression.hpp (original)
+++ sandbox/SOC/2010/phoenix3/boost/phoenix/core/expression.hpp 2010-11-18 11:09:32 EST (Thu, 18 Nov 2010)
@@ -1,5 +1,5 @@
 
-#ifndef BOOST_PP_IS_ITERATING
+#if !PHOENIX_IS_ITERATING
 
 /*=============================================================================
     Copyright (c) 2005-2010 Joel de Guzman
@@ -9,29 +9,75 @@
     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_IS_NULLARY_HPP
-#define PHOENIX_CORE_IS_NULLARY_HPP
+#ifndef PHOENIX_CORE_EXPRESSION_HPP
+#define PHOENIX_CORE_EXPRESSION_HPP
+
+#include <boost/phoenix/support/iterate.hpp>
 
 namespace boost { namespace phoenix
 {
- template <typename Expr> struct actor;
-
- template <
- template <typename> Actor
- , PHOENIX_A_void(PHOENIX_LIMIT)
- , typename Dummy = void>
- struct expr_ext;
-
- template <PHOENIX_A_void(PHOENIX_LIMIT)>
- struct expr : expr_ext<actor, PHOENIX_A(PHOENIX_LIMIT)> {};
+ template <typename Expr> struct actor;
+
+ template <
+ template <typename> class Actor
+ , typename Tag
+ , PHOENIX_typename_A_void(PHOENIX_LIMIT)
+ , typename Dummy = void>
+ struct expr_ext;
+
+ template <typename Tag, PHOENIX_typename_A_void(PHOENIX_LIMIT), typename Dummy = void>
+ struct expr : expr_ext<actor, Tag, PHOENIX_A(PHOENIX_LIMIT)> {};
+
+ struct default_domain_with_basic_expr
+ : proto::domain<proto::use_basic_expr<proto::default_generator> >
+ {};
+
+ #define PHOENIX_ITERATION_PARAMS \
+ (3, (1, PHOENIX_ACTOR_LIMIT, \
+ <boost/phoenix/core/expression.hpp>))
+ #include PHOENIX_ITERATE()
 
 }}
 
 #endif
 
 #else
-
-template <
-struct
+ template <template <typename> class Actor, typename Tag, PHOENIX_typename_A>
+ struct expr_ext<Actor, Tag, PHOENIX_A>
+ : proto::transform<expr_ext<Actor, Tag, PHOENIX_A>, int>
+ {
+ #define BOOST_PHOENIX_AS_EXPR(_, N, __) \
+ typename proto::detail::as_expr<BOOST_PP_CAT(A, N), proto::pod_generator<actor>, true>::result_type
+
+ //typedef typename proto::result_of::make_expr<Tag, default_domain_with_basic_expr, BOOST_PP_ENUM(PHOENIX_ITERATION, BOOST_PHOENIX_AS_EXPR, _)>::type base_type;
+ typedef typename proto::result_of::make_expr<Tag, default_domain_with_basic_expr, PHOENIX_A>::type base_type;
+ typedef Actor<base_type> type;
+ //typedef typename proto::nary_expr<Tag, BOOST_PP_ENUM_PARAMS(PHOENIX_ITERATION, proto::_ BOOST_PP_INTERCEPT)>::proto_grammar proto_grammar;//BOOST_PP_ENUM(PHOENIX_ITERATION, BOOST_PHOENIX_AS_EXPR, _)>::proto_grammar proto_grammar;
+ typedef typename proto::nary_expr<Tag, PHOENIX_A>::proto_grammar proto_grammar;//BOOST_PP_ENUM(PHOENIX_ITERATION, BOOST_PHOENIX_AS_EXPR, _)>::proto_grammar proto_grammar;
+ //typedef typename type::proto_grammar proto_grammar;//BOOST_PP_ENUM(PHOENIX_ITERATION, BOOST_PHOENIX_AS_EXPR, _)>::proto_grammar proto_grammar;
+
+ static type const make(PHOENIX_A_a)
+ {
+ type const e = {PHOENIX_a};
+ //return e;
+ }
+
+ template<typename Expr, typename State, typename Data>
+ struct impl
+ : proto::detail::pass_through_impl<expr_ext, Expr, State, Data>
+ {};
+
+ typedef Tag proto_tag;
+ #define BOOST_PHOENIX_ENUM_CHILDREN(_, N, __) typedef BOOST_PP_CAT(A, N) BOOST_PP_CAT(proto_child, N);
+ BOOST_PP_REPEAT(PHOENIX_ITERATION, BOOST_PHOENIX_ENUM_CHILDREN, _)
+ #undef BOOST_PHOENIX_ENUM_CHILDREN
+ };
+
+/*
+ template <typename Tag, PHOENIX_typename_A>
+ struct expr<Tag, PHOENIX_A>
+ : expr_ext<actor, Tag, PHOENIX_A>
+ {};
+*/
 
 #endif

Modified: sandbox/SOC/2010/phoenix3/boost/phoenix/object.hpp
==============================================================================
--- sandbox/SOC/2010/phoenix3/boost/phoenix/object.hpp (original)
+++ sandbox/SOC/2010/phoenix3/boost/phoenix/object.hpp 2010-11-18 11:09:32 EST (Thu, 18 Nov 2010)
@@ -8,12 +8,12 @@
 #ifndef PHOENIX_OBJECT_HPP
 #define PHOENIX_OBJECT_HPP
 
-//#include <boost/phoenix/object/const_cast.hpp>
+#include <boost/phoenix/object/const_cast.hpp>
 //#include <boost/phoenix/object/construct.hpp>
 //#include <boost/phoenix/object/delete.hpp>
 #include <boost/phoenix/object/dynamic_cast.hpp>
 //#include <boost/phoenix/object/new.hpp>
-//#include <boost/phoenix/object/reinterpret_cast.hpp>
-//#include <boost/phoenix/object/static_cast.hpp>
+#include <boost/phoenix/object/reinterpret_cast.hpp>
+#include <boost/phoenix/object/static_cast.hpp>
 
 #endif

Modified: sandbox/SOC/2010/phoenix3/boost/phoenix/object/const_cast.hpp
==============================================================================
--- sandbox/SOC/2010/phoenix3/boost/phoenix/object/const_cast.hpp (original)
+++ sandbox/SOC/2010/phoenix3/boost/phoenix/object/const_cast.hpp 2010-11-18 11:09:32 EST (Thu, 18 Nov 2010)
@@ -8,40 +8,66 @@
 #ifndef PHOENIX_OBJECT_CONST_CAST_HPP
 #define PHOENIX_OBJECT_CONST_CAST_HPP
 
-#include <boost/phoenix/core/compose.hpp>
+#include <boost/phoenix/core/expression.hpp>
+#include <boost/phoenix/object/detail/cast_target.hpp>
 
 namespace boost { namespace phoenix
 {
- namespace result_of
+ namespace tag {
+ struct const_cast_ {};
+ }
+
+ namespace expression
     {
- template <typename Env, typename T, typename U>
+ template <typename T, typename U>
         struct const_cast_
- {
- typedef T type;
- };
+ : expr<tag::const_cast_, T, U>
+ {};
     }
 
+ namespace rule
+ {
+ struct const_cast_
+ : expression::const_cast_<proto::terminal<detail::cast_target<proto::_> >, meta_grammar>
+ {};
+ }
+
+ template <typename Dummy>
+ struct meta_grammar::case_<tag::const_cast_, Dummy>
+ : proto::when<rule::const_cast_, proto::external_transform>
+ {};
+
     template <typename T>
     struct const_cast_eval
+ : proto::callable
     {
- typedef T result_type;
+ typedef typename T::type result_type;
 
         template <typename Env, typename U>
         result_type
- operator()(Env& env, U const& u)
+ operator()(Env& env, U const& u) const
         {
- return const_cast<T>(eval(u, env));
+ return const_cast<result_type>(eval(u, env));
         }
     };
 
- template <typename T, typename U>
- struct make_const_cast : compose<const_cast_eval<T>, U> {};
+ template <typename Dummy>
+ struct default_actions::when<rule::const_cast_, Dummy>
+ : proto::lazy<const_cast_eval<evaluator(proto::_child_c<0>, _env) >(_env, proto::_child_c<1>)>
+ {};
 
     template <typename T, typename U>
- typename make_const_cast<T, U>::type const
+ typename expression::const_cast_<detail::cast_target<T>, U>::type const
     const_cast_(U const& u)
     {
- return make_const_cast<T, U>()(u);
+ return expression::const_cast_<detail::cast_target<T>, U>::make(detail::cast_target<T>(), u);
+ }
+
+ template <typename T, typename U>
+ typename expression::const_cast_<detail::cast_target<T>, U>::type const
+ const_cast_(U & u)
+ {
+ return expression::const_cast_<detail::cast_target<T>, U>::make(detail::cast_target<T>(), u);
     }
 
 }}

Added: sandbox/SOC/2010/phoenix3/boost/phoenix/object/detail/cast_target.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2010/phoenix3/boost/phoenix/object/detail/cast_target.hpp 2010-11-18 11:09:32 EST (Thu, 18 Nov 2010)
@@ -0,0 +1,23 @@
+/*==============================================================================
+ Copyright (c) 2001-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_OBJECT_DETAIL_CAST_TARGET_HPP
+#define PHOENIX_OBJECT_DETAIL_CAST_TARGET_HPP
+
+namespace boost { namespace phoenix
+{
+ namespace detail
+ {
+ template <typename T>
+ struct cast_target
+ {
+ typedef T type;
+ };
+ }
+}}
+
+#endif

Modified: sandbox/SOC/2010/phoenix3/boost/phoenix/object/dynamic_cast.hpp
==============================================================================
--- sandbox/SOC/2010/phoenix3/boost/phoenix/object/dynamic_cast.hpp (original)
+++ sandbox/SOC/2010/phoenix3/boost/phoenix/object/dynamic_cast.hpp 2010-11-18 11:09:32 EST (Thu, 18 Nov 2010)
@@ -8,7 +8,8 @@
 #ifndef PHOENIX_OBJECT_DYNAMIC_CAST_HPP
 #define PHOENIX_OBJECT_DYNAMIC_CAST_HPP
 
-//#include <boost/phoenix/core/compose.hpp>
+#include <boost/phoenix/core/expression.hpp>
+#include <boost/phoenix/object/detail/cast_target.hpp>
 
 namespace boost { namespace phoenix
 {
@@ -16,10 +17,18 @@
         struct dynamic_cast_ {};
     }
 
+ namespace expression
+ {
+ template <typename T, typename U>
+ struct dynamic_cast_
+ : expr<tag::dynamic_cast_, T, U>
+ {};
+ }
+
         namespace rule
         {
                 struct dynamic_cast_
- : proto::unary_expr<tag::dynamic_cast_, meta_grammar>
+ : expression::dynamic_cast_<proto::terminal<detail::cast_target<proto::_> >, meta_grammar>
                 {};
         }
 
@@ -27,40 +36,39 @@
         struct meta_grammar::case_<tag::dynamic_cast_, Dummy>
                 : proto::when<rule::dynamic_cast_, proto::external_transform>
         {};
-
-
- namespace result_of
- {
- template <typename Env, typename T, typename U>
- struct dynamic_cast_
- {
- typedef T type;
- };
- }
-
+
     template <typename T>
     struct dynamic_cast_eval
+ : proto::callable
     {
- typedef T result_type;
+ typedef typename T::type result_type;
 
         template <typename Env, typename U>
         result_type
- operator()(Env& env, U const& u)
+ operator()(Env& env, U const& u) const
         {
- return dynamic_cast<T>(eval(u, env));
+ return dynamic_cast<result_type>(eval(u, env));
         }
     };
 
- template <typename T, typename U>
- struct make_dynamic_cast : compose<dynamic_cast_eval<T>, U> {};
+ template <typename Dummy>
+ struct default_actions::when<rule::dynamic_cast_, Dummy>
+ : proto::lazy<dynamic_cast_eval<evaluator(proto::_child_c<0>, _env) >(_env, proto::_child_c<1>)>
+ {};
 
     template <typename T, typename U>
- typename make_dynamic_cast<T, U>::type const
+ typename expression::dynamic_cast_<detail::cast_target<T>, U>::type const
     dynamic_cast_(U const& u)
     {
- return make_dynamic_cast<T, U>()(u);
+ return expression::dynamic_cast_<detail::cast_target<T>, U>::make(detail::cast_target<T>(), u);
+ }
+
+ template <typename T, typename U>
+ typename expression::dynamic_cast_<detail::cast_target<T>, U>::type const
+ dynamic_cast_(U & u)
+ {
+ return expression::dynamic_cast_<detail::cast_target<T>, U>::make(detail::cast_target<T>(), u);
     }
-
 }}
 
 #endif

Modified: sandbox/SOC/2010/phoenix3/boost/phoenix/object/reinterpret_cast.hpp
==============================================================================
--- sandbox/SOC/2010/phoenix3/boost/phoenix/object/reinterpret_cast.hpp (original)
+++ sandbox/SOC/2010/phoenix3/boost/phoenix/object/reinterpret_cast.hpp 2010-11-18 11:09:32 EST (Thu, 18 Nov 2010)
@@ -8,40 +8,66 @@
 #ifndef PHOENIX_OBJECT_REINTERPRET_CAST_HPP
 #define PHOENIX_OBJECT_REINTERPRET_CAST_HPP
 
-#include <boost/phoenix/core/compose.hpp>
+#include <boost/phoenix/core/expression.hpp>
+#include <boost/phoenix/object/detail/cast_target.hpp>
 
 namespace boost { namespace phoenix
 {
- namespace result_of
+ namespace tag {
+ struct reinterpret_cast_ {};
+ }
+
+ namespace expression
     {
- template <typename Env, typename T, typename U>
+ template <typename T, typename U>
         struct reinterpret_cast_
- {
- typedef T type;
- };
+ : expr<tag::reinterpret_cast_, T, U>
+ {};
     }
 
+ namespace rule
+ {
+ struct reinterpret_cast_
+ : expression::reinterpret_cast_<proto::terminal<detail::cast_target<proto::_> >, meta_grammar>
+ {};
+ }
+
+ template <typename Dummy>
+ struct meta_grammar::case_<tag::reinterpret_cast_, Dummy>
+ : proto::when<rule::reinterpret_cast_, proto::external_transform>
+ {};
+
     template <typename T>
     struct reinterpret_cast_eval
+ : proto::callable
     {
- typedef T result_type;
+ typedef typename T::type result_type;
 
         template <typename Env, typename U>
         result_type
- operator()(Env& env, U const& u)
+ operator()(Env& env, U const& u) const
         {
- return reinterpret_cast<T>(eval(u, env));
+ return reinterpret_cast<result_type>(eval(u, env));
         }
     };
 
- template <typename T, typename U>
- struct make_reinterpret_cast : compose<reinterpret_cast_eval<T>, U> {};
+ template <typename Dummy>
+ struct default_actions::when<rule::reinterpret_cast_, Dummy>
+ : proto::lazy<reinterpret_cast_eval<evaluator(proto::_child_c<0>, _env) >(_env, proto::_child_c<1>)>
+ {};
 
     template <typename T, typename U>
- typename make_reinterpret_cast<T, U>::type const
+ typename expression::reinterpret_cast_<detail::cast_target<T>, U>::type const
     reinterpret_cast_(U const& u)
     {
- return make_reinterpret_cast<T, U>()(u);
+ return expression::reinterpret_cast_<detail::cast_target<T>, U>::make(detail::cast_target<T>(), u);
+ }
+
+ template <typename T, typename U>
+ typename expression::reinterpret_cast_<detail::cast_target<T>, U>::type const
+ reinterpret_cast_(U & u)
+ {
+ return expression::reinterpret_cast_<detail::cast_target<T>, U>::make(detail::cast_target<T>(), u);
     }
 
 }}

Modified: sandbox/SOC/2010/phoenix3/boost/phoenix/object/static_cast.hpp
==============================================================================
--- sandbox/SOC/2010/phoenix3/boost/phoenix/object/static_cast.hpp (original)
+++ sandbox/SOC/2010/phoenix3/boost/phoenix/object/static_cast.hpp 2010-11-18 11:09:32 EST (Thu, 18 Nov 2010)
@@ -8,40 +8,66 @@
 #ifndef PHOENIX_OBJECT_STATIC_CAST_HPP
 #define PHOENIX_OBJECT_STATIC_CAST_HPP
 
-#include <boost/phoenix/core/compose.hpp>
+#include <boost/phoenix/core/expression.hpp>
+#include <boost/phoenix/object/detail/cast_target.hpp>
 
 namespace boost { namespace phoenix
 {
- namespace result_of
+ namespace tag {
+ struct static_cast_ {};
+ }
+
+ namespace expression
     {
- template <typename Env, typename T, typename U>
+ template <typename T, typename U>
         struct static_cast_
- {
- typedef T type;
- };
+ : expr<tag::static_cast_, T, U>
+ {};
     }
 
+ namespace rule
+ {
+ struct static_cast_
+ : expression::static_cast_<proto::terminal<detail::cast_target<proto::_> >, meta_grammar>
+ {};
+ }
+
+ template <typename Dummy>
+ struct meta_grammar::case_<tag::static_cast_, Dummy>
+ : proto::when<rule::static_cast_, proto::external_transform>
+ {};
+
     template <typename T>
     struct static_cast_eval
+ : proto::callable
     {
- typedef T result_type;
+ typedef typename T::type result_type;
 
         template <typename Env, typename U>
         result_type
- operator()(Env& env, U const& u)
+ operator()(Env& env, U const& u) const
         {
- return static_cast<T>(eval(u, env));
+ return static_cast<result_type>(eval(u, env));
         }
     };
 
- template <typename T, typename U>
- struct make_static_cast : compose<static_cast_eval<T>, U> {};
+ template <typename Dummy>
+ struct default_actions::when<rule::static_cast_, Dummy>
+ : proto::lazy<static_cast_eval<evaluator(proto::_child_c<0>, _env) >(_env, proto::_child_c<1>)>
+ {};
 
     template <typename T, typename U>
- typename make_static_cast<T, U>::type const
+ typename expression::static_cast_<detail::cast_target<T>, U>::type const
     static_cast_(U const& u)
     {
- return make_static_cast<T, U>()(u);
+ return expression::static_cast_<detail::cast_target<T>, U>::make(detail::cast_target<T>(), u);
+ }
+
+ template <typename T, typename U>
+ typename expression::static_cast_<detail::cast_target<T>, U>::type const
+ static_cast_(U & u)
+ {
+ return expression::static_cast_<detail::cast_target<T>, U>::make(detail::cast_target<T>(), u);
     }
 
 }}

Modified: sandbox/SOC/2010/phoenix3/libs/phoenix/test/object/cast_tests.cpp
==============================================================================
--- sandbox/SOC/2010/phoenix3/libs/phoenix/test/object/cast_tests.cpp (original)
+++ sandbox/SOC/2010/phoenix3/libs/phoenix/test/object/cast_tests.cpp 2010-11-18 11:09:32 EST (Thu, 18 Nov 2010)
@@ -35,25 +35,21 @@
 main()
 {
     using boost::phoenix::arg_names::arg1;
- //using boost::phoenix::const_cast_;
+ using boost::phoenix::const_cast_;
     using boost::phoenix::dynamic_cast_;
- //using boost::phoenix::reinterpret_cast_;
- //using boost::phoenix::static_cast_;
+ using boost::phoenix::reinterpret_cast_;
+ using boost::phoenix::static_cast_;
 
- /*
     {
         U u;
         BOOST_TEST(arg1(u).foo() == "U");
         BOOST_TEST(static_cast_<T&>(arg1)(u).foo() == "T");
     }
- */
 
- /*
     {
         U const u = U();
         BOOST_TEST(const_cast_<U&>(arg1)(u).foo() == "U");
     }
- */
 
     {
         VU u;
@@ -62,12 +58,10 @@
         BOOST_TEST(dynamic_cast_<VU*>(arg1)(tp) != 0);
     }
 
- /*
     {
         void* p = 0;
         reinterpret_cast_<VU*>(arg1)(p); // compile test only
     }
- */
 
     return boost::report_errors();
 }


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