8 #include <hilti/ast/id.h> 9 #include <hilti/ast/node.h> 10 #include <hilti/base/type_erase.h> 40 Constant = (1U << 0U),
46 NoInheritScope = (1U << 1U),
57 Flags(Flag f) : _flags(static_cast<uint64_t>(f)) {}
63 bool has(Flag f)
const {
return _flags &
static_cast<uint64_t
>(f); }
66 void set(type::Flag flag,
bool set =
true) {
68 _flags |=
static_cast<uint64_t
>(flag);
70 _flags &= ~static_cast<uint64_t>(flag);
73 Flags operator+(Flag f) {
74 auto x =
Flags(*
this);
81 x._flags = _flags | other._flags;
85 Flags& operator+=(Flag f) {
90 _flags |= other._flags;
96 x._flags = _flags & ~other._flags;
100 Flags& operator-=(Flag f) {
105 _flags &= ~other._flags;
109 Flags& operator=(Flag f) {
116 bool operator==(
Flags other)
const {
return _flags == other._flags; }
118 bool operator!=(
Flags other)
const {
return _flags != other._flags; }
124 inline Flags operator+(Flag f1, Flag f2) {
return Flags(f1) + f2; }
129 std::optional<ID> id;
130 std::optional<ID> cxx;
134 #include <hilti/autogen/__type.h> 137 inline Node to_node(Type t) {
return Node(std::move(t)); }
140 inline std::ostream& operator<<(std::ostream& out, Type t) {
return out << to_node(std::move(t)); }
145 using Type = type::detail::Type;
154 using NodeBase::NodeBase;
157 bool hasFlag(type::Flag f)
const {
return _state().flags.has(f); }
161 bool _isConstant()
const {
return _state().flags.has(type::Flag::Constant); }
163 std::optional<ID>
typeID()
const {
return _state().id; }
165 std::optional<ID>
cxxID()
const {
return _state().cxx; }
186 x._state().flags += flags;
197 inline hilti::Type removeFlags(
const Type& t,
const type::Flags& flags) {
199 x._state().flags -= flags;
213 inline hilti::Type setConstant(
const Type& t,
bool const_) {
215 x._state().flags.set(type::Flag::Constant, const_);
226 inline hilti::Type setCxxID(
const Type& t,
ID id) {
228 x._state().cxx = std::move(
id);
239 inline hilti::Type setTypeID(
const Type& t,
ID id) {
241 x._state().id = std::move(
id);
257 inline Type effectiveType(Type t) {
return t._hasDynamicType() ? t.effectiveType() : std::move(t); }
263 inline std::optional<Type> effectiveOptionalType(std::optional<Type> t) {
265 return effectiveType(*t);
271 inline bool isAllocable(
const Type& t) {
return effectiveType(t)._isAllocable(); }
274 inline bool isDereferencable(
const Type& t) {
return effectiveType(t)._isDereferencable(); }
277 inline bool isIterable(
const Type& t) {
return effectiveType(t)._isIterable(); }
280 inline bool isIterator(
const Type& t) {
return effectiveType(t)._isIterator(); }
283 inline bool isParameterized(
const Type& t) {
return effectiveType(t)._isParameterized(); }
286 inline bool isReferenceType(
const Type& t) {
return effectiveType(t)._isReferenceType(); }
289 inline bool isMutable(
const Type& t) {
return effectiveType(t)._isMutable(); }
292 inline bool isRuntimeNonTrivial(
const Type& t) {
return effectiveType(t)._isRuntimeNonTrivial(); }
295 inline bool isView(
const Type& t) {
return effectiveType(t)._isView(); }
298 inline bool isViewable(
const Type& t) {
return effectiveType(t)._isViewable(); }
301 inline bool isOnHeap(
const Type& t) {
return effectiveType(t)._isOnHeap(); }
310 inline bool isConstant(
const Type& t) {
return effectiveType(t).flags().has(type::Flag::Constant); }
313 inline auto constant(
const Type& t) {
return setConstant(t,
true); }
316 inline auto nonConstant(
const Type& t) {
return setConstant(t,
false); }
319 inline auto transferConstness(
const Type& t,
const Type& from) {
return setConstant(t, isConstant(from)); }
322 inline bool operator==(
const Type& t1,
const Type& t2) {
326 if ( type::isConstant(t1) != type::isConstant(t2) )
329 if ( t1.cxxID() && t2.cxxID() )
330 return t1.cxxID() == t2.cxxID();
332 if ( (t1.flags() - type::Flag::Constant) != (t2.flags() - type::Flag::Constant) )
337 return t1.isEqual(t2) || t2.isEqual(t1);
340 inline bool operator!=(
const Type& t1,
const Type& t2) {
return ! (t1 == t2); }
348 inline bool isConstCompatible(
const Type& src,
const Type& dst) {
349 if ( type::isConstant(dst) )
352 return ! type::isConstant(src);
356 inline bool sameExceptForConstness(
const Type& t1,
const Type& t2) {
return t1.isEqual(t2) || t2.isEqual(t1); }
361 template<typename T, typename std::enable_if_t<std::is_base_of<trait::isType, T>::value>* =
nullptr>
362 inline Node to_node(T t) {
363 return Node(Type(std::move(t)));
std::optional< ID > cxxID() const
Definition: type.h:165
type::Flags flags() const
Definition: type.h:159
bool hasFlag(type::Flag f) const
Definition: type.h:157
const type::detail::State & _state() const
Definition: type.h:167
type::detail::State & _state()
Definition: type.h:169
std::optional< ID > typeID() const
Definition: type.h:163
bool has(Flag f) const
Definition: type.h:63
Definition: elements.cc:17
bool _isConstant() const
Definition: type.h:161