5 #include <hilti/ast/operators/common.h> 6 #include <hilti/ast/types/bool.h> 7 #include <hilti/ast/types/enum.h> 8 #include <hilti/ast/types/integer.h> 9 #include <hilti/ast/types/type.h> 10 #include <hilti/base/logger.h> 14 STANDARD_OPERATOR_2(enum_, Equal, type::Bool(), type::constant(type::Enum(type::Wildcard())),
15 operator_::sameTypeAs(0,
"enum<*>"),
"Compares two enum values.");
16 STANDARD_OPERATOR_2(enum_, Unequal, type::Bool(), type::constant(type::Enum(type::Wildcard())),
17 operator_::sameTypeAs(0,
"enum<*>"),
"Compares two enum values.");
19 enum_, CastToSignedInteger, Cast, operator_::typedType(1,
"int"), type::Enum(type::Wildcard()),
20 type::Type_(type::SignedInteger(type::Wildcard())),
21 "Casts an enum value into a signed integer. If the enum value is ``Undef``, this will return ``-1``.");
23 enum_, CastToUnsignedInteger, Cast, operator_::typedType(1,
"uint"), type::Enum(type::Wildcard()),
24 type::Type_(type::UnsignedInteger(type::Wildcard())),
25 "Casts an enum value into a unsigned integer. This will throw an exception if the enum value is ``Undef``.");
27 BEGIN_CTOR(enum_, CtorSigned)
28 auto ctorType()
const {
return type::Enum(type::Wildcard()); }
30 auto signature()
const {
31 return Signature{.args = {{.id =
"value", .type = type::SignedInteger(type::Wildcard())}}, .doc = R
"( 32 Instantiates an enum instance initialized from a signed integer value. The value does 33 *not* need to correspond to any of the type's enumerator labels. 38 BEGIN_CTOR(enum_, CtorUnsigned) 39 auto ctorType()
const {
return type::Enum(type::Wildcard()); }
41 auto signature()
const {
42 return Signature{.args = {{.id =
"value", .type = type::UnsignedInteger(type::Wildcard())}}, .doc = R
"( 43 Instantiates an enum instance initialized from an unsigned integer 44 value. The value does *not* need to correspond to any of the type's 45 enumerator labels. It must not be larger than the maximum that a 46 *signed* 64-bit integer value can represent. 51 BEGIN_METHOD(enum_, HasLabel) 52 auto signature()
const {
53 return Signature{.self = type::constant(type::Enum(type::Wildcard())),
54 .result = type::Bool(),
58 Returns *true* if the value of *op1* corresponds to a known enum label (other 59 than ``Undef``), as defined by it's type. Definition: operator-registry.h:16