17 #ifndef LLVM_CLANG_AST_TYPE_H 18 #define LLVM_CLANG_AST_TYPE_H 32 #include "llvm/ADT/APInt.h" 33 #include "llvm/ADT/APSInt.h" 34 #include "llvm/ADT/ArrayRef.h" 35 #include "llvm/ADT/FoldingSet.h" 36 #include "llvm/ADT/None.h" 37 #include "llvm/ADT/Optional.h" 38 #include "llvm/ADT/PointerIntPair.h" 39 #include "llvm/ADT/PointerUnion.h" 40 #include "llvm/ADT/StringRef.h" 41 #include "llvm/ADT/Twine.h" 42 #include "llvm/ADT/iterator_range.h" 43 #include "llvm/Support/Casting.h" 44 #include "llvm/Support/Compiler.h" 45 #include "llvm/Support/ErrorHandling.h" 46 #include "llvm/Support/PointerLikeTypeTraits.h" 47 #include "llvm/Support/type_traits.h" 48 #include "llvm/Support/TrailingObjects.h" 54 #include <type_traits> 102 template <
typename>
class CanQual;
107 class ExtQualsTypeCommonBase;
109 class IdentifierInfo;
111 class ObjCInterfaceDecl;
112 class ObjCProtocolDecl;
113 class ObjCTypeParamDecl;
114 struct PrintingPolicy;
118 class TemplateArgument;
119 class TemplateArgumentListInfo;
120 class TemplateArgumentLoc;
121 class TemplateTypeParmDecl;
122 class TypedefNameDecl;
123 class UnresolvedUsingTypenameDecl;
128 #define TYPE(Class, Base) class Class##Type; 129 #include "clang/AST/TypeNodes.inc" 143 CVRMask =
Const | Volatile | Restrict
177 MaxAddressSpace = 0x7fffffu,
183 FastMask = (1 << FastWidth) - 1
190 if (!(L.Mask & ~CVRMask) && !(R.Mask & ~CVRMask)) {
192 Q.Mask = L.Mask & R.Mask;
274 assert(!(mask & ~CVRMask) &&
"bitmask contains non-CVR bits");
275 Mask = (Mask & ~CVRMask) | mask;
278 assert(!(mask & ~CVRMask) &&
"bitmask contains non-CVR bits");
282 removeCVRQualifiers(CVRMask);
285 assert(!(mask & ~CVRMask) &&
"bitmask contains non-CVR bits");
289 assert(!(mask & ~CVRMask & ~UMask) &&
"bitmask contains non-CVRU bits");
295 Mask = (Mask & ~UMask) | (flag ? UMask : 0);
303 Mask = (Mask & ~GCAttrMask) | (type << GCAttrShift);
328 return ObjCLifetime((Mask & LifetimeMask) >> LifetimeShift);
331 Mask = (Mask & ~LifetimeMask) | (type << LifetimeShift);
336 assert(!hasObjCLifetime());
337 Mask |= (type << LifetimeShift);
343 return (lifetime > OCL_ExplicitNone);
349 return (lifetime == OCL_Strong || lifetime == OCL_Weak);
354 return static_cast<LangAS>(Mask >> AddressSpaceShift);
361 auto Addr = getAddressSpace();
374 assert((
unsigned)space <= MaxAddressSpace);
375 Mask = (Mask & ~AddressSpaceMask)
376 | (((uint32_t) space) << AddressSpaceShift);
381 setAddressSpace(space);
389 assert(!(mask & ~FastMask) &&
"bitmask contains non-fast qualifier bits");
390 Mask = (Mask & ~FastMask) | mask;
393 assert(!(mask & ~FastMask) &&
"bitmask contains non-fast qualifier bits");
397 removeFastQualifiers(FastMask);
400 assert(!(mask & ~FastMask) &&
"bitmask contains non-fast qualifier bits");
415 bool empty()
const {
return !Mask; }
421 if (!(Q.Mask & ~CVRMask))
424 Mask |= (Q.Mask & CVRMask);
438 if (!(Q.Mask & ~CVRMask))
441 Mask &= ~(Q.Mask & CVRMask);
445 removeObjCLifetime();
447 removeAddressSpace();
481 return isAddressSpaceSupersetOf(getAddressSpace(), other.
getAddressSpace());
488 return isAddressSpaceSupersetOf(other) &&
491 (getObjCGCAttr() == other.
getObjCGCAttr() || !hasObjCGCAttr() ||
496 (((Mask & CVRMask) | (other.Mask & CVRMask)) == (Mask & CVRMask)) &&
512 if (getObjCLifetime() == OCL_Weak || other.
getObjCLifetime() == OCL_Weak)
515 if (getObjCLifetime() == OCL_None || other.
getObjCLifetime() == OCL_None)
523 bool isStrictSupersetOf(
Qualifiers Other)
const;
528 explicit operator bool()
const {
return hasQualifiers(); }
558 bool appendSpaceIfNonEmpty =
false)
const;
569 static const uint32_t UMask = 0x8;
570 static const uint32_t UShift = 3;
571 static const uint32_t GCAttrMask = 0x30;
572 static const uint32_t GCAttrShift = 4;
573 static const uint32_t LifetimeMask = 0x1C0;
574 static const uint32_t LifetimeShift = 6;
575 static const uint32_t AddressSpaceMask =
576 ~(CVRMask | UMask | GCAttrMask | LifetimeMask);
577 static const uint32_t AddressSpaceShift = 9;
595 std::pair<const Type *,Qualifiers>
asPair()
const {
596 return std::pair<const Type *, Qualifiers>(Ty, Quals);
647 llvm::PointerIntPair<llvm::PointerUnion<const Type *, const ExtQuals *>,
650 const ExtQuals *getExtQualsUnsafe()
const {
651 return Value.getPointer().get<
const ExtQuals*>();
654 const Type *getTypePtrUnsafe()
const {
655 return Value.getPointer().get<
const Type*>();
659 assert(!isNull() &&
"Cannot retrieve a NULL type pointer");
660 auto CommonPtrVal =
reinterpret_cast<uintptr_t>(Value.getOpaqueValue());
677 const Type *getTypePtr()
const;
679 const Type *getTypePtrOrNull()
const;
692 T.Value.setFromOpaqueValue(const_cast<void*>(Ptr));
697 return *getTypePtr();
704 bool isCanonical()
const;
705 bool isCanonicalAsParam()
const;
709 return Value.getPointer().isNull();
720 bool isConstQualified()
const;
730 bool isRestrictQualified()
const;
740 bool isVolatileQualified()
const;
746 return getLocalFastQualifiers() || hasLocalNonFastQualifiers();
750 bool hasQualifiers()
const;
756 return Value.getPointer().is<
const ExtQuals*>();
771 return getLocalFastQualifiers();
776 unsigned getCVRQualifiers()
const;
783 bool isPODType(
const ASTContext &Context)
const;
787 bool isCXX98PODType(
const ASTContext &Context)
const;
793 bool isCXX11PODType(
const ASTContext &Context)
const;
796 bool isTrivialType(
const ASTContext &Context)
const;
799 bool isTriviallyCopyableType(
const ASTContext &Context)
const;
803 bool mayBeDynamicClass()
const;
806 bool mayBeNotDynamicClass()
const;
836 return withFastQualifiers(CVR);
841 &&
"non-fast qualifier bits set in mask!");
842 Value.setInt(Value.getInt() | TQs);
845 void removeLocalConst();
846 void removeLocalVolatile();
847 void removeLocalRestrict();
848 void removeLocalCVRQualifiers(
unsigned Mask);
853 Value.setInt(Value.getInt() & ~Mask);
902 inline QualType getUnqualifiedType()
const;
917 bool isMoreQualifiedThan(
QualType Other)
const;
921 bool isAtLeastAsQualifiedAs(
QualType Other)
const;
923 QualType getNonReferenceType()
const;
944 return getDesugaredType(*
this, Context);
948 return getSplitDesugaredType(*
this);
957 return getSingleStepDesugaredTypeImpl(*
this, Context);
963 if (isa<ParenType>(*
this))
970 return LHS.Value == RHS.Value;
973 return LHS.Value != RHS.Value;
976 return LHS.Value < RHS.Value;
990 const Twine &PlaceHolder = Twine(),
991 unsigned Indentation = 0)
const;
995 unsigned Indentation = 0) {
996 return print(split.
Ty, split.
Quals, OS, policy, PlaceHolder, Indentation);
1001 const Twine &PlaceHolder,
1002 unsigned Indentation = 0);
1004 void getAsStringInternal(std::string &Str,
1009 return getAsStringInternal(split.
Ty, split.
Quals, out, policy);
1019 const Twine &PlaceHolder;
1020 unsigned Indentation;
1024 const Twine &PlaceHolder,
unsigned Indentation)
1025 : T(T), Policy(Policy), PlaceHolder(PlaceHolder),
1026 Indentation(Indentation) {}
1030 SQT.T.
print(OS, SQT.Policy, SQT.PlaceHolder, SQT.Indentation);
1036 const Twine &PlaceHolder = Twine(),
1037 unsigned Indentation = 0)
const {
1041 void dump(
const char *s)
const;
1043 void dump(llvm::raw_ostream &OS)
const;
1046 ID.AddPointer(getAsOpaquePtr());
1050 inline LangAS getAddressSpace()
const;
1079 bool isNonWeakInMRRWithObjCWeak(
const ASTContext &Context)
const;
1105 isNonTrivialToPrimitiveDefaultInitialize()
const;
1153 DK_nontrivial_c_struct
1161 return isDestructedTypeImpl(*
this);
1168 bool hasNonTrivialToPrimitiveDefaultInitializeCUnion()
const;
1173 bool hasNonTrivialToPrimitiveDestructCUnion()
const;
1178 bool hasNonTrivialToPrimitiveCopyCUnion()
const;
1190 bool isCForbiddenLValueType()
const;
1238 QualType getAtomicUnqualifiedType()
const;
1254 static bool hasNonTrivialToPrimitiveDefaultInitializeCUnion(
const RecordDecl *RD);
1255 static bool hasNonTrivialToPrimitiveDestructCUnion(
const RecordDecl *RD);
1256 static bool hasNonTrivialToPrimitiveCopyCUnion(
const RecordDecl *RD);
1285 enum { NumLowBitsAvailable = 0 };
1305 const Type *
const BaseType;
1311 : BaseType(baseType), CanonicalType(canon) {}
1347 canon.isNull() ?
QualType(this_(), 0) : canon),
1350 &&
"ExtQuals created with no fast qualifiers");
1352 &&
"ExtQuals created with fast qualifiers");
1372 Profile(ID, getBaseType(), Quals);
1376 const Type *BaseType,
1379 ID.AddPointer(BaseType);
1439 #define TYPE(Class, Base) Class, 1440 #define LAST_TYPE(Class) TypeLast = Class 1441 #define ABSTRACT_TYPE(Class, Base) 1442 #include "clang/AST/TypeNodes.inc" 1447 class TypeBitfields {
1449 template <
class T>
friend class TypePropertyCache;
1455 unsigned Dependent : 1;
1459 unsigned InstantiationDependent : 1;
1462 unsigned VariablyModified : 1;
1466 unsigned ContainsUnexpandedParameterPack : 1;
1470 mutable unsigned CacheValid : 1;
1473 mutable unsigned CachedLinkage : 3;
1476 mutable unsigned CachedLocalOrUnnamed : 1;
1479 mutable unsigned FromAST : 1;
1481 bool isCacheValid()
const {
1486 assert(isCacheValid() &&
"getting linkage from invalid cache");
1487 return static_cast<Linkage>(CachedLinkage);
1490 bool hasLocalOrUnnamedType()
const {
1491 assert(isCacheValid() &&
"getting linkage from invalid cache");
1492 return CachedLocalOrUnnamed;
1495 enum { NumTypeBits = 18 };
1504 unsigned : NumTypeBits;
1508 unsigned IndexTypeQuals : 3;
1513 unsigned SizeModifier : 3;
1519 unsigned : NumTypeBits + 3 + 3;
1522 unsigned HasStoredSizeExpr : 1;
1528 unsigned : NumTypeBits;
1541 unsigned : NumTypeBits;
1545 unsigned ExtInfo : 12;
1550 unsigned RefQualifier : 2;
1560 unsigned HasExtQuals : 1;
1566 unsigned NumParams : 16;
1569 unsigned ExceptionSpecType : 4;
1572 unsigned HasExtParameterInfos : 1;
1575 unsigned Variadic : 1;
1578 unsigned HasTrailingReturn : 1;
1584 unsigned : NumTypeBits;
1587 unsigned NumTypeArgs : 7;
1590 unsigned NumProtocols : 6;
1593 unsigned IsKindOf : 1;
1599 unsigned : NumTypeBits;
1612 unsigned SpelledAsLValue : 1;
1616 unsigned InnerRef : 1;
1622 unsigned : NumTypeBits;
1625 unsigned Keyword : 8;
1628 enum { NumTypeWithKeywordBits = 8 };
1633 unsigned : NumTypeBits;
1634 unsigned : NumTypeWithKeywordBits;
1637 unsigned HasOwnedTagDecl : 1;
1644 unsigned : NumTypeBits;
1648 unsigned VecKind : 3;
1651 unsigned NumElements : 29 - NumTypeBits;
1653 enum { MaxNumElements = (1 << (29 - NumTypeBits)) - 1 };
1659 unsigned : NumTypeBits;
1662 unsigned AttrKind : 32 - NumTypeBits;
1668 unsigned : NumTypeBits;
1672 unsigned Keyword : 2;
1678 unsigned : NumTypeBits;
1693 unsigned : NumTypeBits;
1696 unsigned TypeAlias : 1;
1711 unsigned : NumTypeBits;
1712 unsigned : NumTypeWithKeywordBits;
1727 unsigned : NumTypeBits;
1740 unsigned NumExpansions;
1762 static_assert(
sizeof(TypeBitfields) <= 8,
1763 "TypeBitfields is larger than 8 bytes!");
1765 "ArrayTypeBitfields is larger than 8 bytes!");
1767 "AttributedTypeBitfields is larger than 8 bytes!");
1769 "AutoTypeBitfields is larger than 8 bytes!");
1771 "BuiltinTypeBitfields is larger than 8 bytes!");
1773 "FunctionTypeBitfields is larger than 8 bytes!");
1775 "ObjCObjectTypeBitfields is larger than 8 bytes!");
1777 "ReferenceTypeBitfields is larger than 8 bytes!");
1779 "TypeWithKeywordBitfields is larger than 8 bytes!");
1781 "ElaboratedTypeBitfields is larger than 8 bytes!");
1783 "VectorTypeBitfields is larger than 8 bytes!");
1785 "SubstTemplateTypeParmPackTypeBitfields is larger" 1788 "TemplateSpecializationTypeBitfields is larger" 1791 "DependentTemplateSpecializationTypeBitfields is larger" 1794 "PackExpansionTypeBitfields is larger than 8 bytes");
1801 void setFromAST(
bool V =
true)
const {
1802 TypeBits.FromAST =
V;
1809 bool InstantiationDependent,
bool VariablyModified,
1810 bool ContainsUnexpandedParameterPack)
1812 canon.isNull() ?
QualType(this_(), 0) : canon) {
1814 TypeBits.Dependent = Dependent;
1815 TypeBits.InstantiationDependent = Dependent || InstantiationDependent;
1816 TypeBits.VariablyModified = VariablyModified;
1817 TypeBits.ContainsUnexpandedParameterPack = ContainsUnexpandedParameterPack;
1818 TypeBits.CacheValid =
false;
1819 TypeBits.CachedLocalOrUnnamed =
false;
1821 TypeBits.FromAST =
false;
1828 TypeBits.Dependent = D;
1830 TypeBits.InstantiationDependent =
true;
1834 TypeBits.InstantiationDependent = D; }
1839 TypeBits.ContainsUnexpandedParameterPack = PP;
1848 Type &operator=(
const Type &) =
delete;
1872 return TypeBits.ContainsUnexpandedParameterPack;
1878 return CanonicalType ==
QualType(
this, 0);
1884 QualType getLocallyUnqualifiedSingleStepDesugaredType()
const;
1897 bool isIncompleteType(
NamedDecl **Def =
nullptr)
const;
1902 return !isFunctionType();
1910 return !isReferenceType() && !isFunctionType() && !isVoidType();
1915 bool isLiteralType(
const ASTContext &Ctx)
const;
1919 bool isStandardLayoutType()
const;
1925 bool isBuiltinType()
const;
1928 bool isSpecificBuiltinType(
unsigned K)
const;
1933 bool isPlaceholderType()
const;
1937 bool isSpecificPlaceholderType(
unsigned K)
const;
1941 bool isNonOverloadPlaceholderType()
const;
1945 bool isIntegerType()
const;
1946 bool isEnumeralType()
const;
1949 bool isScopedEnumeralType()
const;
1952 bool isWideCharType()
const;
1953 bool isChar8Type()
const;
1954 bool isChar16Type()
const;
1955 bool isChar32Type()
const;
1956 bool isAnyCharacterType()
const;
1957 bool isIntegralType(
const ASTContext &Ctx)
const;
1960 bool isIntegralOrEnumerationType()
const;
1963 bool isIntegralOrUnscopedEnumerationType()
const;
1966 bool isRealFloatingType()
const;
1969 bool isComplexType()
const;
1970 bool isAnyComplexType()
const;
1971 bool isFloatingType()
const;
1972 bool isHalfType()
const;
1973 bool isFloat16Type()
const;
1974 bool isFloat128Type()
const;
1975 bool isRealType()
const;
1976 bool isArithmeticType()
const;
1977 bool isVoidType()
const;
1978 bool isScalarType()
const;
1979 bool isAggregateType()
const;
1980 bool isFundamentalType()
const;
1981 bool isCompoundType()
const;
1985 bool isFunctionType()
const;
1988 bool isPointerType()
const;
1989 bool isAnyPointerType()
const;
1990 bool isBlockPointerType()
const;
1991 bool isVoidPointerType()
const;
1992 bool isReferenceType()
const;
1993 bool isLValueReferenceType()
const;
1994 bool isRValueReferenceType()
const;
1995 bool isFunctionPointerType()
const;
1996 bool isFunctionReferenceType()
const;
1997 bool isMemberPointerType()
const;
1998 bool isMemberFunctionPointerType()
const;
1999 bool isMemberDataPointerType()
const;
2000 bool isArrayType()
const;
2001 bool isConstantArrayType()
const;
2002 bool isIncompleteArrayType()
const;
2003 bool isVariableArrayType()
const;
2004 bool isDependentSizedArrayType()
const;
2006 bool isClassType()
const;
2007 bool isStructureType()
const;
2008 bool isObjCBoxableRecordType()
const;
2009 bool isInterfaceType()
const;
2010 bool isStructureOrClassType()
const;
2011 bool isUnionType()
const;
2012 bool isComplexIntegerType()
const;
2013 bool isVectorType()
const;
2014 bool isExtVectorType()
const;
2015 bool isDependentAddressSpaceType()
const;
2016 bool isObjCObjectPointerType()
const;
2017 bool isObjCRetainableType()
const;
2018 bool isObjCLifetimeType()
const;
2019 bool isObjCIndirectLifetimeType()
const;
2020 bool isObjCNSObjectType()
const;
2021 bool isObjCIndependentClassType()
const;
2024 bool isObjCObjectType()
const;
2025 bool isObjCQualifiedInterfaceType()
const;
2026 bool isObjCQualifiedIdType()
const;
2027 bool isObjCQualifiedClassType()
const;
2028 bool isObjCObjectOrInterfaceType()
const;
2029 bool isObjCIdType()
const;
2030 bool isDecltypeType()
const;
2038 return hasAttr(attr::ObjCInertUnsafeUnretained);
2048 bool isObjCIdOrObjectKindOfType(
const ASTContext &ctx,
2051 bool isObjCClassType()
const;
2059 bool isObjCClassOrClassKindOfType()
const;
2061 bool isBlockCompatibleObjCPointerType(
ASTContext &ctx)
const;
2062 bool isObjCSelType()
const;
2063 bool isObjCBuiltinType()
const;
2064 bool isObjCARCBridgableType()
const;
2065 bool isCARCBridgableType()
const;
2066 bool isTemplateTypeParmType()
const;
2067 bool isNullPtrType()
const;
2068 bool isNothrowT()
const;
2069 bool isAlignValT()
const;
2070 bool isStdByteType()
const;
2071 bool isAtomicType()
const;
2073 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ 2074 bool is##Id##Type() const; 2075 #include "clang/Basic/OpenCLImageTypes.def" 2077 bool isImageType()
const;
2079 bool isSamplerT()
const;
2080 bool isEventT()
const;
2081 bool isClkEventT()
const;
2082 bool isQueueT()
const;
2083 bool isReserveIDT()
const;
2085 #define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \ 2086 bool is##Id##Type() const; 2087 #include "clang/Basic/OpenCLExtensionTypes.def" 2089 bool isOCLIntelSubgroupAVCType()
const;
2090 bool isOCLExtOpaqueType()
const;
2092 bool isPipeType()
const;
2093 bool isOpenCLSpecificType()
const;
2098 bool isObjCARCImplicitlyUnretainedType()
const;
2128 return TypeBits.InstantiationDependent;
2134 bool isUndeducedType()
const;
2141 bool hasSizedVLAType()
const;
2144 bool hasUnnamedOrLocalType()
const;
2146 bool isOverloadableType()
const;
2149 bool isElaboratedTypeSpecifier()
const;
2151 bool canDecayToPointerType()
const;
2156 bool hasPointerRepresentation()
const;
2160 bool hasObjCPointerRepresentation()
const;
2164 bool hasIntegerRepresentation()
const;
2168 bool hasSignedIntegerRepresentation()
const;
2172 bool hasUnsignedIntegerRepresentation()
const;
2176 bool hasFloatingRepresentation()
const;
2181 const RecordType *getAsStructureType()
const;
2184 const ComplexType *getAsComplexIntegerType()
const;
2205 TagDecl *getAsTagDecl()
const;
2223 return dyn_cast_or_null<AutoType>(getContainedDeducedType());
2229 bool hasAutoForTrailingReturnType()
const;
2237 template <
typename T>
const T *getAs()
const;
2244 template <
typename T>
const T *getAsAdjusted()
const;
2248 const ArrayType *getAsArrayTypeUnsafe()
const;
2256 template <
typename T>
const T *castAs()
const;
2260 const ArrayType *castAsArrayTypeUnsafe()
const;
2269 const Type *getBaseElementTypeUnsafe()
const;
2274 const Type *getArrayElementTypeNoTypeQual()
const;
2279 const Type *getPointeeOrArrayElementType()
const;
2287 const Type *getUnqualifiedDesugaredType()
const;
2290 bool isPromotableIntegerType()
const;
2295 bool isSignedIntegerType()
const;
2300 bool isUnsignedIntegerType()
const;
2304 bool isSignedIntegerOrEnumerationType()
const;
2308 bool isUnsignedIntegerOrEnumerationType()
const;
2312 bool isFixedPointType()
const;
2315 bool isFixedPointOrIntegerType()
const;
2319 bool isSaturatedFixedPointType()
const;
2323 bool isUnsaturatedFixedPointType()
const;
2327 bool isSignedFixedPointType()
const;
2331 bool isUnsignedFixedPointType()
const;
2336 bool isConstantSizeType()
const;
2340 bool isSpecifierType()
const;
2347 return getLinkageAndVisibility().getVisibility();
2352 return getLinkageAndVisibility().isVisibilityExplicit();
2360 bool isLinkageValid()
const;
2374 bool canHaveNullability(
bool ResultIfUnknown =
true)
const;
2392 getObjCSubstitutions(
const DeclContext *dc)
const;
2396 bool acceptsObjCTypeParams()
const;
2398 const char *getTypeClassName()
const;
2401 return CanonicalType;
2406 void dump(llvm::raw_ostream &OS)
const;
2424 #define TYPE(Class, Base) 2425 #define LEAF_TYPE(Class) \ 2426 template <> inline const Class##Type *Type::getAs() const { \ 2427 return dyn_cast<Class##Type>(CanonicalType); \ 2429 template <> inline const Class##Type *Type::castAs() const { \ 2430 return cast<Class##Type>(CanonicalType); \ 2432 #include "clang/AST/TypeNodes.inc" 2440 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) Id, 2441 #include "clang/Basic/OpenCLImageTypes.def" 2443 #define EXT_OPAQUE_TYPE(ExtType, Id, Ext) Id, 2444 #include "clang/Basic/OpenCLExtensionTypes.def" 2446 #define SVE_TYPE(Name, Id, SingletonId) Id, 2447 #include "clang/Basic/AArch64SVEACLETypes.def" 2449 #define BUILTIN_TYPE(Id, SingletonId) Id, 2450 #define LAST_BUILTIN_TYPE(Id) LastKind = Id 2451 #include "clang/AST/BuiltinTypes.def" 2462 BuiltinTypeBits.Kind = K;
2471 StringRef str =
getName(Policy);
2472 assert(!str.empty() && str.data()[str.size()] ==
'\0');
2497 return K >= Overload;
2504 return isPlaceholderTypeKind(
getKind());
2531 :
Type(
Complex, CanonicalPtr, Element->isDependentType(),
2532 Element->isInstantiationDependentType(),
2533 Element->isVariablyModifiedType(),
2534 Element->containsUnexpandedParameterPack()),
2535 ElementType(Element) {}
2544 Profile(ID, getElementType());
2561 :
Type(
Paren, CanonType, InnerType->isDependentType(),
2562 InnerType->isInstantiationDependentType(),
2563 InnerType->isVariablyModifiedType(),
2564 InnerType->containsUnexpandedParameterPack()),
2574 Profile(ID, getInnerType());
2591 :
Type(
Pointer, CanonicalPtr, Pointee->isDependentType(),
2592 Pointee->isInstantiationDependentType(),
2593 Pointee->isVariablyModifiedType(),
2594 Pointee->containsUnexpandedParameterPack()),
2595 PointeeType(Pointee) {}
2620 Profile(ID, getPointeeType());
2642 :
Type(TC, CanonicalPtr, OriginalTy->isDependentType(),
2643 OriginalTy->isInstantiationDependentType(),
2644 OriginalTy->isVariablyModifiedType(),
2645 OriginalTy->containsUnexpandedParameterPack()),
2646 OriginalTy(OriginalTy), AdjustedTy(AdjustedTy) {}
2656 Profile(ID, OriginalTy, AdjustedTy);
2679 inline QualType getPointeeType()
const;
2694 :
Type(BlockPointer, CanonicalCls, Pointee->isDependentType(),
2695 Pointee->isInstantiationDependentType(),
2696 Pointee->isVariablyModifiedType(),
2697 Pointee->containsUnexpandedParameterPack()),
2698 PointeeType(Pointee) {}
2708 Profile(ID, getPointeeType());
2726 bool SpelledAsLValue)
2727 :
Type(tc, CanonicalRef, Referencee->isDependentType(),
2728 Referencee->isInstantiationDependentType(),
2729 Referencee->isVariablyModifiedType(),
2730 Referencee->containsUnexpandedParameterPack()),
2731 PointeeType(Referencee) {
2732 ReferenceTypeBits.SpelledAsLValue = SpelledAsLValue;
2747 return T->PointeeType;
2751 Profile(ID, PointeeType, isSpelledAsLValue());
2756 bool SpelledAsLValue) {
2758 ID.AddBoolean(SpelledAsLValue);
2772 bool SpelledAsLValue)
2814 :
Type(MemberPointer, CanonicalPtr,
2815 Cls->isDependentType() || Pointee->isDependentType(),
2816 (Cls->isInstantiationDependentType() ||
2817 Pointee->isInstantiationDependentType()),
2818 Pointee->isVariablyModifiedType(),
2819 (Cls->containsUnexpandedParameterPack() ||
2820 Pointee->containsUnexpandedParameterPack())),
2821 PointeeType(Pointee), Class(Cls) {}
2845 Profile(ID, getPointeeType(), getClass());
2849 const Type *Class) {
2851 ID.AddPointer(Class);
2878 unsigned tq,
const Expr *sz =
nullptr);
2892 return ArrayTypeBits.IndexTypeQuals;
2916 :
ArrayType(ConstantArray, et, can, sm, tq, sz), Size(size) {
2917 ConstantArrayTypeBits.HasStoredSizeExpr = sz !=
nullptr;
2918 if (ConstantArrayTypeBits.HasStoredSizeExpr) {
2919 assert(!can.
isNull() &&
"canonical constant array should not have size");
2920 *getTrailingObjects<const Expr*>() = sz;
2924 unsigned numTrailingObjects(OverloadToken<const Expr*>)
const {
2925 return ConstantArrayTypeBits.HasStoredSizeExpr;
2931 return ConstantArrayTypeBits.HasStoredSizeExpr
2932 ? *getTrailingObjects<const Expr *>()
2940 static unsigned getNumAddressingBits(
const ASTContext &Context,
2946 static unsigned getMaxSizeBits(
const ASTContext &Context);
2949 Profile(ID, Ctx, getElementType(), getSize(), getSizeExpr(),
2950 getSizeModifier(), getIndexTypeCVRQualifiers());
2953 static void Profile(llvm::FoldingSetNodeID &
ID,
const ASTContext &Ctx,
2956 unsigned TypeQuals);
2971 :
ArrayType(IncompleteArray, et, can, sm, tq) {}
2984 Profile(ID, getElementType(), getSizeModifier(),
2985 getIndexTypeCVRQualifiers());
2991 ID.AddInteger(SizeMod);
2992 ID.AddInteger(TypeQuals);
3023 :
ArrayType(VariableArray, et, can, sm, tq, e),
3024 SizeExpr((
Stmt*) e), Brackets(brackets) {}
3032 return (
Expr*) SizeExpr;
3047 llvm_unreachable(
"Cannot unique VariableArrayTypes.");
3089 return (
Expr*) SizeExpr;
3104 Profile(ID, Context, getElementType(),
3105 getSizeModifier(), getIndexTypeCVRQualifiers(), getSizeExpr());
3108 static void Profile(llvm::FoldingSetNodeID &
ID,
const ASTContext &Context,
3110 unsigned TypeQuals,
Expr *E);
3128 Expr *AddrSpaceExpr;
3149 Profile(ID, Context, getPointeeType(), getAddrSpaceExpr());
3152 static void Profile(llvm::FoldingSetNodeID &
ID,
const ASTContext &Context,
3193 Profile(ID, Context, getElementType(), getSizeExpr());
3196 static void Profile(llvm::FoldingSetNodeID &
ID,
const ASTContext &Context,
3245 return NumElements > VectorTypeBitfields::MaxNumElements;
3256 Profile(ID, getElementType(), getNumElements(),
3257 getTypeClass(), getVectorKind());
3264 ID.AddInteger(NumElements);
3265 ID.AddInteger(TypeClass);
3266 ID.AddInteger(VecKind);
3311 Profile(ID, Context, getElementType(), getSizeExpr(), getVectorKind());
3314 static void Profile(llvm::FoldingSetNodeID &
ID,
const ASTContext &Context,
3329 :
VectorType(ExtVector, vecType, nElements, canonType, GenericVector) {}
3335 case 'x':
case 'r':
return 0;
3336 case 'y':
case 'g':
return 1;
3337 case 'z':
case 'b':
return 2;
3338 case 'w':
case 'a':
return 3;
3356 case 'a':
return 10;
3358 case 'b':
return 11;
3360 case 'c':
return 12;
3362 case 'd':
return 13;
3364 case 'e':
return 14;
3366 case 'f':
return 15;
3371 if (isNumericAccessor)
3372 return getNumericAccessorIdx(c);
3374 return getPointAccessorIdx(c);
3378 if (
int idx = getAccessorIdx(c, isNumericAccessor)+1)
3379 return unsigned(idx-1) < getNumElements();
3423 HasPassObjSize = 0x20,
3426 unsigned char Data = 0;
3435 copy.Data = (copy.Data & ~ABIMask) |
unsigned(kind);
3445 copy.Data |= IsConsumed;
3447 copy.Data &= ~IsConsumed;
3454 Copy.Data |= HasPassObjSize;
3462 Copy.Data |= IsNoEscape;
3464 Copy.Data &= ~IsNoEscape;
3476 return lhs.Data == rhs.Data;
3480 return lhs.Data != rhs.Data;
3515 enum { CallConvMask = 0x1F };
3516 enum { NoReturnMask = 0x20 };
3517 enum { ProducesResultMask = 0x40 };
3518 enum { NoCallerSavedRegsMask = 0x80 };
3519 enum { NoCfCheckMask = 0x800 };
3521 RegParmMask = ~(CallConvMask | NoReturnMask | ProducesResultMask |
3522 NoCallerSavedRegsMask | NoCfCheckMask),
3525 uint16_t Bits =
CC_C;
3527 ExtInfo(
unsigned Bits) : Bits(static_cast<uint16_t>(Bits)) {}
3533 bool producesResult,
bool noCallerSavedRegs,
bool NoCfCheck) {
3534 assert((!hasRegParm || regParm < 7) &&
"Invalid regparm value");
3535 Bits = ((unsigned)cc) | (noReturn ? NoReturnMask : 0) |
3536 (producesResult ? ProducesResultMask : 0) |
3537 (noCallerSavedRegs ? NoCallerSavedRegsMask : 0) |
3538 (hasRegParm ? ((regParm + 1) << RegParmOffset) : 0) |
3539 (NoCfCheck ? NoCfCheckMask : 0);
3557 unsigned RegParm = (Bits & RegParmMask) >> RegParmOffset;
3566 return Bits == Other.Bits;
3569 return Bits != Other.Bits;
3577 return ExtInfo(Bits | NoReturnMask);
3579 return ExtInfo(Bits & ~NoReturnMask);
3584 return ExtInfo(Bits | ProducesResultMask);
3586 return ExtInfo(Bits & ~ProducesResultMask);
3590 if (noCallerSavedRegs)
3591 return ExtInfo(Bits | NoCallerSavedRegsMask);
3593 return ExtInfo(Bits & ~NoCallerSavedRegsMask);
3598 return ExtInfo(Bits | NoCfCheckMask);
3600 return ExtInfo(Bits & ~NoCfCheckMask);
3604 assert(RegParm < 7 &&
"Invalid regparm value");
3605 return ExtInfo((Bits & ~RegParmMask) |
3606 ((RegParm + 1) << RegParmOffset));
3610 return ExtInfo((Bits & ~CallConvMask) | (
unsigned) cc);
3614 ID.AddInteger(Bits);
3636 QualType Canonical,
bool Dependent,
3637 bool InstantiationDependent,
3638 bool VariablyModified,
bool ContainsUnexpandedParameterPack,
3640 :
Type(tc, Canonical, Dependent, InstantiationDependent, VariablyModified,
3641 ContainsUnexpandedParameterPack),
3643 FunctionTypeBits.ExtInfo = Info.Bits;
3665 "Const, volatile and restrict are assumed to be a subset of " 3666 "the fast qualifiers.");
3668 bool isConst()
const {
return getFastTypeQuals().hasConst(); }
3669 bool isVolatile()
const {
return getFastTypeQuals().hasVolatile(); }
3670 bool isRestrict()
const {
return getFastTypeQuals().hasRestrict(); }
3678 static StringRef getNameForCallConv(
CallingConv CC);
3694 Result->isVariablyModifiedType(),
3704 Profile(ID, getReturnType(), getExtInfo());
3727 public llvm::FoldingSetNode,
3729 FunctionProtoType, QualType, FunctionType::FunctionTypeExtraBitfields,
3730 FunctionType::ExceptionType, Expr *, FunctionDecl *,
3731 FunctionType::ExtParameterInfo, Qualifiers> {
3812 const ExtParameterInfo *ExtParameterInfos =
nullptr;
3817 : ExtInfo(CC), Variadic(
false), HasTrailingReturn(
false) {}
3827 unsigned numTrailingObjects(OverloadToken<QualType>)
const {
3828 return getNumParams();
3831 unsigned numTrailingObjects(OverloadToken<FunctionTypeExtraBitfields>)
const {
3832 return hasExtraBitfields();
3835 unsigned numTrailingObjects(OverloadToken<ExceptionType>)
const {
3836 return getExceptionSpecSize().NumExceptionType;
3839 unsigned numTrailingObjects(OverloadToken<Expr *>)
const {
3840 return getExceptionSpecSize().NumExprPtr;
3843 unsigned numTrailingObjects(OverloadToken<FunctionDecl *>)
const {
3844 return getExceptionSpecSize().NumFunctionDeclPtr;
3847 unsigned numTrailingObjects(OverloadToken<ExtParameterInfo>)
const {
3848 return hasExtParameterInfos() ? getNumParams() : 0;
3853 static bool containsAnyUnexpandedParameterPack(
const QualType *ArgArray,
3855 for (
unsigned Idx = 0; Idx < numArgs; ++Idx)
3856 if (ArgArray[Idx]->containsUnexpandedParameterPack())
3868 struct ExceptionSpecSizeHolder {
3869 unsigned NumExceptionType;
3870 unsigned NumExprPtr;
3871 unsigned NumFunctionDeclPtr;
3876 static ExceptionSpecSizeHolder
3888 return {NumExceptions, 0, 0};
3901 llvm_unreachable(
"bad exception specification kind");
3906 ExceptionSpecSizeHolder getExceptionSpecSize()
const {
3907 return getExceptionSpecSize(getExceptionSpecType(), getNumExceptions());
3918 bool hasExtraBitfields()
const {
3919 return hasExtraBitfields(getExceptionSpecType());
3922 bool hasExtQualifiers()
const {
3923 return FunctionTypeBits.HasExtQuals;
3930 assert(i < getNumParams() &&
"invalid parameter index");
3931 return param_type_begin()[i];
3935 return llvm::makeArrayRef(param_type_begin(), param_type_end());
3963 FunctionTypeBits.ExceptionSpecType);
3980 bool hasDependentExceptionSpec()
const;
3984 bool hasInstantiationDependentExceptionSpec()
const;
3989 ? getTrailingObjects<FunctionTypeExtraBitfields>()
3996 assert(i < getNumExceptions() &&
"Invalid exception number!");
3997 return exception_begin()[i];
4005 return *getTrailingObjects<Expr *>();
4016 return getTrailingObjects<FunctionDecl *>()[0];
4026 return getTrailingObjects<FunctionDecl *>()[1];
4037 return ResultIfDependent ? canThrow() !=
CT_Can : canThrow() ==
CT_Cannot;
4049 bool isTemplateVariadic()
const;
4055 if (hasExtQualifiers())
4056 return *getTrailingObjects<Qualifiers>();
4058 return getFastTypeQuals();
4074 return getTrailingObjects<QualType>();
4078 return param_type_begin() + getNumParams();
4084 return llvm::makeArrayRef(exception_begin(), exception_end());
4089 getTrailingObjects<ExceptionType>());
4093 return exception_begin() + getNumExceptions();
4099 return FunctionTypeBits.HasExtParameterInfos;
4103 assert(hasExtParameterInfos());
4112 if (!hasExtParameterInfos())
4114 return getTrailingObjects<ExtParameterInfo>();
4118 assert(I < getNumParams() &&
"parameter index out of range");
4119 if (hasExtParameterInfos())
4120 return getTrailingObjects<ExtParameterInfo>()[I];
4125 assert(I < getNumParams() &&
"parameter index out of range");
4126 if (hasExtParameterInfos())
4127 return getTrailingObjects<ExtParameterInfo>()[I].getABI();
4132 assert(I < getNumParams() &&
"parameter index out of range");
4133 if (hasExtParameterInfos())
4134 return getTrailingObjects<ExtParameterInfo>()[I].isConsumed();
4141 void printExceptionSpecification(raw_ostream &OS,
4148 void Profile(llvm::FoldingSetNodeID &
ID,
const ASTContext &Ctx);
4181 return Profile(ID, Decl);
4197 :
Type(tc, can, can->isDependentType(),
4198 can->isInstantiationDependentType(),
4199 can->isVariablyModifiedType(),
4202 assert(!isa<TypedefType>(can) &&
"Invalid canonical type");
4224 :
Type(MacroQualified, CanonTy, UnderlyingTy->isDependentType(),
4225 UnderlyingTy->isInstantiationDependentType(),
4226 UnderlyingTy->isVariablyModifiedType(),
4227 UnderlyingTy->containsUnexpandedParameterPack()),
4228 UnderlyingTy(UnderlyingTy), MacroII(MacroII) {
4229 assert(isa<AttributedType>(UnderlyingTy) &&
4230 "Expected a macro qualified type to only wrap attributed types.");
4265 bool isSugared()
const;
4285 Profile(ID, Context, getUnderlyingExpr());
4288 static void Profile(llvm::FoldingSetNodeID &
ID,
const ASTContext &Context,
4299 :
Type(TypeOf, can, T->isDependentType(),
4300 T->isInstantiationDependentType(),
4301 T->isVariablyModifiedType(),
4302 T->containsUnexpandedParameterPack()),
4304 assert(!isa<TypedefType>(can) &&
"Invalid canonical type");
4337 bool isSugared()
const;
4355 Profile(ID, Context, getUnderlyingExpr());
4358 static void Profile(llvm::FoldingSetNodeID &
ID,
const ASTContext &Context,
4405 public llvm::FoldingSetNode {
4411 Profile(ID, getBaseType(), getUTTKind());
4417 ID.AddInteger((
unsigned)UKind);
4435 bool isBeingDefined()
const;
4460 bool hasConstFields()
const;
4511 :
Type(Attributed, canon, equivalent->isDependentType(),
4512 equivalent->isInstantiationDependentType(),
4513 equivalent->isVariablyModifiedType(),
4514 equivalent->containsUnexpandedParameterPack()),
4515 ModifiedType(modified), EquivalentType(equivalent) {
4516 AttributedTypeBits.AttrKind = attrKind;
4521 return static_cast<Kind>(AttributedTypeBits.AttrKind);
4545 bool isQualifier()
const;
4547 bool isMSTypeSpec()
const;
4549 bool isCallingConv()
const;
4558 return attr::TypeNonNull;
4561 return attr::TypeNullable;
4564 return attr::TypeNullUnspecified;
4566 llvm_unreachable(
"Unknown nullability kind.");
4581 Profile(ID, getAttrKind(), ModifiedType, EquivalentType);
4586 ID.AddInteger(attrKind);
4600 struct CanonicalTTPTInfo {
4601 unsigned Depth : 15;
4602 unsigned ParameterPack : 1;
4603 unsigned Index : 16;
4616 :
Type(TemplateTypeParm, Canon,
true,
4619 Canon->containsUnexpandedParameterPack()),
4628 CanTTPTInfo.Depth = D;
4629 CanTTPTInfo.Index = I;
4630 CanTTPTInfo.ParameterPack = PP;
4633 const CanonicalTTPTInfo& getCanTTPTInfo()
const {
4634 QualType Can = getCanonicalTypeInternal();
4639 unsigned getDepth()
const {
return getCanTTPTInfo().Depth; }
4640 unsigned getIndex()
const {
return getCanTTPTInfo().Index; }
4644 return isCanonicalUnqualified() ? nullptr : TTPDecl;
4653 Profile(ID, getDepth(), getIndex(), isParameterPack(), getDecl());
4657 unsigned Index,
bool ParameterPack,
4659 ID.AddInteger(Depth);
4660 ID.AddInteger(Index);
4661 ID.AddBoolean(ParameterPack);
4662 ID.AddPointer(TTPDecl);
4684 :
Type(SubstTemplateTypeParm, Canon, Canon->isDependentType(),
4685 Canon->isInstantiationDependentType(),
4686 Canon->isVariablyModifiedType(),
4687 Canon->containsUnexpandedParameterPack()),
4699 return getCanonicalTypeInternal();
4706 Profile(ID, getReplacedParameter(), getReplacementType());
4712 ID.AddPointer(Replaced);
4756 return SubstTemplateTypeParmPackTypeBits.NumArgs;
4764 void Profile(llvm::FoldingSetNodeID &
ID);
4765 static void Profile(llvm::FoldingSetNodeID &ID,
4786 bool IsInstantiationDependent,
bool ContainsParameterPack)
4789 DeducedAsType.isNull() ?
QualType(this, 0)
4790 : DeducedAsType.getCanonicalType(),
4791 IsDependent, IsInstantiationDependent,
4792 false, ContainsParameterPack) {
4793 if (!DeducedAsType.
isNull()) {
4797 setInstantiationDependent();
4799 setContainsUnexpandedParameterPack();
4804 bool isSugared()
const {
return !isCanonicalUnqualified(); }
4810 return !isCanonicalUnqualified() ? getCanonicalTypeInternal() :
QualType();
4813 return !isCanonicalUnqualified() || isDependentType();
4827 bool IsDeducedAsDependent,
bool IsDeducedAsPack)
4829 IsDeducedAsDependent, IsDeducedAsPack) {
4830 AutoTypeBits.Keyword = (unsigned)Keyword;
4843 Profile(ID, getDeducedType(), getKeyword(), isDependentType(),
4844 containsUnexpandedParameterPack());
4850 ID.AddInteger((
unsigned)Keyword);
4851 ID.AddBoolean(IsDependent);
4852 ID.AddBoolean(IsPack);
4862 public llvm::FoldingSetNode {
4870 bool IsDeducedAsDependent)
4871 :
DeducedType(DeducedTemplateSpecialization, DeducedAsType,
4872 IsDeducedAsDependent || Template.isDependent(),
4873 IsDeducedAsDependent || Template.isInstantiationDependent(),
4874 Template.containsUnexpandedParameterPack()),
4875 Template(Template) {}
4882 Profile(ID, getTemplateName(), getDeducedType(), isDependentType());
4886 QualType Deduced,
bool IsDependent) {
4889 ID.AddBoolean(IsDependent);
4893 return T->
getTypeClass() == DeducedTemplateSpecialization;
4919 public llvm::FoldingSetNode {
4939 bool &InstantiationDependent);
4942 bool &InstantiationDependent);
4947 return isa<InjectedClassNameType>(getCanonicalTypeInternal());
4965 bool isTypeAlias()
const {
return TemplateSpecializationTypeBits.TypeAlias; }
4970 assert(isTypeAlias() &&
"not a type alias template specialization");
4971 return *
reinterpret_cast<const QualType*
>(end());
4989 return TemplateSpecializationTypeBits.NumArgs;
4997 return {getArgs(), getNumArgs()};
5001 return !isDependentType() || isCurrentInstantiation() || isTypeAlias();
5005 return isTypeAlias() ? getAliasedType() : getCanonicalTypeInternal();
5009 Profile(ID, Template, template_arguments(), Ctx);
5011 getAliasedType().Profile(ID);
5079 Decl(D), InjectedType(TST) {
5080 assert(isa<TemplateSpecializationType>(TST));
5089 return cast<TemplateSpecializationType>(InjectedType.
getTypePtr());
5093 return getInjectedTST()->getTemplateName();
5157 QualType Canonical,
bool Dependent,
5158 bool InstantiationDependent,
bool VariablyModified,
5159 bool ContainsUnexpandedParameterPack)
5160 :
Type(tc, Canonical, Dependent, InstantiationDependent, VariablyModified,
5161 ContainsUnexpandedParameterPack) {
5162 TypeWithKeywordBits.Keyword = Keyword;
5175 static TagTypeKind getTagTypeKindForTypeSpec(
unsigned TypeSpec);
5190 return getKeywordName(getKeywordForTagTypeKind(Kind));
5207 public llvm::FoldingSetNode,
5225 NamedType->isDependentType(),
5226 NamedType->isInstantiationDependentType(),
5227 NamedType->isVariablyModifiedType(),
5228 NamedType->containsUnexpandedParameterPack()),
5229 NNS(NNS), NamedType(NamedType) {
5230 ElaboratedTypeBits.HasOwnedTagDecl =
false;
5232 ElaboratedTypeBits.HasOwnedTagDecl =
true;
5233 *getTrailingObjects<TagDecl *>() = OwnedTagDecl;
5235 assert(!(Keyword ==
ETK_None && NNS ==
nullptr) &&