2
0
mirror of https://github.com/boostorg/phoenix.git synced 2026-02-15 13:22:14 +00:00

introduced context, contexts contain the environment and the actions

[SVN r68430]
This commit is contained in:
Thomas Heller
2011-01-25 10:54:07 +00:00
parent 316b4e9f8a
commit 05170cf5cf
31 changed files with 146 additions and 100 deletions

View File

@@ -57,7 +57,7 @@ namespace boost { namespace phoenix
, mpl::int_<0>
, mpl::max<
proto::_state
, evaluator(proto::_, _env)
, evaluator(proto::_, _context)
>()
>
{};

View File

@@ -60,43 +60,10 @@ namespace boost { namespace phoenix
BOOST_PHOENIX_GET_ENVIRONMENT(actions, 1)
#undef BOOST_PHOENIX_GET_ENVIRONMENT
struct args_at
{
BOOST_PROTO_CALLABLE()
template <typename Sig>
struct result;
template <typename This, typename N, typename Env>
struct result<This(N, Env)>
: result<This(N, Env const&)>
{};
template <typename This, typename N, typename Env>
struct result<This(N, Env &)>
: fusion::result_of::at<
typename boost::remove_reference<
typename fusion::result_of::at<
Env
, mpl::int_<0>
>::type
>::type
, typename proto::detail::uncvref<N>::type
>
{};
template <typename N, typename Env>
typename result<args_at(N, Env &)>::type
operator()(N const & n, Env& env) const
{
return proto::functional::at()(args()(env), n);
}
};
}
struct _env
: proto::transform<_env>
struct _context
: proto::transform<_context>
{
template <typename Expr, typename State, typename Data>
struct impl
@@ -115,6 +82,90 @@ namespace boost { namespace phoenix
};
};
struct _env
: proto::transform<_env>
{
template <typename Expr, typename State, typename Data>
struct impl
: proto::transform_impl<Expr, State, Data>
{
typedef State result_type;
result_type operator()(
typename impl::expr_param
, typename impl::state_param s
, typename impl::data_param
) const
{
return s;
}
};
};
template <typename Expr, typename State>
struct _env::impl<Expr, State, int>
: proto::transform_impl<Expr, State, int>
{
typedef
typename fusion::result_of::at_c<
typename boost::remove_reference<State>::type
, 0
>::type
result_type;
result_type operator()(
typename impl::expr_param
, typename impl::state_param s
, typename impl::data_param
) const
{
return fusion::at_c<0>(s);
}
};
/*
struct _actions
: proto::transform<_actions>
{
template <typename Expr, typename State, typename Data>
struct impl
: proto::transform_impl<Expr, State, Data>
{
typedef Data result_type;
result_type operator()(
typename impl::expr_param
, typename impl::state_param
, typename impl::data_param d
) const
{
return d;
}
};
};
template <typename Expr, typename State>
struct _actions::impl<Expr, State, int>
: proto::transform_impl<Expr, State, int>
{
typedef
typename fusion::result_of::at_c<
typename boost::remove_reference<State>::type
, 1
>::type
result_type;
result_type operator()(
typename impl::expr_param
, typename impl::state_param s
, typename impl::data_param
) const
{
return fusion::at_c<1>(s);
}
};
*/
template <typename T, typename Enable = void>
struct is_environment : fusion::traits::is_sequence<T> {};
}}

View File

