5 #include <unordered_set> 8 #include <hilti/ast/id.h> 9 #include <hilti/ast/node.h> 10 #include <hilti/base/type_erase.h> 21 namespace declaration {
46 using ResolvedState = std::unordered_set<uintptr_t>;
51 Constant = (1U << 0U),
54 NonConstant = (1U << 1U),
60 NoInheritScope = (1U << 2U),
64 PruneWalk = (1U << 3U),
75 Flags(Flag f) : _flags(static_cast<uint64_t>(f)) {}
81 bool has(Flag f)
const {
return _flags &
static_cast<uint64_t
>(f); }
84 void set(type::Flag flag,
bool set =
true) {
86 _flags |=
static_cast<uint64_t
>(flag);
88 _flags &= ~static_cast<uint64_t>(flag);
91 Flags operator+(Flag f) {
92 auto x =
Flags(*
this);
99 x._flags = _flags | other._flags;
103 Flags& operator+=(Flag f) {
108 _flags |= other._flags;
114 x._flags = _flags & ~other._flags;
118 Flags& operator-=(Flag f) {
123 _flags &= ~other._flags;
127 Flags& operator=(Flag f) {
134 bool operator==(
Flags other)
const {
return _flags == other._flags; }
136 bool operator!=(
Flags other)
const {
return _flags != other._flags; }
142 inline Flags operator+(Flag f1, Flag f2) {
return Flags(f1) + f2; }
147 std::optional<ID> id;
148 std::optional<ID> cxx;
149 std::optional<ID> resolved_id;
153 #include <hilti/autogen/__type.h> 158 class Type :
public type::detail::Type {
160 using type::detail::Type::Type;
162 std::optional<ID> resolvedID()
const {
return _state().resolved_id; }
164 void setCxxID(
ID id) { _state().cxx = std::move(
id); }
165 void setTypeID(
ID id) { _state().id = std::move(
id); }
166 void addFlag(type::Flag f) { _state().flags += f; }
169 bool hasFlag(type::Flag f)
const {
return _state().flags.has(f); }
173 bool _isConstant()
const {
return _state().flags.has(type::Flag::Constant); }
175 const std::optional<ID>&
typeID()
const {
return _state().id; }
177 const std::optional<ID>&
cxxID()
const {
return _state().cxx; }
183 bool pruneWalk()
const {
return hasFlag(type::Flag::PruneWalk); }
187 inline Node to_node(
Type t) {
return Node(std::move(t)); }
190 inline std::ostream& operator<<(std::ostream& out,
Type t) {
return out << to_node(std::move(t)); }
199 using NodeBase::NodeBase;
208 detail::applyPruneWalk(t);
221 x._state().flags += flags;
234 x._state().flags -= flags;
247 x._state().cxx = std::move(
id);
260 x._state().id = std::move(
id);
271 inline bool isAllocable(
const Type& t) {
return t._isAllocable(); }
274 inline bool isDereferenceable(
const Type& t) {
return t._isDereferenceable(); }
277 inline bool isIterable(
const Type& t) {
return t._isIterable(); }
280 inline bool isIterator(
const Type& t) {
return t._isIterator(); }
283 inline bool isParameterized(
const Type& t) {
return t._isParameterized(); }
286 inline bool isReferenceType(
const Type& t) {
return t._isReferenceType(); }
289 inline bool isMutable(
const Type& t) {
return t._isMutable(); }
292 inline bool isRuntimeNonTrivial(
const Type& t) {
return t._isRuntimeNonTrivial(); }
295 inline bool isView(
const Type& t) {
return t._isView(); }
298 inline bool isViewable(
const Type& t) {
return t._isViewable(); }
301 inline bool takesArguments(
const Type& t) {
return t._takesArguments(); }
310 inline bool isConstant(
const Type& t) {
311 return t.
flags().
has(type::Flag::Constant) || (! isMutable(t) && ! t.
flags().
has(type::Flag::NonConstant));
315 inline auto constant(
Type t) {
316 t.
_state().flags -= type::Flag::NonConstant;
317 t.
_state().flags += type::Flag::Constant;
325 inline auto nonConstant(
Type t,
bool force =
false) {
326 t.
_state().flags -= type::Flag::Constant;
329 t.
_state().flags += type::Flag::NonConstant;
336 extern bool isResolved(
const hilti::Type& t, ResolvedState* rstate);
338 inline bool isResolved(
const std::optional<hilti::Type>& t, ResolvedState* rstate) {
339 return t.has_value() ? isResolved(*t, rstate) :
true;
342 inline bool isResolved(
const std::optional<const hilti::Type>& t, ResolvedState* rstate) {
343 return t.has_value() ? isResolved(*t, rstate) :
true;
348 extern bool isResolved(
const Type& t);
351 inline bool isResolved(
const std::optional<Type>& t) {
return t.has_value() ? isResolved(*t) :
true; }
354 inline bool isResolved(
const std::optional<const Type>& t) {
return t.has_value() ? isResolved(*t) :
true; }
357 inline bool sameExceptForConstness(
const Type& t1,
const Type& t2) {
367 return t1.isEqual(t2) || t2.isEqual(t1);
372 inline bool operator==(
const Type& t1,
const Type& t2) {
376 if ( type::isMutable(t1) || type::isMutable(t2) ) {
377 if ( type::isConstant(t1) && ! type::isConstant(t2) )
380 if ( type::isConstant(t2) && ! type::isConstant(t1) )
392 return t1.isEqual(t2) || t2.isEqual(t1);
395 inline bool operator!=(
const Type& t1,
const Type& t2) {
return ! (t1 == t2); }
398 template<typename T, typename std::enable_if_t<std::is_base_of<trait::isType, T>::value>* =
nullptr>
399 inline Node to_node(T t) {
const std::optional< ID > & typeID() const
Definition: type.h:175
type::detail::State & _state()
Definition: type.h:181
const std::optional< ID > & cxxID() const
Definition: type.h:177
Definition: parameter.h:46
const type::detail::State & _state() const
Definition: type.h:179
bool has(Flag f) const
Definition: type.h:81
bool pruneWalk() const
Definition: type.h:183
bool hasFlag(type::Flag f) const
Definition: type.h:169
Definition: elements.cc:17
const type::Flags & flags() const
Definition: type.h:171
bool _isConstant() const
Definition: type.h:173