9 #include <hilti/ast/id.h> 10 #include <hilti/ast/node.h> 11 #include <hilti/base/type_erase.h> 22 namespace declaration {
47 using ResolvedState = std::set<uintptr_t>;
52 Constant = (1U << 0U),
55 NonConstant = (1U << 1U),
61 NoInheritScope = (1U << 2U),
65 PruneWalk = (1U << 3U),
76 Flags(Flag f) : _flags(static_cast<uint64_t>(f)) {}
82 bool has(Flag f)
const {
return _flags &
static_cast<uint64_t
>(f); }
85 void set(type::Flag flag,
bool set =
true) {
87 _flags |=
static_cast<uint64_t
>(flag);
89 _flags &= ~static_cast<uint64_t>(flag);
92 Flags operator+(Flag f) {
93 auto x =
Flags(*
this);
100 x._flags = _flags | other._flags;
104 Flags& operator+=(Flag f) {
109 _flags |= other._flags;
115 x._flags = _flags & ~other._flags;
119 Flags& operator-=(Flag f) {
124 _flags &= ~other._flags;
128 Flags& operator=(Flag f) {
135 bool operator==(
Flags other)
const {
return _flags == other._flags; }
137 bool operator!=(
Flags other)
const {
return _flags != other._flags; }
143 inline Flags operator+(Flag f1, Flag f2) {
return Flags(f1) + f2; }
148 std::optional<ID> id;
149 std::optional<ID> cxx;
150 std::optional<ID> resolved_id;
154 #include <hilti/autogen/__type.h> 159 class Type :
public type::detail::Type {
161 using type::detail::Type::Type;
163 std::optional<ID> resolvedID()
const {
return _state().resolved_id; }
165 void setCxxID(
ID id) { _state().cxx = std::move(
id); }
166 void setTypeID(
ID id) { _state().id = std::move(
id); }
167 void addFlag(type::Flag f) { _state().flags += f; }
170 bool hasFlag(type::Flag f)
const {
return _state().flags.has(f); }
174 bool _isConstant()
const {
return _state().flags.has(type::Flag::Constant); }
176 std::optional<ID>
typeID()
const {
return _state().id; }
178 std::optional<ID>
cxxID()
const {
return _state().cxx; }
184 bool pruneWalk()
const {
return hasFlag(type::Flag::PruneWalk); }
188 inline Node to_node(
Type t) {
return Node(std::move(t)); }
191 inline std::ostream& operator<<(std::ostream& out,
Type t) {
return out << to_node(std::move(t)); }
200 using NodeBase::NodeBase;
209 detail::applyPruneWalk(t);
222 x._state().flags += flags;
235 x._state().flags -= flags;
248 x._state().cxx = std::move(
id);
261 x._state().id = std::move(
id);
272 inline bool isAllocable(
const Type& t) {
return t._isAllocable(); }
275 inline bool isDereferenceable(
const Type& t) {
return t._isDereferenceable(); }
278 inline bool isIterable(
const Type& t) {
return t._isIterable(); }
281 inline bool isIterator(
const Type& t) {
return t._isIterator(); }
284 inline bool isParameterized(
const Type& t) {
return t._isParameterized(); }
287 inline bool isReferenceType(
const Type& t) {
return t._isReferenceType(); }
290 inline bool isMutable(
const Type& t) {
return t._isMutable(); }
293 inline bool isRuntimeNonTrivial(
const Type& t) {
return t._isRuntimeNonTrivial(); }
296 inline bool isView(
const Type& t) {
return t._isView(); }
299 inline bool isViewable(
const Type& t) {
return t._isViewable(); }
302 inline bool takesArguments(
const Type& t) {
return t._takesArguments(); }
311 inline bool isConstant(
const Type& t) {
312 return t.
flags().
has(type::Flag::Constant) || (! isMutable(t) && ! t.
flags().
has(type::Flag::NonConstant));
316 inline auto constant(
Type t) {
317 t.
_state().flags -= type::Flag::NonConstant;
318 t.
_state().flags += type::Flag::Constant;
326 inline auto nonConstant(
Type t,
bool force =
false) {
327 t.
_state().flags -= type::Flag::Constant;
330 t.
_state().flags += type::Flag::NonConstant;
337 extern bool isResolved(
const hilti::Type& t, ResolvedState* rstate);
339 inline bool isResolved(
const std::optional<hilti::Type>& t, ResolvedState* rstate) {
340 return t.has_value() ? isResolved(*t, rstate) :
true;
343 inline bool isResolved(
const std::optional<const hilti::Type>& t, ResolvedState* rstate) {
344 return t.has_value() ? isResolved(*t, rstate) :
true;
349 extern bool isResolved(
const Type& t);
352 inline bool isResolved(
const std::optional<Type>& t) {
return t.has_value() ? isResolved(*t) :
true; }
355 inline bool isResolved(
const std::optional<const Type>& t) {
return t.has_value() ? isResolved(*t) :
true; }
358 inline bool sameExceptForConstness(
const Type& t1,
const Type& t2) {
368 return t1.isEqual(t2) || t2.isEqual(t1);
373 inline bool operator==(
const Type& t1,
const Type& t2) {
377 if ( type::isMutable(t1) || type::isMutable(t2) ) {
378 if ( type::isConstant(t1) && ! type::isConstant(t2) )
381 if ( type::isConstant(t2) && ! type::isConstant(t1) )
393 return t1.isEqual(t2) || t2.isEqual(t1);
396 inline bool operator!=(
const Type& t1,
const Type& t2) {
return ! (t1 == t2); }
399 template<typename T, typename std::enable_if_t<std::is_base_of<trait::isType, T>::value>* =
nullptr>
400 inline Node to_node(T t) {
type::Flags flags() const
Definition: type.h:172
type::detail::State & _state()
Definition: type.h:182
std::optional< ID > cxxID() const
Definition: type.h:178
std::optional< ID > typeID() const
Definition: type.h:176
Definition: parameter.h:47
const type::detail::State & _state() const
Definition: type.h:180
bool has(Flag f) const
Definition: type.h:82
bool pruneWalk() const
Definition: type.h:184
bool hasFlag(type::Flag f) const
Definition: type.h:170
Definition: elements.cc:17
bool _isConstant() const
Definition: type.h:174