local_variable.hpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*=============================================================================
  2. Copyright (c) 2001-2007 Joel de Guzman
  3. Copyright (c) 2004 Daniel Wallin
  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 PHOENIX_SCOPE_LOCAL_VARIABLE_HPP
  8. #define PHOENIX_SCOPE_LOCAL_VARIABLE_HPP
  9. #include <boost/spirit/home/phoenix/core/limits.hpp>
  10. #include <boost/spirit/home/phoenix/detail/local_reference.hpp>
  11. #include <boost/spirit/home/phoenix/scope/detail/local_variable.hpp>
  12. #include <boost/spirit/home/phoenix/core/actor.hpp>
  13. #include <boost/mpl/bool.hpp>
  14. namespace boost { namespace phoenix
  15. {
  16. template <typename Key>
  17. struct local_variable
  18. {
  19. typedef Key key_type;
  20. // This will prevent actor::operator()() from kicking in.
  21. // Actually, we do not need all actor::operator()s for
  22. // all arities, but this will suffice. The nullary
  23. // actor::operator() is particularly troublesome because
  24. // it is always eagerly evaluated by the compiler.
  25. typedef mpl::true_ no_nullary;
  26. template <typename Env>
  27. struct result : detail::apply_local<local_variable<Key>, Env> {};
  28. template <typename Env>
  29. typename result<Env>::type
  30. eval(Env const& env) const
  31. {
  32. typedef typename result<Env>::type return_type;
  33. typedef typename
  34. detail::get_index<typename Env::map_type, Key>::type
  35. index_type;
  36. typedef detail::eval_local<Key> eval_local;
  37. return eval_local::template get<return_type>(
  38. env
  39. , index_type());
  40. }
  41. private:
  42. // silence MSVC warning C4512: assignment operator could not be generated
  43. local_variable& operator= (local_variable const&);
  44. };
  45. namespace local_names
  46. {
  47. actor<local_variable<struct _a_key> > const _a
  48. = local_variable<struct _a_key>();
  49. actor<local_variable<struct _b_key> > const _b
  50. = local_variable<struct _b_key>();
  51. actor<local_variable<struct _c_key> > const _c
  52. = local_variable<struct _c_key>();
  53. actor<local_variable<struct _d_key> > const _d
  54. = local_variable<struct _d_key>();
  55. actor<local_variable<struct _e_key> > const _e
  56. = local_variable<struct _e_key>();
  57. actor<local_variable<struct _f_key> > const _f
  58. = local_variable<struct _f_key>();
  59. actor<local_variable<struct _g_key> > const _g
  60. = local_variable<struct _g_key>();
  61. actor<local_variable<struct _h_key> > const _h
  62. = local_variable<struct _h_key>();
  63. actor<local_variable<struct _i_key> > const _i
  64. = local_variable<struct _i_key>();
  65. actor<local_variable<struct _j_key> > const _j
  66. = local_variable<struct _j_key>();
  67. actor<local_variable<struct _k_key> > const _k
  68. = local_variable<struct _k_key>();
  69. actor<local_variable<struct _l_key> > const _l
  70. = local_variable<struct _l_key>();
  71. actor<local_variable<struct _m_key> > const _m
  72. = local_variable<struct _m_key>();
  73. actor<local_variable<struct _n_key> > const _n
  74. = local_variable<struct _n_key>();
  75. actor<local_variable<struct _o_key> > const _o
  76. = local_variable<struct _o_key>();
  77. actor<local_variable<struct _p_key> > const _p
  78. = local_variable<struct _p_key>();
  79. actor<local_variable<struct _q_key> > const _q
  80. = local_variable<struct _q_key>();
  81. actor<local_variable<struct _r_key> > const _r
  82. = local_variable<struct _r_key>();
  83. actor<local_variable<struct _s_key> > const _s
  84. = local_variable<struct _s_key>();
  85. actor<local_variable<struct _t_key> > const _t
  86. = local_variable<struct _t_key>();
  87. actor<local_variable<struct _u_key> > const _u
  88. = local_variable<struct _u_key>();
  89. actor<local_variable<struct _v_key> > const _v
  90. = local_variable<struct _v_key>();
  91. actor<local_variable<struct _w_key> > const _w
  92. = local_variable<struct _w_key>();
  93. actor<local_variable<struct _x_key> > const _x
  94. = local_variable<struct _x_key>();
  95. actor<local_variable<struct _y_key> > const _y
  96. = local_variable<struct _y_key>();
  97. actor<local_variable<struct _z_key> > const _z
  98. = local_variable<struct _z_key>();
  99. }
  100. }}
  101. #endif