local_variable.hpp 7.5 KB

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