basic_expr.hpp 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. #if !defined(BOOST_PROTO_DONT_USE_PREPROCESSED_FILES)
  2. #include <boost/proto/detail/preprocessed/basic_expr.hpp>
  3. #elif !defined(BOOST_PP_IS_ITERATING)
  4. /// INTERNAL ONLY
  5. ///
  6. #define BOOST_PROTO_CHILD(Z, N, DATA) \
  7. typedef BOOST_PP_CAT(Arg, N) BOOST_PP_CAT(proto_child, N); \
  8. BOOST_PP_CAT(proto_child, N) BOOST_PP_CAT(child, N); \
  9. /**< INTERNAL ONLY */
  10. /// INTERNAL ONLY
  11. ///
  12. #define BOOST_PROTO_VOID(Z, N, DATA) \
  13. typedef void BOOST_PP_CAT(proto_child, N); \
  14. /**< INTERNAL ONLY */
  15. #if defined(__WAVE__) && defined(BOOST_PROTO_CREATE_PREPROCESSED_FILES)
  16. #pragma wave option(preserve: 2, line: 0, output: "preprocessed/basic_expr.hpp")
  17. #endif
  18. ///////////////////////////////////////////////////////////////////////////////
  19. /// \file basic_expr.hpp
  20. /// Contains definition of basic_expr\<\> class template.
  21. //
  22. // Copyright 2008 Eric Niebler. Distributed under the Boost
  23. // Software License, Version 1.0. (See accompanying file
  24. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  25. #if defined(__WAVE__) && defined(BOOST_PROTO_CREATE_PREPROCESSED_FILES)
  26. #pragma wave option(preserve: 1)
  27. #endif
  28. // The expr<> specializations are actually defined here.
  29. #define BOOST_PROTO_DEFINE_TERMINAL
  30. #define BOOST_PP_ITERATION_PARAMS_1 (3, (0, 0, <boost/proto/detail/basic_expr.hpp>))
  31. #include BOOST_PP_ITERATE()
  32. #undef BOOST_PROTO_DEFINE_TERMINAL
  33. #define BOOST_PP_ITERATION_PARAMS_1 (3, (1, BOOST_PROTO_MAX_ARITY, <boost/proto/detail/basic_expr.hpp>))
  34. #include BOOST_PP_ITERATE()
  35. #if defined(__WAVE__) && defined(BOOST_PROTO_CREATE_PREPROCESSED_FILES)
  36. #pragma wave option(output: null)
  37. #endif
  38. #undef BOOST_PROTO_CHILD
  39. #undef BOOST_PROTO_VOID
  40. #else
  41. #define ARG_COUNT BOOST_PP_MAX(1, BOOST_PP_ITERATION())
  42. /// \brief Simplified representation of a node in an expression tree.
  43. ///
  44. /// \c proto::basic_expr\<\> is a node in an expression template tree. It
  45. /// is a container for its child sub-trees. It also serves as
  46. /// the terminal nodes of the tree.
  47. ///
  48. /// \c Tag is type that represents the operation encoded by
  49. /// this expression. It is typically one of the structs
  50. /// in the \c boost::proto::tag namespace, but it doesn't
  51. /// have to be.
  52. ///
  53. /// \c Args is a type list representing the type of the children
  54. /// of this expression. It is an instantiation of one
  55. /// of \c proto::list1\<\>, \c proto::list2\<\>, etc. The
  56. /// child types must all themselves be either \c expr\<\>
  57. /// or <tt>proto::expr\<\>&</tt>. If \c Args is an
  58. /// instantiation of \c proto::term\<\> then this
  59. /// \c expr\<\> type represents a terminal expression;
  60. /// the parameter to the \c proto::term\<\> template
  61. /// represents the terminal's value type.
  62. ///
  63. /// \c Arity is an integral constant representing the number of child
  64. /// nodes this node contains. If \c Arity is 0, then this
  65. /// node is a terminal.
  66. ///
  67. /// \c proto::basic_expr\<\> is a valid Fusion random-access sequence, where
  68. /// the elements of the sequence are the child expressions.
  69. #ifdef BOOST_PROTO_DEFINE_TERMINAL
  70. template<typename Tag, typename Arg0>
  71. struct basic_expr<Tag, term<Arg0>, 0>
  72. #else
  73. template<typename Tag BOOST_PP_ENUM_TRAILING_PARAMS(ARG_COUNT, typename Arg)>
  74. struct basic_expr<Tag, BOOST_PP_CAT(list, BOOST_PP_ITERATION())<BOOST_PP_ENUM_PARAMS(ARG_COUNT, Arg)>, BOOST_PP_ITERATION() >
  75. #endif
  76. {
  77. typedef Tag proto_tag;
  78. static const long proto_arity_c = BOOST_PP_ITERATION();
  79. typedef mpl::long_<BOOST_PP_ITERATION() > proto_arity;
  80. typedef basic_expr proto_base_expr;
  81. #ifdef BOOST_PROTO_DEFINE_TERMINAL
  82. typedef term<Arg0> proto_args;
  83. #else
  84. typedef BOOST_PP_CAT(list, BOOST_PP_ITERATION())<BOOST_PP_ENUM_PARAMS(ARG_COUNT, Arg)> proto_args;
  85. #endif
  86. typedef basic_expr proto_grammar;
  87. typedef basic_default_domain proto_domain;
  88. typedef default_generator proto_generator;
  89. typedef proto::tag::proto_expr<Tag, proto_domain> fusion_tag;
  90. typedef basic_expr proto_derived_expr;
  91. typedef void proto_is_expr_; /**< INTERNAL ONLY */
  92. BOOST_PP_REPEAT(ARG_COUNT, BOOST_PROTO_CHILD, ~)
  93. BOOST_PP_REPEAT_FROM_TO(ARG_COUNT, BOOST_PROTO_MAX_ARITY, BOOST_PROTO_VOID, ~)
  94. /// \return *this
  95. ///
  96. BOOST_FORCEINLINE
  97. basic_expr const &proto_base() const
  98. {
  99. return *this;
  100. }
  101. /// \overload
  102. ///
  103. BOOST_FORCEINLINE
  104. basic_expr &proto_base()
  105. {
  106. return *this;
  107. }
  108. #ifdef BOOST_PROTO_DEFINE_TERMINAL
  109. /// \return A new \c expr\<\> object initialized with the specified
  110. /// arguments.
  111. ///
  112. template<typename A0>
  113. BOOST_FORCEINLINE
  114. static basic_expr const make(A0 &a0)
  115. {
  116. return detail::make_terminal(a0, static_cast<basic_expr *>(0), static_cast<proto_args *>(0));
  117. }
  118. /// \overload
  119. ///
  120. template<typename A0>
  121. BOOST_FORCEINLINE
  122. static basic_expr const make(A0 const &a0)
  123. {
  124. return detail::make_terminal(a0, static_cast<basic_expr *>(0), static_cast<proto_args *>(0));
  125. }
  126. #else
  127. /// \return A new \c expr\<\> object initialized with the specified
  128. /// arguments.
  129. ///
  130. template<BOOST_PP_ENUM_PARAMS(ARG_COUNT, typename A)>
  131. BOOST_FORCEINLINE
  132. static basic_expr const make(BOOST_PP_ENUM_BINARY_PARAMS(ARG_COUNT, A, const &a))
  133. {
  134. basic_expr that = {BOOST_PP_ENUM_PARAMS(ARG_COUNT, a)};
  135. return that;
  136. }
  137. #endif
  138. #if 1 == BOOST_PP_ITERATION()
  139. /// If \c Tag is \c boost::proto::tag::address_of and \c proto_child0 is
  140. /// <tt>T&</tt>, then \c address_of_hack_type_ is <tt>T*</tt>.
  141. /// Otherwise, it is some undefined type.
  142. typedef typename detail::address_of_hack<Tag, proto_child0>::type address_of_hack_type_;
  143. /// \return The address of <tt>this->child0</tt> if \c Tag is
  144. /// \c boost::proto::tag::address_of. Otherwise, this function will
  145. /// fail to compile.
  146. ///
  147. /// \attention Proto overloads <tt>operator&</tt>, which means that
  148. /// proto-ified objects cannot have their addresses taken, unless we use
  149. /// the following hack to make \c &x implicitly convertible to \c X*.
  150. BOOST_FORCEINLINE
  151. operator address_of_hack_type_() const
  152. {
  153. return boost::addressof(this->child0);
  154. }
  155. #else
  156. /// INTERNAL ONLY
  157. ///
  158. typedef detail::not_a_valid_type address_of_hack_type_;
  159. #endif
  160. };
  161. #undef ARG_COUNT
  162. #endif