local_variable.hpp 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /*==============================================================================
  2. Copyright (c) 2005-2010 Joel de Guzman
  3. Copyright (c) 2010-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_LOCAL_VARIABLE_HPP
  8. #define BOOST_PHOENIX_SCOPE_LOCAL_VARIABLE_HPP
  9. #include <boost/phoenix/core/limits.hpp>
  10. #include <boost/phoenix/core/call.hpp>
  11. #include <boost/phoenix/core/expression.hpp>
  12. #include <boost/phoenix/core/reference.hpp>
  13. #include <boost/phoenix/core/value.hpp>
  14. #include <boost/phoenix/scope/scoped_environment.hpp>
  15. #include <boost/phoenix/scope/detail/local_variable.hpp>
  16. #include <boost/phoenix/statement/sequence.hpp>
  17. namespace boost { namespace phoenix
  18. {
  19. namespace detail
  20. {
  21. }
  22. namespace expression
  23. {
  24. template <typename Key>
  25. struct local_variable
  26. : expression::terminal<detail::local<Key> >
  27. {
  28. typedef typename expression::terminal<detail::local<Key> >::type type;
  29. static type make()
  30. {
  31. type const e = {};
  32. return e;
  33. }
  34. };
  35. }
  36. namespace rule
  37. {
  38. struct local_variable
  39. : expression::local_variable<proto::_>
  40. {};
  41. struct local_var_def
  42. : proto::assign<local_variable, meta_grammar>
  43. {};
  44. }
  45. namespace result_of
  46. {
  47. template <typename Key>
  48. struct is_nullary<custom_terminal<detail::local<Key> > >
  49. : mpl::false_
  50. {};
  51. }
  52. namespace detail
  53. {
  54. struct scope_is_nullary_actions
  55. {
  56. template <typename Rule, typename Dummy = void>
  57. struct when
  58. : boost::phoenix::is_nullary::when<Rule, Dummy>
  59. {};
  60. };
  61. template <typename Dummy>
  62. struct scope_is_nullary_actions::when<boost::phoenix::rule::custom_terminal, Dummy>
  63. : proto::or_<
  64. proto::when<boost::phoenix::rule::local_variable, mpl::true_()>
  65. , proto::otherwise<
  66. is_nullary::when<boost::phoenix::rule::custom_terminal, Dummy>
  67. >
  68. >
  69. {};
  70. struct local_var_not_found
  71. {
  72. };
  73. }
  74. template<typename Key>
  75. struct is_custom_terminal<detail::local<Key> >
  76. : mpl::true_
  77. {};
  78. template <typename Key>
  79. struct custom_terminal<detail::local<Key> >
  80. {
  81. template <typename Sig>
  82. struct result;
  83. template <typename This, typename Local, typename Context>
  84. struct result<This(Local, Context)>
  85. : result<This(Local const &, Context)>
  86. {};
  87. template <typename This, typename Local, typename Context>
  88. struct result<This(Local &, Context)>
  89. {
  90. typedef
  91. typename remove_reference<
  92. typename result_of::env<Context>::type
  93. >::type
  94. env_type;
  95. typedef typename detail::apply_local<detail::local<Key>, env_type>::type type;
  96. };
  97. template <typename Local, typename Context>
  98. typename result<custom_terminal(Local const &, Context const&)>::type
  99. operator()(Local, Context const & ctx)
  100. {
  101. typedef
  102. typename remove_reference<
  103. typename result_of::env<Context>::type
  104. >::type
  105. env_type;
  106. typedef typename detail::apply_local<detail::local<Key>, env_type>::type return_type;
  107. static const int index_value = detail::get_index<typename env_type::map_type, detail::local<Key> >::value;
  108. typedef detail::eval_local<Key> eval_local;
  109. // Detect if the return_type is for a value.
  110. //typedef typename is_value<return_type>::type is_value_type;
  111. return eval_local::template get<return_type, index_value>(
  112. phoenix::env(ctx));
  113. }
  114. };
  115. namespace local_names
  116. {
  117. typedef expression::local_variable<struct _a_key>::type _a_type;
  118. typedef expression::local_variable<struct _b_key>::type _b_type;
  119. typedef expression::local_variable<struct _c_key>::type _c_type;
  120. typedef expression::local_variable<struct _d_key>::type _d_type;
  121. typedef expression::local_variable<struct _e_key>::type _e_type;
  122. typedef expression::local_variable<struct _f_key>::type _f_type;
  123. typedef expression::local_variable<struct _g_key>::type _g_type;
  124. typedef expression::local_variable<struct _h_key>::type _h_type;
  125. typedef expression::local_variable<struct _i_key>::type _i_type;
  126. typedef expression::local_variable<struct _j_key>::type _j_type;
  127. typedef expression::local_variable<struct _k_key>::type _k_type;
  128. typedef expression::local_variable<struct _l_key>::type _l_type;
  129. typedef expression::local_variable<struct _m_key>::type _m_type;
  130. typedef expression::local_variable<struct _n_key>::type _n_type;
  131. typedef expression::local_variable<struct _o_key>::type _o_type;
  132. typedef expression::local_variable<struct _p_key>::type _p_type;
  133. typedef expression::local_variable<struct _q_key>::type _q_type;
  134. typedef expression::local_variable<struct _r_key>::type _r_type;
  135. typedef expression::local_variable<struct _s_key>::type _s_type;
  136. typedef expression::local_variable<struct _t_key>::type _t_type;
  137. typedef expression::local_variable<struct _u_key>::type _u_type;
  138. typedef expression::local_variable<struct _v_key>::type _v_type;
  139. typedef expression::local_variable<struct _w_key>::type _w_type;
  140. typedef expression::local_variable<struct _x_key>::type _x_type;
  141. typedef expression::local_variable<struct _y_key>::type _y_type;
  142. typedef expression::local_variable<struct _z_key>::type _z_type;
  143. #ifndef BOOST_PHOENIX_NO_PREDEFINED_TERMINALS
  144. _a_type const _a = {{{}}};
  145. _b_type const _b = {{{}}};
  146. _c_type const _c = {{{}}};
  147. _d_type const _d = {{{}}};
  148. _e_type const _e = {{{}}};
  149. _f_type const _f = {{{}}};
  150. _g_type const _g = {{{}}};
  151. _h_type const _h = {{{}}};
  152. _i_type const _i = {{{}}};
  153. _j_type const _j = {{{}}};
  154. _k_type const _k = {{{}}};
  155. _l_type const _l = {{{}}};
  156. _m_type const _m = {{{}}};
  157. _n_type const _n = {{{}}};
  158. _o_type const _o = {{{}}};
  159. _p_type const _p = {{{}}};
  160. _q_type const _q = {{{}}};
  161. _r_type const _r = {{{}}};
  162. _s_type const _s = {{{}}};
  163. _t_type const _t = {{{}}};
  164. _u_type const _u = {{{}}};
  165. _v_type const _v = {{{}}};
  166. _w_type const _w = {{{}}};
  167. _x_type const _x = {{{}}};
  168. _y_type const _y = {{{}}};
  169. _z_type const _z = {{{}}};
  170. #endif
  171. }
  172. }}
  173. #endif