|
Boost-Commit : |
From: eric_at_[hidden]
Date: 2008-05-13 02:08:21
Author: eric_niebler
Date: 2008-05-13 02:08:20 EDT (Tue, 13 May 2008)
New Revision: 45318
URL: http://svn.boost.org/trac/boost/changeset/45318
Log:
experimental support for virtual data members of extension classes (e.g., the else_ in if_(foo)[bar].else_[baz])
Text files modified:
branches/proto/v4/boost/proto/extends.hpp | 74 ++++++++++++++++++++++++++++++++++++++++
branches/proto/v4/boost/proto/proto_fwd.hpp | 5 ++
branches/proto/v4/boost/proto/tags.hpp | 3 +
branches/proto/v4/boost/proto/traits.hpp | 11 +++++
4 files changed, 93 insertions(+), 0 deletions(-)
Modified: branches/proto/v4/boost/proto/extends.hpp
==============================================================================
--- branches/proto/v4/boost/proto/extends.hpp (original)
+++ branches/proto/v4/boost/proto/extends.hpp 2008-05-13 02:08:20 EDT (Tue, 13 May 2008)
@@ -31,6 +31,19 @@
namespace boost { namespace proto
{
+ #ifdef __GNUC__
+ /// INTERNAL ONLY
+ ///
+ # define BOOST_PROTO_ADDROF(x) ((char const volatile*)boost::addressof(x))
+ /// INTERNAL ONLY
+ ///
+ # define BOOST_PROTO_OFFSETOF(s,m) (BOOST_PROTO_ADDROF((((s *)this)->m)) - BOOST_PROTO_ADDROF(*((s *)this)))
+ #else
+ /// INTERNAL ONLY
+ ///
+ # define BOOST_PROTO_OFFSETOF offsetof
+ #endif
+
/// INTERNAL ONLY
///
#define BOOST_PROTO_CONST0
@@ -455,6 +468,67 @@
#include BOOST_PP_LOCAL_ITERATE()
};
+ /// INTERNAL ONLY
+ ///
+ template<typename This, typename Fun, typename Domain>
+ struct virtual_member
+ {
+ typedef
+ expr<tag::member, list2<This &, expr<tag::terminal, term<Fun> > const &> >
+ proto_base_expr;
+ typedef Domain proto_domain;
+ typedef virtual_member<This, Fun, Domain> proto_derived_expr;
+ typedef typename proto_base_expr::proto_tag proto_tag;
+ typedef typename proto_base_expr::proto_args proto_args;
+ typedef typename proto_base_expr::proto_arity proto_arity;
+ typedef typename proto_base_expr::address_of_hack_type_ proto_address_of_hack_type_;
+ typedef void proto_is_expr_;
+ BOOST_PROTO_FUSION_DEFINE_TAG(boost::proto::tag::proto_expr)
+ BOOST_PP_REPEAT(BOOST_PROTO_MAX_ARITY, BOOST_PROTO_EXTENDS_CHILD, ~)
+ typedef void proto_is_aggregate_;
+
+ BOOST_PROTO_EXTENDS_ASSIGN()
+ BOOST_PROTO_EXTENDS_SUBSCRIPT()
+ BOOST_PROTO_EXTENDS_FUNCTION()
+
+ proto_base_expr const proto_base() const
+ {
+ proto_base_expr that = {this->child0(), this->child1()};
+ return that;
+ }
+
+ proto_child0 child0() const
+ {
+ return *(This *)((char *)this - BOOST_PROTO_OFFSETOF(This, proto_member_union_start_));
+ }
+
+ proto_child1 child1() const
+ {
+ static expr<tag::terminal, term<Fun> > const that = {Fun()};
+ return that;
+ }
+ };
+
+ /// INTERNAL ONLY
+ ///
+ #define BOOST_PROTO_DECLARE_MEMBER(R, DATA, ELEM) \
+ boost::proto::exprns_::virtual_member< \
+ proto_derived_expr \
+ , BOOST_PP_TUPLE_ELEM(2, 0, ELEM) \
+ , proto_domain \
+ > BOOST_PP_TUPLE_ELEM(2, 1, ELEM); \
+ /**/
+
+ /// \brief For declaring virtual data members in an extension class.
+ ///
+ #define BOOST_PROTO_DECLARE_MEMBERS(SEQ) \
+ union \
+ { \
+ char proto_member_union_start_; \
+ BOOST_PP_SEQ_FOR_EACH(BOOST_PROTO_DECLARE_MEMBER, ~, SEQ) \
+ }; \
+ /**/
+
BOOST_PROTO_END_ADL_NAMESPACE(exprns_)
}}
Modified: branches/proto/v4/boost/proto/proto_fwd.hpp
==============================================================================
--- branches/proto/v4/boost/proto/proto_fwd.hpp (original)
+++ branches/proto/v4/boost/proto/proto_fwd.hpp 2008-05-13 02:08:20 EDT (Tue, 13 May 2008)
@@ -227,6 +227,7 @@
struct bitwise_or_assign;
struct bitwise_xor_assign;
struct subscript;
+ struct member;
struct if_else_;
struct function;
@@ -301,6 +302,9 @@
>
struct extends;
+ template<typename This, typename Fun, typename Domain>
+ struct virtual_member;
+
struct is_proto_expr;
BOOST_PROTO_END_ADL_NAMESPACE(exprns_)
////////////////////////////////////////////////////////////////////////////////////////////////
@@ -541,6 +545,7 @@
template<typename T, typename U> struct bitwise_or_assign;
template<typename T, typename U> struct bitwise_xor_assign;
template<typename T, typename U> struct subscript;
+ template<typename T, typename U> struct member;
template<typename T, typename U, typename V> struct if_else_;
template<BOOST_PP_ENUM_PARAMS_WITH_A_DEFAULT(BOOST_PROTO_MAX_ARITY, typename A, void), typename Dummy = void>
Modified: branches/proto/v4/boost/proto/tags.hpp
==============================================================================
--- branches/proto/v4/boost/proto/tags.hpp (original)
+++ branches/proto/v4/boost/proto/tags.hpp 2008-05-13 02:08:20 EDT (Tue, 13 May 2008)
@@ -145,6 +145,9 @@
/// Tag type for the binary subscript operator.
struct subscript {};
+ /// Tag type for the binary virtual data members.
+ struct member {};
+
/// Tag type for the ternary ?: conditional operator.
struct if_else_ {};
Modified: branches/proto/v4/boost/proto/traits.hpp
==============================================================================
--- branches/proto/v4/boost/proto/traits.hpp (original)
+++ branches/proto/v4/boost/proto/traits.hpp 2008-05-13 02:08:20 EDT (Tue, 13 May 2008)
@@ -1570,6 +1570,17 @@
typedef U proto_child1;
};
+ /// \brief A grammar element for matching virtual data members.
+ ///
+ template<typename T, typename U>
+ struct member
+ {
+ typedef expr<tag::member, list2<T, U> > type;
+ typedef type proto_base_expr;
+
+ // TODO pass-through transform?
+ };
+
} // namespace op
#define BOOST_PROTO_CHILD(Z, N, DATA) \
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