Chris@16
|
1 #if !defined(BOOST_PROTO_DONT_USE_PREPROCESSED_FILES)
|
Chris@16
|
2
|
Chris@16
|
3 #include <boost/proto/detail/preprocessed/basic_expr.hpp>
|
Chris@16
|
4
|
Chris@16
|
5 #elif !defined(BOOST_PP_IS_ITERATING)
|
Chris@16
|
6
|
Chris@16
|
7 /// INTERNAL ONLY
|
Chris@16
|
8 ///
|
Chris@16
|
9 #define BOOST_PROTO_CHILD(Z, N, DATA) \
|
Chris@16
|
10 typedef BOOST_PP_CAT(Arg, N) BOOST_PP_CAT(proto_child, N); \
|
Chris@16
|
11 BOOST_PP_CAT(proto_child, N) BOOST_PP_CAT(child, N); \
|
Chris@16
|
12 /**< INTERNAL ONLY */
|
Chris@16
|
13
|
Chris@16
|
14 /// INTERNAL ONLY
|
Chris@16
|
15 ///
|
Chris@16
|
16 #define BOOST_PROTO_VOID(Z, N, DATA) \
|
Chris@16
|
17 typedef void BOOST_PP_CAT(proto_child, N); \
|
Chris@16
|
18 /**< INTERNAL ONLY */
|
Chris@16
|
19
|
Chris@16
|
20 #if defined(__WAVE__) && defined(BOOST_PROTO_CREATE_PREPROCESSED_FILES)
|
Chris@16
|
21 #pragma wave option(preserve: 2, line: 0, output: "preprocessed/basic_expr.hpp")
|
Chris@16
|
22 #endif
|
Chris@16
|
23
|
Chris@16
|
24 ///////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
25 /// \file basic_expr.hpp
|
Chris@16
|
26 /// Contains definition of basic_expr\<\> class template.
|
Chris@16
|
27 //
|
Chris@16
|
28 // Copyright 2008 Eric Niebler. Distributed under the Boost
|
Chris@16
|
29 // Software License, Version 1.0. (See accompanying file
|
Chris@16
|
30 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
31
|
Chris@16
|
32 #if defined(__WAVE__) && defined(BOOST_PROTO_CREATE_PREPROCESSED_FILES)
|
Chris@16
|
33 #pragma wave option(preserve: 1)
|
Chris@16
|
34 #endif
|
Chris@16
|
35
|
Chris@16
|
36 // The expr<> specializations are actually defined here.
|
Chris@16
|
37 #define BOOST_PROTO_DEFINE_TERMINAL
|
Chris@16
|
38 #define BOOST_PP_ITERATION_PARAMS_1 (3, (0, 0, <boost/proto/detail/basic_expr.hpp>))
|
Chris@16
|
39 #include BOOST_PP_ITERATE()
|
Chris@16
|
40
|
Chris@16
|
41 #undef BOOST_PROTO_DEFINE_TERMINAL
|
Chris@16
|
42 #define BOOST_PP_ITERATION_PARAMS_1 (3, (1, BOOST_PROTO_MAX_ARITY, <boost/proto/detail/basic_expr.hpp>))
|
Chris@16
|
43 #include BOOST_PP_ITERATE()
|
Chris@16
|
44
|
Chris@16
|
45 #if defined(__WAVE__) && defined(BOOST_PROTO_CREATE_PREPROCESSED_FILES)
|
Chris@16
|
46 #pragma wave option(output: null)
|
Chris@16
|
47 #endif
|
Chris@16
|
48
|
Chris@16
|
49 #undef BOOST_PROTO_CHILD
|
Chris@16
|
50 #undef BOOST_PROTO_VOID
|
Chris@16
|
51
|
Chris@16
|
52 #else
|
Chris@16
|
53
|
Chris@16
|
54 #define ARG_COUNT BOOST_PP_MAX(1, BOOST_PP_ITERATION())
|
Chris@16
|
55
|
Chris@16
|
56 /// \brief Simplified representation of a node in an expression tree.
|
Chris@16
|
57 ///
|
Chris@16
|
58 /// \c proto::basic_expr\<\> is a node in an expression template tree. It
|
Chris@16
|
59 /// is a container for its child sub-trees. It also serves as
|
Chris@16
|
60 /// the terminal nodes of the tree.
|
Chris@16
|
61 ///
|
Chris@16
|
62 /// \c Tag is type that represents the operation encoded by
|
Chris@16
|
63 /// this expression. It is typically one of the structs
|
Chris@16
|
64 /// in the \c boost::proto::tag namespace, but it doesn't
|
Chris@16
|
65 /// have to be.
|
Chris@16
|
66 ///
|
Chris@16
|
67 /// \c Args is a type list representing the type of the children
|
Chris@16
|
68 /// of this expression. It is an instantiation of one
|
Chris@16
|
69 /// of \c proto::list1\<\>, \c proto::list2\<\>, etc. The
|
Chris@16
|
70 /// child types must all themselves be either \c expr\<\>
|
Chris@16
|
71 /// or <tt>proto::expr\<\>&</tt>. If \c Args is an
|
Chris@16
|
72 /// instantiation of \c proto::term\<\> then this
|
Chris@16
|
73 /// \c expr\<\> type represents a terminal expression;
|
Chris@16
|
74 /// the parameter to the \c proto::term\<\> template
|
Chris@16
|
75 /// represents the terminal's value type.
|
Chris@16
|
76 ///
|
Chris@16
|
77 /// \c Arity is an integral constant representing the number of child
|
Chris@16
|
78 /// nodes this node contains. If \c Arity is 0, then this
|
Chris@16
|
79 /// node is a terminal.
|
Chris@16
|
80 ///
|
Chris@16
|
81 /// \c proto::basic_expr\<\> is a valid Fusion random-access sequence, where
|
Chris@16
|
82 /// the elements of the sequence are the child expressions.
|
Chris@16
|
83 #ifdef BOOST_PROTO_DEFINE_TERMINAL
|
Chris@16
|
84 template<typename Tag, typename Arg0>
|
Chris@16
|
85 struct basic_expr<Tag, term<Arg0>, 0>
|
Chris@16
|
86 #else
|
Chris@16
|
87 template<typename Tag BOOST_PP_ENUM_TRAILING_PARAMS(ARG_COUNT, typename Arg)>
|
Chris@16
|
88 struct basic_expr<Tag, BOOST_PP_CAT(list, BOOST_PP_ITERATION())<BOOST_PP_ENUM_PARAMS(ARG_COUNT, Arg)>, BOOST_PP_ITERATION() >
|
Chris@16
|
89 #endif
|
Chris@16
|
90 {
|
Chris@16
|
91 typedef Tag proto_tag;
|
Chris@16
|
92 static const long proto_arity_c = BOOST_PP_ITERATION();
|
Chris@16
|
93 typedef mpl::long_<BOOST_PP_ITERATION() > proto_arity;
|
Chris@16
|
94 typedef basic_expr proto_base_expr;
|
Chris@16
|
95 #ifdef BOOST_PROTO_DEFINE_TERMINAL
|
Chris@16
|
96 typedef term<Arg0> proto_args;
|
Chris@16
|
97 #else
|
Chris@16
|
98 typedef BOOST_PP_CAT(list, BOOST_PP_ITERATION())<BOOST_PP_ENUM_PARAMS(ARG_COUNT, Arg)> proto_args;
|
Chris@16
|
99 #endif
|
Chris@16
|
100 typedef basic_expr proto_grammar;
|
Chris@16
|
101 typedef basic_default_domain proto_domain;
|
Chris@16
|
102 typedef default_generator proto_generator;
|
Chris@16
|
103 typedef proto::tag::proto_expr<Tag, proto_domain> fusion_tag;
|
Chris@16
|
104 typedef basic_expr proto_derived_expr;
|
Chris@16
|
105 typedef void proto_is_expr_; /**< INTERNAL ONLY */
|
Chris@16
|
106
|
Chris@16
|
107 BOOST_PP_REPEAT(ARG_COUNT, BOOST_PROTO_CHILD, ~)
|
Chris@16
|
108 BOOST_PP_REPEAT_FROM_TO(ARG_COUNT, BOOST_PROTO_MAX_ARITY, BOOST_PROTO_VOID, ~)
|
Chris@16
|
109
|
Chris@16
|
110 /// \return *this
|
Chris@16
|
111 ///
|
Chris@16
|
112 BOOST_FORCEINLINE
|
Chris@16
|
113 basic_expr const &proto_base() const
|
Chris@16
|
114 {
|
Chris@16
|
115 return *this;
|
Chris@16
|
116 }
|
Chris@16
|
117
|
Chris@16
|
118 /// \overload
|
Chris@16
|
119 ///
|
Chris@16
|
120 BOOST_FORCEINLINE
|
Chris@16
|
121 basic_expr &proto_base()
|
Chris@16
|
122 {
|
Chris@16
|
123 return *this;
|
Chris@16
|
124 }
|
Chris@16
|
125
|
Chris@16
|
126 #ifdef BOOST_PROTO_DEFINE_TERMINAL
|
Chris@16
|
127 /// \return A new \c expr\<\> object initialized with the specified
|
Chris@16
|
128 /// arguments.
|
Chris@16
|
129 ///
|
Chris@16
|
130 template<typename A0>
|
Chris@16
|
131 BOOST_FORCEINLINE
|
Chris@16
|
132 static basic_expr const make(A0 &a0)
|
Chris@16
|
133 {
|
Chris@16
|
134 return detail::make_terminal(a0, static_cast<basic_expr *>(0), static_cast<proto_args *>(0));
|
Chris@16
|
135 }
|
Chris@16
|
136
|
Chris@16
|
137 /// \overload
|
Chris@16
|
138 ///
|
Chris@16
|
139 template<typename A0>
|
Chris@16
|
140 BOOST_FORCEINLINE
|
Chris@16
|
141 static basic_expr const make(A0 const &a0)
|
Chris@16
|
142 {
|
Chris@16
|
143 return detail::make_terminal(a0, static_cast<basic_expr *>(0), static_cast<proto_args *>(0));
|
Chris@16
|
144 }
|
Chris@16
|
145 #else
|
Chris@16
|
146 /// \return A new \c expr\<\> object initialized with the specified
|
Chris@16
|
147 /// arguments.
|
Chris@16
|
148 ///
|
Chris@16
|
149 template<BOOST_PP_ENUM_PARAMS(ARG_COUNT, typename A)>
|
Chris@16
|
150 BOOST_FORCEINLINE
|
Chris@16
|
151 static basic_expr const make(BOOST_PP_ENUM_BINARY_PARAMS(ARG_COUNT, A, const &a))
|
Chris@16
|
152 {
|
Chris@16
|
153 basic_expr that = {BOOST_PP_ENUM_PARAMS(ARG_COUNT, a)};
|
Chris@16
|
154 return that;
|
Chris@16
|
155 }
|
Chris@16
|
156 #endif
|
Chris@16
|
157
|
Chris@16
|
158 #if 1 == BOOST_PP_ITERATION()
|
Chris@16
|
159 /// If \c Tag is \c boost::proto::tag::address_of and \c proto_child0 is
|
Chris@16
|
160 /// <tt>T&</tt>, then \c address_of_hack_type_ is <tt>T*</tt>.
|
Chris@16
|
161 /// Otherwise, it is some undefined type.
|
Chris@16
|
162 typedef typename detail::address_of_hack<Tag, proto_child0>::type address_of_hack_type_;
|
Chris@16
|
163
|
Chris@16
|
164 /// \return The address of <tt>this->child0</tt> if \c Tag is
|
Chris@16
|
165 /// \c boost::proto::tag::address_of. Otherwise, this function will
|
Chris@16
|
166 /// fail to compile.
|
Chris@16
|
167 ///
|
Chris@16
|
168 /// \attention Proto overloads <tt>operator&</tt>, which means that
|
Chris@16
|
169 /// proto-ified objects cannot have their addresses taken, unless we use
|
Chris@16
|
170 /// the following hack to make \c &x implicitly convertible to \c X*.
|
Chris@16
|
171 BOOST_FORCEINLINE
|
Chris@16
|
172 operator address_of_hack_type_() const
|
Chris@16
|
173 {
|
Chris@16
|
174 return boost::addressof(this->child0);
|
Chris@16
|
175 }
|
Chris@16
|
176 #else
|
Chris@16
|
177 /// INTERNAL ONLY
|
Chris@16
|
178 ///
|
Chris@16
|
179 typedef detail::not_a_valid_type address_of_hack_type_;
|
Chris@16
|
180 #endif
|
Chris@16
|
181 };
|
Chris@16
|
182
|
Chris@16
|
183 #undef ARG_COUNT
|
Chris@16
|
184
|
Chris@16
|
185 #endif
|