File indexing completed on 2025-01-18 09:46:33
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_PHOENIX_SCOPE_LAMBDA_HPP
0012 #define BOOST_PHOENIX_SCOPE_LAMBDA_HPP
0013
0014 #include <boost/phoenix/core/limits.hpp>
0015 #include <boost/fusion/include/transform.hpp>
0016 #include <boost/fusion/include/as_vector.hpp>
0017 #include <boost/mpl/int.hpp>
0018 #include <boost/phoenix/core/call.hpp>
0019 #include <boost/phoenix/core/expression.hpp>
0020 #include <boost/phoenix/core/meta_grammar.hpp>
0021 #include <boost/phoenix/scope/local_variable.hpp>
0022 #include <boost/phoenix/scope/scoped_environment.hpp>
0023
0024 BOOST_PHOENIX_DEFINE_EXPRESSION(
0025 (boost)(phoenix)(lambda_actor)
0026 , (proto::terminal<proto::_>)
0027 (proto::terminal<proto::_>)
0028 (meta_grammar)
0029 )
0030
0031 BOOST_PHOENIX_DEFINE_EXPRESSION(
0032 (boost)(phoenix)(lambda)
0033 , (proto::terminal<proto::_>)
0034 (proto::terminal<proto::_>)
0035 (proto::terminal<proto::_>)
0036 (meta_grammar)
0037 )
0038
0039 namespace boost { namespace phoenix
0040 {
0041 struct lambda_eval
0042 {
0043 BOOST_PROTO_CALLABLE()
0044
0045 template <typename Sig>
0046 struct result;
0047
0048 template <
0049 typename This
0050 , typename OuterEnv
0051 , typename Locals
0052 , typename Map
0053 , typename Lambda
0054 , typename Context
0055 >
0056 struct result<This(OuterEnv, Locals, Map, Lambda, Context)>
0057 {
0058 typedef
0059 typename proto::detail::uncvref<
0060 typename proto::result_of::value<
0061 OuterEnv
0062 >::type
0063 >::type
0064 outer_env_type;
0065
0066 typedef
0067 typename proto::detail::uncvref<
0068 typename proto::result_of::value<
0069 Locals
0070 >::type
0071 >::type
0072 locals_type;
0073
0074 typedef
0075 typename proto::detail::uncvref<
0076 typename proto::result_of::value<
0077 Map
0078 >::type
0079 >::type
0080 map_type;
0081
0082 typedef
0083 typename proto::detail::uncvref<
0084 typename result_of::env<Context>::type
0085 >::type
0086 env_type;
0087
0088 typedef
0089 typename result_of::eval<
0090 Lambda
0091 , typename result_of::context<
0092 scoped_environment<
0093 env_type
0094 , outer_env_type
0095 , locals_type
0096 , map_type
0097 >
0098 , typename result_of::actions<
0099 Context
0100 >::type
0101 >::type
0102 >::type
0103 type;
0104 };
0105
0106 template <typename OuterEnv, typename Locals, typename Map, typename Lambda, typename Context>
0107 typename result<lambda_eval(OuterEnv const &, Locals const &, Map const &, Lambda const &, Context const &)>::type
0108 operator()(OuterEnv const & outer_env, Locals const & locals, Map const &, Lambda const & lambda, Context const & ctx) const
0109 {
0110 typedef
0111 typename proto::detail::uncvref<
0112 typename proto::result_of::value<
0113 OuterEnv
0114 >::type
0115 >::type
0116 outer_env_type;
0117
0118 typedef
0119 typename proto::detail::uncvref<
0120 typename proto::result_of::value<
0121 Locals
0122 >::type
0123 >::type
0124 locals_type;
0125
0126 typedef
0127 typename proto::detail::uncvref<
0128 typename proto::result_of::value<
0129 Map
0130 >::type
0131 >::type
0132 map_type;
0133
0134 typedef
0135 typename proto::detail::uncvref<
0136 typename result_of::env<Context>::type
0137 >::type
0138 env_type;
0139
0140 scoped_environment<
0141 env_type
0142 , outer_env_type
0143 , locals_type
0144 , map_type
0145 >
0146 env(phoenix::env(ctx), proto::value(outer_env), proto::value(locals));
0147
0148 return eval(lambda, phoenix::context(env, phoenix::actions(ctx)));
0149 }
0150 };
0151
0152 template <typename Dummy>
0153 struct default_actions::when<rule::lambda, Dummy>
0154 : call<lambda_eval, Dummy>
0155 {};
0156
0157 template <typename Dummy>
0158 struct is_nullary::when<rule::lambda, Dummy>
0159 : proto::call<
0160 evaluator(
0161 proto::_child_c<3>
0162 , proto::call<
0163 functional::context(
0164 proto::make<
0165 mpl::true_()
0166 >
0167 , proto::make<
0168 detail::scope_is_nullary_actions()
0169 >
0170 )
0171 >
0172 , proto::make<
0173 proto::empty_env()
0174 >
0175 )
0176 >
0177 {};
0178
0179 template <typename Dummy>
0180 struct is_nullary::when<rule::lambda_actor, Dummy>
0181 : proto::or_<
0182 proto::when<
0183 expression::lambda_actor<
0184 proto::terminal<vector0<> >
0185 , proto::terminal<proto::_>
0186 , meta_grammar
0187 >
0188 , mpl::true_()
0189 >
0190 , proto::when<
0191 expression::lambda_actor<
0192 proto::terminal<proto::_>
0193 , proto::terminal<proto::_>
0194 , meta_grammar
0195 >
0196 , proto::fold<
0197 proto::call<proto::_value(proto::_child_c<0>)>
0198 , proto::make<mpl::true_()>
0199 , proto::make<
0200 mpl::and_<
0201 proto::_state
0202 , proto::call<
0203 evaluator(
0204 proto::_
0205 , _context
0206 , proto::make<proto::empty_env()>
0207 )
0208 >
0209 >()
0210 >
0211 >
0212 >
0213 >
0214 {};
0215
0216 struct lambda_actor_eval
0217 {
0218 template <typename Sig>
0219 struct result;
0220
0221 template <typename This, typename Vars, typename Map, typename Lambda, typename Context>
0222 struct result<This(Vars, Map, Lambda, Context)>
0223 {
0224 typedef
0225 typename proto::detail::uncvref<
0226 typename result_of::env<Context>::type
0227 >::type
0228 env_type;
0229 typedef
0230 typename proto::detail::uncvref<
0231 typename result_of::actions<Context>::type
0232 >::type
0233 actions_type;
0234 typedef
0235 typename proto::detail::uncvref<
0236 typename proto::result_of::value<Vars>::type
0237 >::type
0238 vars_type;
0239
0240 typedef typename
0241 detail::result_of::initialize_locals<
0242 vars_type
0243 , Context
0244 >::type
0245 locals_type;
0246
0247 typedef
0248 typename expression::lambda<
0249 env_type
0250 , locals_type
0251 , Map
0252 , Lambda
0253 >::type const
0254 type;
0255 };
0256
0257 template <
0258 typename Vars
0259 , typename Map
0260 , typename Lambda
0261 , typename Context
0262 >
0263 typename result<
0264 lambda_actor_eval(Vars const&, Map const &, Lambda const&, Context const &)
0265 >::type const
0266 operator()(Vars const& vars, Map const& map, Lambda const& lambda, Context const & ctx) const
0267 {
0268 typedef
0269 typename proto::detail::uncvref<
0270 typename result_of::env<Context>::type
0271 >::type
0272 env_type;
0273
0274
0275
0276
0277
0278 typedef
0279 typename proto::detail::uncvref<
0280 typename proto::result_of::value<Vars>::type
0281 >::type
0282 vars_type;
0283
0284
0285
0286
0287
0288
0289 typedef typename
0290 detail::result_of::initialize_locals<
0291 vars_type
0292 , Context
0293 >::type
0294 locals_type;
0295
0296 locals_type locals = initialize_locals(proto::value(vars), ctx);
0297
0298 return
0299 expression::
0300 lambda<env_type, locals_type, Map, Lambda>::
0301 make(phoenix::env(ctx), locals, map, lambda);
0302 }
0303 };
0304
0305 template <typename Dummy>
0306 struct default_actions::when<rule::lambda_actor, Dummy>
0307 : call<lambda_actor_eval, Dummy>
0308 {};
0309
0310 template <typename Locals = vector0<>,
0311 typename Map = detail::map_local_index_to_tuple<>,
0312 typename Dummy = void>
0313 struct lambda_actor_gen;
0314
0315 template <>
0316 struct lambda_actor_gen<vector0<>, detail::map_local_index_to_tuple<>, void>
0317 {
0318 template <typename Expr>
0319 typename expression::lambda_actor<vector0<>, detail::map_local_index_to_tuple<>, Expr>::type const
0320 operator[](Expr const & expr) const
0321 {
0322 typedef vector0<> locals_type;
0323 typedef detail::map_local_index_to_tuple<> map_type;
0324 return expression::lambda_actor<locals_type, map_type, Expr>::make(locals_type(), map_type(), expr);
0325 }
0326 };
0327
0328 template <typename Locals, typename Map>
0329 struct lambda_actor_gen<Locals, Map>
0330 {
0331 lambda_actor_gen(Locals const & locals_)
0332 : locals(locals_)
0333 {}
0334
0335 lambda_actor_gen(lambda_actor_gen const & o)
0336 : locals(o.locals)
0337 {};
0338
0339 template <typename Expr>
0340 typename expression::lambda_actor<
0341 Locals
0342 , Map
0343 , Expr
0344 >::type const
0345 operator[](Expr const & expr) const
0346 {
0347 return expression::lambda_actor<Locals, Map, Expr>::make(locals, Map(), expr);
0348 }
0349
0350 Locals locals;
0351 };
0352
0353 struct lambda_local_gen
0354 : lambda_actor_gen<>
0355 {
0356 #if defined(BOOST_PHOENIX_NO_VARIADIC_SCOPE)
0357 lambda_actor_gen<> const
0358 operator()() const
0359 {
0360 return lambda_actor_gen<>();
0361 }
0362
0363 #include <boost/phoenix/scope/detail/cpp03/lambda.hpp>
0364 #else
0365 #define BOOST_PHOENIX_SCOPE_ACTOR_GEN_NAME lambda_actor_gen
0366 #define BOOST_PHOENIX_SCOPE_ACTOR_GEN_FUNCTION operator()
0367 #define BOOST_PHOENIX_SCOPE_ACTOR_GEN_CONST const
0368 #include <boost/phoenix/scope/detail/local_gen.hpp>
0369 #undef BOOST_PHOENIX_SCOPE_ACTOR_GEN_NAME
0370 #undef BOOST_PHOENIX_SCOPE_ACTOR_GEN_FUNCTION
0371 #undef BOOST_PHOENIX_SCOPE_ACTOR_GEN_CONST
0372 #endif
0373 };
0374
0375 typedef lambda_local_gen lambda_type;
0376 lambda_local_gen const lambda = lambda_local_gen();
0377
0378 }}
0379
0380 #endif