@@ -32,7 +32,7 @@ namespace boost { namespace phoenix
, mpl::true_()
, mpl::and_<
proto::_state
, evaluator(proto::_, _env)
, evaluator(proto::_, _context)
>()
>
{};
@@ -48,7 +48,7 @@ namespace boost { namespace phoenix
: proto::lazy<
result_of::is_nullary<custom_terminal<proto::_value> >(
proto::_
, _env
, _context
)
>
{};

View File

@@ -53,6 +53,8 @@ namespace boost { namespace phoenix
// construct
struct default_actions
{
typedef void is_phoenix_action;
template <typename Rule, typename Dummy = void>
struct when
: proto::_default<meta_grammar>

View File

@@ -45,7 +45,7 @@ namespace boost { namespace phoenix
template <typename Grammar>
struct default_actions::when<rule::custom_terminal, Grammar>
: proto::lazy<custom_terminal<proto::_value>(proto::_value, _env)>
: proto::lazy<custom_terminal<proto::_value>(proto::_value, _context)>
{};
namespace detail
@@ -59,10 +59,9 @@ namespace boost { namespace phoenix
template <typename Grammar>
struct default_actions::when<rule::argument, Grammar>
: proto::call<
functional::args_at(
//mpl::prior<boost::is_placeholder<proto::_value>()>()
detail::placeholder_idx<boost::is_placeholder<proto::_value>()>()
, _env
proto::functional::at(
_env
, detail::placeholder_idx<boost::is_placeholder<proto::_value>()>()
)
>
{};

View File

@@ -26,7 +26,7 @@ namespace boost { namespace phoenix
struct default_actions::when<rule::at_c, Dummy>
: proto::call<
proto::functional::at(
evaluator(proto::_child_c<1>, _env)
evaluator(proto::_child_c<1>, _context)
, proto::_value(proto::_child_c<0>)
)
>

View File

@@ -38,8 +38,8 @@ namespace boost { namespace phoenix
struct default_actions::when<rule::const_cast_, Dummy>
: proto::lazy<
const_cast_eval<
evaluator(proto::_child_c<0>, _env)
>(_env, proto::_child_c<1>)
evaluator(proto::_child_c<0>, _context)
>(_context, proto::_child_c<1>)
>
{};

View File

@@ -48,7 +48,7 @@ namespace boost { namespace phoenix
> \
, proto::lazy< \
construct_eval<proto::_value(proto::_child_c<0>)>( \
_env \
_context \
, BOOST_PP_ENUM_SHIFTED( \
BOOST_PP_INC(N) \
, PHOENIX_CONSTRUCT_CHILD \
@@ -67,7 +67,7 @@ namespace boost { namespace phoenix
, proto::lazy<
construct_eval<
proto::_value(proto::_child_c<0>)
>(_env)
>(_context)
>
>
, BOOST_PP_ENUM_SHIFTED(PHOENIX_COMPOSITE_LIMIT, PHOENIX_CONSTRUCT_CALL, _)

View File

@@ -45,13 +45,13 @@ namespace boost { namespace phoenix
result_type
operator()(Env& env, P const& p) const
{
/*return*/ delete eval(p, env);
delete eval(p, env);
}
};
template <typename Dummy>
struct default_actions::when<rule::delete_, Dummy>
: proto::call<delete_eval(_env, proto::_child_c<0>)>
: proto::call<delete_eval(_context, proto::_child_c<0>)>
{};
template <typename P>

View File

@@ -38,8 +38,8 @@ namespace boost { namespace phoenix
struct default_actions::when<rule::dynamic_cast_, Dummy>
: proto::lazy<
dynamic_cast_eval<
evaluator(proto::_child_c<0>, _env)
>(_env, proto::_child_c<1>)
evaluator(proto::_child_c<0>, _context)
>(_context, proto::_child_c<1>)
>
{};

View File

@@ -49,7 +49,7 @@ namespace boost { namespace phoenix
> \
, proto::lazy< \
new_eval<proto::_value(proto::_child_c<0>)>( \
_env \
_context \
, BOOST_PP_ENUM_SHIFTED( \
BOOST_PP_INC(N) \
, PHOENIX_NEW_CHILD \
@@ -68,7 +68,7 @@ namespace boost { namespace phoenix
, proto::lazy<
new_eval<
proto::_value(proto::_child_c<0>)
>(_env)
>(_context)
>
>
, BOOST_PP_ENUM_SHIFTED(PHOENIX_COMPOSITE_LIMIT, PHOENIX_NEW_CALL, _)

View File

@@ -37,8 +37,8 @@ namespace boost { namespace phoenix
template <typename Dummy>
struct default_actions::when<rule::reinterpret_cast_, Dummy>
: proto::lazy<
reinterpret_cast_eval<evaluator(proto::_child_c<0>, _env)
>(_env, proto::_child_c<1>)>
reinterpret_cast_eval<evaluator(proto::_child_c<0>, _context)
>(_context, proto::_child_c<1>)>
{};
template <typename T, typename U>

View File

@@ -37,8 +37,8 @@ namespace boost { namespace phoenix
template <typename Dummy>
struct default_actions::when<rule::static_cast_, Dummy>
: proto::lazy<
static_cast_eval<evaluator(proto::_child_c<0>, _env)
>(_env, proto::_child_c<1>)>
static_cast_eval<evaluator(proto::_child_c<0>, _context)
>(_context, proto::_child_c<1>)>
{};
template <typename T, typename U>

View File

@@ -115,7 +115,7 @@ namespace boost { namespace phoenix
template <typename Dummy>
struct default_actions::when<rule::mem_fun_ptr, Dummy>
: proto::call<mem_fun_ptr_eval(_env, proto::_)>
: proto::call<mem_fun_ptr_eval(_context, proto::_)>
{};
}}

View File

@@ -452,6 +452,6 @@ namespace boost { namespace phoenix
};
template <typename Dummy>
struct default_actions::when<rule::mem_fun_ptr, Dummy>
: proto::call<mem_fun_ptr_eval(_env, proto::_)>
: proto::call<mem_fun_ptr_eval(_context, proto::_)>
{};
}}

View File

@@ -892,6 +892,6 @@ namespace boost { namespace phoenix
};
template <typename Dummy>
struct default_actions::when<rule::mem_fun_ptr, Dummy>
: proto::call<mem_fun_ptr_eval(_env, proto::_)>
: proto::call<mem_fun_ptr_eval(_context, proto::_)>
{};
}}

View File

@@ -1332,6 +1332,6 @@ namespace boost { namespace phoenix
};
template <typename Dummy>
struct default_actions::when<rule::mem_fun_ptr, Dummy>
: proto::call<mem_fun_ptr_eval(_env, proto::_)>
: proto::call<mem_fun_ptr_eval(_context, proto::_)>
{};
}}

View File

@@ -1772,6 +1772,6 @@ namespace boost { namespace phoenix
};
template <typename Dummy>
struct default_actions::when<rule::mem_fun_ptr, Dummy>
: proto::call<mem_fun_ptr_eval(_env, proto::_)>
: proto::call<mem_fun_ptr_eval(_context, proto::_)>
{};
}}

View File

@@ -2212,6 +2212,6 @@ namespace boost { namespace phoenix
};
template <typename Dummy>
struct default_actions::when<rule::mem_fun_ptr, Dummy>
: proto::call<mem_fun_ptr_eval(_env, proto::_)>
: proto::call<mem_fun_ptr_eval(_context, proto::_)>
{};
}}

View File

@@ -148,7 +148,7 @@ namespace boost { namespace phoenix
struct default_actions::when<rule::dynamic_member, Dummy>
: proto::call<
dynamic_member_eval(
_env
_context
, proto::_value(proto::_child_c<0>)
, proto::_value(proto::_child_c<1>)
)

View File

@@ -169,7 +169,7 @@ namespace boost { namespace phoenix
struct default_actions::when<rule::lambda, Dummy>
: proto::call<
lambda_eval(
_env
_context
, proto::_value(proto::_child_c<0>)
, proto::_child_c<1>
, proto::_child_c<2>
@@ -238,7 +238,7 @@ namespace boost { namespace phoenix
rule::local_var_def_list
, meta_grammar
>
, detail::local_var_def_is_nullary(proto::_child_c<0>, _env)// mpl::true_()//evaluator(proto::_child_c<1>, _env)
, detail::local_var_def_is_nullary(proto::_child_c<0>, _context)// mpl::true_()//evaluator(proto::_child_c<1>, _context)
>
>
{};
@@ -435,14 +435,14 @@ namespace boost { namespace phoenix
: proto::or_<
proto::when<
expression::lambda_actor<meta_grammar>
, lambda_actor_eval(_env, proto::_child_c<0>)
, lambda_actor_eval(_context, proto::_child_c<0>)
>
, proto::when<
expression::lambda_actor<
rule::local_var_def_list
, meta_grammar
>
, lambda_actor_eval(_env, proto::_child_c<0>, proto::_child_c<1>)
, lambda_actor_eval(_context, proto::_child_c<0>, proto::_child_c<1>)
>
>
{};

View File

@@ -110,7 +110,7 @@ namespace boost { namespace phoenix
template <typename Dummy>
struct default_actions::when<rule::let, Dummy>
: proto::call<let_eval(_env, proto::_child_c<0>, proto::_child_c<1>)>
: proto::call<let_eval(_context, proto::_child_c<0>, proto::_child_c<1>)>
{};
template <typename Locals = void, typename Dummy = void>
@@ -172,7 +172,7 @@ namespace boost { namespace phoenix
struct is_nullary::when<rule::let, Dummy>
: proto::make<
mpl::and_<
detail::local_var_def_is_nullary(proto::_child_c<0>, _env)
detail::local_var_def_is_nullary(proto::_child_c<0>, _context)
, evaluator(
proto::_child_c<1>
, fusion::vector2<

View File

@@ -208,7 +208,7 @@ namespace boost { namespace phoenix
, proto::when<
rule::local_var_def
, evaluator(
proto::_child_c<1>
proto::_right
, fusion::vector2<
mpl::true_
, boost::phoenix::is_nullary
@@ -453,7 +453,7 @@ namespace boost { namespace phoenix
template <typename Dummy>
struct default_actions::when<rule::local_variable, Dummy>
: proto::call<local_var_eval(proto::_value(proto::_child_c<0>), _env)>
: proto::call<local_var_eval(proto::_value(proto::_child_c<0>), _context)>
{};
namespace local_names

View File

@@ -58,16 +58,14 @@ namespace boost { namespace phoenix
{ \
typedef \
typename boost::remove_reference< \
typename boost::result_of< \
functional::args(typename Seq::env_type) \
>::type \
typename fusion::result_of::at_c<typename Seq::env_type, 0>::type \
>::type \
env_type; \
typedef typename fusion::result_of::INTRINSIC<env_type>::type type; \
\
static type call(Seq & seq) \
{ \
return fusion::INTRINSIC(seq); \
return fusion::INTRINSIC(seq.env); \
} \
} \
/**/
@@ -81,9 +79,7 @@ namespace boost { namespace phoenix
{
typedef
typename boost::remove_reference<
typename boost::result_of<
functional::args(typename Seq::env_type)
>::type
typename fusion::result_of::at_c<typename Seq::env_type, 0>::type
>::type
env_type;
typedef
@@ -96,16 +92,14 @@ namespace boost { namespace phoenix
{
typedef
typename boost::remove_reference<
typename boost::result_of<
functional::args(typename Seq::env_type)
>::type
typename fusion::result_of::at_c<typename Seq::env_type, 0>::type
>::type
env_type;
typedef typename fusion::result_of::at<env_type, N>::type type;
static type call(Seq & seq)
{
return fusion::at<N>(functional::args()(seq.env));
return fusion::at<N>(fusion::at_c<0>(seq.env));
}
};
};

View File

@@ -37,7 +37,7 @@ namespace boost { namespace phoenix
struct default_actions::when<rule::do_while, Dummy>
: proto::call<
do_while_eval(
_env
_context
, proto::_child_c<0> // Cond
, proto::_child_c<1> // Do
)

View File

@@ -25,21 +25,21 @@ namespace boost { namespace phoenix
typedef void result_type;
template <
typename Env
typename Context
, typename Init
, typename Cond
, typename Step
, typename Do>
result_type
operator()(
Env& env
Context& ctx
, Init const& init
, Cond const& cond
, Step const& step
, Do const& do_) const
{
for(eval(init, env); eval(cond, env); eval(step, env))
eval(do_, env);
for(eval(init, ctx); eval(cond, ctx); eval(step, ctx))
eval(do_, ctx);
}
};
@@ -47,7 +47,7 @@ namespace boost { namespace phoenix
struct default_actions::when<rule::for_, Dummy>
: proto::call<
for_eval(
_env
_context
, proto::_child_c<0> // Cond
, proto::_child_c<1> // Init
, proto::_child_c<2> // Step

View File

@@ -78,7 +78,7 @@ namespace boost { namespace phoenix
struct default_actions::when<rule::if_, Dummy>
: proto::call<
if_else_eval(
_env
_context
, proto::_child_c<0> // Cond
, proto::_child_c<1> // Then
)
@@ -89,7 +89,7 @@ namespace boost { namespace phoenix
struct default_actions::when<rule::if_else, Dummy>
: proto::call<
if_else_eval(
_env
_context
, proto::_child_c<0> // Cond
, proto::_child_c<1> // Then
, proto::_child_c<2> // Else

View File

@@ -148,8 +148,8 @@ namespace boost { namespace phoenix
struct is_nullary::when<rule::switch_, Dummy>
: proto::make<
mpl::and_<
evaluator(proto::_child_c<0>, _env)
, detail::switch_case_is_nullary(proto::_child_c<1>, _env)
evaluator(proto::_child_c<0>, _context)
, detail::switch_case_is_nullary(proto::_child_c<1>, _context)
>()
>
{};
@@ -189,7 +189,7 @@ namespace boost { namespace phoenix
struct default_actions::when<rule::switch_, Dummy>
: proto::call<
switch_eval(
_env
_context
, proto::_child_c<0> // Cond
, proto::_child_c<1> // Cases
)

View File

@@ -66,12 +66,12 @@ namespace boost { namespace phoenix
template <typename Dummy>
struct default_actions::when<rule::rethrow_, Dummy>
: proto::call<throw_eval(_env)>
: proto::call<throw_eval(_context)>
{};
template <typename Dummy>
struct default_actions::when<rule::throw_, Dummy>
: proto::call<throw_eval(_env, proto::_child_c<0>)>
: proto::call<throw_eval(_context, proto::_child_c<0>)>
{};
expression::throw_<>::type const

View File

@@ -109,7 +109,7 @@ namespace boost { namespace phoenix
BOOST_PP_ENUM_PARAMS(N, proto::_ BOOST_PP_INTERCEPT) \
> \
, try_catch_eval( \
_env \
_context \
, BOOST_PP_ENUM( \
N \
, PHOENIX_TRY_CATCH_CHILD \
@@ -250,7 +250,7 @@ namespace boost { namespace phoenix
template <typename Dummy>
struct is_nullary::when<rule::try_catch, Dummy>
: proto::call<detail::try_catch_is_nullary(proto::_, int(), _env)>
: proto::call<detail::try_catch_is_nullary(proto::_, int(), _context)>
{};
template <typename TryCatch, typename Exception>

View File

@@ -37,7 +37,7 @@ namespace boost { namespace phoenix
struct default_actions::when<rule::while_, Dummy>
: proto::call<
while_eval(
_env
_context
, proto::_child_c<0> // Cond
, proto::_child_c<1> // Do
)