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@101: Copyright (c) 2015 John Fletcher 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: #ifndef BOOST_PHOENIX_SCOPE_LET_HPP Chris@16: #define BOOST_PHOENIX_SCOPE_LET_HPP Chris@16: Chris@101: //#include Chris@101: //#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: #include Chris@16: #include Chris@16: Chris@16: BOOST_PHOENIX_DEFINE_EXPRESSION( Chris@16: (boost)(phoenix)(let_) Chris@16: , (proto::terminal) // Locals Chris@16: (proto::terminal) // Map Chris@16: (meta_grammar) Chris@16: ) Chris@16: Chris@16: namespace boost { namespace phoenix Chris@16: { Chris@16: struct let_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: typedef Chris@16: typename proto::detail::uncvref< Chris@16: typename proto::result_of::value::type Chris@16: >::type Chris@16: map_type; Chris@101: Chris@101: typedef Chris@101: typename proto::detail::uncvref::type Chris@101: expr_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 typename Chris@16: result_of::eval< Chris@101: expr_type Chris@16: , typename result_of::context< Chris@16: scoped_environment< Chris@16: env_type Chris@16: , env_type Chris@16: , locals_type Chris@16: , map_type Chris@16: > Chris@16: , actions_type Chris@16: >::type Chris@16: >::type Chris@16: type; Chris@16: }; Chris@16: Chris@16: template Chris@16: typename result::type const Chris@16: operator()(Vars const & vars, Map, Expr const & expr, Context const & ctx) const Chris@16: { Chris@101: Vars vars_(vars); Chris@101: 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 proto::result_of::value::type Chris@16: >::type Chris@16: vars_type; Chris@16: typedef Chris@16: typename proto::detail::uncvref< Chris@16: typename proto::result_of::value::type Chris@16: >::type Chris@16: map_type; Chris@16: Chris@16: 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@101: locals_type locals = initialize_locals(proto::value(vars_), ctx); Chris@101: Chris@101: typedef typename result::type result_type; Chris@16: Chris@16: scoped_environment< Chris@16: env_type Chris@16: , env_type Chris@16: , locals_type Chris@16: , map_type Chris@16: > Chris@16: env(phoenix::env(ctx), phoenix::env(ctx), locals); Chris@16: Chris@101: // Fix for bugs (trial) Chris@101: // The idea is to do something which will not be optimised away. Chris@101: //int vsize = boost::fusion::size(vars); Chris@101: //std::stringstream strm; Chris@101: //strm << vsize << std::endl; Chris@101: //int size = strm.str().length(); Chris@101: //BOOST_ASSERT(size >= 0); Chris@101: result_type r = eval(expr, phoenix::context(env, phoenix::actions(ctx))); Chris@101: // typedef is_value is_val; Chris@101: //if(is_val::value) This seems always to be true Chris@101: //{ Chris@101: // std::cout << "let result has value type" << std::endl; Chris@101: // } Chris@101: //if (is_val(r) ) std::cout << "let returns val" << std::endl; Chris@101: //std::cout << "result is " << r << std::endl; Chris@101: return r; 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 let_actor_gen Chris@16: { Chris@101: let_actor_gen(Locals const & locals_) Chris@101: : locals(locals_) Chris@16: {} Chris@16: Chris@16: let_actor_gen(let_actor_gen const & o) Chris@16: : locals(o.locals) Chris@16: {} Chris@16: Chris@16: template Chris@16: typename expression::let_< Chris@16: Locals Chris@16: , Map Chris@16: , Expr Chris@16: >::type const Chris@16: operator[](Expr const & expr) const Chris@16: { Chris@101: typedef typename expression::let_< Chris@101: Locals Chris@101: , Map Chris@101: , Expr Chris@101: >::type let_type; Chris@101: //typedef is_value is_val; Chris@101: Chris@101: let_type let_exp = expression::let_::make(locals, Map(), expr); Chris@101: //if(is_val::value) //This seems always to be true Chris@101: //{ Chris@101: // std::cout << "let has value type" << std::endl; Chris@101: //} Chris@101: return let_exp; Chris@16: } Chris@16: Chris@16: Locals locals; Chris@16: }; Chris@16: Chris@16: #define BOOST_PHOENIX_SCOPE_ACTOR_GEN_NAME let_actor_gen Chris@16: #define BOOST_PHOENIX_SCOPE_ACTOR_GEN_FUNCTION let Chris@16: #define BOOST_PHOENIX_SCOPE_ACTOR_GEN_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: template Chris@16: struct is_nullary::when Chris@16: : proto::make< Chris@16: mpl::and_< 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: , evaluator( Chris@16: proto::_child_c<2> 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: }} Chris@16: Chris@16: #endif