arithmetic.hpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*=============================================================================
  2. Copyright (c) 2001-2007 Joel de Guzman
  3. Distributed under the Boost Software License, Version 1.0. (See accompanying
  4. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. ==============================================================================*/
  6. #ifndef PHOENIX_OPERATOR_ARITHMETIC_HPP
  7. #define PHOENIX_OPERATOR_ARITHMETIC_HPP
  8. #include <boost/spirit/home/phoenix/core/composite.hpp>
  9. #include <boost/spirit/home/phoenix/core/compose.hpp>
  10. #include <boost/spirit/home/phoenix/detail/type_deduction.hpp>
  11. #include <boost/spirit/home/phoenix/operator/detail/unary_eval.hpp>
  12. #include <boost/spirit/home/phoenix/operator/detail/unary_compose.hpp>
  13. #include <boost/spirit/home/phoenix/operator/detail/binary_eval.hpp>
  14. #include <boost/spirit/home/phoenix/operator/detail/binary_compose.hpp>
  15. namespace boost { namespace phoenix
  16. {
  17. struct negate_eval;
  18. struct posit_eval;
  19. struct pre_increment_eval;
  20. struct pre_decrement_eval;
  21. struct post_increment_eval;
  22. struct post_decrement_eval;
  23. struct plus_assign_eval;
  24. struct minus_assign_eval;
  25. struct multiplies_assign_eval;
  26. struct divides_assign_eval;
  27. struct modulus_assign_eval;
  28. struct plus_eval;
  29. struct minus_eval;
  30. struct multiplies_eval;
  31. struct divides_eval;
  32. struct modulus_eval;
  33. BOOST_UNARY_RESULT_OF(-x, result_of_negate)
  34. BOOST_UNARY_RESULT_OF(+x, result_of_posit)
  35. BOOST_UNARY_RESULT_OF(++x, result_of_pre_increment)
  36. BOOST_UNARY_RESULT_OF(--x, result_of_pre_decrement)
  37. BOOST_UNARY_RESULT_OF(x++, result_of_post_increment)
  38. BOOST_UNARY_RESULT_OF(x--, result_of_post_decrement)
  39. BOOST_BINARY_RESULT_OF(x += y, result_of_plus_assign)
  40. BOOST_BINARY_RESULT_OF(x -= y, result_of_minus_assign)
  41. BOOST_BINARY_RESULT_OF(x *= y, result_of_multiplies_assign)
  42. BOOST_BINARY_RESULT_OF(x /= y, result_of_divides_assign)
  43. BOOST_BINARY_RESULT_OF(x %= y, result_of_modulus_assign)
  44. BOOST_BINARY_RESULT_OF(x + y, result_of_plus)
  45. BOOST_BINARY_RESULT_OF(x - y, result_of_minus)
  46. BOOST_BINARY_RESULT_OF(x * y, result_of_multiplies)
  47. BOOST_BINARY_RESULT_OF(x / y, result_of_divides)
  48. BOOST_BINARY_RESULT_OF(x % y, result_of_modulus)
  49. #define x a0.eval(env)
  50. #define y a1.eval(env)
  51. PHOENIX_UNARY_EVAL(negate_eval, result_of_negate, -x)
  52. PHOENIX_UNARY_EVAL(posit_eval, result_of_posit, +x)
  53. PHOENIX_UNARY_EVAL(pre_increment_eval, result_of_pre_increment, ++x)
  54. PHOENIX_UNARY_EVAL(pre_decrement_eval, result_of_pre_decrement, --x)
  55. PHOENIX_UNARY_EVAL(post_increment_eval, result_of_post_increment, x++)
  56. PHOENIX_UNARY_EVAL(post_decrement_eval, result_of_post_decrement, x--)
  57. PHOENIX_BINARY_EVAL(plus_assign_eval, result_of_plus_assign, x += y)
  58. PHOENIX_BINARY_EVAL(minus_assign_eval, result_of_minus_assign, x -= y)
  59. PHOENIX_BINARY_EVAL(multiplies_assign_eval, result_of_multiplies_assign, x *= y)
  60. PHOENIX_BINARY_EVAL(divides_assign_eval, result_of_divides_assign, x /= y)
  61. PHOENIX_BINARY_EVAL(modulus_assign_eval, result_of_modulus_assign, x %= y)
  62. PHOENIX_BINARY_EVAL(plus_eval, result_of_plus, x + y)
  63. PHOENIX_BINARY_EVAL(minus_eval, result_of_minus, x - y)
  64. PHOENIX_BINARY_EVAL(multiplies_eval, result_of_multiplies, x * y)
  65. PHOENIX_BINARY_EVAL(divides_eval, result_of_divides, x / y)
  66. PHOENIX_BINARY_EVAL(modulus_eval, result_of_modulus, x % y)
  67. PHOENIX_UNARY_COMPOSE(negate_eval, -)
  68. PHOENIX_UNARY_COMPOSE(posit_eval, +)
  69. PHOENIX_UNARY_COMPOSE(pre_increment_eval, ++)
  70. PHOENIX_UNARY_COMPOSE(pre_decrement_eval, --)
  71. template <typename T0>
  72. inline actor<typename as_composite<post_increment_eval, actor<T0> >::type>
  73. operator++(actor<T0> const& a0, int) // special case
  74. {
  75. return compose<post_increment_eval>(a0);
  76. }
  77. template <typename T0>
  78. inline actor<typename as_composite<post_decrement_eval, actor<T0> >::type>
  79. operator--(actor<T0> const& a0, int) // special case
  80. {
  81. return compose<post_decrement_eval>(a0);
  82. }
  83. PHOENIX_BINARY_COMPOSE(plus_assign_eval, +=)
  84. PHOENIX_BINARY_COMPOSE(minus_assign_eval, -=)
  85. PHOENIX_BINARY_COMPOSE(multiplies_assign_eval, *=)
  86. PHOENIX_BINARY_COMPOSE(divides_assign_eval, /=)
  87. PHOENIX_BINARY_COMPOSE(modulus_assign_eval, %=)
  88. PHOENIX_BINARY_COMPOSE(plus_eval, +)
  89. PHOENIX_BINARY_COMPOSE(minus_eval, -)
  90. PHOENIX_BINARY_COMPOSE(multiplies_eval, *)
  91. PHOENIX_BINARY_COMPOSE(divides_eval, /)
  92. PHOENIX_BINARY_COMPOSE(modulus_eval, %)
  93. #undef x
  94. #undef y
  95. }}
  96. #endif