Chris@16
|
1 /*=============================================================================
|
Chris@16
|
2 Copyright (c) 2005-2011 Joel de Guzman
|
Chris@16
|
3 Copyright (c) 2011 Thomas Heller
|
Chris@16
|
4
|
Chris@16
|
5 Distributed under the Boost Software License, Version 1.0. (See accompanying
|
Chris@16
|
6 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
7 ==============================================================================*/
|
Chris@16
|
8 #ifndef BOOST_PHOENIX_SCOPE_THIS_HPP
|
Chris@16
|
9 #define BOOST_PHOENIX_SCOPE_THIS_HPP
|
Chris@16
|
10
|
Chris@16
|
11 #include <boost/phoenix/core/limits.hpp>
|
Chris@16
|
12 #include <boost/phoenix/core/actor.hpp>
|
Chris@16
|
13 #include <boost/phoenix/core/environment.hpp>
|
Chris@16
|
14 #include <boost/phoenix/core/expression.hpp>
|
Chris@16
|
15 #include <boost/phoenix/core/meta_grammar.hpp>
|
Chris@16
|
16 #include <boost/phoenix/core/terminal.hpp>
|
Chris@16
|
17 #include <boost/phoenix/scope/lambda.hpp>
|
Chris@16
|
18 #include <boost/type_traits/remove_pointer.hpp>
|
Chris@16
|
19
|
Chris@16
|
20 BOOST_PHOENIX_DEFINE_EXPRESSION_VARARG(
|
Chris@16
|
21 (boost)(phoenix)(this_)
|
Chris@16
|
22 , (meta_grammar)(meta_grammar)
|
Chris@16
|
23 , BOOST_PHOENIX_LIMIT
|
Chris@16
|
24 )
|
Chris@16
|
25
|
Chris@16
|
26 namespace boost { namespace phoenix {
|
Chris@16
|
27 namespace detail
|
Chris@16
|
28 {
|
Chris@16
|
29 /*
|
Chris@16
|
30 struct infinite_recursion_detected {};
|
Chris@16
|
31
|
Chris@16
|
32 struct last_non_this_actor
|
Chris@16
|
33 : proto::or_<
|
Chris@16
|
34 proto::when<
|
Chris@16
|
35 proto::nary_expr<
|
Chris@16
|
36 proto::_
|
Chris@16
|
37 , proto::_
|
Chris@16
|
38 , proto::_
|
Chris@16
|
39 >
|
Chris@16
|
40 , proto::_child_c<1>
|
Chris@16
|
41 >
|
Chris@16
|
42 , proto::when<
|
Chris@16
|
43 proto::nary_expr<
|
Chris@16
|
44 proto::_
|
Chris@16
|
45 , proto::_
|
Chris@16
|
46 , proto::_
|
Chris@16
|
47 , proto::_
|
Chris@16
|
48 >
|
Chris@16
|
49 , proto::_child_c<2>
|
Chris@16
|
50 >
|
Chris@16
|
51 >
|
Chris@16
|
52 {};
|
Chris@16
|
53 */
|
Chris@16
|
54 }
|
Chris@16
|
55 struct this_eval
|
Chris@16
|
56 {
|
Chris@16
|
57 BOOST_PROTO_CALLABLE()
|
Chris@16
|
58
|
Chris@16
|
59 template <typename Sig>
|
Chris@16
|
60 struct result;
|
Chris@16
|
61
|
Chris@16
|
62 template <typename This, typename A0, typename Context>
|
Chris@16
|
63 struct result<This(A0, Context)>
|
Chris@16
|
64 {
|
Chris@101
|
65 typedef
|
Chris@101
|
66 typename proto::detail::uncvref<
|
Chris@101
|
67 typename result_of::env<
|
Chris@101
|
68 Context
|
Chris@101
|
69 >::type
|
Chris@101
|
70 >::type
|
Chris@101
|
71 outer_env_type;
|
Chris@16
|
72
|
Chris@101
|
73 typedef
|
Chris@101
|
74 typename remove_pointer<
|
Chris@101
|
75 typename remove_reference<
|
Chris@101
|
76 typename fusion::result_of::at_c<
|
Chris@101
|
77 outer_env_type
|
Chris@101
|
78 , 0
|
Chris@101
|
79 >::type
|
Chris@101
|
80 >::type
|
Chris@101
|
81 >::type
|
Chris@101
|
82 actor_type;
|
Chris@16
|
83
|
Chris@101
|
84 typedef
|
Chris@101
|
85 typename result_of::eval<
|
Chris@101
|
86 A0 const &
|
Chris@101
|
87 , Context const &
|
Chris@101
|
88 >::type
|
Chris@101
|
89 a0_type;
|
Chris@101
|
90
|
Chris@101
|
91 typedef
|
Chris@101
|
92 vector2<actor_type const *, a0_type>
|
Chris@101
|
93 inner_env_type;
|
Chris@101
|
94
|
Chris@101
|
95 typedef
|
Chris@101
|
96 scoped_environment<
|
Chris@101
|
97 inner_env_type
|
Chris@101
|
98 , outer_env_type
|
Chris@101
|
99 , vector0<>
|
Chris@101
|
100 , detail::map_local_index_to_tuple<>
|
Chris@101
|
101 >
|
Chris@101
|
102 env_type;
|
Chris@101
|
103
|
Chris@101
|
104 typedef
|
Chris@101
|
105 typename result_of::eval<
|
Chris@101
|
106 actor_type const &
|
Chris@101
|
107 , typename result_of::context<
|
Chris@101
|
108 inner_env_type
|
Chris@101
|
109 , typename result_of::actions<
|
Chris@101
|
110 Context
|
Chris@101
|
111 >::type
|
Chris@101
|
112 >::type
|
Chris@101
|
113 >::type
|
Chris@101
|
114 type;
|
Chris@16
|
115 };
|
Chris@16
|
116
|
Chris@16
|
117 template <typename A0, typename Context>
|
Chris@16
|
118 typename result<this_eval(A0 const&, Context const &)>::type
|
Chris@16
|
119 operator()(A0 const & a0, Context const & ctx) const
|
Chris@16
|
120 {
|
Chris@16
|
121
|
Chris@16
|
122 //std::cout << typeid(checker).name() << "\n";
|
Chris@16
|
123 //std::cout << typeid(checker).name() << "\n";
|
Chris@101
|
124 typedef
|
Chris@101
|
125 typename proto::detail::uncvref<
|
Chris@101
|
126 typename result_of::env<
|
Chris@101
|
127 Context
|
Chris@101
|
128 >::type
|
Chris@101
|
129 >::type
|
Chris@101
|
130 outer_env_type;
|
Chris@16
|
131
|
Chris@101
|
132 typedef
|
Chris@101
|
133 typename remove_pointer<
|
Chris@101
|
134 typename remove_reference<
|
Chris@101
|
135 typename fusion::result_of::at_c<
|
Chris@101
|
136 outer_env_type
|
Chris@101
|
137 , 0
|
Chris@101
|
138 >::type
|
Chris@101
|
139 >::type
|
Chris@101
|
140 >::type
|
Chris@101
|
141 actor_type;
|
Chris@16
|
142
|
Chris@101
|
143 typedef
|
Chris@101
|
144 typename result_of::eval<
|
Chris@101
|
145 A0 const &
|
Chris@101
|
146 , Context const &
|
Chris@101
|
147 >::type
|
Chris@101
|
148 a0_type;
|
Chris@16
|
149
|
Chris@101
|
150 typedef
|
Chris@101
|
151 vector2<actor_type const *, a0_type>
|
Chris@101
|
152 inner_env_type;
|
Chris@16
|
153
|
Chris@101
|
154 typedef
|
Chris@101
|
155 scoped_environment<
|
Chris@101
|
156 inner_env_type
|
Chris@101
|
157 , outer_env_type
|
Chris@101
|
158 , vector0<>
|
Chris@101
|
159 , detail::map_local_index_to_tuple<>
|
Chris@101
|
160 >
|
Chris@101
|
161 env_type;
|
Chris@101
|
162
|
Chris@101
|
163 inner_env_type inner_env = {fusion::at_c<0>(phoenix::env(ctx)), phoenix::eval(a0, ctx)};
|
Chris@101
|
164 vector0<> locals;
|
Chris@101
|
165 env_type env(inner_env, phoenix::env(ctx), locals);
|
Chris@101
|
166
|
Chris@101
|
167 return phoenix::eval(*fusion::at_c<0>(phoenix::env(ctx)), phoenix::context(inner_env, phoenix::actions(ctx)));
|
Chris@16
|
168 //return (*fusion::at_c<0>(phoenix::env(ctx)))(eval(a0, ctx));
|
Chris@16
|
169 }
|
Chris@16
|
170 };
|
Chris@16
|
171
|
Chris@16
|
172 template <typename Dummy>
|
Chris@16
|
173 struct default_actions::when<rule::this_, Dummy>
|
Chris@16
|
174 : call<this_eval>
|
Chris@16
|
175 {};
|
Chris@16
|
176
|
Chris@101
|
177 template <typename Dummy>
|
Chris@16
|
178 struct is_nullary::when<rule::this_, Dummy>
|
Chris@16
|
179 : proto::make<mpl::false_()>
|
Chris@16
|
180 {};
|
Chris@16
|
181
|
Chris@101
|
182 template <typename A0>
|
Chris@101
|
183 typename expression::this_<A0>::type const
|
Chris@101
|
184 this_(A0 const & a0)
|
Chris@101
|
185 {
|
Chris@101
|
186 return expression::this_<A0>::make(a0);
|
Chris@101
|
187 }
|
Chris@16
|
188
|
Chris@16
|
189 }}
|
Chris@16
|
190
|
Chris@16
|
191 #endif
|