this.hpp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /*=============================================================================
  2. Copyright (c) 2005-2011 Joel de Guzman
  3. Copyright (c) 2011 Thomas Heller
  4. Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. ==============================================================================*/
  7. #ifndef BOOST_PHOENIX_SCOPE_THIS_HPP
  8. #define BOOST_PHOENIX_SCOPE_THIS_HPP
  9. #include <boost/phoenix/core/limits.hpp>
  10. #include <boost/phoenix/core/actor.hpp>
  11. #include <boost/phoenix/core/environment.hpp>
  12. #include <boost/phoenix/core/expression.hpp>
  13. #include <boost/phoenix/core/meta_grammar.hpp>
  14. #include <boost/phoenix/core/terminal.hpp>
  15. #include <boost/phoenix/scope/lambda.hpp>
  16. #include <boost/type_traits/remove_pointer.hpp>
  17. BOOST_PHOENIX_DEFINE_EXPRESSION_VARARG(
  18. (boost)(phoenix)(this_)
  19. , (meta_grammar)(meta_grammar)
  20. , BOOST_PHOENIX_LIMIT
  21. )
  22. namespace boost { namespace phoenix {
  23. namespace detail
  24. {
  25. /*
  26. struct infinite_recursion_detected {};
  27. struct last_non_this_actor
  28. : proto::or_<
  29. proto::when<
  30. proto::nary_expr<
  31. proto::_
  32. , proto::_
  33. , proto::_
  34. >
  35. , proto::_child_c<1>
  36. >
  37. , proto::when<
  38. proto::nary_expr<
  39. proto::_
  40. , proto::_
  41. , proto::_
  42. , proto::_
  43. >
  44. , proto::_child_c<2>
  45. >
  46. >
  47. {};
  48. */
  49. }
  50. struct this_eval
  51. {
  52. BOOST_PROTO_CALLABLE()
  53. template <typename Sig>
  54. struct result;
  55. template <typename This, typename A0, typename Context>
  56. struct result<This(A0, Context)>
  57. {
  58. typedef
  59. typename proto::detail::uncvref<
  60. typename result_of::env<
  61. Context
  62. >::type
  63. >::type
  64. outer_env_type;
  65. typedef
  66. typename remove_pointer<
  67. typename remove_reference<
  68. typename fusion::result_of::at_c<
  69. outer_env_type
  70. , 0
  71. >::type
  72. >::type
  73. >::type
  74. actor_type;
  75. typedef
  76. typename result_of::eval<
  77. A0 const &
  78. , Context const &
  79. >::type
  80. a0_type;
  81. typedef
  82. vector2<actor_type const *, a0_type>
  83. inner_env_type;
  84. typedef
  85. scoped_environment<
  86. inner_env_type
  87. , outer_env_type
  88. , vector0<>
  89. , detail::map_local_index_to_tuple<>
  90. >
  91. env_type;
  92. typedef
  93. typename result_of::eval<
  94. actor_type const &
  95. , typename result_of::context<
  96. inner_env_type
  97. , typename result_of::actions<
  98. Context
  99. >::type
  100. >::type
  101. >::type
  102. type;
  103. };
  104. template <typename A0, typename Context>
  105. typename result<this_eval(A0 const&, Context const &)>::type
  106. operator()(A0 const & a0, Context const & ctx) const
  107. {
  108. //std::cout << typeid(checker).name() << "\n";
  109. //std::cout << typeid(checker).name() << "\n";
  110. typedef
  111. typename proto::detail::uncvref<
  112. typename result_of::env<
  113. Context
  114. >::type
  115. >::type
  116. outer_env_type;
  117. typedef
  118. typename remove_pointer<
  119. typename remove_reference<
  120. typename fusion::result_of::at_c<
  121. outer_env_type
  122. , 0
  123. >::type
  124. >::type
  125. >::type
  126. actor_type;
  127. typedef
  128. typename result_of::eval<
  129. A0 const &
  130. , Context const &
  131. >::type
  132. a0_type;
  133. typedef
  134. vector2<actor_type const *, a0_type>
  135. inner_env_type;
  136. typedef
  137. scoped_environment<
  138. inner_env_type
  139. , outer_env_type
  140. , vector0<>
  141. , detail::map_local_index_to_tuple<>
  142. >
  143. env_type;
  144. inner_env_type inner_env = {fusion::at_c<0>(phoenix::env(ctx)), phoenix::eval(a0, ctx)};
  145. vector0<> locals;
  146. env_type env(inner_env, phoenix::env(ctx), locals);
  147. return phoenix::eval(*fusion::at_c<0>(phoenix::env(ctx)), phoenix::context(inner_env, phoenix::actions(ctx)));
  148. //return (*fusion::at_c<0>(phoenix::env(ctx)))(eval(a0, ctx));
  149. }
  150. };
  151. template <typename Dummy>
  152. struct default_actions::when<rule::this_, Dummy>
  153. : call<this_eval>
  154. {};
  155. template <typename Dummy>
  156. struct is_nullary::when<rule::this_, Dummy>
  157. : proto::make<mpl::false_()>
  158. {};
  159. template <typename A0>
  160. typename expression::this_<A0>::type const
  161. this_(A0 const & a0)
  162. {
  163. return expression::this_<A0>::make(a0);
  164. }
  165. }}
  166. #endif