Chris@16: #ifndef BOOST_PHOENIX_SCOPE_LAMBDA_HPP Chris@16: #define BOOST_PHOENIX_SCOPE_LAMBDA_HPP Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: #if !defined(BOOST_PHOENIX_DONT_USE_PREPROCESSED_FILES) Chris@16: Chris@16: #include Chris@16: Chris@16: #else Chris@16: Chris@16: #if defined(__WAVE__) && defined(BOOST_PHOENIX_CREATE_PREPROCESSED_FILES) Chris@16: #pragma wave option(preserve: 2, line: 0, output: "preprocessed/lambda_" BOOST_PHOENIX_LIMIT_STR ".hpp") Chris@16: #endif Chris@16: /*============================================================================== Chris@16: Copyright (c) 2001-2010 Joel de Guzman Chris@16: Copyright (c) 2004 Daniel Wallin Chris@16: Copyright (c) 2010 Thomas Heller Chris@16: Chris@16: Distributed under the Boost Software License, Version 1.0. (See accompanying Chris@16: file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) Chris@16: ==============================================================================*/ Chris@16: #if defined(__WAVE__) && defined(BOOST_PHOENIX_CREATE_PREPROCESSED_FILES) Chris@16: #pragma wave option(preserve: 1) Chris@16: #endif Chris@16: Chris@16: BOOST_PHOENIX_DEFINE_EXPRESSION( Chris@16: (boost)(phoenix)(lambda_actor) Chris@16: , (proto::terminal) // Locals Chris@16: (proto::terminal) // Map Chris@16: (meta_grammar) // Lambda Chris@16: ) Chris@16: Chris@16: BOOST_PHOENIX_DEFINE_EXPRESSION( Chris@16: (boost)(phoenix)(lambda) Chris@16: , (proto::terminal) // OuterEnv Chris@16: (proto::terminal) // Locals Chris@16: (proto::terminal) // Map Chris@16: (meta_grammar) // Lambda Chris@16: ) Chris@16: Chris@16: namespace boost { namespace phoenix Chris@16: { Chris@16: struct lambda_eval Chris@16: { Chris@16: BOOST_PROTO_CALLABLE() Chris@16: Chris@16: template Chris@16: struct result; Chris@16: Chris@16: template < Chris@16: typename This Chris@16: , typename OuterEnv Chris@16: , typename Locals Chris@16: , typename Map Chris@16: , typename Lambda Chris@16: , typename Context Chris@16: > Chris@16: struct result Chris@16: { Chris@16: typedef Chris@16: typename proto::detail::uncvref< Chris@16: typename proto::result_of::value< Chris@16: OuterEnv Chris@16: >::type Chris@16: >::type Chris@16: outer_env_type; Chris@16: Chris@16: typedef Chris@16: typename proto::detail::uncvref< Chris@16: typename proto::result_of::value< Chris@16: Locals Chris@16: >::type Chris@16: >::type Chris@16: locals_type; Chris@16: Chris@16: typedef Chris@16: typename proto::detail::uncvref< Chris@16: typename proto::result_of::value< Chris@16: Map Chris@16: >::type Chris@16: >::type Chris@16: map_type; Chris@16: Chris@16: typedef Chris@16: typename proto::detail::uncvref< Chris@16: typename result_of::env::type Chris@16: >::type Chris@16: env_type; Chris@16: Chris@101: typedef Chris@101: typename result_of::eval< Chris@101: Lambda Chris@101: , typename result_of::context< Chris@101: scoped_environment< Chris@101: env_type Chris@101: , outer_env_type Chris@101: , locals_type Chris@101: , map_type Chris@101: > Chris@101: , typename result_of::actions< Chris@101: Context Chris@101: >::type Chris@101: >::type Chris@101: >::type Chris@101: type; Chris@16: }; Chris@16: Chris@16: template Chris@16: typename result::type Chris@16: operator()(OuterEnv const & outer_env, Locals const & locals, Map const &, Lambda const & lambda, Context const & ctx) const Chris@16: { Chris@16: typedef Chris@16: typename proto::detail::uncvref< Chris@16: typename proto::result_of::value< Chris@16: OuterEnv Chris@16: >::type Chris@16: >::type Chris@16: outer_env_type; Chris@16: Chris@16: typedef Chris@16: typename proto::detail::uncvref< Chris@16: typename proto::result_of::value< Chris@16: Locals Chris@16: >::type Chris@16: >::type Chris@16: locals_type; Chris@16: Chris@16: typedef Chris@16: typename proto::detail::uncvref< Chris@16: typename proto::result_of::value< Chris@16: Map Chris@16: >::type Chris@16: >::type Chris@16: map_type; Chris@16: Chris@16: typedef Chris@16: typename proto::detail::uncvref< Chris@16: typename result_of::env::type Chris@16: >::type Chris@16: env_type; Chris@16: Chris@101: scoped_environment< Chris@16: env_type Chris@16: , outer_env_type Chris@16: , locals_type Chris@16: , map_type Chris@16: > Chris@16: env(phoenix::env(ctx), proto::value(outer_env), proto::value(locals)); Chris@16: Chris@16: return eval(lambda, phoenix::context(env, phoenix::actions(ctx))); Chris@16: } Chris@16: }; Chris@16: Chris@16: template Chris@16: struct default_actions::when Chris@16: : call Chris@16: {}; Chris@16: Chris@16: template Chris@16: struct is_nullary::when Chris@16: : proto::call< Chris@16: evaluator( Chris@16: proto::_child_c<3> Chris@16: , proto::call< Chris@16: functional::context( Chris@16: proto::make< Chris@16: mpl::true_() Chris@16: > Chris@16: , proto::make< Chris@16: detail::scope_is_nullary_actions() Chris@16: > Chris@16: ) Chris@16: > Chris@16: , proto::make< Chris@16: proto::empty_env() Chris@16: > Chris@16: ) Chris@16: > Chris@16: {}; Chris@16: Chris@16: template Chris@16: struct is_nullary::when Chris@16: : proto::or_< Chris@16: proto::when< Chris@16: expression::lambda_actor< Chris@16: proto::terminal > Chris@16: , proto::terminal Chris@16: , meta_grammar Chris@16: > Chris@16: , mpl::true_() Chris@16: > Chris@16: , proto::when< Chris@16: expression::lambda_actor< Chris@16: proto::terminal Chris@16: , proto::terminal Chris@16: , meta_grammar Chris@16: > Chris@16: , proto::fold< Chris@16: proto::call)> Chris@16: , proto::make Chris@16: , proto::make< Chris@16: mpl::and_< Chris@16: proto::_state Chris@16: , proto::call< Chris@16: evaluator( Chris@16: proto::_ Chris@16: , _context Chris@16: , proto::make Chris@16: ) Chris@16: > Chris@16: >() Chris@16: > Chris@16: > Chris@16: > Chris@16: > Chris@16: {}; Chris@16: Chris@16: struct lambda_actor_eval Chris@16: { Chris@16: template Chris@16: struct result; Chris@16: Chris@16: template Chris@16: struct result Chris@16: { Chris@16: typedef Chris@16: typename proto::detail::uncvref< Chris@16: typename result_of::env::type Chris@16: >::type Chris@16: env_type; Chris@16: typedef Chris@16: typename proto::detail::uncvref< Chris@16: typename result_of::actions::type Chris@16: >::type Chris@16: actions_type; Chris@16: typedef Chris@16: typename proto::detail::uncvref< Chris@16: typename proto::result_of::value::type Chris@16: >::type Chris@16: vars_type; Chris@16: Chris@101: typedef typename Chris@16: detail::result_of::initialize_locals< Chris@16: vars_type Chris@16: , Context Chris@16: >::type Chris@16: locals_type; Chris@16: Chris@16: typedef Chris@16: typename expression::lambda< Chris@16: env_type Chris@16: , locals_type Chris@16: , Map Chris@16: , Lambda Chris@16: >::type const Chris@16: type; Chris@16: }; Chris@16: Chris@16: template < Chris@16: typename Vars Chris@16: , typename Map Chris@16: , typename Lambda Chris@16: , typename Context Chris@16: > Chris@16: typename result< Chris@16: lambda_actor_eval(Vars const&, Map const &, Lambda const&, Context const &) Chris@16: >::type const Chris@16: operator()(Vars const& vars, Map const& map, Lambda const& lambda, Context const & ctx) const Chris@16: { Chris@16: typedef Chris@16: typename proto::detail::uncvref< Chris@16: typename result_of::env::type Chris@16: >::type Chris@16: env_type; Chris@101: /*typedef Chris@16: typename proto::detail::uncvref< Chris@16: typename result_of::actions::type Chris@16: >::type Chris@101: actions_type;*/ Chris@16: typedef Chris@16: typename proto::detail::uncvref< Chris@16: typename proto::result_of::value::type Chris@16: >::type Chris@16: vars_type; Chris@101: /*typedef Chris@16: typename proto::detail::uncvref< Chris@16: typename proto::result_of::value::type Chris@16: >::type Chris@101: map_type;*/ Chris@101: Chris@101: typedef typename Chris@16: detail::result_of::initialize_locals< Chris@16: vars_type Chris@16: , Context Chris@16: >::type Chris@16: locals_type; Chris@16: Chris@16: locals_type locals = initialize_locals(proto::value(vars), ctx); Chris@16: Chris@16: return Chris@16: expression:: Chris@16: lambda:: Chris@16: make(phoenix::env(ctx), locals, map, lambda); Chris@16: } Chris@16: }; Chris@16: Chris@16: template Chris@16: struct default_actions::when Chris@16: : call Chris@16: {}; Chris@16: Chris@16: template Chris@16: struct lambda_actor_gen; Chris@16: Chris@16: template <> Chris@16: struct lambda_actor_gen Chris@16: { Chris@16: template Chris@16: typename expression::lambda_actor, detail::map_local_index_to_tuple<>, Expr>::type const Chris@16: operator[](Expr const & expr) const Chris@16: { Chris@16: typedef vector0<> locals_type; Chris@16: typedef detail::map_local_index_to_tuple<> map_type; Chris@16: return expression::lambda_actor::make(locals_type(), map_type(), expr); Chris@16: } Chris@16: }; Chris@16: Chris@16: template Chris@16: struct lambda_actor_gen Chris@16: { Chris@101: lambda_actor_gen(Locals const & locals_) Chris@101: : locals(locals_) Chris@16: {} Chris@16: Chris@16: lambda_actor_gen(lambda_actor_gen const & o) Chris@16: : locals(o.locals) Chris@16: {}; Chris@16: Chris@16: template Chris@16: typename expression::lambda_actor< Chris@16: Locals Chris@16: , Map Chris@16: , Expr Chris@16: >::type const Chris@16: operator[](Expr const & expr) const Chris@16: { Chris@16: return expression::lambda_actor::make(locals, Map(), expr); Chris@16: } Chris@16: Chris@16: Locals locals; Chris@16: }; Chris@16: Chris@16: struct lambda_local_gen Chris@16: : lambda_actor_gen<> Chris@16: { Chris@16: lambda_actor_gen<> const Chris@16: operator()() const Chris@16: { Chris@16: return lambda_actor_gen<>(); Chris@16: } Chris@16: Chris@16: #define BOOST_PHOENIX_SCOPE_ACTOR_GEN_NAME lambda_actor_gen Chris@16: #define BOOST_PHOENIX_SCOPE_ACTOR_GEN_FUNCTION operator() Chris@16: #define BOOST_PHOENIX_SCOPE_ACTOR_GEN_CONST const Chris@16: #include Chris@16: #undef BOOST_PHOENIX_SCOPE_ACTOR_GEN_NAME Chris@16: #undef BOOST_PHOENIX_SCOPE_ACTOR_GEN_FUNCTION Chris@16: #undef BOOST_PHOENIX_SCOPE_ACTOR_GEN_CONST Chris@16: Chris@16: Chris@16: }; Chris@16: Chris@16: typedef lambda_local_gen lambda_type; Chris@16: lambda_local_gen const lambda = lambda_local_gen(); Chris@16: Chris@16: }} Chris@16: Chris@16: #if defined(__WAVE__) && defined(BOOST_PHOENIX_CREATE_PREPROCESSED_FILES) Chris@16: #pragma wave option(output: null) Chris@16: #endif Chris@16: Chris@16: #endif Chris@16: Chris@16: #endif