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> 74 struct PointerLikeTypeTraits;
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.def" 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);
323 return ObjCLifetime((Mask & LifetimeMask) >> LifetimeShift);
326 Mask = (Mask & ~LifetimeMask) | (type << LifetimeShift);
331 assert(!hasObjCLifetime());
332 Mask |= (type << LifetimeShift);
338 return (lifetime > OCL_ExplicitNone);
344 return (lifetime == OCL_Strong || lifetime == OCL_Weak);
349 return static_cast<LangAS>(Mask >> AddressSpaceShift);
356 auto Addr = getAddressSpace();
369 assert((
unsigned)space <= MaxAddressSpace);
370 Mask = (Mask & ~AddressSpaceMask)
371 | (((uint32_t) space) << AddressSpaceShift);
376 setAddressSpace(space);
384 assert(!(mask & ~FastMask) &&
"bitmask contains non-fast qualifier bits");
385 Mask = (Mask & ~FastMask) | mask;
388 assert(!(mask & ~FastMask) &&
"bitmask contains non-fast qualifier bits");
392 removeFastQualifiers(FastMask);
395 assert(!(mask & ~FastMask) &&
"bitmask contains non-fast qualifier bits");
410 bool empty()
const {
return !Mask; }
416 if (!(Q.Mask & ~CVRMask))
419 Mask |= (Q.Mask & CVRMask);
433 if (!(Q.Mask & ~CVRMask))
436 Mask &= ~(Q.Mask & CVRMask);
440 removeObjCLifetime();
442 removeAddressSpace();
479 return isAddressSpaceSupersetOf(other) &&
482 (getObjCGCAttr() == other.
getObjCGCAttr() || !hasObjCGCAttr() ||
487 (((Mask & CVRMask) | (other.Mask & CVRMask)) == (Mask & CVRMask)) &&
503 if (getObjCLifetime() == OCL_Weak || other.
getObjCLifetime() == OCL_Weak)
506 if (getObjCLifetime() == OCL_None || other.
getObjCLifetime() == OCL_None)
514 bool isStrictSupersetOf(
Qualifiers Other)
const;
519 explicit operator bool()
const {
return hasQualifiers(); }
549 bool appendSpaceIfNonEmpty =
false)
const;
560 static const uint32_t UMask = 0x8;
561 static const uint32_t UShift = 3;
562 static const uint32_t GCAttrMask = 0x30;
563 static const uint32_t GCAttrShift = 4;
564 static const uint32_t LifetimeMask = 0x1C0;
565 static const uint32_t LifetimeShift = 6;
566 static const uint32_t AddressSpaceMask =
567 ~(CVRMask | UMask | GCAttrMask | LifetimeMask);
568 static const uint32_t AddressSpaceShift = 9;
586 std::pair<const Type *,Qualifiers>
asPair()
const {
587 return std::pair<const Type *, Qualifiers>(Ty, Quals);
638 llvm::PointerIntPair<llvm::PointerUnion<const Type *, const ExtQuals *>,
641 const ExtQuals *getExtQualsUnsafe()
const {
642 return Value.getPointer().get<
const ExtQuals*>();
645 const Type *getTypePtrUnsafe()
const {
646 return Value.getPointer().get<
const Type*>();
650 assert(!isNull() &&
"Cannot retrieve a NULL type pointer");
651 auto CommonPtrVal =
reinterpret_cast<uintptr_t>(Value.getOpaqueValue());
668 const Type *getTypePtr()
const;
670 const Type *getTypePtrOrNull()
const;
683 T.Value.setFromOpaqueValue(const_cast<void*>(Ptr));
688 return *getTypePtr();
695 bool isCanonical()
const;
696 bool isCanonicalAsParam()
const;
700 return Value.getPointer().isNull();
711 bool isConstQualified()
const;
721 bool isRestrictQualified()
const;
731 bool isVolatileQualified()
const;
737 return getLocalFastQualifiers() || hasLocalNonFastQualifiers();
741 bool hasQualifiers()
const;
747 return Value.getPointer().is<
const ExtQuals*>();
762 return getLocalFastQualifiers();
767 unsigned getCVRQualifiers()
const;
774 bool isPODType(
const ASTContext &Context)
const;
778 bool isCXX98PODType(
const ASTContext &Context)
const;
784 bool isCXX11PODType(
const ASTContext &Context)
const;
787 bool isTrivialType(
const ASTContext &Context)
const;
790 bool isTriviallyCopyableType(
const ASTContext &Context)
const;
794 bool mayBeDynamicClass()
const;
797 bool mayBeNotDynamicClass()
const;
827 return withFastQualifiers(CVR);
832 &&
"non-fast qualifier bits set in mask!");
833 Value.setInt(Value.getInt() | TQs);
836 void removeLocalConst();
837 void removeLocalVolatile();
838 void removeLocalRestrict();
839 void removeLocalCVRQualifiers(
unsigned Mask);
844 Value.setInt(Value.getInt() & ~Mask);
893 inline QualType getUnqualifiedType()
const;
908 bool isMoreQualifiedThan(
QualType Other)
const;
912 bool isAtLeastAsQualifiedAs(
QualType Other)
const;
914 QualType getNonReferenceType()
const;
935 return getDesugaredType(*
this, Context);
939 return getSplitDesugaredType(*
this);
948 return getSingleStepDesugaredTypeImpl(*
this, Context);
954 if (isa<ParenType>(*
this))
961 return LHS.Value == RHS.Value;
964 return LHS.Value != RHS.Value;
978 const Twine &PlaceHolder = Twine(),
979 unsigned Indentation = 0)
const;
983 unsigned Indentation = 0) {
984 return print(split.
Ty, split.
Quals, OS, policy, PlaceHolder, Indentation);
989 const Twine &PlaceHolder,
990 unsigned Indentation = 0);
992 void getAsStringInternal(std::string &Str,
997 return getAsStringInternal(split.
Ty, split.
Quals, out, policy);
1007 const Twine &PlaceHolder;
1008 unsigned Indentation;
1012 const Twine &PlaceHolder,
unsigned Indentation)
1013 : T(T), Policy(Policy), PlaceHolder(PlaceHolder),
1014 Indentation(Indentation) {}
1018 SQT.T.
print(OS, SQT.Policy, SQT.PlaceHolder, SQT.Indentation);
1024 const Twine &PlaceHolder = Twine(),
1025 unsigned Indentation = 0)
const {
1029 void dump(
const char *s)
const;
1031 void dump(llvm::raw_ostream &OS)
const;
1034 ID.AddPointer(getAsOpaquePtr());
1038 inline LangAS getAddressSpace()
const;
1067 bool isNonWeakInMRRWithObjCWeak(
const ASTContext &Context)
const;
1093 isNonTrivialToPrimitiveDefaultInitialize()
const;
1127 bool isNonTrivialPrimitiveCType(
const ASTContext &Ctx)
const;
1147 DK_nontrivial_c_struct
1155 return isDestructedTypeImpl(*
this);
1168 bool isCForbiddenLValueType()
const;
1216 QualType getAtomicUnqualifiedType()
const;
1258 enum { NumLowBitsAvailable = 0 };
1278 const Type *
const BaseType;
1284 : BaseType(baseType), CanonicalType(canon) {}
1320 canon.isNull() ?
QualType(this_(), 0) : canon),
1323 &&
"ExtQuals created with no fast qualifiers");
1325 &&
"ExtQuals created with fast qualifiers");
1345 Profile(ID, getBaseType(), Quals);
1349 const Type *BaseType,
1352 ID.AddPointer(BaseType);
1412 #define TYPE(Class, Base) Class, 1413 #define LAST_TYPE(Class) TypeLast = Class, 1414 #define ABSTRACT_TYPE(Class, Base) 1415 #include "clang/AST/TypeNodes.def" 1416 TagFirst = Record, TagLast = Enum
1421 class TypeBitfields {
1429 unsigned Dependent : 1;
1433 unsigned InstantiationDependent : 1;
1436 unsigned VariablyModified : 1;
1440 unsigned ContainsUnexpandedParameterPack : 1;
1444 mutable unsigned CacheValid : 1;
1447 mutable unsigned CachedLinkage : 3;
1450 mutable unsigned CachedLocalOrUnnamed : 1;
1453 mutable unsigned FromAST : 1;
1455 bool isCacheValid()
const {
1460 assert(isCacheValid() &&
"getting linkage from invalid cache");
1461 return static_cast<Linkage>(CachedLinkage);
1464 bool hasLocalOrUnnamedType()
const {
1465 assert(isCacheValid() &&
"getting linkage from invalid cache");
1466 return CachedLocalOrUnnamed;
1469 enum { NumTypeBits = 18 };
1478 unsigned : NumTypeBits;
1482 unsigned IndexTypeQuals : 3;
1487 unsigned SizeModifier : 3;
1493 unsigned : NumTypeBits;
1506 unsigned : NumTypeBits;
1510 unsigned ExtInfo : 12;
1515 unsigned RefQualifier : 2;
1525 unsigned HasExtQuals : 1;
1531 unsigned NumParams : 16;
1534 unsigned ExceptionSpecType : 4;
1537 unsigned HasExtParameterInfos : 1;
1540 unsigned Variadic : 1;
1543 unsigned HasTrailingReturn : 1;
1549 unsigned : NumTypeBits;
1552 unsigned NumTypeArgs : 7;
1555 unsigned NumProtocols : 6;
1558 unsigned IsKindOf : 1;
1564 unsigned : NumTypeBits;
1577 unsigned SpelledAsLValue : 1;
1581 unsigned InnerRef : 1;
1587 unsigned : NumTypeBits;
1590 unsigned Keyword : 8;
1593 enum { NumTypeWithKeywordBits = 8 };
1598 unsigned : NumTypeBits;
1599 unsigned : NumTypeWithKeywordBits;
1602 unsigned HasOwnedTagDecl : 1;
1609 unsigned : NumTypeBits;
1613 unsigned VecKind : 3;
1616 unsigned NumElements : 29 - NumTypeBits;
1618 enum { MaxNumElements = (1 << (29 - NumTypeBits)) - 1 };
1624 unsigned : NumTypeBits;
1627 unsigned AttrKind : 32 - NumTypeBits;
1633 unsigned : NumTypeBits;
1637 unsigned Keyword : 2;
1643 unsigned : NumTypeBits;
1658 unsigned : NumTypeBits;
1661 unsigned TypeAlias : 1;
1676 unsigned : NumTypeBits;
1677 unsigned : NumTypeWithKeywordBits;
1692 unsigned : NumTypeBits;
1705 unsigned NumExpansions;
1726 static_assert(
sizeof(TypeBitfields) <= 8,
1727 "TypeBitfields is larger than 8 bytes!");
1729 "ArrayTypeBitfields is larger than 8 bytes!");
1731 "AttributedTypeBitfields is larger than 8 bytes!");
1733 "AutoTypeBitfields is larger than 8 bytes!");
1735 "BuiltinTypeBitfields is larger than 8 bytes!");
1737 "FunctionTypeBitfields is larger than 8 bytes!");
1739 "ObjCObjectTypeBitfields is larger than 8 bytes!");
1741 "ReferenceTypeBitfields is larger than 8 bytes!");
1743 "TypeWithKeywordBitfields is larger than 8 bytes!");
1745 "ElaboratedTypeBitfields is larger than 8 bytes!");
1747 "VectorTypeBitfields is larger than 8 bytes!");
1749 "SubstTemplateTypeParmPackTypeBitfields is larger" 1752 "TemplateSpecializationTypeBitfields is larger" 1755 "DependentTemplateSpecializationTypeBitfields is larger" 1758 "PackExpansionTypeBitfields is larger than 8 bytes");
1765 void setFromAST(
bool V =
true)
const {
1766 TypeBits.FromAST = V;
1773 bool InstantiationDependent,
bool VariablyModified,
1774 bool ContainsUnexpandedParameterPack)
1776 canon.isNull() ?
QualType(this_(), 0) : canon) {
1778 TypeBits.Dependent = Dependent;
1779 TypeBits.InstantiationDependent = Dependent || InstantiationDependent;
1780 TypeBits.VariablyModified = VariablyModified;
1781 TypeBits.ContainsUnexpandedParameterPack = ContainsUnexpandedParameterPack;
1782 TypeBits.CacheValid =
false;
1783 TypeBits.CachedLocalOrUnnamed =
false;
1785 TypeBits.FromAST =
false;
1792 TypeBits.Dependent = D;
1794 TypeBits.InstantiationDependent =
true;
1798 TypeBits.InstantiationDependent = D; }
1803 TypeBits.ContainsUnexpandedParameterPack = PP;
1811 Type &operator=(
const Type &) =
delete;
1834 return TypeBits.ContainsUnexpandedParameterPack;
1840 return CanonicalType ==
QualType(
this, 0);
1846 QualType getLocallyUnqualifiedSingleStepDesugaredType()
const;
1859 bool isIncompleteType(
NamedDecl **Def =
nullptr)
const;
1864 return !isFunctionType();
1872 return !isReferenceType() && !isFunctionType() && !isVoidType();
1877 bool isLiteralType(
const ASTContext &Ctx)
const;
1881 bool isStandardLayoutType()
const;
1887 bool isBuiltinType()
const;
1890 bool isSpecificBuiltinType(
unsigned K)
const;
1895 bool isPlaceholderType()
const;
1899 bool isSpecificPlaceholderType(
unsigned K)
const;
1903 bool isNonOverloadPlaceholderType()
const;
1907 bool isIntegerType()
const;
1908 bool isEnumeralType()
const;
1911 bool isScopedEnumeralType()
const;
1914 bool isWideCharType()
const;
1915 bool isChar8Type()
const;
1916 bool isChar16Type()
const;
1917 bool isChar32Type()
const;
1918 bool isAnyCharacterType()
const;
1919 bool isIntegralType(
const ASTContext &Ctx)
const;
1922 bool isIntegralOrEnumerationType()
const;
1925 bool isIntegralOrUnscopedEnumerationType()
const;
1928 bool isRealFloatingType()
const;
1931 bool isComplexType()
const;
1932 bool isAnyComplexType()
const;
1933 bool isFloatingType()
const;
1934 bool isHalfType()
const;
1935 bool isFloat16Type()
const;
1936 bool isFloat128Type()
const;
1937 bool isRealType()
const;
1938 bool isArithmeticType()
const;
1939 bool isVoidType()
const;
1940 bool isScalarType()
const;
1941 bool isAggregateType()
const;
1942 bool isFundamentalType()
const;
1943 bool isCompoundType()
const;
1947 bool isFunctionType()
const;
1950 bool isPointerType()
const;
1951 bool isAnyPointerType()
const;
1952 bool isBlockPointerType()
const;
1953 bool isVoidPointerType()
const;
1954 bool isReferenceType()
const;
1955 bool isLValueReferenceType()
const;
1956 bool isRValueReferenceType()
const;
1957 bool isFunctionPointerType()
const;
1958 bool isMemberPointerType()
const;
1959 bool isMemberFunctionPointerType()
const;
1960 bool isMemberDataPointerType()
const;
1961 bool isArrayType()
const;
1962 bool isConstantArrayType()
const;
1963 bool isIncompleteArrayType()
const;
1964 bool isVariableArrayType()
const;
1965 bool isDependentSizedArrayType()
const;
1967 bool isClassType()
const;
1968 bool isStructureType()
const;
1969 bool isObjCBoxableRecordType()
const;
1970 bool isInterfaceType()
const;
1971 bool isStructureOrClassType()
const;
1972 bool isUnionType()
const;
1973 bool isComplexIntegerType()
const;
1974 bool isVectorType()
const;
1975 bool isExtVectorType()
const;
1976 bool isDependentAddressSpaceType()
const;
1977 bool isObjCObjectPointerType()
const;
1978 bool isObjCRetainableType()
const;
1979 bool isObjCLifetimeType()
const;
1980 bool isObjCIndirectLifetimeType()
const;
1981 bool isObjCNSObjectType()
const;
1982 bool isObjCIndependentClassType()
const;
1985 bool isObjCObjectType()
const;
1986 bool isObjCQualifiedInterfaceType()
const;
1987 bool isObjCQualifiedIdType()
const;
1988 bool isObjCQualifiedClassType()
const;
1989 bool isObjCObjectOrInterfaceType()
const;
1990 bool isObjCIdType()
const;
1991 bool isDecltypeType()
const;
1999 return hasAttr(attr::ObjCInertUnsafeUnretained);
2009 bool isObjCIdOrObjectKindOfType(
const ASTContext &ctx,
2012 bool isObjCClassType()
const;
2020 bool isObjCClassOrClassKindOfType()
const;
2022 bool isBlockCompatibleObjCPointerType(
ASTContext &ctx)
const;
2023 bool isObjCSelType()
const;
2024 bool isObjCBuiltinType()
const;
2025 bool isObjCARCBridgableType()
const;
2026 bool isCARCBridgableType()
const;
2027 bool isTemplateTypeParmType()
const;
2028 bool isNullPtrType()
const;
2029 bool isAlignValT()
const;
2030 bool isStdByteType()
const;
2031 bool isAtomicType()
const;
2033 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ 2034 bool is##Id##Type() const; 2035 #include "clang/Basic/OpenCLImageTypes.def" 2037 bool isImageType()
const;
2039 bool isSamplerT()
const;
2040 bool isEventT()
const;
2041 bool isClkEventT()
const;
2042 bool isQueueT()
const;
2043 bool isReserveIDT()
const;
2045 #define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \ 2046 bool is##Id##Type() const; 2047 #include "clang/Basic/OpenCLExtensionTypes.def" 2049 bool isOCLIntelSubgroupAVCType()
const;
2050 bool isOCLExtOpaqueType()
const;
2052 bool isPipeType()
const;
2053 bool isOpenCLSpecificType()
const;
2058 bool isObjCARCImplicitlyUnretainedType()
const;
2088 return TypeBits.InstantiationDependent;
2094 bool isUndeducedType()
const;
2101 bool hasSizedVLAType()
const;
2104 bool hasUnnamedOrLocalType()
const;
2106 bool isOverloadableType()
const;
2109 bool isElaboratedTypeSpecifier()
const;
2111 bool canDecayToPointerType()
const;
2116 bool hasPointerRepresentation()
const;
2120 bool hasObjCPointerRepresentation()
const;
2124 bool hasIntegerRepresentation()
const;
2128 bool hasSignedIntegerRepresentation()
const;
2132 bool hasUnsignedIntegerRepresentation()
const;
2136 bool hasFloatingRepresentation()
const;
2141 const RecordType *getAsStructureType()
const;
2144 const ComplexType *getAsComplexIntegerType()
const;
2165 TagDecl *getAsTagDecl()
const;
2183 return dyn_cast_or_null<AutoType>(getContainedDeducedType());
2189 bool hasAutoForTrailingReturnType()
const;
2197 template <
typename T>
const T *getAs()
const;
2204 template <
typename T>
const T *getAsAdjusted()
const;
2208 const ArrayType *getAsArrayTypeUnsafe()
const;
2216 template <
typename T>
const T *castAs()
const;
2220 const ArrayType *castAsArrayTypeUnsafe()
const;
2229 const Type *getBaseElementTypeUnsafe()
const;
2234 const Type *getArrayElementTypeNoTypeQual()
const;
2239 const Type *getPointeeOrArrayElementType()
const;
2247 const Type *getUnqualifiedDesugaredType()
const;
2250 bool isPromotableIntegerType()
const;
2255 bool isSignedIntegerType()
const;
2260 bool isUnsignedIntegerType()
const;
2264 bool isSignedIntegerOrEnumerationType()
const;
2268 bool isUnsignedIntegerOrEnumerationType()
const;
2272 bool isFixedPointType()
const;
2275 bool isFixedPointOrIntegerType()
const;
2279 bool isSaturatedFixedPointType()
const;
2283 bool isUnsaturatedFixedPointType()
const;
2287 bool isSignedFixedPointType()
const;
2291 bool isUnsignedFixedPointType()
const;
2296 bool isConstantSizeType()
const;
2300 bool isSpecifierType()
const;
2307 return getLinkageAndVisibility().getVisibility();
2312 return getLinkageAndVisibility().isVisibilityExplicit();
2320 bool isLinkageValid()
const;
2334 bool canHaveNullability(
bool ResultIfUnknown =
true)
const;
2352 getObjCSubstitutions(
const DeclContext *dc)
const;
2356 bool acceptsObjCTypeParams()
const;
2358 const char *getTypeClassName()
const;
2361 return CanonicalType;
2366 void dump(llvm::raw_ostream &OS)
const;
2384 #define TYPE(Class, Base) 2385 #define LEAF_TYPE(Class) \ 2386 template <> inline const Class##Type *Type::getAs() const { \ 2387 return dyn_cast<Class##Type>(CanonicalType); \ 2389 template <> inline const Class##Type *Type::castAs() const { \ 2390 return cast<Class##Type>(CanonicalType); \ 2392 #include "clang/AST/TypeNodes.def" 2400 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) Id, 2401 #include "clang/Basic/OpenCLImageTypes.def" 2403 #define EXT_OPAQUE_TYPE(ExtType, Id, Ext) Id, 2404 #include "clang/Basic/OpenCLExtensionTypes.def" 2406 #define BUILTIN_TYPE(Id, SingletonId) Id, 2407 #define LAST_BUILTIN_TYPE(Id) LastKind = Id 2408 #include "clang/AST/BuiltinTypes.def" 2419 BuiltinTypeBits.Kind = K;
2429 assert(!str.empty() && str.data()[str.size()] ==
'\0');
2454 return K >= Overload;
2461 return isPlaceholderTypeKind(
getKind());
2488 :
Type(
Complex, CanonicalPtr, Element->isDependentType(),
2489 Element->isInstantiationDependentType(),
2490 Element->isVariablyModifiedType(),
2491 Element->containsUnexpandedParameterPack()),
2492 ElementType(Element) {}
2501 Profile(ID, getElementType());
2518 :
Type(
Paren, CanonType, InnerType->isDependentType(),
2519 InnerType->isInstantiationDependentType(),
2520 InnerType->isVariablyModifiedType(),
2521 InnerType->containsUnexpandedParameterPack()),
2531 Profile(ID, getInnerType());
2548 :
Type(
Pointer, CanonicalPtr, Pointee->isDependentType(),
2549 Pointee->isInstantiationDependentType(),
2550 Pointee->isVariablyModifiedType(),
2551 Pointee->containsUnexpandedParameterPack()),
2552 PointeeType(Pointee) {}
2577 Profile(ID, getPointeeType());
2599 :
Type(TC, CanonicalPtr, OriginalTy->isDependentType(),
2600 OriginalTy->isInstantiationDependentType(),
2601 OriginalTy->isVariablyModifiedType(),
2602 OriginalTy->containsUnexpandedParameterPack()),
2603 OriginalTy(OriginalTy), AdjustedTy(AdjustedTy) {}
2613 Profile(ID, OriginalTy, AdjustedTy);
2636 inline QualType getPointeeType()
const;
2651 :
Type(BlockPointer, CanonicalCls, Pointee->isDependentType(),
2652 Pointee->isInstantiationDependentType(),
2653 Pointee->isVariablyModifiedType(),
2654 Pointee->containsUnexpandedParameterPack()),
2655 PointeeType(Pointee) {}
2665 Profile(ID, getPointeeType());
2683 bool SpelledAsLValue)
2684 :
Type(tc, CanonicalRef, Referencee->isDependentType(),
2685 Referencee->isInstantiationDependentType(),
2686 Referencee->isVariablyModifiedType(),
2687 Referencee->containsUnexpandedParameterPack()),
2688 PointeeType(Referencee) {
2689 ReferenceTypeBits.SpelledAsLValue = SpelledAsLValue;
2704 return T->PointeeType;
2708 Profile(ID, PointeeType, isSpelledAsLValue());
2713 bool SpelledAsLValue) {
2715 ID.AddBoolean(SpelledAsLValue);
2729 bool SpelledAsLValue)
2771 :
Type(MemberPointer, CanonicalPtr,
2772 Cls->isDependentType() || Pointee->isDependentType(),
2773 (Cls->isInstantiationDependentType() ||
2774 Pointee->isInstantiationDependentType()),
2775 Pointee->isVariablyModifiedType(),
2776 (Cls->containsUnexpandedParameterPack() ||
2777 Pointee->containsUnexpandedParameterPack())),
2778 PointeeType(Pointee), Class(Cls) {}
2802 Profile(ID, getPointeeType(), getClass());
2806 const Type *Class) {
2808 ID.AddPointer(Class);
2841 bool ContainsUnexpandedParameterPack)
2842 :
Type(tc, can, et->isDependentType() || tc == DependentSizedArray,
2843 et->isInstantiationDependentType() || tc == DependentSizedArray,
2844 (tc == VariableArray || et->isVariablyModifiedType()),
2845 ContainsUnexpandedParameterPack),
2847 ArrayTypeBits.IndexTypeQuals = tq;
2848 ArrayTypeBits.SizeModifier = sm;
2863 return ArrayTypeBits.IndexTypeQuals;
2882 :
ArrayType(ConstantArray, et, can, sm, tq,
2891 :
ArrayType(tc, et, can, sm, tq, et->containsUnexpandedParameterPack()),
2895 const llvm::APInt &
getSize()
const {
return Size; }
2901 static unsigned getNumAddressingBits(
const ASTContext &Context,
2903 const llvm::APInt &NumElements);
2907 static unsigned getMaxSizeBits(
const ASTContext &Context);
2910 Profile(ID, getElementType(), getSize(),
2911 getSizeModifier(), getIndexTypeCVRQualifiers());
2916 unsigned TypeQuals) {
2918 ID.AddInteger(ArraySize.getZExtValue());
2919 ID.AddInteger(SizeMod);
2920 ID.AddInteger(TypeQuals);
2936 :
ArrayType(IncompleteArray, et, can, sm, tq,
2937 et->containsUnexpandedParameterPack()) {}
2950 Profile(ID, getElementType(), getSizeModifier(),
2951 getIndexTypeCVRQualifiers());
2957 ID.AddInteger(SizeMod);
2958 ID.AddInteger(TypeQuals);
2989 :
ArrayType(VariableArray, et, can, sm, tq,
2990 et->containsUnexpandedParameterPack()),
2991 SizeExpr((
Stmt*) e), Brackets(brackets) {}
2999 return (
Expr*) SizeExpr;
3014 llvm_unreachable(
"Cannot unique VariableArrayTypes.");
3056 return (
Expr*) SizeExpr;
3071 Profile(ID, Context, getElementType(),
3072 getSizeModifier(), getIndexTypeCVRQualifiers(), getSizeExpr());
3075 static void Profile(llvm::FoldingSetNodeID &
ID,
const ASTContext &Context,
3077 unsigned TypeQuals,
Expr *E);
3095 Expr *AddrSpaceExpr;
3116 Profile(ID, Context, getPointeeType(), getAddrSpaceExpr());
3119 static void Profile(llvm::FoldingSetNodeID &
ID,
const ASTContext &Context,
3160 Profile(ID, Context, getElementType(), getSizeExpr());
3163 static void Profile(llvm::FoldingSetNodeID &
ID,
const ASTContext &Context,
3212 return NumElements > VectorTypeBitfields::MaxNumElements;
3223 Profile(ID, getElementType(), getNumElements(),
3224 getTypeClass(), getVectorKind());
3231 ID.AddInteger(NumElements);
3232 ID.AddInteger(TypeClass);
3233 ID.AddInteger(VecKind);
3278 Profile(ID, Context, getElementType(), getSizeExpr(), getVectorKind());
3281 static void Profile(llvm::FoldingSetNodeID &
ID,
const ASTContext &Context,
3296 :
VectorType(ExtVector, vecType, nElements, canonType, GenericVector) {}
3302 case 'x':
case 'r':
return 0;
3303 case 'y':
case 'g':
return 1;
3304 case 'z':
case 'b':
return 2;
3305 case 'w':
case 'a':
return 3;
3323 case 'a':
return 10;
3325 case 'b':
return 11;
3327 case 'c':
return 12;
3329 case 'd':
return 13;
3331 case 'e':
return 14;
3333 case 'f':
return 15;
3338 if (isNumericAccessor)
3339 return getNumericAccessorIdx(c);
3341 return getPointAccessorIdx(c);
3345 if (
int idx = getAccessorIdx(c, isNumericAccessor)+1)
3346 return unsigned(idx-1) < getNumElements();
3390 HasPassObjSize = 0x20,
3393 unsigned char Data = 0;
3402 copy.Data = (copy.Data & ~ABIMask) |
unsigned(kind);
3412 copy.Data |= IsConsumed;
3414 copy.Data &= ~IsConsumed;
3421 Copy.Data |= HasPassObjSize;
3429 Copy.Data |= IsNoEscape;
3431 Copy.Data &= ~IsNoEscape;
3443 return lhs.Data == rhs.Data;
3447 return lhs.Data != rhs.Data;
3482 enum { CallConvMask = 0x1F };
3483 enum { NoReturnMask = 0x20 };
3484 enum { ProducesResultMask = 0x40 };
3485 enum { NoCallerSavedRegsMask = 0x80 };
3486 enum { NoCfCheckMask = 0x800 };
3488 RegParmMask = ~(CallConvMask | NoReturnMask | ProducesResultMask |
3489 NoCallerSavedRegsMask | NoCfCheckMask),
3492 uint16_t Bits =
CC_C;
3494 ExtInfo(
unsigned Bits) : Bits(static_cast<uint16_t>(Bits)) {}
3500 bool producesResult,
bool noCallerSavedRegs,
bool NoCfCheck) {
3501 assert((!hasRegParm || regParm < 7) &&
"Invalid regparm value");
3502 Bits = ((unsigned)cc) | (noReturn ? NoReturnMask : 0) |
3503 (producesResult ? ProducesResultMask : 0) |
3504 (noCallerSavedRegs ? NoCallerSavedRegsMask : 0) |
3505 (hasRegParm ? ((regParm + 1) << RegParmOffset) : 0) |
3506 (NoCfCheck ? NoCfCheckMask : 0);
3524 unsigned RegParm = (Bits & RegParmMask) >> RegParmOffset;
3533 return Bits == Other.Bits;
3536 return Bits != Other.Bits;
3544 return ExtInfo(Bits | NoReturnMask);
3546 return ExtInfo(Bits & ~NoReturnMask);
3551 return ExtInfo(Bits | ProducesResultMask);
3553 return ExtInfo(Bits & ~ProducesResultMask);
3557 if (noCallerSavedRegs)
3558 return ExtInfo(Bits | NoCallerSavedRegsMask);
3560 return ExtInfo(Bits & ~NoCallerSavedRegsMask);
3565 return ExtInfo(Bits | NoCfCheckMask);
3567 return ExtInfo(Bits & ~NoCfCheckMask);
3571 assert(RegParm < 7 &&
"Invalid regparm value");
3572 return ExtInfo((Bits & ~RegParmMask) |
3573 ((RegParm + 1) << RegParmOffset));
3577 return ExtInfo((Bits & ~CallConvMask) | (
unsigned) cc);
3581 ID.AddInteger(Bits);
3603 QualType Canonical,
bool Dependent,
3604 bool InstantiationDependent,
3605 bool VariablyModified,
bool ContainsUnexpandedParameterPack,
3607 :
Type(tc, Canonical, Dependent, InstantiationDependent, VariablyModified,
3608 ContainsUnexpandedParameterPack),
3610 FunctionTypeBits.ExtInfo = Info.Bits;
3632 "Const, volatile and restrict are assumed to be a subset of " 3633 "the fast qualifiers.");
3635 bool isConst()
const {
return getFastTypeQuals().hasConst(); }
3636 bool isVolatile()
const {
return getFastTypeQuals().hasVolatile(); }
3637 bool isRestrict()
const {
return getFastTypeQuals().hasRestrict(); }
3645 static StringRef getNameForCallConv(
CallingConv CC);
3661 Result->isVariablyModifiedType(),
3671 Profile(ID, getReturnType(), getExtInfo());
3694 public llvm::FoldingSetNode,
3696 FunctionProtoType, QualType, FunctionType::FunctionTypeExtraBitfields,
3697 FunctionType::ExceptionType, Expr *, FunctionDecl *,
3698 FunctionType::ExtParameterInfo, Qualifiers> {
3779 const ExtParameterInfo *ExtParameterInfos =
nullptr;
3784 : ExtInfo(CC), Variadic(
false), HasTrailingReturn(
false) {}
3794 unsigned numTrailingObjects(OverloadToken<QualType>)
const {
3795 return getNumParams();
3798 unsigned numTrailingObjects(OverloadToken<FunctionTypeExtraBitfields>)
const {
3799 return hasExtraBitfields();
3802 unsigned numTrailingObjects(OverloadToken<ExceptionType>)
const {
3803 return getExceptionSpecSize().NumExceptionType;
3806 unsigned numTrailingObjects(OverloadToken<Expr *>)
const {
3807 return getExceptionSpecSize().NumExprPtr;
3810 unsigned numTrailingObjects(OverloadToken<FunctionDecl *>)
const {
3811 return getExceptionSpecSize().NumFunctionDeclPtr;
3814 unsigned numTrailingObjects(OverloadToken<ExtParameterInfo>)
const {
3815 return hasExtParameterInfos() ? getNumParams() : 0;
3820 static bool containsAnyUnexpandedParameterPack(
const QualType *ArgArray,
3822 for (
unsigned Idx = 0; Idx < numArgs; ++Idx)
3823 if (ArgArray[Idx]->containsUnexpandedParameterPack())
3835 struct ExceptionSpecSizeHolder {
3836 unsigned NumExceptionType;
3837 unsigned NumExprPtr;
3838 unsigned NumFunctionDeclPtr;
3843 static ExceptionSpecSizeHolder
3854 return {NumExceptions, 0, 0};
3867 llvm_unreachable(
"bad exception specification kind");
3872 ExceptionSpecSizeHolder getExceptionSpecSize()
const {
3873 return getExceptionSpecSize(getExceptionSpecType(), getNumExceptions());
3884 bool hasExtraBitfields()
const {
3885 return hasExtraBitfields(getExceptionSpecType());
3888 bool hasExtQualifiers()
const {
3889 return FunctionTypeBits.HasExtQuals;
3896 assert(i < getNumParams() &&
"invalid parameter index");
3897 return param_type_begin()[i];
3901 return llvm::makeArrayRef(param_type_begin(), param_type_end());
3929 FunctionTypeBits.ExceptionSpecType);
3946 bool hasDependentExceptionSpec()
const;
3950 bool hasInstantiationDependentExceptionSpec()
const;
3955 ? getTrailingObjects<FunctionTypeExtraBitfields>()
3962 assert(i < getNumExceptions() &&
"Invalid exception number!");
3963 return exception_begin()[i];
3971 return *getTrailingObjects<Expr *>();
3982 return getTrailingObjects<FunctionDecl *>()[0];
3992 return getTrailingObjects<FunctionDecl *>()[1];
4003 return ResultIfDependent ? canThrow() !=
CT_Can : canThrow() ==
CT_Cannot;
4015 bool isTemplateVariadic()
const;
4021 if (hasExtQualifiers())
4022 return *getTrailingObjects<Qualifiers>();
4024 return getFastTypeQuals();
4040 return getTrailingObjects<QualType>();
4044 return param_type_begin() + getNumParams();
4050 return llvm::makeArrayRef(exception_begin(), exception_end());
4055 getTrailingObjects<ExceptionType>());
4059 return exception_begin() + getNumExceptions();
4065 return FunctionTypeBits.HasExtParameterInfos;
4069 assert(hasExtParameterInfos());
4078 if (!hasExtParameterInfos())
4080 return getTrailingObjects<ExtParameterInfo>();
4084 assert(I < getNumParams() &&
"parameter index out of range");
4085 if (hasExtParameterInfos())
4086 return getTrailingObjects<ExtParameterInfo>()[I];
4091 assert(I < getNumParams() &&
"parameter index out of range");
4092 if (hasExtParameterInfos())
4093 return getTrailingObjects<ExtParameterInfo>()[I].getABI();
4098 assert(I < getNumParams() &&
"parameter index out of range");
4099 if (hasExtParameterInfos())
4100 return getTrailingObjects<ExtParameterInfo>()[I].isConsumed();
4107 void printExceptionSpecification(raw_ostream &OS,
4114 void Profile(llvm::FoldingSetNodeID &
ID,
const ASTContext &Ctx);
4147 return Profile(ID, Decl);
4163 :
Type(tc, can, can->isDependentType(),
4164 can->isInstantiationDependentType(),
4165 can->isVariablyModifiedType(),
4168 assert(!isa<TypedefType>(can) &&
"Invalid canonical type");
4196 bool isSugared()
const;
4216 Profile(ID, Context, getUnderlyingExpr());
4219 static void Profile(llvm::FoldingSetNodeID &
ID,
const ASTContext &Context,
4230 :
Type(TypeOf, can, T->isDependentType(),
4231 T->isInstantiationDependentType(),
4232 T->isVariablyModifiedType(),
4233 T->containsUnexpandedParameterPack()),
4235 assert(!isa<TypedefType>(can) &&
"Invalid canonical type");
4268 bool isSugared()
const;
4286 Profile(ID, Context, getUnderlyingExpr());
4289 static void Profile(llvm::FoldingSetNodeID &
ID,
const ASTContext &Context,
4336 public llvm::FoldingSetNode {
4342 Profile(ID, getBaseType(), getUTTKind());
4348 ID.AddInteger((
unsigned)UKind);
4366 bool isBeingDefined()
const;
4391 bool hasConstFields()
const;
4442 :
Type(Attributed, canon, equivalent->isDependentType(),
4443 equivalent->isInstantiationDependentType(),
4444 equivalent->isVariablyModifiedType(),
4445 equivalent->containsUnexpandedParameterPack()),
4446 ModifiedType(modified), EquivalentType(equivalent) {
4447 AttributedTypeBits.AttrKind = attrKind;
4452 return static_cast<Kind>(AttributedTypeBits.AttrKind);
4476 bool isQualifier()
const;
4478 bool isMSTypeSpec()
const;
4480 bool isCallingConv()
const;
4489 return attr::TypeNonNull;
4492 return attr::TypeNullable;
4495 return attr::TypeNullUnspecified;
4497 llvm_unreachable(
"Unknown nullability kind.");
4512 Profile(ID, getAttrKind(), ModifiedType, EquivalentType);
4517 ID.AddInteger(attrKind);
4531 struct CanonicalTTPTInfo {
4532 unsigned Depth : 15;
4533 unsigned ParameterPack : 1;
4534 unsigned Index : 16;
4547 :
Type(TemplateTypeParm, Canon,
true,
4550 Canon->containsUnexpandedParameterPack()),
4559 CanTTPTInfo.Depth = D;
4560 CanTTPTInfo.Index = I;
4561 CanTTPTInfo.ParameterPack = PP;
4564 const CanonicalTTPTInfo& getCanTTPTInfo()
const {
4565 QualType Can = getCanonicalTypeInternal();
4570 unsigned getDepth()
const {
return getCanTTPTInfo().Depth; }
4571 unsigned getIndex()
const {
return getCanTTPTInfo().Index; }
4575 return isCanonicalUnqualified() ? nullptr : TTPDecl;
4584 Profile(ID, getDepth(), getIndex(), isParameterPack(), getDecl());
4588 unsigned Index,
bool ParameterPack,
4590 ID.AddInteger(Depth);
4591 ID.AddInteger(Index);
4592 ID.AddBoolean(ParameterPack);
4593 ID.AddPointer(TTPDecl);
4615 :
Type(SubstTemplateTypeParm, Canon, Canon->isDependentType(),
4616 Canon->isInstantiationDependentType(),
4617 Canon->isVariablyModifiedType(),
4618 Canon->containsUnexpandedParameterPack()),
4630 return getCanonicalTypeInternal();
4637 Profile(ID, getReplacedParameter(), getReplacementType());
4643 ID.AddPointer(Replaced);
4687 return SubstTemplateTypeParmPackTypeBits.NumArgs;
4695 void Profile(llvm::FoldingSetNodeID &
ID);
4696 static void Profile(llvm::FoldingSetNodeID &ID,
4717 bool IsInstantiationDependent,
bool ContainsParameterPack)
4720 DeducedAsType.isNull() ?
QualType(this, 0)
4721 : DeducedAsType.getCanonicalType(),
4722 IsDependent, IsInstantiationDependent,
4723 false, ContainsParameterPack) {
4724 if (!DeducedAsType.
isNull()) {
4728 setInstantiationDependent();
4730 setContainsUnexpandedParameterPack();
4735 bool isSugared()
const {
return !isCanonicalUnqualified(); }
4741 return !isCanonicalUnqualified() ? getCanonicalTypeInternal() :
QualType();
4744 return !isCanonicalUnqualified() || isDependentType();
4758 bool IsDeducedAsDependent)
4760 IsDeducedAsDependent,
false) {
4761 AutoTypeBits.Keyword = (unsigned)Keyword;
4774 Profile(ID, getDeducedType(), getKeyword(), isDependentType());
4780 ID.AddInteger((
unsigned)Keyword);
4781 ID.AddBoolean(IsDependent);
4791 public llvm::FoldingSetNode {
4799 bool IsDeducedAsDependent)
4800 :
DeducedType(DeducedTemplateSpecialization, DeducedAsType,
4801 IsDeducedAsDependent || Template.isDependent(),
4802 IsDeducedAsDependent || Template.isInstantiationDependent(),
4803 Template.containsUnexpandedParameterPack()),
4804 Template(Template) {}
4811 Profile(ID, getTemplateName(), getDeducedType(), isDependentType());
4815 QualType Deduced,
bool IsDependent) {
4818 ID.AddBoolean(IsDependent);
4822 return T->
getTypeClass() == DeducedTemplateSpecialization;
4848 public llvm::FoldingSetNode {
4868 bool &InstantiationDependent);
4871 bool &InstantiationDependent);
4876 return isa<InjectedClassNameType>(getCanonicalTypeInternal());
4894 bool isTypeAlias()
const {
return TemplateSpecializationTypeBits.TypeAlias; }
4899 assert(isTypeAlias() &&
"not a type alias template specialization");
4900 return *
reinterpret_cast<const QualType*
>(end());
4918 return TemplateSpecializationTypeBits.NumArgs;
4926 return {getArgs(), getNumArgs()};
4930 return !isDependentType() || isCurrentInstantiation() || isTypeAlias();
4934 return isTypeAlias() ? getAliasedType() : getCanonicalTypeInternal();
4938 Profile(ID, Template, template_arguments(), Ctx);
4940 getAliasedType().Profile(ID);
5008 Decl(D), InjectedType(TST) {
5009 assert(isa<TemplateSpecializationType>(TST));
5018 return cast<TemplateSpecializationType>(InjectedType.
getTypePtr());
5022 return getInjectedTST()->getTemplateName();
5086 QualType Canonical,
bool Dependent,
5087 bool InstantiationDependent,
bool VariablyModified,
5088 bool ContainsUnexpandedParameterPack)
5089 :
Type(tc, Canonical, Dependent, InstantiationDependent, VariablyModified,
5090 ContainsUnexpandedParameterPack) {
5091 TypeWithKeywordBits.Keyword = Keyword;
5104 static TagTypeKind getTagTypeKindForTypeSpec(
unsigned TypeSpec);
5119 return getKeywordName(getKeywordForTagTypeKind(Kind));
5136 public llvm::FoldingSetNode,
5154 NamedType->isDependentType(),
5155 NamedType->isInstantiationDependentType(),
5156 NamedType->isVariablyModifiedType(),
5157 NamedType->containsUnexpandedParameterPack()),
5158 NNS(NNS), NamedType(NamedType) {
5159 ElaboratedTypeBits.HasOwnedTagDecl =
false;
5161 ElaboratedTypeBits.HasOwnedTagDecl =
true;
5162 *getTrailingObjects<TagDecl *>() = OwnedTagDecl;
5164 assert(!(Keyword ==
ETK_None && NNS ==
nullptr) &&
5165 "ElaboratedType cannot have elaborated type keyword " 5166 "and name qualifier both null.");
5185 return ElaboratedTypeBits.HasOwnedTagDecl ? *getTrailingObjects<TagDecl *>()
5190 Profile(ID, getKeyword(), NNS, NamedType, getOwnedTagDecl());
5196 ID.AddInteger(Keyword);
5199 ID.AddPointer(OwnedTagDecl);
5231 NNS->containsUnexpandedParameterPack()),
5232 NNS(NNS), Name(Name) {}