5 #include <unordered_set> 8 #include <hilti/ast/id.h> 9 #include <hilti/ast/node.h> 10 #include <hilti/base/type_erase.h> 11 #include <hilti/base/util.h> 22 namespace declaration {
48 using ResolvedState = std::unordered_set<uintptr_t>;
53 Constant = (1U << 0U),
56 NonConstant = (1U << 1U),
62 NoInheritScope = (1U << 2U),
66 PruneWalk = (1U << 3U),
77 Flags(Flag f) : _flags(static_cast<uint64_t>(f)) {}
83 bool has(Flag f)
const {
return _flags &
static_cast<uint64_t
>(f); }
86 void set(type::Flag flag,
bool set =
true) {
88 _flags |=
static_cast<uint64_t
>(flag);
90 _flags &= ~static_cast<uint64_t>(flag);
93 Flags operator+(Flag f) {
94 auto x =
Flags(*
this);
101 x._flags = _flags | other._flags;
105 Flags& operator+=(Flag f) {
110 _flags |= other._flags;
116 x._flags = _flags & ~other._flags;
120 Flags& operator-=(Flag f) {
125 _flags &= ~other._flags;
129 Flags& operator=(Flag f) {
136 bool operator==(
Flags other)
const {
return _flags == other._flags; }
138 bool operator!=(
Flags other)
const {
return _flags != other._flags; }
144 inline Flags operator+(Flag f1, Flag f2) {
return Flags(f1) + f2; }
149 std::optional<ID> id;
150 std::optional<ID> cxx;
151 std::optional<ID> resolved_id;
155 #include <hilti/autogen/__type.h> 160 class Type :
public type::detail::Type {
162 using type::detail::Type::Type;
164 std::optional<ID> resolvedID()
const {
return _state().resolved_id; }
166 void setCxxID(
ID id) {
168 if ( ! util::startsWith(
id,
"::") )
169 _state().cxx = util::fmt(
"::%s",
id);
171 _state().cxx = std::move(
id);
174 void setTypeID(
ID id) { _state().id = std::move(
id); }
175 void addFlag(type::Flag f) { _state().flags += f; }
178 bool hasFlag(type::Flag f)
const {
return _state().flags.has(f); }
182 bool _isConstant()
const {
return _state().flags.has(type::Flag::Constant); }
184 const std::optional<ID>&
typeID()
const {
return _state().id; }
186 const std::optional<ID>&
cxxID()
const {
return _state().cxx; }
192 bool pruneWalk()
const {
return hasFlag(type::Flag::PruneWalk); }
196 inline Node to_node(
Type t) {
return Node(std::move(t)); }
199 inline std::ostream& operator<<(std::ostream& out,
Type t) {
return out << to_node(std::move(t)); }
208 using NodeBase::NodeBase;
217 detail::applyPruneWalk(t);
230 x._state().flags += flags;
243 x._state().flags -= flags;
256 x._state().cxx = std::move(
id);
269 x._state().id = std::move(
id);
280 inline bool isAllocable(
const Type& t) {
return t._isAllocable(); }
283 inline bool isSortable(
const Type& t) {
return t._isSortable(); }
286 inline bool isDereferenceable(
const Type& t) {
return t._isDereferenceable(); }
289 inline bool isIterable(
const Type& t) {
return t._isIterable(); }
292 inline bool isIterator(
const Type& t) {
return t._isIterator(); }
295 inline bool isParameterized(
const Type& t) {
return t._isParameterized(); }
298 inline bool isReferenceType(
const Type& t) {
return t._isReferenceType(); }
301 inline bool isMutable(
const Type& t) {
return t._isMutable(); }
304 inline bool isRuntimeNonTrivial(
const Type& t) {
return t._isRuntimeNonTrivial(); }
307 inline bool isView(
const Type& t) {
return t._isView(); }
310 inline bool isViewable(
const Type& t) {
return t._isViewable(); }
313 inline bool takesArguments(
const Type& t) {
return t._takesArguments(); }
322 inline bool isConstant(
const Type& t) {
323 return t.
flags().
has(type::Flag::Constant) || (! isMutable(t) && ! t.
flags().
has(type::Flag::NonConstant));
327 inline auto constant(
Type t) {
328 t.
_state().flags -= type::Flag::NonConstant;
329 t.
_state().flags += type::Flag::Constant;
337 inline auto nonConstant(
Type t,
bool force =
false) {
338 t.
_state().flags -= type::Flag::Constant;
341 t.
_state().flags += type::Flag::NonConstant;
348 extern bool isResolved(
const hilti::Type& t, ResolvedState* rstate);
350 inline bool isResolved(
const std::optional<hilti::Type>& t, ResolvedState* rstate) {
351 return t.has_value() ? isResolved(*t, rstate) :
true;
354 inline bool isResolved(
const std::optional<const hilti::Type>& t, ResolvedState* rstate) {
355 return t.has_value() ? isResolved(*t, rstate) :
true;
360 extern bool isResolved(
const Type& t);
363 inline bool isResolved(
const std::optional<Type>& t) {
return t.has_value() ? isResolved(*t) :
true; }
366 inline bool isResolved(
const std::optional<const Type>& t) {
return t.has_value() ? isResolved(*t) :
true; }
369 inline bool sameExceptForConstness(
const Type& t1,
const Type& t2) {
379 return t1.isEqual(t2) || t2.isEqual(t1);
384 inline bool operator==(
const Type& t1,
const Type& t2) {
388 if ( type::isMutable(t1) || type::isMutable(t2) ) {
389 if ( type::isConstant(t1) && ! type::isConstant(t2) )
392 if ( type::isConstant(t2) && ! type::isConstant(t1) )
404 return t1.isEqual(t2) || t2.isEqual(t1);
407 inline bool operator!=(
const Type& t1,
const Type& t2) {
return ! (t1 == t2); }
410 template<typename T, typename std::enable_if_t<std::is_base_of<trait::isType, T>::value>* =
nullptr>
411 inline Node to_node(T t) {
const std::optional< ID > & typeID() const
Definition: type.h:184
type::detail::State & _state()
Definition: type.h:190
const std::optional< ID > & cxxID() const
Definition: type.h:186
Definition: parameter.h:46
const type::detail::State & _state() const
Definition: type.h:188
bool has(Flag f) const
Definition: type.h:83
bool pruneWalk() const
Definition: type.h:192
bool hasFlag(type::Flag f) const
Definition: type.h:178
Definition: elements.cc:17
const type::Flags & flags() const
Definition: type.h:180
bool _isConstant() const
Definition: type.h:182