summaryrefslogtreecommitdiffstats
blob: e51b23e14a5e642f93c785d8cd5d493b17883f30 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*=============================================================================
    Copyright (c) 2001-2007 Joel de Guzman

    Distributed under the Boost Software License, Version 1.0. (See accompanying 
    file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
==============================================================================*/
#ifndef PHOENIX_OPERATOR_ARITHMETIC_HPP
#define PHOENIX_OPERATOR_ARITHMETIC_HPP

#include <boost/spirit/home/phoenix/core/composite.hpp>
#include <boost/spirit/home/phoenix/core/compose.hpp>
#include <boost/spirit/home/phoenix/detail/type_deduction.hpp>
#include <boost/spirit/home/phoenix/operator/detail/unary_eval.hpp>
#include <boost/spirit/home/phoenix/operator/detail/unary_compose.hpp>
#include <boost/spirit/home/phoenix/operator/detail/binary_eval.hpp>
#include <boost/spirit/home/phoenix/operator/detail/binary_compose.hpp>

namespace boost { namespace phoenix
{
    struct negate_eval;
    struct posit_eval;
    struct pre_increment_eval;
    struct pre_decrement_eval;
    struct post_increment_eval;
    struct post_decrement_eval;

    struct plus_assign_eval;
    struct minus_assign_eval;
    struct multiplies_assign_eval;
    struct divides_assign_eval;
    struct modulus_assign_eval;

    struct plus_eval;
    struct minus_eval;
    struct multiplies_eval;
    struct divides_eval;
    struct modulus_eval;

    BOOST_UNARY_RESULT_OF(-x, result_of_negate)
    BOOST_UNARY_RESULT_OF(+x, result_of_posit)
    BOOST_UNARY_RESULT_OF(++x, result_of_pre_increment)
    BOOST_UNARY_RESULT_OF(--x, result_of_pre_decrement)
    BOOST_UNARY_RESULT_OF(x++, result_of_post_increment)
    BOOST_UNARY_RESULT_OF(x--, result_of_post_decrement)

    BOOST_BINARY_RESULT_OF(x += y, result_of_plus_assign)
    BOOST_BINARY_RESULT_OF(x -= y, result_of_minus_assign)
    BOOST_BINARY_RESULT_OF(x *= y, result_of_multiplies_assign)
    BOOST_BINARY_RESULT_OF(x /= y, result_of_divides_assign)
    BOOST_BINARY_RESULT_OF(x %= y, result_of_modulus_assign)

    BOOST_BINARY_RESULT_OF(x + y, result_of_plus)
    BOOST_BINARY_RESULT_OF(x - y, result_of_minus)
    BOOST_BINARY_RESULT_OF(x * y, result_of_multiplies)
    BOOST_BINARY_RESULT_OF(x / y, result_of_divides)
    BOOST_BINARY_RESULT_OF(x % y, result_of_modulus)

#define x a0.eval(env)
#define y a1.eval(env)

    PHOENIX_UNARY_EVAL(negate_eval, result_of_negate, -x)
    PHOENIX_UNARY_EVAL(posit_eval, result_of_posit, +x)
    PHOENIX_UNARY_EVAL(pre_increment_eval, result_of_pre_increment, ++x)
    PHOENIX_UNARY_EVAL(pre_decrement_eval, result_of_pre_decrement, --x)
    PHOENIX_UNARY_EVAL(post_increment_eval, result_of_post_increment, x++)
    PHOENIX_UNARY_EVAL(post_decrement_eval, result_of_post_decrement, x--)

    PHOENIX_BINARY_EVAL(plus_assign_eval, result_of_plus_assign, x += y)
    PHOENIX_BINARY_EVAL(minus_assign_eval, result_of_minus_assign, x -= y)
    PHOENIX_BINARY_EVAL(multiplies_assign_eval, result_of_multiplies_assign, x *= y)
    PHOENIX_BINARY_EVAL(divides_assign_eval, result_of_divides_assign, x /= y)
    PHOENIX_BINARY_EVAL(modulus_assign_eval, result_of_modulus_assign, x %= y)

    PHOENIX_BINARY_EVAL(plus_eval, result_of_plus, x + y)
    PHOENIX_BINARY_EVAL(minus_eval, result_of_minus, x - y)
    PHOENIX_BINARY_EVAL(multiplies_eval, result_of_multiplies, x * y)
    PHOENIX_BINARY_EVAL(divides_eval, result_of_divides, x / y)
    PHOENIX_BINARY_EVAL(modulus_eval, result_of_modulus, x % y)

    PHOENIX_UNARY_COMPOSE(negate_eval, -)
    PHOENIX_UNARY_COMPOSE(posit_eval, +)
    PHOENIX_UNARY_COMPOSE(pre_increment_eval, ++)
    PHOENIX_UNARY_COMPOSE(pre_decrement_eval, --)

    template <typename T0>
    inline actor<typename as_composite<post_increment_eval, actor<T0> >::type>
    operator++(actor<T0> const& a0, int) // special case
    {
        return compose<post_increment_eval>(a0);
    }

    template <typename T0>
    inline actor<typename as_composite<post_decrement_eval, actor<T0> >::type>
    operator--(actor<T0> const& a0, int) // special case
    {
        return compose<post_decrement_eval>(a0);
    }

    PHOENIX_BINARY_COMPOSE(plus_assign_eval, +=)
    PHOENIX_BINARY_COMPOSE(minus_assign_eval, -=)
    PHOENIX_BINARY_COMPOSE(multiplies_assign_eval, *=)
    PHOENIX_BINARY_COMPOSE(divides_assign_eval, /=)
    PHOENIX_BINARY_COMPOSE(modulus_assign_eval, %=)

    PHOENIX_BINARY_COMPOSE(plus_eval, +)
    PHOENIX_BINARY_COMPOSE(minus_eval, -)
    PHOENIX_BINARY_COMPOSE(multiplies_eval, *)
    PHOENIX_BINARY_COMPOSE(divides_eval, /)
    PHOENIX_BINARY_COMPOSE(modulus_eval, %)

#undef x
#undef y
}}

#endif