1 /*==============================================================================
2 Copyright (c) 2001-2010 Joel de Guzman
3 Copyright (c) 2004 Daniel Wallin
4 Copyright (c) 2010 Thomas Heller
5 Copyright (c) 2015 John Fletcher
7 Distributed under the Boost Software License, Version 1.0. (See accompanying
8 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9 ==============================================================================*/
10 #ifndef BOOST_PHOENIX_SCOPE_LET_HPP
11 #define BOOST_PHOENIX_SCOPE_LET_HPP
13 //#include <boost/assert.hpp>
15 #include <boost/phoenix/core/limits.hpp>
16 #include <boost/fusion/include/transform.hpp>
17 #include <boost/fusion/include/as_vector.hpp>
18 #include <boost/phoenix/core/call.hpp>
19 #include <boost/phoenix/core/expression.hpp>
20 #include <boost/phoenix/core/meta_grammar.hpp>
21 #include <boost/phoenix/scope/scoped_environment.hpp>
22 #include <boost/phoenix/scope/local_variable.hpp>
23 #include <boost/phoenix/support/iterate.hpp>
24 #include <boost/phoenix/support/vector.hpp>
26 BOOST_PHOENIX_DEFINE_EXPRESSION(
27 (boost)(phoenix)(let_)
28 , (proto::terminal<proto::_>) // Locals
29 (proto::terminal<proto::_>) // Map
33 namespace boost { namespace phoenix
37 template <typename Sig>
40 template <typename This, typename Vars, typename Map, typename Expr, typename Context>
41 struct result<This(Vars, Map, Expr, Context)>
44 typename proto::detail::uncvref<
45 typename result_of::env<Context>::type
49 typename proto::detail::uncvref<
50 typename result_of::actions<Context>::type
54 typename proto::detail::uncvref<
55 typename proto::result_of::value<Vars>::type
59 typename proto::detail::uncvref<
60 typename proto::result_of::value<Map>::type
65 typename proto::detail::uncvref<Expr>::type
69 detail::result_of::initialize_locals<
78 , typename result_of::context<
91 template <typename Vars, typename Map, typename Expr, typename Context>
92 typename result<let_eval(Vars const&, Map const&, Expr const &, Context const &)>::type const
93 operator()(Vars const & vars, Map, Expr const & expr, Context const & ctx) const
98 typename proto::detail::uncvref<
99 typename result_of::env<Context>::type
103 typename proto::detail::uncvref<
104 typename proto::result_of::value<Vars>::type
108 typename proto::detail::uncvref<
109 typename proto::result_of::value<Map>::type
114 detail::result_of::initialize_locals<
120 locals_type locals = initialize_locals(proto::value(vars_), ctx);
122 //typedef typename result<let_eval(Vars const&, Map const&, Expr const &, Context const &)>::type result_type;
130 env(phoenix::env(ctx), phoenix::env(ctx), locals);
132 // Fix for bugs (trial)
133 // The idea is to do something which will not be optimised away.
134 //int vsize = boost::fusion::size(vars);
135 //std::stringstream strm;
136 //strm << vsize << std::endl;
137 //int size = strm.str().length();
138 //BOOST_ASSERT(size >= 0);
139 return eval(expr, phoenix::context(env, phoenix::actions(ctx)));
140 // typedef is_value<result_type> is_val;
141 //if(is_val::value) This seems always to be true
143 // std::cout << "let result has value type" << std::endl;
145 //if (is_val(r) ) std::cout << "let returns val" << std::endl;
146 //std::cout << "result is " << r << std::endl;
151 template <typename Dummy>
152 struct default_actions::when<rule::let_, Dummy>
153 : call<let_eval, Dummy>
156 template <typename Locals, typename Map>
159 let_actor_gen(Locals const & locals_)
163 let_actor_gen(let_actor_gen const & o)
167 template <typename Expr>
168 typename expression::let_<
173 operator[](Expr const & expr) const
175 typedef typename expression::let_<
180 //typedef is_value<let_type> is_val;
182 let_type let_exp = expression::let_<Locals, Map, Expr>::make(locals, Map(), expr);
183 //if(is_val::value) //This seems always to be true
185 // std::cout << "let has value type" << std::endl;
193 #define BOOST_PHOENIX_SCOPE_ACTOR_GEN_NAME let_actor_gen
194 #define BOOST_PHOENIX_SCOPE_ACTOR_GEN_FUNCTION let
195 #define BOOST_PHOENIX_SCOPE_ACTOR_GEN_CONST
196 #if defined(BOOST_PHOENIX_NO_VARIADIC_SCOPE)
197 #include <boost/phoenix/scope/detail/cpp03/local_gen.hpp>
199 #include <boost/phoenix/scope/detail/local_gen.hpp>
201 #undef BOOST_PHOENIX_SCOPE_ACTOR_GEN_NAME
202 #undef BOOST_PHOENIX_SCOPE_ACTOR_GEN_FUNCTION
203 #undef BOOST_PHOENIX_SCOPE_ACTOR_GEN_CONST
205 template <typename Dummy>
206 struct is_nullary::when<rule::let_, Dummy>
210 proto::call<proto::_value(proto::_child_c<0>)>
211 , proto::make<mpl::true_()>
219 , proto::make<proto::empty_env()>
233 detail::scope_is_nullary_actions()