8 #include <hilti/ast/operators/common.h> 9 #include <hilti/ast/types/bool.h> 10 #include <hilti/ast/types/integer.h> 11 #include <hilti/ast/types/real.h> 12 #include <hilti/ast/types/string.h> 13 #include <hilti/ast/types/type.h> 14 #include <hilti/base/logger.h> 19 inline static auto widestTypeSigned() {
22 if ( orig_ops.empty() && resolved_ops.empty() )
23 return type::DocOnly(
"int<*>");
28 if (
auto t = orig_ops[0].type().tryAs<type::SignedInteger>() )
30 else if (
auto t = orig_ops[0].type().tryAs<type::UnsignedInteger>() )
33 if (
auto t = orig_ops[1].type().tryAs<type::SignedInteger>() )
35 else if (
auto t = orig_ops[1].type().tryAs<type::UnsignedInteger>() )
41 const bool is_ctor1 = orig_ops[0].isA<expression::Ctor>();
42 const bool is_ctor2 = orig_ops[1].isA<expression::Ctor>();
44 if ( is_ctor1 && ! is_ctor2 )
45 return type::SignedInteger(w2);
47 if ( is_ctor2 && ! is_ctor1 )
48 return type::SignedInteger(w1);
50 return type::SignedInteger(std::max(w1, w2));
55 STANDARD_OPERATOR_1(signed_integer, DecrPostfix, operator_::sameTypeAs(0,
"int"), type::SignedInteger(type::Wildcard()),
56 "Decrements the value, returning the old value.");
57 STANDARD_OPERATOR_1(signed_integer, DecrPrefix, operator_::sameTypeAs(0,
"int"), type::SignedInteger(type::Wildcard()),
58 "Increments the value, returning the new value.");
59 STANDARD_OPERATOR_1(signed_integer, IncrPostfix, operator_::sameTypeAs(0,
"int"), type::SignedInteger(type::Wildcard()),
60 "Increments the value, returning the old value.");
61 STANDARD_OPERATOR_1(signed_integer, IncrPrefix, operator_::sameTypeAs(0,
"int"), type::SignedInteger(type::Wildcard()),
62 "Increments the value, returning the new value.");
63 STANDARD_OPERATOR_1(signed_integer, SignNeg, operator_::sameTypeAs(0,
"int"), type::SignedInteger(type::Wildcard()),
64 "Inverts the sign of the integer.");
65 STANDARD_OPERATOR_2(signed_integer, Difference, detail::widestTypeSigned(), detail::widestTypeSigned(),
66 detail::widestTypeSigned(),
"Computes the difference between the two integers.");
67 STANDARD_OPERATOR_2(signed_integer, DifferenceAssign, operator_::sameTypeAs(0,
"int"),
68 type::SignedInteger(type::Wildcard()), operator_::sameTypeAs(0,
"int"),
69 "Decrements the first value by the second, assigning the new value.");
70 STANDARD_OPERATOR_2(signed_integer, Division, detail::widestTypeSigned(), detail::widestTypeSigned(),
71 detail::widestTypeSigned(),
"Divides the first integer by the second.");
72 STANDARD_OPERATOR_2(signed_integer, DivisionAssign, operator_::sameTypeAs(0,
"int"),
73 type::SignedInteger(type::Wildcard()), operator_::sameTypeAs(0,
"int"),
74 "Divides the first value by the second, assigning the new value.");
75 STANDARD_OPERATOR_2(signed_integer, Equal, type::Bool(), detail::widestTypeSigned(), detail::widestTypeSigned(),
76 "Compares the two integers.");
77 STANDARD_OPERATOR_2(signed_integer, Greater, type::Bool(), detail::widestTypeSigned(), detail::widestTypeSigned(),
78 "Compares the two integers.");
79 STANDARD_OPERATOR_2(signed_integer, GreaterEqual, type::Bool(), detail::widestTypeSigned(), detail::widestTypeSigned(),
80 "Compares the two integers.");
81 STANDARD_OPERATOR_2(signed_integer, Lower, type::Bool(), detail::widestTypeSigned(), detail::widestTypeSigned(),
82 "Compares the two integers.");
83 STANDARD_OPERATOR_2(signed_integer, LowerEqual, type::Bool(), detail::widestTypeSigned(), detail::widestTypeSigned(),
84 "Compares the two integers.");
85 STANDARD_OPERATOR_2(signed_integer, Modulo, detail::widestTypeSigned(), detail::widestTypeSigned(),
86 detail::widestTypeSigned(),
"Computes the modulus of the first integer divided by the second.");
87 STANDARD_OPERATOR_2(signed_integer, Multiple, detail::widestTypeSigned(), detail::widestTypeSigned(),
88 detail::widestTypeSigned(),
"Multiplies the first integer by the second.");
89 STANDARD_OPERATOR_2(signed_integer, MultipleAssign, operator_::sameTypeAs(0,
"int"),
90 type::SignedInteger(type::Wildcard()), operator_::sameTypeAs(0,
"int"),
91 "Multiplies the first value by the second, assigning the new value.");
92 STANDARD_OPERATOR_2(signed_integer, Power, detail::widestTypeSigned(), detail::widestTypeSigned(),
93 detail::widestTypeSigned(),
"Computes the first integer raised to the power of the second.");
94 STANDARD_OPERATOR_2(signed_integer, Sum, detail::widestTypeSigned(), detail::widestTypeSigned(),
95 detail::widestTypeSigned(),
"Computes the sum of the integers.");
96 STANDARD_OPERATOR_2(signed_integer, SumAssign, operator_::sameTypeAs(0,
"int"), type::SignedInteger(type::Wildcard()),
97 operator_::sameTypeAs(0,
"int"),
"Increments the first integer by the second.");
98 STANDARD_OPERATOR_2(signed_integer, Unequal, type::Bool(), detail::widestTypeSigned(), detail::widestTypeSigned(),
99 "Compares the two integers.");
100 STANDARD_OPERATOR_2x(signed_integer, CastToSigned, Cast, operator_::typedType(1,
"int<*>"),
101 type::SignedInteger(type::Wildcard()), type::Type_(type::SignedInteger(type::Wildcard())),
102 "Converts the value into another signed integer type, accepting any loss of information.");
103 STANDARD_OPERATOR_2x(signed_integer, CastToUnsigned, Cast, operator_::typedType(1,
"uint<*>"),
104 type::SignedInteger(type::Wildcard()), type::Type_(type::UnsignedInteger(type::Wildcard())),
105 "Converts the value into an unsigned integer type, accepting any loss of information.");
106 STANDARD_OPERATOR_2x(signed_integer, CastToReal, Cast, type::Real(), type::SignedInteger(type::Wildcard()),
107 type::Type_(type::Real()),
"Converts the value into a real, accepting any loss of information.");
108 STANDARD_OPERATOR_2x(signed_integer, CastToEnum, Cast, operator_::typedType(1,
"enum<*>"),
109 type::SignedInteger(type::Wildcard()), type::Type_(type::Enum(type::Wildcard())),
110 "Converts the value into an enum instance. The value does *not* need to correspond to " 111 "any of the target type's enumerator labels.");
112 STANDARD_OPERATOR_2x(signed_integer, CastToInterval, Cast, type::Interval(), type::SignedInteger(type::Wildcard()),
113 type::Type_(type::Interval()),
"Interprets the value as number of seconds.");
Definition: operator-registry.h:15