Type.cpp revision c910d4cfa5042f2c9da1eb4e0b6ed59240c0eeee
15f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===--- Type.cpp - Type representation and manipulation ------------------===// 25f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 35f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// The LLVM Compiler Infrastructure 45f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 50bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// This file is distributed under the University of Illinois Open Source 60bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// License. See LICENSE.TXT for details. 75f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 85f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 95f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// This file implements type-related functionality. 115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 14b381aac9bae6d608c72267dd0ed08ec6369e94e4Nuno Lopes#include "clang/AST/ASTContext.h" 152fa67efeaf66a9332c30a026dc1c21bef6c33a6cBenjamin Kramer#include "clang/AST/Attr.h" 162767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor#include "clang/AST/CharUnits.h" 1749aa7ff1245abd03e6e998e01302df31e4c6f8f6Argyrios Kyrtzidis#include "clang/AST/DeclCXX.h" 18980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff#include "clang/AST/DeclObjC.h" 19aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor#include "clang/AST/DeclTemplate.h" 205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "clang/AST/Expr.h" 21d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor#include "clang/AST/PrettyPrinter.h" 222fa67efeaf66a9332c30a026dc1c21bef6c33a6cBenjamin Kramer#include "clang/AST/Type.h" 23b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall#include "clang/AST/TypeVisitor.h" 24465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara#include "clang/Basic/Specifiers.h" 2560618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl#include "llvm/ADT/APSInt.h" 265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "llvm/ADT/StringExtras.h" 27bad351822117eaf280081494e3dbe4a06c0dbfcfDouglas Gregor#include "llvm/Support/raw_ostream.h" 282767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor#include <algorithm> 295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing namespace clang; 305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 31769d0cc72b1831785596d0e76f327bdb887823beDouglas Gregorbool Qualifiers::isStrictSupersetOf(Qualifiers Other) const { 32769d0cc72b1831785596d0e76f327bdb887823beDouglas Gregor return (*this != Other) && 33769d0cc72b1831785596d0e76f327bdb887823beDouglas Gregor // CVR qualifiers superset 34769d0cc72b1831785596d0e76f327bdb887823beDouglas Gregor (((Mask & CVRMask) | (Other.Mask & CVRMask)) == (Mask & CVRMask)) && 35769d0cc72b1831785596d0e76f327bdb887823beDouglas Gregor // ObjC GC qualifiers superset 36769d0cc72b1831785596d0e76f327bdb887823beDouglas Gregor ((getObjCGCAttr() == Other.getObjCGCAttr()) || 37769d0cc72b1831785596d0e76f327bdb887823beDouglas Gregor (hasObjCGCAttr() && !Other.hasObjCGCAttr())) && 38769d0cc72b1831785596d0e76f327bdb887823beDouglas Gregor // Address space superset. 39769d0cc72b1831785596d0e76f327bdb887823beDouglas Gregor ((getAddressSpace() == Other.getAddressSpace()) || 40f85e193739c953358c865005855253af4f68a497John McCall (hasAddressSpace()&& !Other.hasAddressSpace())) && 41f85e193739c953358c865005855253af4f68a497John McCall // Lifetime qualifier superset. 42f85e193739c953358c865005855253af4f68a497John McCall ((getObjCLifetime() == Other.getObjCLifetime()) || 43f85e193739c953358c865005855253af4f68a497John McCall (hasObjCLifetime() && !Other.hasObjCLifetime())); 44769d0cc72b1831785596d0e76f327bdb887823beDouglas Gregor} 45769d0cc72b1831785596d0e76f327bdb887823beDouglas Gregor 464d9d157afb35742bc6348defbe45bc6de780ec77Kaelyn Uhrainconst IdentifierInfo* QualType::getBaseTypeIdentifier() const { 474d9d157afb35742bc6348defbe45bc6de780ec77Kaelyn Uhrain const Type* ty = getTypePtr(); 484d9d157afb35742bc6348defbe45bc6de780ec77Kaelyn Uhrain NamedDecl *ND = NULL; 494d9d157afb35742bc6348defbe45bc6de780ec77Kaelyn Uhrain if (ty->isPointerType() || ty->isReferenceType()) 504d9d157afb35742bc6348defbe45bc6de780ec77Kaelyn Uhrain return ty->getPointeeType().getBaseTypeIdentifier(); 514d9d157afb35742bc6348defbe45bc6de780ec77Kaelyn Uhrain else if (ty->isRecordType()) 524d9d157afb35742bc6348defbe45bc6de780ec77Kaelyn Uhrain ND = ty->getAs<RecordType>()->getDecl(); 534d9d157afb35742bc6348defbe45bc6de780ec77Kaelyn Uhrain else if (ty->isEnumeralType()) 544d9d157afb35742bc6348defbe45bc6de780ec77Kaelyn Uhrain ND = ty->getAs<EnumType>()->getDecl(); 554d9d157afb35742bc6348defbe45bc6de780ec77Kaelyn Uhrain else if (ty->getTypeClass() == Type::Typedef) 564d9d157afb35742bc6348defbe45bc6de780ec77Kaelyn Uhrain ND = ty->getAs<TypedefType>()->getDecl(); 574d9d157afb35742bc6348defbe45bc6de780ec77Kaelyn Uhrain else if (ty->isArrayType()) 584d9d157afb35742bc6348defbe45bc6de780ec77Kaelyn Uhrain return ty->castAsArrayTypeUnsafe()-> 594d9d157afb35742bc6348defbe45bc6de780ec77Kaelyn Uhrain getElementType().getBaseTypeIdentifier(); 604d9d157afb35742bc6348defbe45bc6de780ec77Kaelyn Uhrain 614d9d157afb35742bc6348defbe45bc6de780ec77Kaelyn Uhrain if (ND) 624d9d157afb35742bc6348defbe45bc6de780ec77Kaelyn Uhrain return ND->getIdentifier(); 634d9d157afb35742bc6348defbe45bc6de780ec77Kaelyn Uhrain return NULL; 644d9d157afb35742bc6348defbe45bc6de780ec77Kaelyn Uhrain} 654d9d157afb35742bc6348defbe45bc6de780ec77Kaelyn Uhrain 66bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCallbool QualType::isConstant(QualType T, ASTContext &Ctx) { 67bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall if (T.isConstQualified()) 68b381aac9bae6d608c72267dd0ed08ec6369e94e4Nuno Lopes return true; 69b381aac9bae6d608c72267dd0ed08ec6369e94e4Nuno Lopes 70bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall if (const ArrayType *AT = Ctx.getAsArrayType(T)) 71bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall return AT->getElementType().isConstant(Ctx); 72b381aac9bae6d608c72267dd0ed08ec6369e94e4Nuno Lopes 73b381aac9bae6d608c72267dd0ed08ec6369e94e4Nuno Lopes return false; 74b381aac9bae6d608c72267dd0ed08ec6369e94e4Nuno Lopes} 75b381aac9bae6d608c72267dd0ed08ec6369e94e4Nuno Lopes 762767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregorunsigned ConstantArrayType::getNumAddressingBits(ASTContext &Context, 772767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor QualType ElementType, 782767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor const llvm::APInt &NumElements) { 79e738fc5145984235a8f084077791271c4d266236Daniel Dunbar uint64_t ElementSize = Context.getTypeSizeInChars(ElementType).getQuantity(); 80e738fc5145984235a8f084077791271c4d266236Daniel Dunbar 81e738fc5145984235a8f084077791271c4d266236Daniel Dunbar // Fast path the common cases so we can avoid the conservative computation 82e738fc5145984235a8f084077791271c4d266236Daniel Dunbar // below, which in common cases allocates "large" APSInt values, which are 83e738fc5145984235a8f084077791271c4d266236Daniel Dunbar // slow. 84e738fc5145984235a8f084077791271c4d266236Daniel Dunbar 85e738fc5145984235a8f084077791271c4d266236Daniel Dunbar // If the element size is a power of 2, we can directly compute the additional 86e738fc5145984235a8f084077791271c4d266236Daniel Dunbar // number of addressing bits beyond those required for the element count. 87e738fc5145984235a8f084077791271c4d266236Daniel Dunbar if (llvm::isPowerOf2_64(ElementSize)) { 88e738fc5145984235a8f084077791271c4d266236Daniel Dunbar return NumElements.getActiveBits() + llvm::Log2_64(ElementSize); 89e738fc5145984235a8f084077791271c4d266236Daniel Dunbar } 90e738fc5145984235a8f084077791271c4d266236Daniel Dunbar 91e738fc5145984235a8f084077791271c4d266236Daniel Dunbar // If both the element count and element size fit in 32-bits, we can do the 92e738fc5145984235a8f084077791271c4d266236Daniel Dunbar // computation directly in 64-bits. 93e738fc5145984235a8f084077791271c4d266236Daniel Dunbar if ((ElementSize >> 32) == 0 && NumElements.getBitWidth() <= 64 && 94e738fc5145984235a8f084077791271c4d266236Daniel Dunbar (NumElements.getZExtValue() >> 32) == 0) { 95e738fc5145984235a8f084077791271c4d266236Daniel Dunbar uint64_t TotalSize = NumElements.getZExtValue() * ElementSize; 969779fdd271bb6a938bdee93f901e4ef7b1a88610Michael J. Spencer return 64 - llvm::countLeadingZeros(TotalSize); 97e738fc5145984235a8f084077791271c4d266236Daniel Dunbar } 98e738fc5145984235a8f084077791271c4d266236Daniel Dunbar 99e738fc5145984235a8f084077791271c4d266236Daniel Dunbar // Otherwise, use APSInt to handle arbitrary sized values. 1002767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor llvm::APSInt SizeExtended(NumElements, true); 1012767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor unsigned SizeTypeBits = Context.getTypeSize(Context.getSizeType()); 1029f71a8f4c7a182a5236da9e747d57cc1d1bd24c2Jay Foad SizeExtended = SizeExtended.extend(std::max(SizeTypeBits, 1039f71a8f4c7a182a5236da9e747d57cc1d1bd24c2Jay Foad SizeExtended.getBitWidth()) * 2); 1042767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor 1052767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor llvm::APSInt TotalSize(llvm::APInt(SizeExtended.getBitWidth(), ElementSize)); 1062767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor TotalSize *= SizeExtended; 107e738fc5145984235a8f084077791271c4d266236Daniel Dunbar 1082767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor return TotalSize.getActiveBits(); 1092767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor} 1102767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor 1112767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregorunsigned ConstantArrayType::getMaxSizeBits(ASTContext &Context) { 1122767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor unsigned Bits = Context.getTypeSize(Context.getSizeType()); 1132767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor 1142767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor // GCC appears to only allow 63 bits worth of address space when compiling 1152767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor // for 64-bit, so we do the same. 1162767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor if (Bits == 64) 1172767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor --Bits; 1182767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor 1192767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor return Bits; 1202767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor} 1212767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor 1224ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadDependentSizedArrayType::DependentSizedArrayType(const ASTContext &Context, 123d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor QualType et, QualType can, 124d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor Expr *e, ArraySizeModifier sm, 125d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor unsigned tq, 126d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor SourceRange brackets) 127d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor : ArrayType(DependentSizedArray, et, can, sm, tq, 128d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor (et->containsUnexpandedParameterPack() || 129d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor (e && e->containsUnexpandedParameterPack()))), 130d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor Context(Context), SizeExpr((Stmt*) e), Brackets(brackets) 131d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor{ 132d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor} 133d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 1341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpvoid DependentSizedArrayType::Profile(llvm::FoldingSetNodeID &ID, 1354ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad const ASTContext &Context, 13604d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor QualType ET, 13704d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor ArraySizeModifier SizeMod, 13804d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor unsigned TypeQuals, 13904d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor Expr *E) { 14004d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor ID.AddPointer(ET.getAsOpaquePtr()); 14104d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor ID.AddInteger(SizeMod); 14204d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor ID.AddInteger(TypeQuals); 14304d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor E->Profile(ID, Context, true); 14404d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor} 14504d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor 1464ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadDependentSizedExtVectorType::DependentSizedExtVectorType(const 1474ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad ASTContext &Context, 148d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor QualType ElementType, 149d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor QualType can, 150d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor Expr *SizeExpr, 151d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor SourceLocation loc) 152d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor : Type(DependentSizedExtVector, can, /*Dependent=*/true, 153561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /*InstantiationDependent=*/true, 154d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor ElementType->isVariablyModifiedType(), 155d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor (ElementType->containsUnexpandedParameterPack() || 156d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor (SizeExpr && SizeExpr->containsUnexpandedParameterPack()))), 157d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor Context(Context), SizeExpr(SizeExpr), ElementType(ElementType), 158d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor loc(loc) 159d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor{ 160d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor} 161d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 1621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpvoid 1631eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpDependentSizedExtVectorType::Profile(llvm::FoldingSetNodeID &ID, 1644ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad const ASTContext &Context, 1652ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor QualType ElementType, Expr *SizeExpr) { 1662ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor ID.AddPointer(ElementType.getAsOpaquePtr()); 1672ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor SizeExpr->Profile(ID, Context, true); 1682ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor} 1692ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor 170d0937224f383c7cc72c947119380f9713a070c73Douglas GregorVectorType::VectorType(QualType vecType, unsigned nElements, QualType canonType, 171d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor VectorKind vecKind) 172d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor : Type(Vector, canonType, vecType->isDependentType(), 173561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor vecType->isInstantiationDependentType(), 174d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor vecType->isVariablyModifiedType(), 175d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor vecType->containsUnexpandedParameterPack()), 176d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor ElementType(vecType) 177d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor{ 178d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor VectorTypeBits.VecKind = vecKind; 179d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor VectorTypeBits.NumElements = nElements; 180d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor} 181d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 182d0937224f383c7cc72c947119380f9713a070c73Douglas GregorVectorType::VectorType(TypeClass tc, QualType vecType, unsigned nElements, 183d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor QualType canonType, VectorKind vecKind) 184d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor : Type(tc, canonType, vecType->isDependentType(), 185561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor vecType->isInstantiationDependentType(), 186d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor vecType->isVariablyModifiedType(), 187d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor vecType->containsUnexpandedParameterPack()), 188d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor ElementType(vecType) 189d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor{ 190d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor VectorTypeBits.VecKind = vecKind; 191d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor VectorTypeBits.NumElements = nElements; 192d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor} 193d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 194c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner/// getArrayElementTypeNoTypeQual - If this is an array type, return the 195c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner/// element type of the array, potentially with type qualifiers missing. 196c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner/// This method should never be used when type qualifiers are meaningful. 197c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattnerconst Type *Type::getArrayElementTypeNoTypeQual() const { 198c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // If this is directly an array type, return it. 199c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner if (const ArrayType *ATy = dyn_cast<ArrayType>(this)) 200c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return ATy->getElementType().getTypePtr(); 2011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 202c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // If the canonical form of this type isn't the right kind, reject it. 2030953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (!isa<ArrayType>(CanonicalType)) 204c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return 0; 2051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 206c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // If this is a typedef for an array type, strip the typedef off without 207c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // losing all typedef information. 208bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall return cast<ArrayType>(getUnqualifiedDesugaredType()) 209bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall ->getElementType().getTypePtr(); 2102fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner} 2112fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner 2122fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner/// getDesugaredType - Return the specified type with any "sugar" removed from 2132fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner/// the type. This takes off typedefs, typeof's etc. If the outer level of 2142fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner/// the type is already concrete, it returns it unmodified. This is similar 2152fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner/// to getting the canonical type, but it doesn't remove *all* typedefs. For 2162fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner/// example, it returns "T*" as "T*", (not as "int*"), because the pointer is 2172fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner/// concrete. 2184ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualType QualType::getDesugaredType(QualType T, const ASTContext &Context) { 21949f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall SplitQualType split = getSplitDesugaredType(T); 220200fa53fd420aa8369586f569dbece04930ad6a3John McCall return Context.getQualifiedType(split.Ty, split.Quals); 22149f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall} 22249f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall 223200fa53fd420aa8369586f569dbece04930ad6a3John McCallQualType QualType::getSingleStepDesugaredTypeImpl(QualType type, 224200fa53fd420aa8369586f569dbece04930ad6a3John McCall const ASTContext &Context) { 225200fa53fd420aa8369586f569dbece04930ad6a3John McCall SplitQualType split = type.split(); 226200fa53fd420aa8369586f569dbece04930ad6a3John McCall QualType desugar = split.Ty->getLocallyUnqualifiedSingleStepDesugaredType(); 227200fa53fd420aa8369586f569dbece04930ad6a3John McCall return Context.getQualifiedType(desugar, split.Quals); 228200fa53fd420aa8369586f569dbece04930ad6a3John McCall} 229200fa53fd420aa8369586f569dbece04930ad6a3John McCall 230200fa53fd420aa8369586f569dbece04930ad6a3John McCallQualType Type::getLocallyUnqualifiedSingleStepDesugaredType() const { 231200fa53fd420aa8369586f569dbece04930ad6a3John McCall switch (getTypeClass()) { 232f1588660c109610e6a79c786b83b7c9bbd6ed31eDouglas Gregor#define ABSTRACT_TYPE(Class, Parent) 233f1588660c109610e6a79c786b83b7c9bbd6ed31eDouglas Gregor#define TYPE(Class, Parent) \ 234f1588660c109610e6a79c786b83b7c9bbd6ed31eDouglas Gregor case Type::Class: { \ 235200fa53fd420aa8369586f569dbece04930ad6a3John McCall const Class##Type *ty = cast<Class##Type>(this); \ 236200fa53fd420aa8369586f569dbece04930ad6a3John McCall if (!ty->isSugared()) return QualType(ty, 0); \ 237200fa53fd420aa8369586f569dbece04930ad6a3John McCall return ty->desugar(); \ 238f1588660c109610e6a79c786b83b7c9bbd6ed31eDouglas Gregor } 239f1588660c109610e6a79c786b83b7c9bbd6ed31eDouglas Gregor#include "clang/AST/TypeNodes.def" 240f1588660c109610e6a79c786b83b7c9bbd6ed31eDouglas Gregor } 241200fa53fd420aa8369586f569dbece04930ad6a3John McCall llvm_unreachable("bad type kind!"); 242f1588660c109610e6a79c786b83b7c9bbd6ed31eDouglas Gregor} 243f1588660c109610e6a79c786b83b7c9bbd6ed31eDouglas Gregor 24449f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCallSplitQualType QualType::getSplitDesugaredType(QualType T) { 2450953e767ff7817f97b3ab20896b229891eeff45bJohn McCall QualifierCollector Qs; 246c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner 247bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType Cur = T; 248bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall while (true) { 249bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall const Type *CurTy = Qs.strip(Cur); 250bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall switch (CurTy->getTypeClass()) { 251bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall#define ABSTRACT_TYPE(Class, Parent) 252bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall#define TYPE(Class, Parent) \ 253bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall case Type::Class: { \ 254bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall const Class##Type *Ty = cast<Class##Type>(CurTy); \ 255bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall if (!Ty->isSugared()) \ 25649f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall return SplitQualType(Ty, Qs); \ 257bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall Cur = Ty->desugar(); \ 258bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall break; \ 259bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall } 260bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall#include "clang/AST/TypeNodes.def" 261bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall } 262969c689d893a248eca4f049f5b89f747e66e4bffDouglas Gregor } 263bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall} 2645cdf82164dd7c2b2320d6735c63ace4331e0716dDouglas Gregor 26562c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCallSplitQualType QualType::getSplitUnqualifiedTypeImpl(QualType type) { 26662c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall SplitQualType split = type.split(); 26762c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall 26862c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall // All the qualifiers we've seen so far. 269200fa53fd420aa8369586f569dbece04930ad6a3John McCall Qualifiers quals = split.Quals; 27062c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall 27162c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall // The last type node we saw with any nodes inside it. 272200fa53fd420aa8369586f569dbece04930ad6a3John McCall const Type *lastTypeWithQuals = split.Ty; 27362c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall 27462c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall while (true) { 27562c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall QualType next; 27662c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall 27762c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall // Do a single-step desugar, aborting the loop if the type isn't 27862c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall // sugared. 279200fa53fd420aa8369586f569dbece04930ad6a3John McCall switch (split.Ty->getTypeClass()) { 28062c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall#define ABSTRACT_TYPE(Class, Parent) 28162c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall#define TYPE(Class, Parent) \ 28262c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall case Type::Class: { \ 283200fa53fd420aa8369586f569dbece04930ad6a3John McCall const Class##Type *ty = cast<Class##Type>(split.Ty); \ 28462c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall if (!ty->isSugared()) goto done; \ 28562c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall next = ty->desugar(); \ 28662c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall break; \ 28762c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall } 28862c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall#include "clang/AST/TypeNodes.def" 28962c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall } 29062c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall 29162c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall // Otherwise, split the underlying type. If that yields qualifiers, 29262c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall // update the information. 29362c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall split = next.split(); 294200fa53fd420aa8369586f569dbece04930ad6a3John McCall if (!split.Quals.empty()) { 295200fa53fd420aa8369586f569dbece04930ad6a3John McCall lastTypeWithQuals = split.Ty; 296200fa53fd420aa8369586f569dbece04930ad6a3John McCall quals.addConsistentQualifiers(split.Quals); 29762c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall } 29862c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall } 29962c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall 30062c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall done: 30162c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall return SplitQualType(lastTypeWithQuals, quals); 30262c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall} 30362c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall 304075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo BagnaraQualType QualType::IgnoreParens(QualType T) { 30562c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall // FIXME: this seems inherently un-qualifiers-safe. 306075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara while (const ParenType *PT = T->getAs<ParenType>()) 307075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara T = PT->getInnerType(); 308075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara return T; 309075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara} 310075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 311073819806ba2441e2a3e550107f1e756a6ee3ad0Richard Smith/// \brief This will check for a T (which should be a Type which can act as 312073819806ba2441e2a3e550107f1e756a6ee3ad0Richard Smith/// sugar, such as a TypedefType) by removing any existing sugar until it 313073819806ba2441e2a3e550107f1e756a6ee3ad0Richard Smith/// reaches a T or a non-sugared type. 314073819806ba2441e2a3e550107f1e756a6ee3ad0Richard Smithtemplate<typename T> static const T *getAsSugar(const Type *Cur) { 3152df1a5819fd98708ff3b4772f3477f6c1a8da59aArgyrios Kyrtzidis while (true) { 316073819806ba2441e2a3e550107f1e756a6ee3ad0Richard Smith if (const T *Sugar = dyn_cast<T>(Cur)) 317073819806ba2441e2a3e550107f1e756a6ee3ad0Richard Smith return Sugar; 3182df1a5819fd98708ff3b4772f3477f6c1a8da59aArgyrios Kyrtzidis switch (Cur->getTypeClass()) { 3192df1a5819fd98708ff3b4772f3477f6c1a8da59aArgyrios Kyrtzidis#define ABSTRACT_TYPE(Class, Parent) 3202df1a5819fd98708ff3b4772f3477f6c1a8da59aArgyrios Kyrtzidis#define TYPE(Class, Parent) \ 321073819806ba2441e2a3e550107f1e756a6ee3ad0Richard Smith case Type::Class: { \ 3222df1a5819fd98708ff3b4772f3477f6c1a8da59aArgyrios Kyrtzidis const Class##Type *Ty = cast<Class##Type>(Cur); \ 3232df1a5819fd98708ff3b4772f3477f6c1a8da59aArgyrios Kyrtzidis if (!Ty->isSugared()) return 0; \ 3242df1a5819fd98708ff3b4772f3477f6c1a8da59aArgyrios Kyrtzidis Cur = Ty->desugar().getTypePtr(); \ 3252df1a5819fd98708ff3b4772f3477f6c1a8da59aArgyrios Kyrtzidis break; \ 3262df1a5819fd98708ff3b4772f3477f6c1a8da59aArgyrios Kyrtzidis } 3272df1a5819fd98708ff3b4772f3477f6c1a8da59aArgyrios Kyrtzidis#include "clang/AST/TypeNodes.def" 3282df1a5819fd98708ff3b4772f3477f6c1a8da59aArgyrios Kyrtzidis } 3292df1a5819fd98708ff3b4772f3477f6c1a8da59aArgyrios Kyrtzidis } 3302df1a5819fd98708ff3b4772f3477f6c1a8da59aArgyrios Kyrtzidis} 3312df1a5819fd98708ff3b4772f3477f6c1a8da59aArgyrios Kyrtzidis 332073819806ba2441e2a3e550107f1e756a6ee3ad0Richard Smithtemplate <> const TypedefType *Type::getAs() const { 333073819806ba2441e2a3e550107f1e756a6ee3ad0Richard Smith return getAsSugar<TypedefType>(this); 334073819806ba2441e2a3e550107f1e756a6ee3ad0Richard Smith} 335073819806ba2441e2a3e550107f1e756a6ee3ad0Richard Smith 336073819806ba2441e2a3e550107f1e756a6ee3ad0Richard Smithtemplate <> const TemplateSpecializationType *Type::getAs() const { 337073819806ba2441e2a3e550107f1e756a6ee3ad0Richard Smith return getAsSugar<TemplateSpecializationType>(this); 338073819806ba2441e2a3e550107f1e756a6ee3ad0Richard Smith} 339073819806ba2441e2a3e550107f1e756a6ee3ad0Richard Smith 340bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall/// getUnqualifiedDesugaredType - Pull any qualifiers and syntactic 341bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall/// sugar off the given type. This should produce an object of the 342bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall/// same dynamic type as the canonical type. 343bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCallconst Type *Type::getUnqualifiedDesugaredType() const { 344bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall const Type *Cur = this; 345bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 346bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall while (true) { 347bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall switch (Cur->getTypeClass()) { 348bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall#define ABSTRACT_TYPE(Class, Parent) 349bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall#define TYPE(Class, Parent) \ 350bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall case Class: { \ 351bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall const Class##Type *Ty = cast<Class##Type>(Cur); \ 352bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall if (!Ty->isSugared()) return Cur; \ 353bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall Cur = Ty->desugar().getTypePtr(); \ 354bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall break; \ 355bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall } 356bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall#include "clang/AST/TypeNodes.def" 357bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall } 358bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall } 359c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner} 360c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner 3615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isDerivedType() const { 3625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer switch (CanonicalType->getTypeClass()) { 3635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Pointer: 364fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff case VariableArray: 365fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff case ConstantArray: 366c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman case IncompleteArray: 3675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case FunctionProto: 3685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case FunctionNoProto: 3697c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl case LValueReference: 3707c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl case RValueReference: 37172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor case Record: 3725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return true; 3735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer default: 3745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return false; 3755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 3765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 37799dc91422144483c20d1c7381bc9ac634b646b04Chris Lattnerbool Type::isClassType() const { 3786217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const RecordType *RT = getAs<RecordType>()) 379f728a4a05df2455e1c6e62173ab720a92cd4a074Chris Lattner return RT->getDecl()->isClass(); 38099dc91422144483c20d1c7381bc9ac634b646b04Chris Lattner return false; 38199dc91422144483c20d1c7381bc9ac634b646b04Chris Lattner} 382c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattnerbool Type::isStructureType() const { 3836217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const RecordType *RT = getAs<RecordType>()) 384f728a4a05df2455e1c6e62173ab720a92cd4a074Chris Lattner return RT->getDecl()->isStruct(); 385c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner return false; 386c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner} 3876666ed4ed2e2bc13da5ac5d0a4947019137d45beJoao Matosbool Type::isInterfaceType() const { 3886666ed4ed2e2bc13da5ac5d0a4947019137d45beJoao Matos if (const RecordType *RT = getAs<RecordType>()) 3896666ed4ed2e2bc13da5ac5d0a4947019137d45beJoao Matos return RT->getDecl()->isInterface(); 3906666ed4ed2e2bc13da5ac5d0a4947019137d45beJoao Matos return false; 3916666ed4ed2e2bc13da5ac5d0a4947019137d45beJoao Matos} 392fb87b89fc9eb103e19fb8e4b925c23f0bd091b99Douglas Gregorbool Type::isStructureOrClassType() const { 393fb87b89fc9eb103e19fb8e4b925c23f0bd091b99Douglas Gregor if (const RecordType *RT = getAs<RecordType>()) 3946666ed4ed2e2bc13da5ac5d0a4947019137d45beJoao Matos return RT->getDecl()->isStruct() || RT->getDecl()->isClass() || 3956666ed4ed2e2bc13da5ac5d0a4947019137d45beJoao Matos RT->getDecl()->isInterface(); 396fb87b89fc9eb103e19fb8e4b925c23f0bd091b99Douglas Gregor return false; 397fb87b89fc9eb103e19fb8e4b925c23f0bd091b99Douglas Gregor} 3987154a77e7c1f23418342d3b72836ab504aa7821eSteve Naroffbool Type::isVoidPointerType() const { 3996217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const PointerType *PT = getAs<PointerType>()) 4007154a77e7c1f23418342d3b72836ab504aa7821eSteve Naroff return PT->getPointeeType()->isVoidType(); 4017154a77e7c1f23418342d3b72836ab504aa7821eSteve Naroff return false; 4027154a77e7c1f23418342d3b72836ab504aa7821eSteve Naroff} 4037154a77e7c1f23418342d3b72836ab504aa7821eSteve Naroff 404c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattnerbool Type::isUnionType() const { 4056217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const RecordType *RT = getAs<RecordType>()) 406f728a4a05df2455e1c6e62173ab720a92cd4a074Chris Lattner return RT->getDecl()->isUnion(); 407c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner return false; 408c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner} 409c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner 410c6fb90a7246c2d5d3233e70107bf9d8c7c9e535bChris Lattnerbool Type::isComplexType() const { 41102f62a9fedbc370fba081303399410a3afdde29fSteve Naroff if (const ComplexType *CT = dyn_cast<ComplexType>(CanonicalType)) 41202f62a9fedbc370fba081303399410a3afdde29fSteve Naroff return CT->getElementType()->isFloatingType(); 41302f62a9fedbc370fba081303399410a3afdde29fSteve Naroff return false; 414c6fb90a7246c2d5d3233e70107bf9d8c7c9e535bChris Lattner} 415c6fb90a7246c2d5d3233e70107bf9d8c7c9e535bChris Lattner 4164cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroffbool Type::isComplexIntegerType() const { 4174cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroff // Check for GCC complex integer extension. 4180953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return getAsComplexIntegerType(); 4194cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroff} 4204cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroff 4214cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroffconst ComplexType *Type::getAsComplexIntegerType() const { 4220953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (const ComplexType *Complex = getAs<ComplexType>()) 4230953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (Complex->getElementType()->isIntegerType()) 4240953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return Complex; 4250953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return 0; 4264cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroff} 4274cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroff 42814108da7f7fc059772711e4ffee1322a27b152a7Steve NaroffQualType Type::getPointeeType() const { 4296217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const PointerType *PT = getAs<PointerType>()) 43014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return PT->getPointeeType(); 431183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) 43214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return OPT->getPointeeType(); 4336217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const BlockPointerType *BPT = getAs<BlockPointerType>()) 43414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return BPT->getPointeeType(); 4359c21289a866b677d21ed3d5ecfdfd5ced5a55410Mike Stump if (const ReferenceType *RT = getAs<ReferenceType>()) 4369c21289a866b677d21ed3d5ecfdfd5ced5a55410Mike Stump return RT->getPointeeType(); 43714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return QualType(); 43814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff} 439b77792eabf5882cf9af8cc810599b20432fda6c2Chris Lattner 440c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattnerconst RecordType *Type::getAsStructureType() const { 4417064f5c95bbdb17680d0ea658d4090898c2592d3Steve Naroff // If this is directly a structure type, return it. 442c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner if (const RecordType *RT = dyn_cast<RecordType>(this)) { 44339ba4aeca296b1c9f04bde7d9d3cbbf129f1abd3Argyrios Kyrtzidis if (RT->getDecl()->isStruct()) 444c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner return RT; 4457064f5c95bbdb17680d0ea658d4090898c2592d3Steve Naroff } 446dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner 447dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner // If the canonical form of this type isn't the right kind, reject it. 448c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner if (const RecordType *RT = dyn_cast<RecordType>(CanonicalType)) { 44939ba4aeca296b1c9f04bde7d9d3cbbf129f1abd3Argyrios Kyrtzidis if (!RT->getDecl()->isStruct()) 450dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner return 0; 4511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 452dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner // If this is a typedef for a structure type, strip the typedef off without 453dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner // losing all typedef information. 454bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall return cast<RecordType>(getUnqualifiedDesugaredType()); 4555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 4567064f5c95bbdb17680d0ea658d4090898c2592d3Steve Naroff return 0; 4575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 4585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpconst RecordType *Type::getAsUnionType() const { 4607064f5c95bbdb17680d0ea658d4090898c2592d3Steve Naroff // If this is directly a union type, return it. 461c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner if (const RecordType *RT = dyn_cast<RecordType>(this)) { 46239ba4aeca296b1c9f04bde7d9d3cbbf129f1abd3Argyrios Kyrtzidis if (RT->getDecl()->isUnion()) 463c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner return RT; 4647064f5c95bbdb17680d0ea658d4090898c2592d3Steve Naroff } 4651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 466dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner // If the canonical form of this type isn't the right kind, reject it. 467c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner if (const RecordType *RT = dyn_cast<RecordType>(CanonicalType)) { 46839ba4aeca296b1c9f04bde7d9d3cbbf129f1abd3Argyrios Kyrtzidis if (!RT->getDecl()->isUnion()) 469dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner return 0; 470dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner 471dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner // If this is a typedef for a union type, strip the typedef off without 472dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner // losing all typedef information. 473bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall return cast<RecordType>(getUnqualifiedDesugaredType()); 4745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 4751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4767064f5c95bbdb17680d0ea658d4090898c2592d3Steve Naroff return 0; 4775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 4785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 479c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallObjCObjectType::ObjCObjectType(QualType Canonical, QualType Base, 480c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCProtocolDecl * const *Protocols, 481c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall unsigned NumProtocols) 482561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor : Type(ObjCObject, Canonical, false, false, false, false), 483d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor BaseType(Base) 484d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor{ 485b870b88df784c2940efce448ebfaf54dece14666John McCall ObjCObjectTypeBits.NumProtocols = NumProtocols; 48671c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall assert(getNumProtocols() == NumProtocols && 487c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall "bitfield overflow in protocol count"); 488fd6a0887a099256c35a5b23e9afd517ffe95fa0aDouglas Gregor if (NumProtocols) 489c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall memcpy(getProtocolStorage(), Protocols, 490c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall NumProtocols * sizeof(ObjCProtocolDecl*)); 49171842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek} 49271842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek 493c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallconst ObjCObjectType *Type::getAsObjCQualifiedInterfaceType() const { 494c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall // There is no sugar for ObjCObjectType's, just return the canonical 495c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff // type pointer if it is the right class. There is no typedef information to 496c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff // return and these cannot be Address-space qualified. 497c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall if (const ObjCObjectType *T = getAs<ObjCObjectType>()) 498c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall if (T->getNumProtocols() && T->getInterface()) 499c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return T; 500c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff return 0; 501c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff} 502c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff 503c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroffbool Type::isObjCQualifiedInterfaceType() const { 504e61ad0b7063fcd97204b1cce5558685144267eb6Steve Naroff return getAsObjCQualifiedInterfaceType() != 0; 505c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff} 506c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff 507d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroffconst ObjCObjectPointerType *Type::getAsObjCQualifiedIdType() const { 508eca7be6b7ebd93682eeaab2c71d59f2995dacdccChris Lattner // There is no sugar for ObjCQualifiedIdType's, just return the canonical 509eca7be6b7ebd93682eeaab2c71d59f2995dacdccChris Lattner // type pointer if it is the right class. 510183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) { 511d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff if (OPT->isObjCQualifiedIdType()) 512d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff return OPT; 513d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff } 514d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff return 0; 515368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner} 516368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner 517759abb4d9ec14ae32104a9677b60f0542b60d1d8Fariborz Jahanianconst ObjCObjectPointerType *Type::getAsObjCQualifiedClassType() const { 518759abb4d9ec14ae32104a9677b60f0542b60d1d8Fariborz Jahanian // There is no sugar for ObjCQualifiedClassType's, just return the canonical 519759abb4d9ec14ae32104a9677b60f0542b60d1d8Fariborz Jahanian // type pointer if it is the right class. 520759abb4d9ec14ae32104a9677b60f0542b60d1d8Fariborz Jahanian if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) { 521759abb4d9ec14ae32104a9677b60f0542b60d1d8Fariborz Jahanian if (OPT->isObjCQualifiedClassType()) 522759abb4d9ec14ae32104a9677b60f0542b60d1d8Fariborz Jahanian return OPT; 523759abb4d9ec14ae32104a9677b60f0542b60d1d8Fariborz Jahanian } 524759abb4d9ec14ae32104a9677b60f0542b60d1d8Fariborz Jahanian return 0; 525759abb4d9ec14ae32104a9677b60f0542b60d1d8Fariborz Jahanian} 526759abb4d9ec14ae32104a9677b60f0542b60d1d8Fariborz Jahanian 52714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroffconst ObjCObjectPointerType *Type::getAsObjCInterfacePointerType() const { 528183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) { 52914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff if (OPT->getInterfaceType()) 53014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return OPT; 53114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff } 53214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return 0; 53314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff} 53414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff 535041ce8e00afd1185549a25d5c2b97d219ae032d9Jordan Roseconst CXXRecordDecl *Type::getPointeeCXXRecordDecl() const { 536041ce8e00afd1185549a25d5c2b97d219ae032d9Jordan Rose QualType PointeeType; 5376217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const PointerType *PT = getAs<PointerType>()) 538041ce8e00afd1185549a25d5c2b97d219ae032d9Jordan Rose PointeeType = PT->getPointeeType(); 539041ce8e00afd1185549a25d5c2b97d219ae032d9Jordan Rose else if (const ReferenceType *RT = getAs<ReferenceType>()) 540041ce8e00afd1185549a25d5c2b97d219ae032d9Jordan Rose PointeeType = RT->getPointeeType(); 541041ce8e00afd1185549a25d5c2b97d219ae032d9Jordan Rose else 542041ce8e00afd1185549a25d5c2b97d219ae032d9Jordan Rose return 0; 543041ce8e00afd1185549a25d5c2b97d219ae032d9Jordan Rose 544041ce8e00afd1185549a25d5c2b97d219ae032d9Jordan Rose if (const RecordType *RT = PointeeType->getAs<RecordType>()) 545041ce8e00afd1185549a25d5c2b97d219ae032d9Jordan Rose return dyn_cast<CXXRecordDecl>(RT->getDecl()); 546041ce8e00afd1185549a25d5c2b97d219ae032d9Jordan Rose 547a91d6a6619a91d0ca7102d8ab5678d855f04d850Fariborz Jahanian return 0; 548a91d6a6619a91d0ca7102d8ab5678d855f04d850Fariborz Jahanian} 549a91d6a6619a91d0ca7102d8ab5678d855f04d850Fariborz Jahanian 550c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas GregorCXXRecordDecl *Type::getAsCXXRecordDecl() const { 551c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor if (const RecordType *RT = getAs<RecordType>()) 552c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor return dyn_cast<CXXRecordDecl>(RT->getDecl()); 553c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor else if (const InjectedClassNameType *Injected 554c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor = getAs<InjectedClassNameType>()) 555c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor return Injected->getDecl(); 556c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor 557c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor return 0; 558c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor} 559c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor 56034b41d939a1328f484511c6002ba2456db879a29Richard Smithnamespace { 56134b41d939a1328f484511c6002ba2456db879a29Richard Smith class GetContainedAutoVisitor : 56234b41d939a1328f484511c6002ba2456db879a29Richard Smith public TypeVisitor<GetContainedAutoVisitor, AutoType*> { 56334b41d939a1328f484511c6002ba2456db879a29Richard Smith public: 56434b41d939a1328f484511c6002ba2456db879a29Richard Smith using TypeVisitor<GetContainedAutoVisitor, AutoType*>::Visit; 56534b41d939a1328f484511c6002ba2456db879a29Richard Smith AutoType *Visit(QualType T) { 56634b41d939a1328f484511c6002ba2456db879a29Richard Smith if (T.isNull()) 56734b41d939a1328f484511c6002ba2456db879a29Richard Smith return 0; 56834b41d939a1328f484511c6002ba2456db879a29Richard Smith return Visit(T.getTypePtr()); 56934b41d939a1328f484511c6002ba2456db879a29Richard Smith } 57034b41d939a1328f484511c6002ba2456db879a29Richard Smith 57134b41d939a1328f484511c6002ba2456db879a29Richard Smith // The 'auto' type itself. 57234b41d939a1328f484511c6002ba2456db879a29Richard Smith AutoType *VisitAutoType(const AutoType *AT) { 57334b41d939a1328f484511c6002ba2456db879a29Richard Smith return const_cast<AutoType*>(AT); 57434b41d939a1328f484511c6002ba2456db879a29Richard Smith } 57534b41d939a1328f484511c6002ba2456db879a29Richard Smith 57634b41d939a1328f484511c6002ba2456db879a29Richard Smith // Only these types can contain the desired 'auto' type. 57734b41d939a1328f484511c6002ba2456db879a29Richard Smith AutoType *VisitPointerType(const PointerType *T) { 57834b41d939a1328f484511c6002ba2456db879a29Richard Smith return Visit(T->getPointeeType()); 57934b41d939a1328f484511c6002ba2456db879a29Richard Smith } 58034b41d939a1328f484511c6002ba2456db879a29Richard Smith AutoType *VisitBlockPointerType(const BlockPointerType *T) { 58134b41d939a1328f484511c6002ba2456db879a29Richard Smith return Visit(T->getPointeeType()); 58234b41d939a1328f484511c6002ba2456db879a29Richard Smith } 58334b41d939a1328f484511c6002ba2456db879a29Richard Smith AutoType *VisitReferenceType(const ReferenceType *T) { 58434b41d939a1328f484511c6002ba2456db879a29Richard Smith return Visit(T->getPointeeTypeAsWritten()); 58534b41d939a1328f484511c6002ba2456db879a29Richard Smith } 58634b41d939a1328f484511c6002ba2456db879a29Richard Smith AutoType *VisitMemberPointerType(const MemberPointerType *T) { 58734b41d939a1328f484511c6002ba2456db879a29Richard Smith return Visit(T->getPointeeType()); 58834b41d939a1328f484511c6002ba2456db879a29Richard Smith } 58934b41d939a1328f484511c6002ba2456db879a29Richard Smith AutoType *VisitArrayType(const ArrayType *T) { 59034b41d939a1328f484511c6002ba2456db879a29Richard Smith return Visit(T->getElementType()); 59134b41d939a1328f484511c6002ba2456db879a29Richard Smith } 59234b41d939a1328f484511c6002ba2456db879a29Richard Smith AutoType *VisitDependentSizedExtVectorType( 59334b41d939a1328f484511c6002ba2456db879a29Richard Smith const DependentSizedExtVectorType *T) { 59434b41d939a1328f484511c6002ba2456db879a29Richard Smith return Visit(T->getElementType()); 59534b41d939a1328f484511c6002ba2456db879a29Richard Smith } 59634b41d939a1328f484511c6002ba2456db879a29Richard Smith AutoType *VisitVectorType(const VectorType *T) { 59734b41d939a1328f484511c6002ba2456db879a29Richard Smith return Visit(T->getElementType()); 59834b41d939a1328f484511c6002ba2456db879a29Richard Smith } 59934b41d939a1328f484511c6002ba2456db879a29Richard Smith AutoType *VisitFunctionType(const FunctionType *T) { 60034b41d939a1328f484511c6002ba2456db879a29Richard Smith return Visit(T->getResultType()); 60134b41d939a1328f484511c6002ba2456db879a29Richard Smith } 60234b41d939a1328f484511c6002ba2456db879a29Richard Smith AutoType *VisitParenType(const ParenType *T) { 60334b41d939a1328f484511c6002ba2456db879a29Richard Smith return Visit(T->getInnerType()); 60434b41d939a1328f484511c6002ba2456db879a29Richard Smith } 60534b41d939a1328f484511c6002ba2456db879a29Richard Smith AutoType *VisitAttributedType(const AttributedType *T) { 60634b41d939a1328f484511c6002ba2456db879a29Richard Smith return Visit(T->getModifiedType()); 60734b41d939a1328f484511c6002ba2456db879a29Richard Smith } 60834b41d939a1328f484511c6002ba2456db879a29Richard Smith }; 60934b41d939a1328f484511c6002ba2456db879a29Richard Smith} 61034b41d939a1328f484511c6002ba2456db879a29Richard Smith 61134b41d939a1328f484511c6002ba2456db879a29Richard SmithAutoType *Type::getContainedAutoType() const { 61234b41d939a1328f484511c6002ba2456db879a29Richard Smith return GetContainedAutoVisitor().Visit(this); 61334b41d939a1328f484511c6002ba2456db879a29Richard Smith} 61434b41d939a1328f484511c6002ba2456db879a29Richard Smith 615f60946222721d9ba3c059563935c17b84703187aDouglas Gregorbool Type::hasIntegerRepresentation() const { 616c63b96ad706e054a1390dd2ab53af9f05d33bbb1Steve Naroff if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType)) 617c63b96ad706e054a1390dd2ab53af9f05d33bbb1Steve Naroff return VT->getElementType()->isIntegerType(); 618f60946222721d9ba3c059563935c17b84703187aDouglas Gregor else 619f60946222721d9ba3c059563935c17b84703187aDouglas Gregor return isIntegerType(); 6205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 6215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6229d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// \brief Determine whether this type is an integral type. 6239d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// 6249d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// This routine determines whether the given type is an integral type per 6259d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// C++ [basic.fundamental]p7. Although the C standard does not define the 6269d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// term "integral type", it has a similar term "integer type", and in C++ 6279d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// the two terms are equivalent. However, C's "integer type" includes 6289d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// enumeration types, while C++'s "integer type" does not. The \c ASTContext 6299d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// parameter is used to determine whether we should be following the C or 6309d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// C++ rules when determining whether this type is an integral/integer type. 6319d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// 6329d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// For cases where C permits "an integer type" and C++ permits "an integral 6339d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// type", use this routine. 6349d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// 6359d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// For cases where C permits "an integer type" and C++ permits "an integral 6369d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// or enumeration type", use \c isIntegralOrEnumerationType() instead. 6379d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// 6389d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// \param Ctx The context in which this type occurs. 6399d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// 6409d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// \returns true if the type is considered an integral type, false otherwise. 6419d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregorbool Type::isIntegralType(ASTContext &Ctx) const { 64233e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 64333e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian return BT->getKind() >= BuiltinType::Bool && 644f5f7d864f5067d1ea4bff7fcf41b53a43b7b48baAnders Carlsson BT->getKind() <= BuiltinType::Int128; 6459d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor 6464e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie if (!Ctx.getLangOpts().CPlusPlus) 6471274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) 6481274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor return ET->getDecl()->isComplete(); // Complete enum types are integral in C. 6499d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor 65033e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian return false; 65133e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian} 65233e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian 6532ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor 6541274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregorbool Type::isIntegralOrUnscopedEnumerationType() const { 6551274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 6561274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor return BT->getKind() >= BuiltinType::Bool && 6571274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor BT->getKind() <= BuiltinType::Int128; 6581274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor 6591274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor // Check for a complete enum type; incomplete enum types are not properly an 6601274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor // enumeration type in the sense required here. 6611274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor // C++0x: However, if the underlying type of the enum is fixed, it is 6621274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor // considered complete. 6631274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) 6641274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor return ET->getDecl()->isComplete() && !ET->getDecl()->isScoped(); 6651274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor 6661274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor return false; 6671274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor} 6681274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor 6691274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor 670f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbar 67113b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroffbool Type::isCharType() const { 67213b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 67313b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff return BT->getKind() == BuiltinType::Char_U || 67413b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff BT->getKind() == BuiltinType::UChar || 675c67ad5f299bb2c09e4567def8ff0d34bd15a42fdAnders Carlsson BT->getKind() == BuiltinType::Char_S || 676c67ad5f299bb2c09e4567def8ff0d34bd15a42fdAnders Carlsson BT->getKind() == BuiltinType::SChar; 67713b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff return false; 67813b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff} 67913b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff 68077a52233f7c0f162672652051bfe78b65ad4f789Douglas Gregorbool Type::isWideCharType() const { 68177a52233f7c0f162672652051bfe78b65ad4f789Douglas Gregor if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 6823f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner return BT->getKind() == BuiltinType::WChar_S || 6833f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner BT->getKind() == BuiltinType::WChar_U; 68477a52233f7c0f162672652051bfe78b65ad4f789Douglas Gregor return false; 68577a52233f7c0f162672652051bfe78b65ad4f789Douglas Gregor} 68677a52233f7c0f162672652051bfe78b65ad4f789Douglas Gregor 6875cee1195584fa8672253139c86e922daeda69b9eDouglas Gregorbool Type::isChar16Type() const { 6885cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 6895cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor return BT->getKind() == BuiltinType::Char16; 6905cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor return false; 6915cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor} 6925cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor 6935cee1195584fa8672253139c86e922daeda69b9eDouglas Gregorbool Type::isChar32Type() const { 6945cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 6955cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor return BT->getKind() == BuiltinType::Char32; 6965cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor return false; 6975cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor} 6985cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor 69920093b4bf698f292c664676987541d5103b65b15Douglas Gregor/// \brief Determine whether this type is any of the built-in character 70020093b4bf698f292c664676987541d5103b65b15Douglas Gregor/// types. 70120093b4bf698f292c664676987541d5103b65b15Douglas Gregorbool Type::isAnyCharacterType() const { 7023f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType); 7033f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner if (BT == 0) return false; 7043f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner switch (BT->getKind()) { 7053f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner default: return false; 7063f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner case BuiltinType::Char_U: 7073f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner case BuiltinType::UChar: 7083f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner case BuiltinType::WChar_U: 7093f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner case BuiltinType::Char16: 7103f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner case BuiltinType::Char32: 7113f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner case BuiltinType::Char_S: 7123f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner case BuiltinType::SChar: 7133f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner case BuiltinType::WChar_S: 7143f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner return true; 7153f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner } 71620093b4bf698f292c664676987541d5103b65b15Douglas Gregor} 71720093b4bf698f292c664676987541d5103b65b15Douglas Gregor 718d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner/// isSignedIntegerType - Return true if this is an integer type that is 719d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner/// signed, according to C99 6.2.5p4 [char, signed char, short, int, long..], 720f60946222721d9ba3c059563935c17b84703187aDouglas Gregor/// an enum decl which has a signed representation 7215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isSignedIntegerType() const { 7225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) { 7235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return BT->getKind() >= BuiltinType::Char_S && 724f5f7d864f5067d1ea4bff7fcf41b53a43b7b48baAnders Carlsson BT->getKind() <= BuiltinType::Int128; 7255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 7261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 727bbd340717422bf011d56cd0164d2576601368111Fariborz Jahanian if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) { 728bbd340717422bf011d56cd0164d2576601368111Fariborz Jahanian // Incomplete enum types are not treated as integer types. 729bbd340717422bf011d56cd0164d2576601368111Fariborz Jahanian // FIXME: In C++, enum types are never integer types. 730b6adf2c889bb17c1be44e6c8e67e3b2762e9ceccDouglas Gregor if (ET->getDecl()->isComplete() && !ET->getDecl()->isScoped()) 731bbd340717422bf011d56cd0164d2576601368111Fariborz Jahanian return ET->getDecl()->getIntegerType()->isSignedIntegerType(); 732bbd340717422bf011d56cd0164d2576601368111Fariborz Jahanian } 7331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 734f60946222721d9ba3c059563935c17b84703187aDouglas Gregor return false; 735f60946222721d9ba3c059563935c17b84703187aDouglas Gregor} 736f60946222721d9ba3c059563935c17b84703187aDouglas Gregor 737575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregorbool Type::isSignedIntegerOrEnumerationType() const { 738575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) { 739575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor return BT->getKind() >= BuiltinType::Char_S && 740575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor BT->getKind() <= BuiltinType::Int128; 741575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor } 742575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor 743575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) { 744575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor if (ET->getDecl()->isComplete()) 745575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor return ET->getDecl()->getIntegerType()->isSignedIntegerType(); 746575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor } 747575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor 748575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor return false; 749575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor} 750575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor 751f60946222721d9ba3c059563935c17b84703187aDouglas Gregorbool Type::hasSignedIntegerRepresentation() const { 752c63b96ad706e054a1390dd2ab53af9f05d33bbb1Steve Naroff if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType)) 753c63b96ad706e054a1390dd2ab53af9f05d33bbb1Steve Naroff return VT->getElementType()->isSignedIntegerType(); 754f60946222721d9ba3c059563935c17b84703187aDouglas Gregor else 755f60946222721d9ba3c059563935c17b84703187aDouglas Gregor return isSignedIntegerType(); 7565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 7575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 758d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner/// isUnsignedIntegerType - Return true if this is an integer type that is 759d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner/// unsigned, according to C99 6.2.5p6 [which returns true for _Bool], an enum 760f60946222721d9ba3c059563935c17b84703187aDouglas Gregor/// decl which has an unsigned representation 7615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isUnsignedIntegerType() const { 7625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) { 7635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return BT->getKind() >= BuiltinType::Bool && 7641c03ca30ae962199ef702324b48550f6af7fdc32Anders Carlsson BT->getKind() <= BuiltinType::UInt128; 7655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 766d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner 767bbd340717422bf011d56cd0164d2576601368111Fariborz Jahanian if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) { 768bbd340717422bf011d56cd0164d2576601368111Fariborz Jahanian // Incomplete enum types are not treated as integer types. 769bbd340717422bf011d56cd0164d2576601368111Fariborz Jahanian // FIXME: In C++, enum types are never integer types. 770b6adf2c889bb17c1be44e6c8e67e3b2762e9ceccDouglas Gregor if (ET->getDecl()->isComplete() && !ET->getDecl()->isScoped()) 771bbd340717422bf011d56cd0164d2576601368111Fariborz Jahanian return ET->getDecl()->getIntegerType()->isUnsignedIntegerType(); 772bbd340717422bf011d56cd0164d2576601368111Fariborz Jahanian } 773d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner 774f60946222721d9ba3c059563935c17b84703187aDouglas Gregor return false; 775f60946222721d9ba3c059563935c17b84703187aDouglas Gregor} 776f60946222721d9ba3c059563935c17b84703187aDouglas Gregor 777575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregorbool Type::isUnsignedIntegerOrEnumerationType() const { 778575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) { 779575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor return BT->getKind() >= BuiltinType::Bool && 780575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor BT->getKind() <= BuiltinType::UInt128; 781575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor } 782575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor 783575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) { 784575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor if (ET->getDecl()->isComplete()) 785575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor return ET->getDecl()->getIntegerType()->isUnsignedIntegerType(); 786575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor } 787575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor 788575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor return false; 789575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor} 790575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor 791f60946222721d9ba3c059563935c17b84703187aDouglas Gregorbool Type::hasUnsignedIntegerRepresentation() const { 792c63b96ad706e054a1390dd2ab53af9f05d33bbb1Steve Naroff if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType)) 793c63b96ad706e054a1390dd2ab53af9f05d33bbb1Steve Naroff return VT->getElementType()->isUnsignedIntegerType(); 794f60946222721d9ba3c059563935c17b84703187aDouglas Gregor else 795f60946222721d9ba3c059563935c17b84703187aDouglas Gregor return isUnsignedIntegerType(); 7965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 7975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isFloatingType() const { 7995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 800aa4a99b4a62615db243f7a5c433169f2fc704420Anton Korobeynikov return BT->getKind() >= BuiltinType::Half && 8015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer BT->getKind() <= BuiltinType::LongDouble; 8025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (const ComplexType *CT = dyn_cast<ComplexType>(CanonicalType)) 803729a2131228cb7fcbc00bd8af36bc6f14d12317dChris Lattner return CT->getElementType()->isFloatingType(); 8048eee119bf4f1693dde17b8552c1f9f81bf2b681eDouglas Gregor return false; 8058eee119bf4f1693dde17b8552c1f9f81bf2b681eDouglas Gregor} 8068eee119bf4f1693dde17b8552c1f9f81bf2b681eDouglas Gregor 8078eee119bf4f1693dde17b8552c1f9f81bf2b681eDouglas Gregorbool Type::hasFloatingRepresentation() const { 808c63b96ad706e054a1390dd2ab53af9f05d33bbb1Steve Naroff if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType)) 809c63b96ad706e054a1390dd2ab53af9f05d33bbb1Steve Naroff return VT->getElementType()->isFloatingType(); 8108eee119bf4f1693dde17b8552c1f9f81bf2b681eDouglas Gregor else 8118eee119bf4f1693dde17b8552c1f9f81bf2b681eDouglas Gregor return isFloatingType(); 8125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 8135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isRealFloatingType() const { 8155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 816680523a91dd3351389667c8de17121ba7ae82673John McCall return BT->isFloatingPoint(); 8175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return false; 8185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 8195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isRealType() const { 8215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 8225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return BT->getKind() >= BuiltinType::Bool && 8235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer BT->getKind() <= BuiltinType::LongDouble; 8241274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) 8251274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor return ET->getDecl()->isComplete() && !ET->getDecl()->isScoped(); 8265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return false; 8275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 8285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isArithmeticType() const { 8305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 831a7fbf7282eadebaf1293d9f970b01fb57f4b0ae4Douglas Gregor return BT->getKind() >= BuiltinType::Bool && 832a7fbf7282eadebaf1293d9f970b01fb57f4b0ae4Douglas Gregor BT->getKind() <= BuiltinType::LongDouble; 83337c1b78a20a09b0456aa5caa15e159027010ca22Chris Lattner if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) 83437c1b78a20a09b0456aa5caa15e159027010ca22Chris Lattner // GCC allows forward declaration of enum types (forbid by C99 6.7.2.3p2). 83537c1b78a20a09b0456aa5caa15e159027010ca22Chris Lattner // If a body isn't seen by the time we get here, return false. 8361274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor // 8371274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor // C++0x: Enumerations are not arithmetic types. For now, just return 8381274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor // false for scoped enumerations since that will disable any 8391274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor // unwanted implicit conversions. 8401274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor return !ET->getDecl()->isScoped() && ET->getDecl()->isComplete(); 84100619623af0b9d3271e31402ec1a95e84c2c4526Douglas Gregor return isa<ComplexType>(CanonicalType); 8425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 8435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 844daa8e4e888758d55a7a759dd4a91b83921cef222John McCallType::ScalarTypeKind Type::getScalarTypeKind() const { 845daa8e4e888758d55a7a759dd4a91b83921cef222John McCall assert(isScalarType()); 846daa8e4e888758d55a7a759dd4a91b83921cef222John McCall 847daa8e4e888758d55a7a759dd4a91b83921cef222John McCall const Type *T = CanonicalType.getTypePtr(); 848daa8e4e888758d55a7a759dd4a91b83921cef222John McCall if (const BuiltinType *BT = dyn_cast<BuiltinType>(T)) { 849daa8e4e888758d55a7a759dd4a91b83921cef222John McCall if (BT->getKind() == BuiltinType::Bool) return STK_Bool; 8501d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall if (BT->getKind() == BuiltinType::NullPtr) return STK_CPointer; 851daa8e4e888758d55a7a759dd4a91b83921cef222John McCall if (BT->isInteger()) return STK_Integral; 852daa8e4e888758d55a7a759dd4a91b83921cef222John McCall if (BT->isFloatingPoint()) return STK_Floating; 853daa8e4e888758d55a7a759dd4a91b83921cef222John McCall llvm_unreachable("unknown scalar builtin type"); 8541d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall } else if (isa<PointerType>(T)) { 8551d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall return STK_CPointer; 8561d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall } else if (isa<BlockPointerType>(T)) { 8571d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall return STK_BlockPointer; 8581d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall } else if (isa<ObjCObjectPointerType>(T)) { 8591d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall return STK_ObjCObjectPointer; 860daa8e4e888758d55a7a759dd4a91b83921cef222John McCall } else if (isa<MemberPointerType>(T)) { 861daa8e4e888758d55a7a759dd4a91b83921cef222John McCall return STK_MemberPointer; 862daa8e4e888758d55a7a759dd4a91b83921cef222John McCall } else if (isa<EnumType>(T)) { 863daa8e4e888758d55a7a759dd4a91b83921cef222John McCall assert(cast<EnumType>(T)->getDecl()->isComplete()); 864daa8e4e888758d55a7a759dd4a91b83921cef222John McCall return STK_Integral; 865daa8e4e888758d55a7a759dd4a91b83921cef222John McCall } else if (const ComplexType *CT = dyn_cast<ComplexType>(T)) { 866daa8e4e888758d55a7a759dd4a91b83921cef222John McCall if (CT->getElementType()->isRealFloatingType()) 867daa8e4e888758d55a7a759dd4a91b83921cef222John McCall return STK_FloatingComplex; 868daa8e4e888758d55a7a759dd4a91b83921cef222John McCall return STK_IntegralComplex; 869daa8e4e888758d55a7a759dd4a91b83921cef222John McCall } 870daa8e4e888758d55a7a759dd4a91b83921cef222John McCall 871daa8e4e888758d55a7a759dd4a91b83921cef222John McCall llvm_unreachable("unknown scalar type"); 872daa8e4e888758d55a7a759dd4a91b83921cef222John McCall} 873daa8e4e888758d55a7a759dd4a91b83921cef222John McCall 874d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor/// \brief Determines whether the type is a C++ aggregate type or C 875d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor/// aggregate or union type. 876d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor/// 877d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor/// An aggregate type is an array or a class type (struct, union, or 878d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor/// class) that has no user-declared constructors, no private or 879d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor/// protected non-static data members, no base classes, and no virtual 880d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor/// functions (C++ [dcl.init.aggr]p1). The notion of an aggregate type 881d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor/// subsumes the notion of C aggregates (C99 6.2.5p21) because it also 882d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor/// includes union types. 8835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isAggregateType() const { 884c1efaecf0373f1a55c5ef4c234357cf726fc0600Douglas Gregor if (const RecordType *Record = dyn_cast<RecordType>(CanonicalType)) { 885c1efaecf0373f1a55c5ef4c234357cf726fc0600Douglas Gregor if (CXXRecordDecl *ClassDecl = dyn_cast<CXXRecordDecl>(Record->getDecl())) 886c1efaecf0373f1a55c5ef4c234357cf726fc0600Douglas Gregor return ClassDecl->isAggregate(); 887c1efaecf0373f1a55c5ef4c234357cf726fc0600Douglas Gregor 888d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor return true; 889c1efaecf0373f1a55c5ef4c234357cf726fc0600Douglas Gregor } 890c1efaecf0373f1a55c5ef4c234357cf726fc0600Douglas Gregor 891c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman return isa<ArrayType>(CanonicalType); 8925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 8935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8949bfa73c5ab7bf4b0e749d04f29da6884e8d5bd9fChris Lattner/// isConstantSizeType - Return true if this is not a variable sized type, 8959bfa73c5ab7bf4b0e749d04f29da6884e8d5bd9fChris Lattner/// according to the rules of C99 6.7.5p3. It is not legal to call this on 896898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// incomplete types or dependent types. 8973c2b3170041f69a92904e3bab9b6d654eaf260acEli Friedmanbool Type::isConstantSizeType() const { 898d52a4578144ab2887912e52eabec58a857a44adbChris Lattner assert(!isIncompleteType() && "This doesn't make sense for incomplete types"); 899898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor assert(!isDependentType() && "This doesn't make sense for dependent types"); 9009bfa73c5ab7bf4b0e749d04f29da6884e8d5bd9fChris Lattner // The VAT must have a size, as it is known to be complete. 9019bfa73c5ab7bf4b0e749d04f29da6884e8d5bd9fChris Lattner return !isa<VariableArrayType>(CanonicalType); 9025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 9035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 9045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// isIncompleteType - Return true if this is an incomplete type (C99 6.2.5p1) 9055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// - a type that can describe objects, but which lacks information needed to 9065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// determine its size. 907d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregorbool Type::isIncompleteType(NamedDecl **Def) const { 908d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor if (Def) 909d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor *Def = 0; 910d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor 9111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump switch (CanonicalType->getTypeClass()) { 9125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer default: return false; 9135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Builtin: 9145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Void is the only incomplete builtin type. Per C99 6.2.5p19, it can never 9155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // be completed. 9165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return isVoidType(); 917d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor case Enum: { 918d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor EnumDecl *EnumD = cast<EnumType>(CanonicalType)->getDecl(); 919d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor if (Def) 920d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor *Def = EnumD; 921d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor 9221274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor // An enumeration with fixed underlying type is complete (C++0x 7.2p3). 923d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor if (EnumD->isFixed()) 924d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor return false; 925d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor 926d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor return !EnumD->isCompleteDefinition(); 927d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor } 928d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor case Record: { 9295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // A tagged type (struct/union/enum/class) is incomplete if the decl is a 9305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // forward declaration, but not a full definition (C99 6.2.5p22). 931d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor RecordDecl *Rec = cast<RecordType>(CanonicalType)->getDecl(); 932d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor if (Def) 933d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor *Def = Rec; 934d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor return !Rec->isCompleteDefinition(); 935d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor } 936923d56d436f750bc1f29db50e641078725558a1bSebastian Redl case ConstantArray: 937923d56d436f750bc1f29db50e641078725558a1bSebastian Redl // An array is incomplete if its element type is incomplete 938923d56d436f750bc1f29db50e641078725558a1bSebastian Redl // (C++ [dcl.array]p1). 939923d56d436f750bc1f29db50e641078725558a1bSebastian Redl // We don't handle variable arrays (they're not allowed in C++) or 940923d56d436f750bc1f29db50e641078725558a1bSebastian Redl // dependent-sized arrays (dependent types are never treated as incomplete). 941d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor return cast<ArrayType>(CanonicalType)->getElementType() 942d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor ->isIncompleteType(Def); 943c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman case IncompleteArray: 9445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // An array of unknown size is an incomplete type (C99 6.2.5p22). 945c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman return true; 946c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall case ObjCObject: 947d0221526bcc81f49eff5c992978176e83ada3bc7Douglas Gregor return cast<ObjCObjectType>(CanonicalType)->getBaseType() 948d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor ->isIncompleteType(Def); 949d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor case ObjCInterface: { 9501efaa9594a81709a17658fd80ae7e783e1026407Chris Lattner // ObjC interfaces are incomplete if they are @class, not @interface. 951d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor ObjCInterfaceDecl *Interface 952d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor = cast<ObjCInterfaceType>(CanonicalType)->getDecl(); 953d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor if (Def) 954d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor *Def = Interface; 955d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor return !Interface->hasDefinition(); 956d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor } 9575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 9585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 9595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 960f85e193739c953358c865005855253af4f68a497John McCallbool QualType::isPODType(ASTContext &Context) const { 961152f6b7be508fbc61543f3736ebd390d7ac84bd1Benjamin Kramer // C++11 has a more relaxed definition of POD. 96280ad52f327b532bded5c5b0ee38779d841c6cd35Richard Smith if (Context.getLangOpts().CPlusPlus11) 963152f6b7be508fbc61543f3736ebd390d7ac84bd1Benjamin Kramer return isCXX11PODType(Context); 964152f6b7be508fbc61543f3736ebd390d7ac84bd1Benjamin Kramer 965152f6b7be508fbc61543f3736ebd390d7ac84bd1Benjamin Kramer return isCXX98PODType(Context); 966152f6b7be508fbc61543f3736ebd390d7ac84bd1Benjamin Kramer} 967152f6b7be508fbc61543f3736ebd390d7ac84bd1Benjamin Kramer 968152f6b7be508fbc61543f3736ebd390d7ac84bd1Benjamin Kramerbool QualType::isCXX98PODType(ASTContext &Context) const { 96964b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl // The compiler shouldn't query this for incomplete types, but the user might. 970607a1788d9529c8e8494ac528764aa2c678a1a97Sebastian Redl // We return false for that case. Except for incomplete arrays of PODs, which 971607a1788d9529c8e8494ac528764aa2c678a1a97Sebastian Redl // are PODs according to the standard. 972f85e193739c953358c865005855253af4f68a497John McCall if (isNull()) 973f85e193739c953358c865005855253af4f68a497John McCall return 0; 974f85e193739c953358c865005855253af4f68a497John McCall 975f85e193739c953358c865005855253af4f68a497John McCall if ((*this)->isIncompleteArrayType()) 9768907832ddee33d8a0b0d8432d4c7470360353d67Benjamin Kramer return Context.getBaseElementType(*this).isCXX98PODType(Context); 977f85e193739c953358c865005855253af4f68a497John McCall 978f85e193739c953358c865005855253af4f68a497John McCall if ((*this)->isIncompleteType()) 97964b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl return false; 98064b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 9814e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie if (Context.getLangOpts().ObjCAutoRefCount) { 982f85e193739c953358c865005855253af4f68a497John McCall switch (getObjCLifetime()) { 983f85e193739c953358c865005855253af4f68a497John McCall case Qualifiers::OCL_ExplicitNone: 984f85e193739c953358c865005855253af4f68a497John McCall return true; 985f85e193739c953358c865005855253af4f68a497John McCall 986f85e193739c953358c865005855253af4f68a497John McCall case Qualifiers::OCL_Strong: 987f85e193739c953358c865005855253af4f68a497John McCall case Qualifiers::OCL_Weak: 988f85e193739c953358c865005855253af4f68a497John McCall case Qualifiers::OCL_Autoreleasing: 989f85e193739c953358c865005855253af4f68a497John McCall return false; 990f85e193739c953358c865005855253af4f68a497John McCall 991f85e193739c953358c865005855253af4f68a497John McCall case Qualifiers::OCL_None: 992f85e193739c953358c865005855253af4f68a497John McCall break; 993f85e193739c953358c865005855253af4f68a497John McCall } 994f85e193739c953358c865005855253af4f68a497John McCall } 995f85e193739c953358c865005855253af4f68a497John McCall 996f85e193739c953358c865005855253af4f68a497John McCall QualType CanonicalType = getTypePtr()->CanonicalType; 99764b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl switch (CanonicalType->getTypeClass()) { 99864b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl // Everything not explicitly mentioned is not POD. 99964b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl default: return false; 1000f85e193739c953358c865005855253af4f68a497John McCall case Type::VariableArray: 1001f85e193739c953358c865005855253af4f68a497John McCall case Type::ConstantArray: 1002607a1788d9529c8e8494ac528764aa2c678a1a97Sebastian Redl // IncompleteArray is handled above. 10038907832ddee33d8a0b0d8432d4c7470360353d67Benjamin Kramer return Context.getBaseElementType(*this).isCXX98PODType(Context); 1004f85e193739c953358c865005855253af4f68a497John McCall 1005f85e193739c953358c865005855253af4f68a497John McCall case Type::ObjCObjectPointer: 1006f85e193739c953358c865005855253af4f68a497John McCall case Type::BlockPointer: 1007f85e193739c953358c865005855253af4f68a497John McCall case Type::Builtin: 1008f85e193739c953358c865005855253af4f68a497John McCall case Type::Complex: 1009f85e193739c953358c865005855253af4f68a497John McCall case Type::Pointer: 1010f85e193739c953358c865005855253af4f68a497John McCall case Type::MemberPointer: 1011f85e193739c953358c865005855253af4f68a497John McCall case Type::Vector: 1012f85e193739c953358c865005855253af4f68a497John McCall case Type::ExtVector: 101364b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl return true; 101464b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 1015f85e193739c953358c865005855253af4f68a497John McCall case Type::Enum: 101672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor return true; 101772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor 1018f85e193739c953358c865005855253af4f68a497John McCall case Type::Record: 10191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (CXXRecordDecl *ClassDecl 1020c1efaecf0373f1a55c5ef4c234357cf726fc0600Douglas Gregor = dyn_cast<CXXRecordDecl>(cast<RecordType>(CanonicalType)->getDecl())) 1021c1efaecf0373f1a55c5ef4c234357cf726fc0600Douglas Gregor return ClassDecl->isPOD(); 1022c1efaecf0373f1a55c5ef4c234357cf726fc0600Douglas Gregor 102364b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl // C struct/union is POD. 102464b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl return true; 102564b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl } 102664b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl} 102764b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 1028f85e193739c953358c865005855253af4f68a497John McCallbool QualType::isTrivialType(ASTContext &Context) const { 1029f85e193739c953358c865005855253af4f68a497John McCall // The compiler shouldn't query this for incomplete types, but the user might. 1030f85e193739c953358c865005855253af4f68a497John McCall // We return false for that case. Except for incomplete arrays of PODs, which 1031f85e193739c953358c865005855253af4f68a497John McCall // are PODs according to the standard. 1032f85e193739c953358c865005855253af4f68a497John McCall if (isNull()) 1033f85e193739c953358c865005855253af4f68a497John McCall return 0; 1034f85e193739c953358c865005855253af4f68a497John McCall 1035f85e193739c953358c865005855253af4f68a497John McCall if ((*this)->isArrayType()) 1036f85e193739c953358c865005855253af4f68a497John McCall return Context.getBaseElementType(*this).isTrivialType(Context); 1037f85e193739c953358c865005855253af4f68a497John McCall 1038f85e193739c953358c865005855253af4f68a497John McCall // Return false for incomplete types after skipping any incomplete array 1039f85e193739c953358c865005855253af4f68a497John McCall // types which are expressly allowed by the standard and thus our API. 1040f85e193739c953358c865005855253af4f68a497John McCall if ((*this)->isIncompleteType()) 1041f85e193739c953358c865005855253af4f68a497John McCall return false; 1042f85e193739c953358c865005855253af4f68a497John McCall 10434e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie if (Context.getLangOpts().ObjCAutoRefCount) { 1044f85e193739c953358c865005855253af4f68a497John McCall switch (getObjCLifetime()) { 1045f85e193739c953358c865005855253af4f68a497John McCall case Qualifiers::OCL_ExplicitNone: 1046f85e193739c953358c865005855253af4f68a497John McCall return true; 1047f85e193739c953358c865005855253af4f68a497John McCall 1048f85e193739c953358c865005855253af4f68a497John McCall case Qualifiers::OCL_Strong: 1049f85e193739c953358c865005855253af4f68a497John McCall case Qualifiers::OCL_Weak: 1050f85e193739c953358c865005855253af4f68a497John McCall case Qualifiers::OCL_Autoreleasing: 1051f85e193739c953358c865005855253af4f68a497John McCall return false; 1052f85e193739c953358c865005855253af4f68a497John McCall 1053f85e193739c953358c865005855253af4f68a497John McCall case Qualifiers::OCL_None: 1054f85e193739c953358c865005855253af4f68a497John McCall if ((*this)->isObjCLifetimeType()) 1055f85e193739c953358c865005855253af4f68a497John McCall return false; 1056f85e193739c953358c865005855253af4f68a497John McCall break; 1057f85e193739c953358c865005855253af4f68a497John McCall } 1058f85e193739c953358c865005855253af4f68a497John McCall } 1059f85e193739c953358c865005855253af4f68a497John McCall 1060f85e193739c953358c865005855253af4f68a497John McCall QualType CanonicalType = getTypePtr()->CanonicalType; 1061f85e193739c953358c865005855253af4f68a497John McCall if (CanonicalType->isDependentType()) 1062f85e193739c953358c865005855253af4f68a497John McCall return false; 1063f85e193739c953358c865005855253af4f68a497John McCall 1064f85e193739c953358c865005855253af4f68a497John McCall // C++0x [basic.types]p9: 1065f85e193739c953358c865005855253af4f68a497John McCall // Scalar types, trivial class types, arrays of such types, and 1066f85e193739c953358c865005855253af4f68a497John McCall // cv-qualified versions of these types are collectively called trivial 1067f85e193739c953358c865005855253af4f68a497John McCall // types. 1068f85e193739c953358c865005855253af4f68a497John McCall 1069f85e193739c953358c865005855253af4f68a497John McCall // As an extension, Clang treats vector types as Scalar types. 1070f85e193739c953358c865005855253af4f68a497John McCall if (CanonicalType->isScalarType() || CanonicalType->isVectorType()) 1071f85e193739c953358c865005855253af4f68a497John McCall return true; 1072f85e193739c953358c865005855253af4f68a497John McCall if (const RecordType *RT = CanonicalType->getAs<RecordType>()) { 1073f85e193739c953358c865005855253af4f68a497John McCall if (const CXXRecordDecl *ClassDecl = 1074f85e193739c953358c865005855253af4f68a497John McCall dyn_cast<CXXRecordDecl>(RT->getDecl())) { 1075426391cd51af86f9d59eceb0fb1c42153eccbb9aRichard Smith // C++11 [class]p6: 1076426391cd51af86f9d59eceb0fb1c42153eccbb9aRichard Smith // A trivial class is a class that has a default constructor, 1077426391cd51af86f9d59eceb0fb1c42153eccbb9aRichard Smith // has no non-trivial default constructors, and is trivially 1078426391cd51af86f9d59eceb0fb1c42153eccbb9aRichard Smith // copyable. 1079426391cd51af86f9d59eceb0fb1c42153eccbb9aRichard Smith return ClassDecl->hasDefaultConstructor() && 1080426391cd51af86f9d59eceb0fb1c42153eccbb9aRichard Smith !ClassDecl->hasNonTrivialDefaultConstructor() && 1081426391cd51af86f9d59eceb0fb1c42153eccbb9aRichard Smith ClassDecl->isTriviallyCopyable(); 1082f85e193739c953358c865005855253af4f68a497John McCall } 1083f85e193739c953358c865005855253af4f68a497John McCall 1084f85e193739c953358c865005855253af4f68a497John McCall return true; 1085f85e193739c953358c865005855253af4f68a497John McCall } 1086f85e193739c953358c865005855253af4f68a497John McCall 1087f85e193739c953358c865005855253af4f68a497John McCall // No other types can match. 1088f85e193739c953358c865005855253af4f68a497John McCall return false; 1089f85e193739c953358c865005855253af4f68a497John McCall} 1090f85e193739c953358c865005855253af4f68a497John McCall 1091f85e193739c953358c865005855253af4f68a497John McCallbool QualType::isTriviallyCopyableType(ASTContext &Context) const { 1092f85e193739c953358c865005855253af4f68a497John McCall if ((*this)->isArrayType()) 1093f85e193739c953358c865005855253af4f68a497John McCall return Context.getBaseElementType(*this).isTrivialType(Context); 1094f85e193739c953358c865005855253af4f68a497John McCall 10954e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie if (Context.getLangOpts().ObjCAutoRefCount) { 1096f85e193739c953358c865005855253af4f68a497John McCall switch (getObjCLifetime()) { 1097f85e193739c953358c865005855253af4f68a497John McCall case Qualifiers::OCL_ExplicitNone: 1098f85e193739c953358c865005855253af4f68a497John McCall return true; 1099f85e193739c953358c865005855253af4f68a497John McCall 1100f85e193739c953358c865005855253af4f68a497John McCall case Qualifiers::OCL_Strong: 1101f85e193739c953358c865005855253af4f68a497John McCall case Qualifiers::OCL_Weak: 1102f85e193739c953358c865005855253af4f68a497John McCall case Qualifiers::OCL_Autoreleasing: 1103f85e193739c953358c865005855253af4f68a497John McCall return false; 1104f85e193739c953358c865005855253af4f68a497John McCall 1105f85e193739c953358c865005855253af4f68a497John McCall case Qualifiers::OCL_None: 1106f85e193739c953358c865005855253af4f68a497John McCall if ((*this)->isObjCLifetimeType()) 1107f85e193739c953358c865005855253af4f68a497John McCall return false; 1108f85e193739c953358c865005855253af4f68a497John McCall break; 1109f85e193739c953358c865005855253af4f68a497John McCall } 1110f85e193739c953358c865005855253af4f68a497John McCall } 1111f85e193739c953358c865005855253af4f68a497John McCall 1112f85e193739c953358c865005855253af4f68a497John McCall // C++0x [basic.types]p9 1113f85e193739c953358c865005855253af4f68a497John McCall // Scalar types, trivially copyable class types, arrays of such types, and 1114f85e193739c953358c865005855253af4f68a497John McCall // cv-qualified versions of these types are collectively called trivial 1115f85e193739c953358c865005855253af4f68a497John McCall // types. 1116f85e193739c953358c865005855253af4f68a497John McCall 1117f85e193739c953358c865005855253af4f68a497John McCall QualType CanonicalType = getCanonicalType(); 1118f85e193739c953358c865005855253af4f68a497John McCall if (CanonicalType->isDependentType()) 1119f85e193739c953358c865005855253af4f68a497John McCall return false; 1120f85e193739c953358c865005855253af4f68a497John McCall 1121f85e193739c953358c865005855253af4f68a497John McCall // Return false for incomplete types after skipping any incomplete array types 1122f85e193739c953358c865005855253af4f68a497John McCall // which are expressly allowed by the standard and thus our API. 1123f85e193739c953358c865005855253af4f68a497John McCall if (CanonicalType->isIncompleteType()) 1124f85e193739c953358c865005855253af4f68a497John McCall return false; 1125f85e193739c953358c865005855253af4f68a497John McCall 1126f85e193739c953358c865005855253af4f68a497John McCall // As an extension, Clang treats vector types as Scalar types. 1127f85e193739c953358c865005855253af4f68a497John McCall if (CanonicalType->isScalarType() || CanonicalType->isVectorType()) 1128f85e193739c953358c865005855253af4f68a497John McCall return true; 1129f85e193739c953358c865005855253af4f68a497John McCall 1130f85e193739c953358c865005855253af4f68a497John McCall if (const RecordType *RT = CanonicalType->getAs<RecordType>()) { 1131f85e193739c953358c865005855253af4f68a497John McCall if (const CXXRecordDecl *ClassDecl = 1132f85e193739c953358c865005855253af4f68a497John McCall dyn_cast<CXXRecordDecl>(RT->getDecl())) { 1133f85e193739c953358c865005855253af4f68a497John McCall if (!ClassDecl->isTriviallyCopyable()) return false; 1134f85e193739c953358c865005855253af4f68a497John McCall } 1135f85e193739c953358c865005855253af4f68a497John McCall 1136f85e193739c953358c865005855253af4f68a497John McCall return true; 1137f85e193739c953358c865005855253af4f68a497John McCall } 1138f85e193739c953358c865005855253af4f68a497John McCall 1139f85e193739c953358c865005855253af4f68a497John McCall // No other types can match. 1140f85e193739c953358c865005855253af4f68a497John McCall return false; 1141f85e193739c953358c865005855253af4f68a497John McCall} 1142f85e193739c953358c865005855253af4f68a497John McCall 1143f85e193739c953358c865005855253af4f68a497John McCall 1144f85e193739c953358c865005855253af4f68a497John McCall 1145a10b97898ee6339c3110e6ca33f178ff52f05238Richard Smithbool Type::isLiteralType(ASTContext &Ctx) const { 1146018a088b3b30e500efa9173f7cd4b1b1f6a065a8Chandler Carruth if (isDependentType()) 1147ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl return false; 1148ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl 1149a10b97898ee6339c3110e6ca33f178ff52f05238Richard Smith // C++1y [basic.types]p10: 1150a10b97898ee6339c3110e6ca33f178ff52f05238Richard Smith // A type is a literal type if it is: 1151a10b97898ee6339c3110e6ca33f178ff52f05238Richard Smith // -- cv void; or 1152a10b97898ee6339c3110e6ca33f178ff52f05238Richard Smith if (Ctx.getLangOpts().CPlusPlus1y && isVoidType()) 1153a10b97898ee6339c3110e6ca33f178ff52f05238Richard Smith return true; 1154a10b97898ee6339c3110e6ca33f178ff52f05238Richard Smith 1155a10b97898ee6339c3110e6ca33f178ff52f05238Richard Smith // C++11 [basic.types]p10: 1156ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl // A type is a literal type if it is: 11579b6347cd410be55425f7062d22fd6e4ecb4e1a58Chandler Carruth // [...] 1158a10b97898ee6339c3110e6ca33f178ff52f05238Richard Smith // -- an array of literal type other than an array of runtime bound; or 1159018a088b3b30e500efa9173f7cd4b1b1f6a065a8Chandler Carruth if (isVariableArrayType()) 1160ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl return false; 11619b6347cd410be55425f7062d22fd6e4ecb4e1a58Chandler Carruth const Type *BaseTy = getBaseElementTypeUnsafe(); 11629b6347cd410be55425f7062d22fd6e4ecb4e1a58Chandler Carruth assert(BaseTy && "NULL element type"); 1163ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl 1164018a088b3b30e500efa9173f7cd4b1b1f6a065a8Chandler Carruth // Return false for incomplete types after skipping any incomplete array 1165018a088b3b30e500efa9173f7cd4b1b1f6a065a8Chandler Carruth // types; those are expressly allowed by the standard and thus our API. 1166018a088b3b30e500efa9173f7cd4b1b1f6a065a8Chandler Carruth if (BaseTy->isIncompleteType()) 1167018a088b3b30e500efa9173f7cd4b1b1f6a065a8Chandler Carruth return false; 1168018a088b3b30e500efa9173f7cd4b1b1f6a065a8Chandler Carruth 1169a10b97898ee6339c3110e6ca33f178ff52f05238Richard Smith // C++11 [basic.types]p10: 11709b6347cd410be55425f7062d22fd6e4ecb4e1a58Chandler Carruth // A type is a literal type if it is: 11719b6347cd410be55425f7062d22fd6e4ecb4e1a58Chandler Carruth // -- a scalar type; or 11727ead5c7b6fd48cf549e55b4db499c26ecf88ae75Eli Friedman // As an extension, Clang treats vector types and complex types as 11737ead5c7b6fd48cf549e55b4db499c26ecf88ae75Eli Friedman // literal types. 11747ead5c7b6fd48cf549e55b4db499c26ecf88ae75Eli Friedman if (BaseTy->isScalarType() || BaseTy->isVectorType() || 11757ead5c7b6fd48cf549e55b4db499c26ecf88ae75Eli Friedman BaseTy->isAnyComplexType()) 1176af1fc7af351758b0ea0d285bdfe5640128109a4eRichard Smith return true; 11779b6347cd410be55425f7062d22fd6e4ecb4e1a58Chandler Carruth // -- a reference type; or 1178af1fc7af351758b0ea0d285bdfe5640128109a4eRichard Smith if (BaseTy->isReferenceType()) 1179af1fc7af351758b0ea0d285bdfe5640128109a4eRichard Smith return true; 11809b6347cd410be55425f7062d22fd6e4ecb4e1a58Chandler Carruth // -- a class type that has all of the following properties: 11819b6347cd410be55425f7062d22fd6e4ecb4e1a58Chandler Carruth if (const RecordType *RT = BaseTy->getAs<RecordType>()) { 11829f569cca2a4c5fb6026005434e27025b9e71309dRichard Smith // -- a trivial destructor, 11839f569cca2a4c5fb6026005434e27025b9e71309dRichard Smith // -- every constructor call and full-expression in the 11849f569cca2a4c5fb6026005434e27025b9e71309dRichard Smith // brace-or-equal-initializers for non-static data members (if any) 11859f569cca2a4c5fb6026005434e27025b9e71309dRichard Smith // is a constant expression, 11869f569cca2a4c5fb6026005434e27025b9e71309dRichard Smith // -- it is an aggregate type or has at least one constexpr 11879f569cca2a4c5fb6026005434e27025b9e71309dRichard Smith // constructor or constructor template that is not a copy or move 11889f569cca2a4c5fb6026005434e27025b9e71309dRichard Smith // constructor, and 11899f569cca2a4c5fb6026005434e27025b9e71309dRichard Smith // -- all non-static data members and base classes of literal types 11909f569cca2a4c5fb6026005434e27025b9e71309dRichard Smith // 11919f569cca2a4c5fb6026005434e27025b9e71309dRichard Smith // We resolve DR1361 by ignoring the second bullet. 11925751838965eefa1c08e4fc545498a3ee45cd9611Chandler Carruth if (const CXXRecordDecl *ClassDecl = 11939f569cca2a4c5fb6026005434e27025b9e71309dRichard Smith dyn_cast<CXXRecordDecl>(RT->getDecl())) 11949f569cca2a4c5fb6026005434e27025b9e71309dRichard Smith return ClassDecl->isLiteral(); 11959b6347cd410be55425f7062d22fd6e4ecb4e1a58Chandler Carruth 11969b6347cd410be55425f7062d22fd6e4ecb4e1a58Chandler Carruth return true; 1197ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl } 1198af1fc7af351758b0ea0d285bdfe5640128109a4eRichard Smith 11995705f211472f19fc38e58d81365f9261024b3ba3Richard Smith // We treat _Atomic T as a literal type if T is a literal type. 12005705f211472f19fc38e58d81365f9261024b3ba3Richard Smith if (const AtomicType *AT = BaseTy->getAs<AtomicType>()) 12015705f211472f19fc38e58d81365f9261024b3ba3Richard Smith return AT->getValueType()->isLiteralType(Ctx); 12025705f211472f19fc38e58d81365f9261024b3ba3Richard Smith 1203bdaeaed3e3293f1915cdf336f406d4d391331039Richard Smith // If this type hasn't been deduced yet, then conservatively assume that 1204bdaeaed3e3293f1915cdf336f406d4d391331039Richard Smith // it'll work out to be a literal type. 1205bdaeaed3e3293f1915cdf336f406d4d391331039Richard Smith if (isa<AutoType>(BaseTy->getCanonicalTypeInternal())) 1206bdaeaed3e3293f1915cdf336f406d4d391331039Richard Smith return true; 1207bdaeaed3e3293f1915cdf336f406d4d391331039Richard Smith 12089b6347cd410be55425f7062d22fd6e4ecb4e1a58Chandler Carruth return false; 1209ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl} 1210ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl 1211636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruthbool Type::isStandardLayoutType() const { 1212018a088b3b30e500efa9173f7cd4b1b1f6a065a8Chandler Carruth if (isDependentType()) 1213636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth return false; 1214636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth 1215636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth // C++0x [basic.types]p9: 1216636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth // Scalar types, standard-layout class types, arrays of such types, and 1217636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth // cv-qualified versions of these types are collectively called 1218636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth // standard-layout types. 1219636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth const Type *BaseTy = getBaseElementTypeUnsafe(); 1220636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth assert(BaseTy && "NULL element type"); 1221018a088b3b30e500efa9173f7cd4b1b1f6a065a8Chandler Carruth 1222018a088b3b30e500efa9173f7cd4b1b1f6a065a8Chandler Carruth // Return false for incomplete types after skipping any incomplete array 1223018a088b3b30e500efa9173f7cd4b1b1f6a065a8Chandler Carruth // types which are expressly allowed by the standard and thus our API. 1224018a088b3b30e500efa9173f7cd4b1b1f6a065a8Chandler Carruth if (BaseTy->isIncompleteType()) 1225018a088b3b30e500efa9173f7cd4b1b1f6a065a8Chandler Carruth return false; 1226018a088b3b30e500efa9173f7cd4b1b1f6a065a8Chandler Carruth 122725df423cfc6689cf21d51a66af84ea1e70d489dfChandler Carruth // As an extension, Clang treats vector types as Scalar types. 122825df423cfc6689cf21d51a66af84ea1e70d489dfChandler Carruth if (BaseTy->isScalarType() || BaseTy->isVectorType()) return true; 1229636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth if (const RecordType *RT = BaseTy->getAs<RecordType>()) { 1230636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth if (const CXXRecordDecl *ClassDecl = 1231636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth dyn_cast<CXXRecordDecl>(RT->getDecl())) 1232ec997dc66627957bcdcd3db7906a68c1e14a279cChandler Carruth if (!ClassDecl->isStandardLayout()) 1233636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth return false; 1234636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth 1235636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth // Default to 'true' for non-C++ class types. 1236636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth // FIXME: This is a bit dubious, but plain C structs should trivially meet 1237636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth // all the requirements of standard layout classes. 1238636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth return true; 1239636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth } 1240636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth 1241636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth // No other types can match. 1242636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth return false; 1243636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth} 1244636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth 1245636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth// This is effectively the intersection of isTrivialType and 12467426f793844407021ffeb5afcf917fff1a57f196Richard Smith// isStandardLayoutType. We implement it directly to avoid redundant 1247636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth// conversions from a type to a CXXRecordDecl. 1248f85e193739c953358c865005855253af4f68a497John McCallbool QualType::isCXX11PODType(ASTContext &Context) const { 1249f85e193739c953358c865005855253af4f68a497John McCall const Type *ty = getTypePtr(); 1250f85e193739c953358c865005855253af4f68a497John McCall if (ty->isDependentType()) 125143fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth return false; 125243fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth 12534e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie if (Context.getLangOpts().ObjCAutoRefCount) { 1254f85e193739c953358c865005855253af4f68a497John McCall switch (getObjCLifetime()) { 1255f85e193739c953358c865005855253af4f68a497John McCall case Qualifiers::OCL_ExplicitNone: 1256f85e193739c953358c865005855253af4f68a497John McCall return true; 1257f85e193739c953358c865005855253af4f68a497John McCall 1258f85e193739c953358c865005855253af4f68a497John McCall case Qualifiers::OCL_Strong: 1259f85e193739c953358c865005855253af4f68a497John McCall case Qualifiers::OCL_Weak: 1260f85e193739c953358c865005855253af4f68a497John McCall case Qualifiers::OCL_Autoreleasing: 1261f85e193739c953358c865005855253af4f68a497John McCall return false; 1262f85e193739c953358c865005855253af4f68a497John McCall 1263f85e193739c953358c865005855253af4f68a497John McCall case Qualifiers::OCL_None: 1264f85e193739c953358c865005855253af4f68a497John McCall break; 1265f85e193739c953358c865005855253af4f68a497John McCall } 1266f85e193739c953358c865005855253af4f68a497John McCall } 1267f85e193739c953358c865005855253af4f68a497John McCall 126843fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth // C++11 [basic.types]p9: 126943fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth // Scalar types, POD classes, arrays of such types, and cv-qualified 127043fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth // versions of these types are collectively called trivial types. 1271f85e193739c953358c865005855253af4f68a497John McCall const Type *BaseTy = ty->getBaseElementTypeUnsafe(); 127243fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth assert(BaseTy && "NULL element type"); 1273018a088b3b30e500efa9173f7cd4b1b1f6a065a8Chandler Carruth 1274018a088b3b30e500efa9173f7cd4b1b1f6a065a8Chandler Carruth // Return false for incomplete types after skipping any incomplete array 1275018a088b3b30e500efa9173f7cd4b1b1f6a065a8Chandler Carruth // types which are expressly allowed by the standard and thus our API. 1276018a088b3b30e500efa9173f7cd4b1b1f6a065a8Chandler Carruth if (BaseTy->isIncompleteType()) 1277018a088b3b30e500efa9173f7cd4b1b1f6a065a8Chandler Carruth return false; 1278018a088b3b30e500efa9173f7cd4b1b1f6a065a8Chandler Carruth 127925df423cfc6689cf21d51a66af84ea1e70d489dfChandler Carruth // As an extension, Clang treats vector types as Scalar types. 128025df423cfc6689cf21d51a66af84ea1e70d489dfChandler Carruth if (BaseTy->isScalarType() || BaseTy->isVectorType()) return true; 128143fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth if (const RecordType *RT = BaseTy->getAs<RecordType>()) { 128243fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth if (const CXXRecordDecl *ClassDecl = 128343fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth dyn_cast<CXXRecordDecl>(RT->getDecl())) { 128443fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth // C++11 [class]p10: 128543fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth // A POD struct is a non-union class that is both a trivial class [...] 1286023df37c27ee8035664fb62f206ca58f4e2a169dSean Hunt if (!ClassDecl->isTrivial()) return false; 128743fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth 128843fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth // C++11 [class]p10: 128943fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth // A POD struct is a non-union class that is both a trivial class and 129043fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth // a standard-layout class [...] 1291ec997dc66627957bcdcd3db7906a68c1e14a279cChandler Carruth if (!ClassDecl->isStandardLayout()) return false; 129243fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth 129343fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth // C++11 [class]p10: 129443fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth // A POD struct is a non-union class that is both a trivial class and 129543fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth // a standard-layout class, and has no non-static data members of type 129643fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth // non-POD struct, non-POD union (or array of such types). [...] 129743fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth // 129843fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth // We don't directly query the recursive aspect as the requiremets for 129943fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth // both standard-layout classes and trivial classes apply recursively 130043fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth // already. 130143fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth } 130243fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth 130343fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth return true; 130443fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth } 130543fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth 130643fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth // No other types can match. 130743fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth return false; 130843fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth} 130943fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth 13105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isPromotableIntegerType() const { 1311183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const BuiltinType *BT = getAs<BuiltinType>()) 13122a18dfe292cf3c406a769c3672080970ac586345Chris Lattner switch (BT->getKind()) { 13132a18dfe292cf3c406a769c3672080970ac586345Chris Lattner case BuiltinType::Bool: 13142a18dfe292cf3c406a769c3672080970ac586345Chris Lattner case BuiltinType::Char_S: 13152a18dfe292cf3c406a769c3672080970ac586345Chris Lattner case BuiltinType::Char_U: 13162a18dfe292cf3c406a769c3672080970ac586345Chris Lattner case BuiltinType::SChar: 13172a18dfe292cf3c406a769c3672080970ac586345Chris Lattner case BuiltinType::UChar: 13182a18dfe292cf3c406a769c3672080970ac586345Chris Lattner case BuiltinType::Short: 13192a18dfe292cf3c406a769c3672080970ac586345Chris Lattner case BuiltinType::UShort: 132068a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman case BuiltinType::WChar_S: 132168a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman case BuiltinType::WChar_U: 132268a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman case BuiltinType::Char16: 132368a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman case BuiltinType::Char32: 13242a18dfe292cf3c406a769c3672080970ac586345Chris Lattner return true; 13251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump default: 13262a18dfe292cf3c406a769c3672080970ac586345Chris Lattner return false; 13272a18dfe292cf3c406a769c3672080970ac586345Chris Lattner } 1328aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor 1329aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor // Enumerated types are promotable to their compatible integer types 1330aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor // (C99 6.3.1.1) a.k.a. its underlying type (C++ [conv.prom]p2). 1331aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor if (const EnumType *ET = getAs<EnumType>()){ 13321274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor if (this->isDependentType() || ET->getDecl()->getPromotionType().isNull() 13331274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor || ET->getDecl()->isScoped()) 1334aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor return false; 1335aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor 133668a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman return true; 1337aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor } 1338aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor 13392a18dfe292cf3c406a769c3672080970ac586345Chris Lattner return false; 13405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 13415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 134222b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedmanbool Type::isSpecifierType() const { 134322b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman // Note that this intentionally does not use the canonical type. 134422b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman switch (getTypeClass()) { 134522b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman case Builtin: 134622b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman case Record: 134722b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman case Enum: 134822b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman case Typedef: 1349c8f2c61f4f667c2bc3e4e74b274fa397a4232393Eli Friedman case Complex: 1350c8f2c61f4f667c2bc3e4e74b274fa397a4232393Eli Friedman case TypeOfExpr: 1351c8f2c61f4f667c2bc3e4e74b274fa397a4232393Eli Friedman case TypeOf: 1352c8f2c61f4f667c2bc3e4e74b274fa397a4232393Eli Friedman case TemplateTypeParm: 135349a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall case SubstTemplateTypeParm: 1354c8f2c61f4f667c2bc3e4e74b274fa397a4232393Eli Friedman case TemplateSpecialization: 1355465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case Elaborated: 13564714c12a1ab759156b78be8f109ea4c12213af57Douglas Gregor case DependentName: 135733500955d731c73717af52088b7fc0e7a85681e7John McCall case DependentTemplateSpecialization: 1358c8f2c61f4f667c2bc3e4e74b274fa397a4232393Eli Friedman case ObjCInterface: 1359c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall case ObjCObject: 1360c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall case ObjCObjectPointer: // FIXME: object pointers aren't really specifiers 136122b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman return true; 136222b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman default: 136322b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman return false; 136422b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman } 136522b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman} 136622b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman 1367465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraElaboratedTypeKeyword 1368465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraTypeWithKeyword::getKeywordForTypeSpec(unsigned TypeSpec) { 1369465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara switch (TypeSpec) { 1370465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara default: return ETK_None; 1371465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TST_typename: return ETK_Typename; 1372465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TST_class: return ETK_Class; 1373465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TST_struct: return ETK_Struct; 13746666ed4ed2e2bc13da5ac5d0a4947019137d45beJoao Matos case TST_interface: return ETK_Interface; 1375465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TST_union: return ETK_Union; 1376465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TST_enum: return ETK_Enum; 1377465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara } 1378465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara} 1379465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 1380465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraTagTypeKind 1381465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraTypeWithKeyword::getTagTypeKindForTypeSpec(unsigned TypeSpec) { 1382465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara switch(TypeSpec) { 1383465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TST_class: return TTK_Class; 1384465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TST_struct: return TTK_Struct; 13856666ed4ed2e2bc13da5ac5d0a4947019137d45beJoao Matos case TST_interface: return TTK_Interface; 1386465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TST_union: return TTK_Union; 1387465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TST_enum: return TTK_Enum; 1388465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara } 13897907fad723a0f4764a2396df620d9c58725b3053Douglas Gregor 13907907fad723a0f4764a2396df620d9c58725b3053Douglas Gregor llvm_unreachable("Type specifier is not a tag type kind."); 1391465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara} 1392465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 1393465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraElaboratedTypeKeyword 1394465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraTypeWithKeyword::getKeywordForTagTypeKind(TagTypeKind Kind) { 1395465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara switch (Kind) { 1396465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TTK_Class: return ETK_Class; 1397465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TTK_Struct: return ETK_Struct; 13986666ed4ed2e2bc13da5ac5d0a4947019137d45beJoao Matos case TTK_Interface: return ETK_Interface; 1399465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TTK_Union: return ETK_Union; 1400465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TTK_Enum: return ETK_Enum; 1401465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara } 1402465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara llvm_unreachable("Unknown tag type kind."); 1403465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara} 1404465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 1405465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraTagTypeKind 1406465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraTypeWithKeyword::getTagTypeKindForKeyword(ElaboratedTypeKeyword Keyword) { 1407465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara switch (Keyword) { 1408465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Class: return TTK_Class; 1409465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Struct: return TTK_Struct; 14106666ed4ed2e2bc13da5ac5d0a4947019137d45beJoao Matos case ETK_Interface: return TTK_Interface; 1411465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Union: return TTK_Union; 1412465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Enum: return TTK_Enum; 1413465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_None: // Fall through. 1414465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Typename: 1415465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara llvm_unreachable("Elaborated type keyword is not a tag type kind."); 1416465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara } 1417465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara llvm_unreachable("Unknown elaborated type keyword."); 1418465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara} 1419465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 1420465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnarabool 1421465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraTypeWithKeyword::KeywordIsTagTypeKind(ElaboratedTypeKeyword Keyword) { 1422465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara switch (Keyword) { 1423465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_None: 1424465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Typename: 1425465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara return false; 1426465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Class: 1427465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Struct: 14286666ed4ed2e2bc13da5ac5d0a4947019137d45beJoao Matos case ETK_Interface: 1429465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Union: 1430465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Enum: 14314033642464e8ba0982f88f34cffad808d247b393Douglas Gregor return true; 14324033642464e8ba0982f88f34cffad808d247b393Douglas Gregor } 1433465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara llvm_unreachable("Unknown elaborated type keyword."); 1434465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara} 1435465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 1436465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnaraconst char* 1437465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraTypeWithKeyword::getKeywordName(ElaboratedTypeKeyword Keyword) { 1438465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara switch (Keyword) { 1439465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_None: return ""; 1440465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Typename: return "typename"; 1441465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Class: return "class"; 1442465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Struct: return "struct"; 14436666ed4ed2e2bc13da5ac5d0a4947019137d45beJoao Matos case ETK_Interface: return "__interface"; 1444465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Union: return "union"; 1445465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Enum: return "enum"; 1446465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara } 14477907fad723a0f4764a2396df620d9c58725b3053Douglas Gregor 14487907fad723a0f4764a2396df620d9c58725b3053Douglas Gregor llvm_unreachable("Unknown elaborated type keyword."); 1449465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara} 1450465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 145133500955d731c73717af52088b7fc0e7a85681e7John McCallDependentTemplateSpecializationType::DependentTemplateSpecializationType( 1452ef99001908e799c388f1363b1e607dad5f5b57d3John McCall ElaboratedTypeKeyword Keyword, 145333500955d731c73717af52088b7fc0e7a85681e7John McCall NestedNameSpecifier *NNS, const IdentifierInfo *Name, 145433500955d731c73717af52088b7fc0e7a85681e7John McCall unsigned NumArgs, const TemplateArgument *Args, 145533500955d731c73717af52088b7fc0e7a85681e7John McCall QualType Canon) 1456561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor : TypeWithKeyword(Keyword, DependentTemplateSpecialization, Canon, true, true, 1457d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /*VariablyModified=*/false, 1458aa2187de137e5b809dcbbe14f3b61ae907a3d8aaDouglas Gregor NNS && NNS->containsUnexpandedParameterPack()), 1459ef99001908e799c388f1363b1e607dad5f5b57d3John McCall NNS(NNS), Name(Name), NumArgs(NumArgs) { 1460aa2187de137e5b809dcbbe14f3b61ae907a3d8aaDouglas Gregor assert((!NNS || NNS->isDependent()) && 146133500955d731c73717af52088b7fc0e7a85681e7John McCall "DependentTemplateSpecializatonType requires dependent qualifier"); 1462d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor for (unsigned I = 0; I != NumArgs; ++I) { 1463d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor if (Args[I].containsUnexpandedParameterPack()) 1464d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor setContainsUnexpandedParameterPack(); 1465d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 146633500955d731c73717af52088b7fc0e7a85681e7John McCall new (&getArgBuffer()[I]) TemplateArgument(Args[I]); 1467d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor } 146833500955d731c73717af52088b7fc0e7a85681e7John McCall} 146933500955d731c73717af52088b7fc0e7a85681e7John McCall 147033500955d731c73717af52088b7fc0e7a85681e7John McCallvoid 147133500955d731c73717af52088b7fc0e7a85681e7John McCallDependentTemplateSpecializationType::Profile(llvm::FoldingSetNodeID &ID, 14724ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad const ASTContext &Context, 147333500955d731c73717af52088b7fc0e7a85681e7John McCall ElaboratedTypeKeyword Keyword, 147433500955d731c73717af52088b7fc0e7a85681e7John McCall NestedNameSpecifier *Qualifier, 147533500955d731c73717af52088b7fc0e7a85681e7John McCall const IdentifierInfo *Name, 147633500955d731c73717af52088b7fc0e7a85681e7John McCall unsigned NumArgs, 147733500955d731c73717af52088b7fc0e7a85681e7John McCall const TemplateArgument *Args) { 147833500955d731c73717af52088b7fc0e7a85681e7John McCall ID.AddInteger(Keyword); 147933500955d731c73717af52088b7fc0e7a85681e7John McCall ID.AddPointer(Qualifier); 148033500955d731c73717af52088b7fc0e7a85681e7John McCall ID.AddPointer(Name); 148133500955d731c73717af52088b7fc0e7a85681e7John McCall for (unsigned Idx = 0; Idx < NumArgs; ++Idx) 148233500955d731c73717af52088b7fc0e7a85681e7John McCall Args[Idx].Profile(ID, Context); 148333500955d731c73717af52088b7fc0e7a85681e7John McCall} 148433500955d731c73717af52088b7fc0e7a85681e7John McCall 1485465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnarabool Type::isElaboratedTypeSpecifier() const { 1486465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara ElaboratedTypeKeyword Keyword; 1487465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara if (const ElaboratedType *Elab = dyn_cast<ElaboratedType>(this)) 1488465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara Keyword = Elab->getKeyword(); 1489465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara else if (const DependentNameType *DepName = dyn_cast<DependentNameType>(this)) 1490465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara Keyword = DepName->getKeyword(); 149133500955d731c73717af52088b7fc0e7a85681e7John McCall else if (const DependentTemplateSpecializationType *DepTST = 149233500955d731c73717af52088b7fc0e7a85681e7John McCall dyn_cast<DependentTemplateSpecializationType>(this)) 149333500955d731c73717af52088b7fc0e7a85681e7John McCall Keyword = DepTST->getKeyword(); 1494465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara else 1495465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara return false; 1496465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 1497465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara return TypeWithKeyword::KeywordIsTagTypeKind(Keyword); 14984033642464e8ba0982f88f34cffad808d247b393Douglas Gregor} 14994033642464e8ba0982f88f34cffad808d247b393Douglas Gregor 1500cd01f17358dc8ef19338c0e2321138dd0a6160d9Argyrios Kyrtzidisconst char *Type::getTypeClassName() const { 1501b870b88df784c2940efce448ebfaf54dece14666John McCall switch (TypeBits.TC) { 1502cd01f17358dc8ef19338c0e2321138dd0a6160d9Argyrios Kyrtzidis#define ABSTRACT_TYPE(Derived, Base) 1503cd01f17358dc8ef19338c0e2321138dd0a6160d9Argyrios Kyrtzidis#define TYPE(Derived, Base) case Derived: return #Derived; 1504cd01f17358dc8ef19338c0e2321138dd0a6160d9Argyrios Kyrtzidis#include "clang/AST/TypeNodes.def" 1505cd01f17358dc8ef19338c0e2321138dd0a6160d9Argyrios Kyrtzidis } 15067907fad723a0f4764a2396df620d9c58725b3053Douglas Gregor 15077907fad723a0f4764a2396df620d9c58725b3053Douglas Gregor llvm_unreachable("Invalid type class."); 1508cd01f17358dc8ef19338c0e2321138dd0a6160d9Argyrios Kyrtzidis} 1509cd01f17358dc8ef19338c0e2321138dd0a6160d9Argyrios Kyrtzidis 151027a00970bf4ababdc115e54383e6252cc3276dfaArgyrios KyrtzidisStringRef BuiltinType::getName(const PrintingPolicy &Policy) const { 15115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer switch (getKind()) { 15125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Void: return "void"; 151330c42404202d2e2512e51efc6066bd614cfdb5a4Douglas Gregor case Bool: return Policy.Bool ? "bool" : "_Bool"; 15145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Char_S: return "char"; 15155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Char_U: return "char"; 15165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case SChar: return "signed char"; 15175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Short: return "short"; 15185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Int: return "int"; 15195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Long: return "long"; 15205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case LongLong: return "long long"; 15215a5a971908a1fd064454db44c42333a3aecf3d5bRichard Smith case Int128: return "__int128"; 15225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case UChar: return "unsigned char"; 15235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case UShort: return "unsigned short"; 15245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case UInt: return "unsigned int"; 15255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case ULong: return "unsigned long"; 15265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case ULongLong: return "unsigned long long"; 15275a5a971908a1fd064454db44c42333a3aecf3d5bRichard Smith case UInt128: return "unsigned __int128"; 1528aa4a99b4a62615db243f7a5c433169f2fc704420Anton Korobeynikov case Half: return "half"; 15295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Float: return "float"; 15305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Double: return "double"; 15315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case LongDouble: return "long double"; 15323f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner case WChar_S: 153315f92bad58c8650b1306729744b1a1230197497aHans Wennborg case WChar_U: return Policy.MSWChar ? "__wchar_t" : "wchar_t"; 1534f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith case Char16: return "char16_t"; 1535f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith case Char32: return "char32_t"; 15366e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl case NullPtr: return "nullptr_t"; 15378e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor case Overload: return "<overloaded function type>"; 1538864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall case BoundMember: return "<bound member function type>"; 15393c3b7f90a863af43fa63043d396553ecf205351cJohn McCall case PseudoObject: return "<pseudo-object type>"; 1540898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor case Dependent: return "<dependent type>"; 15411de4d4e8cb2e9c88809fea8092bc6e835a5473d2John McCall case UnknownAny: return "<unknown type>"; 15420ddaeb9b031070ec64afe92d9892875ac44df427John McCall case ARCUnbridgedCast: return "<ARC unbridged cast type>"; 1543a6c66cedc022c9e5d45a937d6b8cff491a6bf81bEli Friedman case BuiltinFn: return "<builtin fn type>"; 1544de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff case ObjCId: return "id"; 1545de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff case ObjCClass: return "Class"; 1546bef0efd11bc4430a3ee437a3213cec5c18af855aChris Lattner case ObjCSel: return "SEL"; 1547b13621d08e20ac7aa550e05896de8a57ee99c1e8Guy Benyei case OCLImage1d: return "image1d_t"; 1548b13621d08e20ac7aa550e05896de8a57ee99c1e8Guy Benyei case OCLImage1dArray: return "image1d_array_t"; 1549b13621d08e20ac7aa550e05896de8a57ee99c1e8Guy Benyei case OCLImage1dBuffer: return "image1d_buffer_t"; 1550b13621d08e20ac7aa550e05896de8a57ee99c1e8Guy Benyei case OCLImage2d: return "image2d_t"; 1551b13621d08e20ac7aa550e05896de8a57ee99c1e8Guy Benyei case OCLImage2dArray: return "image2d_array_t"; 1552b13621d08e20ac7aa550e05896de8a57ee99c1e8Guy Benyei case OCLImage3d: return "image3d_t"; 155321f18c4fda167dc5f72feddbd6a7ac1b63200a0dGuy Benyei case OCLSampler: return "sampler_t"; 1554e6b9d802fb7b16d93474c4f1c179ab36202e8a8bGuy Benyei case OCLEvent: return "event_t"; 15555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 15567907fad723a0f4764a2396df620d9c58725b3053Douglas Gregor 1557aab440b2cb0e583aeaf21f08c8247456f3142a23Nick Lewycky llvm_unreachable("Invalid builtin type."); 15585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 15595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 15606398235d7890a81b785ea5af3b6e66d86bf184ccDouglas GregorQualType QualType::getNonLValueExprType(ASTContext &Context) const { 15615291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor if (const ReferenceType *RefType = getTypePtr()->getAs<ReferenceType>()) 15625291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor return RefType->getPointeeType(); 15635291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor 15645291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor // C++0x [basic.lval]: 15655291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor // Class prvalues can have cv-qualified types; non-class prvalues always 15665291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor // have cv-unqualified types. 15675291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor // 15685291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor // See also C99 6.3.2.1p2. 15694e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie if (!Context.getLangOpts().CPlusPlus || 15706dc1ef87044e6b177d4df0d2b593a94616180b3dChandler Carruth (!getTypePtr()->isDependentType() && !getTypePtr()->isRecordType())) 15715291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor return getUnqualifiedType(); 15725291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor 15735291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor return *this; 15745291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor} 15755291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor 15765f9e272e632e951b1efe824cd16acb4d96077930Chris LattnerStringRef FunctionType::getNameForCallConv(CallingConv CC) { 157704a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall switch (CC) { 15787907fad723a0f4764a2396df620d9c58725b3053Douglas Gregor case CC_Default: 15797907fad723a0f4764a2396df620d9c58725b3053Douglas Gregor llvm_unreachable("no name for default cc"); 158004a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall 158104a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall case CC_C: return "cdecl"; 158204a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall case CC_X86StdCall: return "stdcall"; 158304a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall case CC_X86FastCall: return "fastcall"; 1584f813a2c03fcb05381b3252010435f557eb6b3cdeDouglas Gregor case CC_X86ThisCall: return "thiscall"; 158552fc314e1b5e1baee6305067cf831763d02bd243Dawn Perchik case CC_X86Pascal: return "pascal"; 1586414d8967e1d760ea1e19a4aca96b13777a8cf8c5Anton Korobeynikov case CC_AAPCS: return "aapcs"; 1587414d8967e1d760ea1e19a4aca96b13777a8cf8c5Anton Korobeynikov case CC_AAPCS_VFP: return "aapcs-vfp"; 1588263366f9241366f29ba65b703120f302490c39ffDerek Schuff case CC_PnaclCall: return "pnaclcall"; 158938980086c0f791e8c23cc882574f18e5b4a87db6Guy Benyei case CC_IntelOclBicc: return "intel_ocl_bicc"; 159004a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall } 15917907fad723a0f4764a2396df620d9c58725b3053Douglas Gregor 15927907fad723a0f4764a2396df620d9c58725b3053Douglas Gregor llvm_unreachable("Invalid calling convention."); 159304a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall} 159404a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall 1595bea522ff43a3f11c7a2bc7949119dbb9fce19e39Jordan RoseFunctionProtoType::FunctionProtoType(QualType result, ArrayRef<QualType> args, 1596bea522ff43a3f11c7a2bc7949119dbb9fce19e39Jordan Rose QualType canonical, 15978026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redl const ExtProtoInfo &epi) 1598aa46d513f47280a9786e8e9aa77f7089b3f8fee6Richard Smith : FunctionType(FunctionProto, result, epi.TypeQuals, 1599eefb3d5b49c844347f212073a7e975b8118fe8e9Richard Smith canonical, 1600e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall result->isDependentType(), 1601561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor result->isInstantiationDependentType(), 1602e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall result->isVariablyModifiedType(), 1603e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall result->containsUnexpandedParameterPack(), 1604e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall epi.ExtInfo), 1605bea522ff43a3f11c7a2bc7949119dbb9fce19e39Jordan Rose NumArgs(args.size()), NumExceptions(epi.NumExceptions), 1606f85e193739c953358c865005855253af4f68a497John McCall ExceptionSpecType(epi.ExceptionSpecType), 1607eefb3d5b49c844347f212073a7e975b8118fe8e9Richard Smith HasAnyConsumedArgs(epi.ConsumedArguments != 0), 1608aa46d513f47280a9786e8e9aa77f7089b3f8fee6Richard Smith Variadic(epi.Variadic), HasTrailingReturn(epi.HasTrailingReturn), 1609aa46d513f47280a9786e8e9aa77f7089b3f8fee6Richard Smith RefQualifier(epi.RefQualifier) 161035495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor{ 1611bea522ff43a3f11c7a2bc7949119dbb9fce19e39Jordan Rose assert(NumArgs == args.size() && "function has too many parameters"); 1612aa46d513f47280a9786e8e9aa77f7089b3f8fee6Richard Smith 161335495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor // Fill in the trailing argument array. 1614e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall QualType *argSlot = reinterpret_cast<QualType*>(this+1); 1615bea522ff43a3f11c7a2bc7949119dbb9fce19e39Jordan Rose for (unsigned i = 0; i != NumArgs; ++i) { 1616e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall if (args[i]->isDependentType()) 161735495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor setDependent(); 1618561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor else if (args[i]->isInstantiationDependentType()) 1619561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor setInstantiationDependent(); 1620561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor 1621e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall if (args[i]->containsUnexpandedParameterPack()) 1622d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor setContainsUnexpandedParameterPack(); 1623d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 1624e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall argSlot[i] = args[i]; 162535495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor } 1626e186269a8a41dbff1ebea2c251048892979d1078Douglas Gregor 162760618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl if (getExceptionSpecType() == EST_Dynamic) { 162860618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl // Fill in the exception array. 1629bea522ff43a3f11c7a2bc7949119dbb9fce19e39Jordan Rose QualType *exnSlot = argSlot + NumArgs; 163060618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl for (unsigned i = 0, e = epi.NumExceptions; i != e; ++i) { 163160618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl if (epi.Exceptions[i]->isDependentType()) 163260618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl setDependent(); 1633561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor else if (epi.Exceptions[i]->isInstantiationDependentType()) 1634561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor setInstantiationDependent(); 1635561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor 163660618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl if (epi.Exceptions[i]->containsUnexpandedParameterPack()) 163760618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl setContainsUnexpandedParameterPack(); 163860618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl 163960618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl exnSlot[i] = epi.Exceptions[i]; 164060618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl } 164160618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl } else if (getExceptionSpecType() == EST_ComputedNoexcept) { 164260618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl // Store the noexcept expression and context. 1643bea522ff43a3f11c7a2bc7949119dbb9fce19e39Jordan Rose Expr **noexSlot = reinterpret_cast<Expr**>(argSlot + NumArgs); 164460618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl *noexSlot = epi.NoexceptExpr; 1645561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor 1646561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (epi.NoexceptExpr) { 1647561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (epi.NoexceptExpr->isValueDependent() 1648561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor || epi.NoexceptExpr->isTypeDependent()) 1649561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor setDependent(); 1650561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor else if (epi.NoexceptExpr->isInstantiationDependent()) 1651561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor setInstantiationDependent(); 1652561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor } 1653e6975e9b0985ad7f7ff9187e38d95bfe9ac4181bRichard Smith } else if (getExceptionSpecType() == EST_Uninstantiated) { 1654e6975e9b0985ad7f7ff9187e38d95bfe9ac4181bRichard Smith // Store the function decl from which we will resolve our 1655e6975e9b0985ad7f7ff9187e38d95bfe9ac4181bRichard Smith // exception specification. 1656bea522ff43a3f11c7a2bc7949119dbb9fce19e39Jordan Rose FunctionDecl **slot = reinterpret_cast<FunctionDecl**>(argSlot + NumArgs); 165713bffc532bafd45d4a77867993c1afb83c7661beRichard Smith slot[0] = epi.ExceptionSpecDecl; 165813bffc532bafd45d4a77867993c1afb83c7661beRichard Smith slot[1] = epi.ExceptionSpecTemplate; 1659e6975e9b0985ad7f7ff9187e38d95bfe9ac4181bRichard Smith // This exception specification doesn't make the type dependent, because 1660e6975e9b0985ad7f7ff9187e38d95bfe9ac4181bRichard Smith // it's not instantiated as part of instantiating the type. 1661b9d0b76e42fd2d4cdfd135220302458d03ad09feRichard Smith } else if (getExceptionSpecType() == EST_Unevaluated) { 1662b9d0b76e42fd2d4cdfd135220302458d03ad09feRichard Smith // Store the function decl from which we will resolve our 1663b9d0b76e42fd2d4cdfd135220302458d03ad09feRichard Smith // exception specification. 1664bea522ff43a3f11c7a2bc7949119dbb9fce19e39Jordan Rose FunctionDecl **slot = reinterpret_cast<FunctionDecl**>(argSlot + NumArgs); 1665b9d0b76e42fd2d4cdfd135220302458d03ad09feRichard Smith slot[0] = epi.ExceptionSpecDecl; 1666e186269a8a41dbff1ebea2c251048892979d1078Douglas Gregor } 1667f85e193739c953358c865005855253af4f68a497John McCall 1668f85e193739c953358c865005855253af4f68a497John McCall if (epi.ConsumedArguments) { 1669f85e193739c953358c865005855253af4f68a497John McCall bool *consumedArgs = const_cast<bool*>(getConsumedArgsBuffer()); 1670bea522ff43a3f11c7a2bc7949119dbb9fce19e39Jordan Rose for (unsigned i = 0; i != NumArgs; ++i) 1671f85e193739c953358c865005855253af4f68a497John McCall consumedArgs[i] = epi.ConsumedArguments[i]; 1672f85e193739c953358c865005855253af4f68a497John McCall } 167335495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor} 167435495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor 167560618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian RedlFunctionProtoType::NoexceptResult 16768026f6d82f7fa544bc0453714fe94bca62a1196eSebastian RedlFunctionProtoType::getNoexceptSpec(ASTContext &ctx) const { 167760618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl ExceptionSpecificationType est = getExceptionSpecType(); 167860618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl if (est == EST_BasicNoexcept) 167960618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl return NR_Nothrow; 168060618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl 168160618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl if (est != EST_ComputedNoexcept) 168260618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl return NR_NoNoexcept; 168360618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl 168460618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl Expr *noexceptExpr = getNoexceptExpr(); 168560618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl if (!noexceptExpr) 168660618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl return NR_BadNoexcept; 168760618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl if (noexceptExpr->isValueDependent()) 168860618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl return NR_Dependent; 168960618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl 169060618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl llvm::APSInt value; 169160618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl bool isICE = noexceptExpr->isIntegerConstantExpr(value, ctx, 0, 169260618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl /*evaluated*/false); 169360618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl (void)isICE; 169460618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl assert(isICE && "AST should not contain bad noexcept expressions."); 169560618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl 169660618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl return value.getBoolValue() ? NR_Nothrow : NR_Throw; 169760618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl} 169860618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl 1699f5c65ffbd7374b6c8d9f1e361041578640cab320Douglas Gregorbool FunctionProtoType::isTemplateVariadic() const { 17007d5c0c1273bdc1cb3dff1cb5a62d07b1439e82c7Douglas Gregor for (unsigned ArgIdx = getNumArgs(); ArgIdx; --ArgIdx) 17017d5c0c1273bdc1cb3dff1cb5a62d07b1439e82c7Douglas Gregor if (isa<PackExpansionType>(getArgType(ArgIdx - 1))) 17027d5c0c1273bdc1cb3dff1cb5a62d07b1439e82c7Douglas Gregor return true; 17037d5c0c1273bdc1cb3dff1cb5a62d07b1439e82c7Douglas Gregor 17047d5c0c1273bdc1cb3dff1cb5a62d07b1439e82c7Douglas Gregor return false; 1705f5c65ffbd7374b6c8d9f1e361041578640cab320Douglas Gregor} 170635495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor 170772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregorvoid FunctionProtoType::Profile(llvm::FoldingSetNodeID &ID, QualType Result, 1708e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall const QualType *ArgTys, unsigned NumArgs, 170960618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl const ExtProtoInfo &epi, 17108026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redl const ASTContext &Context) { 1711f85e193739c953358c865005855253af4f68a497John McCall 1712f85e193739c953358c865005855253af4f68a497John McCall // We have to be careful not to get ambiguous profile encodings. 1713f85e193739c953358c865005855253af4f68a497John McCall // Note that valid type pointers are never ambiguous with anything else. 1714f85e193739c953358c865005855253af4f68a497John McCall // 1715f85e193739c953358c865005855253af4f68a497John McCall // The encoding grammar begins: 1716f85e193739c953358c865005855253af4f68a497John McCall // type type* bool int bool 1717f85e193739c953358c865005855253af4f68a497John McCall // If that final bool is true, then there is a section for the EH spec: 1718f85e193739c953358c865005855253af4f68a497John McCall // bool type* 1719f85e193739c953358c865005855253af4f68a497John McCall // This is followed by an optional "consumed argument" section of the 1720f85e193739c953358c865005855253af4f68a497John McCall // same length as the first type sequence: 1721f85e193739c953358c865005855253af4f68a497John McCall // bool* 1722eefb3d5b49c844347f212073a7e975b8118fe8e9Richard Smith // Finally, we have the ext info and trailing return type flag: 1723eefb3d5b49c844347f212073a7e975b8118fe8e9Richard Smith // int bool 1724f85e193739c953358c865005855253af4f68a497John McCall // 1725f85e193739c953358c865005855253af4f68a497John McCall // There is no ambiguity between the consumed arguments and an empty EH 1726f85e193739c953358c865005855253af4f68a497John McCall // spec because of the leading 'bool' which unambiguously indicates 1727f85e193739c953358c865005855253af4f68a497John McCall // whether the following bool is the EH spec or part of the arguments. 1728f85e193739c953358c865005855253af4f68a497John McCall 17295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddPointer(Result.getAsOpaquePtr()); 17305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer for (unsigned i = 0; i != NumArgs; ++i) 17315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddPointer(ArgTys[i].getAsOpaquePtr()); 17320c051221bd06fe1b24b9459292584e5264a131c5Eli Friedman // This method is relatively performance sensitive, so as a performance 17330c051221bd06fe1b24b9459292584e5264a131c5Eli Friedman // shortcut, use one AddInteger call instead of four for the next four 17340c051221bd06fe1b24b9459292584e5264a131c5Eli Friedman // fields. 17350c051221bd06fe1b24b9459292584e5264a131c5Eli Friedman assert(!(unsigned(epi.Variadic) & ~1) && 17360c051221bd06fe1b24b9459292584e5264a131c5Eli Friedman !(unsigned(epi.TypeQuals) & ~255) && 17370c051221bd06fe1b24b9459292584e5264a131c5Eli Friedman !(unsigned(epi.RefQualifier) & ~3) && 17380c051221bd06fe1b24b9459292584e5264a131c5Eli Friedman !(unsigned(epi.ExceptionSpecType) & ~7) && 17390c051221bd06fe1b24b9459292584e5264a131c5Eli Friedman "Values larger than expected."); 17400c051221bd06fe1b24b9459292584e5264a131c5Eli Friedman ID.AddInteger(unsigned(epi.Variadic) + 17410c051221bd06fe1b24b9459292584e5264a131c5Eli Friedman (epi.TypeQuals << 1) + 17420c051221bd06fe1b24b9459292584e5264a131c5Eli Friedman (epi.RefQualifier << 9) + 17430c051221bd06fe1b24b9459292584e5264a131c5Eli Friedman (epi.ExceptionSpecType << 11)); 174460618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl if (epi.ExceptionSpecType == EST_Dynamic) { 1745e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall for (unsigned i = 0; i != epi.NumExceptions; ++i) 1746e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall ID.AddPointer(epi.Exceptions[i].getAsOpaquePtr()); 174760618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl } else if (epi.ExceptionSpecType == EST_ComputedNoexcept && epi.NoexceptExpr){ 17481abd35950bcb0761887dca0995c68b8a9dc8916fDouglas Gregor epi.NoexceptExpr->Profile(ID, Context, false); 1749b9d0b76e42fd2d4cdfd135220302458d03ad09feRichard Smith } else if (epi.ExceptionSpecType == EST_Uninstantiated || 1750b9d0b76e42fd2d4cdfd135220302458d03ad09feRichard Smith epi.ExceptionSpecType == EST_Unevaluated) { 1751e6975e9b0985ad7f7ff9187e38d95bfe9ac4181bRichard Smith ID.AddPointer(epi.ExceptionSpecDecl->getCanonicalDecl()); 1752465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl } 1753f85e193739c953358c865005855253af4f68a497John McCall if (epi.ConsumedArguments) { 1754f85e193739c953358c865005855253af4f68a497John McCall for (unsigned i = 0; i != NumArgs; ++i) 1755f85e193739c953358c865005855253af4f68a497John McCall ID.AddBoolean(epi.ConsumedArguments[i]); 1756f85e193739c953358c865005855253af4f68a497John McCall } 1757e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall epi.ExtInfo.Profile(ID); 1758eefb3d5b49c844347f212073a7e975b8118fe8e9Richard Smith ID.AddBoolean(epi.HasTrailingReturn); 17595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 17605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 17618026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redlvoid FunctionProtoType::Profile(llvm::FoldingSetNodeID &ID, 17628026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redl const ASTContext &Ctx) { 176360618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl Profile(ID, getResultType(), arg_type_begin(), NumArgs, getExtProtoInfo(), 17648026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redl Ctx); 17655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 17665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1767bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCallQualType TypedefType::desugar() const { 1768bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall return getDecl()->getUnderlyingType(); 1769bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall} 1770bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 177172564e73277e29f6db3305d1f27ba408abb7ed88Douglas GregorTypeOfExprType::TypeOfExprType(Expr *E, QualType can) 177235495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor : Type(TypeOfExpr, can, E->isTypeDependent(), 1773561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor E->isInstantiationDependent(), 1774d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor E->getType()->isVariablyModifiedType(), 1775d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor E->containsUnexpandedParameterPack()), 1776d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor TOExpr(E) { 1777898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor} 1778898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 17796af9f3ca25157379efd5c1caad82e9d01c17b9ffDouglas Gregorbool TypeOfExprType::isSugared() const { 17806af9f3ca25157379efd5c1caad82e9d01c17b9ffDouglas Gregor return !TOExpr->isTypeDependent(); 17816af9f3ca25157379efd5c1caad82e9d01c17b9ffDouglas Gregor} 17826af9f3ca25157379efd5c1caad82e9d01c17b9ffDouglas Gregor 1783bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCallQualType TypeOfExprType::desugar() const { 1784c910d4cfa5042f2c9da1eb4e0b6ed59240c0eeeeReid Kleckner if (isSugared()) 1785c910d4cfa5042f2c9da1eb4e0b6ed59240c0eeeeReid Kleckner return getUnderlyingExpr()->getType(); 17866af9f3ca25157379efd5c1caad82e9d01c17b9ffDouglas Gregor 17876af9f3ca25157379efd5c1caad82e9d01c17b9ffDouglas Gregor return QualType(this, 0); 1788bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall} 1789bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 17901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpvoid DependentTypeOfExprType::Profile(llvm::FoldingSetNodeID &ID, 17914ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad const ASTContext &Context, Expr *E) { 1792b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor E->Profile(ID, Context, true); 1793b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor} 1794b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor 1795563a03b1338d31c2462def43253a722bc885d384Anders CarlssonDecltypeType::DecltypeType(Expr *E, QualType underlyingType, QualType can) 1796fa16125aaf667c2bd80efcea403a7a71aa65da14Richard Smith // C++11 [temp.type]p2: "If an expression e involves a template parameter, 1797fa16125aaf667c2bd80efcea403a7a71aa65da14Richard Smith // decltype(e) denotes a unique dependent type." Hence a decltype type is 1798fa16125aaf667c2bd80efcea403a7a71aa65da14Richard Smith // type-dependent even if its expression is only instantiation-dependent. 1799fa16125aaf667c2bd80efcea403a7a71aa65da14Richard Smith : Type(Decltype, can, E->isInstantiationDependent(), 1800561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor E->isInstantiationDependent(), 1801d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor E->getType()->isVariablyModifiedType(), 1802d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor E->containsUnexpandedParameterPack()), 1803d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor E(E), 1804563a03b1338d31c2462def43253a722bc885d384Anders Carlsson UnderlyingType(underlyingType) { 1805395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson} 1806395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson 18076af9f3ca25157379efd5c1caad82e9d01c17b9ffDouglas Gregorbool DecltypeType::isSugared() const { return !E->isInstantiationDependent(); } 18086af9f3ca25157379efd5c1caad82e9d01c17b9ffDouglas Gregor 18096af9f3ca25157379efd5c1caad82e9d01c17b9ffDouglas GregorQualType DecltypeType::desugar() const { 18106af9f3ca25157379efd5c1caad82e9d01c17b9ffDouglas Gregor if (isSugared()) 18116af9f3ca25157379efd5c1caad82e9d01c17b9ffDouglas Gregor return getUnderlyingType(); 18126af9f3ca25157379efd5c1caad82e9d01c17b9ffDouglas Gregor 18136af9f3ca25157379efd5c1caad82e9d01c17b9ffDouglas Gregor return QualType(this, 0); 18146af9f3ca25157379efd5c1caad82e9d01c17b9ffDouglas Gregor} 18156af9f3ca25157379efd5c1caad82e9d01c17b9ffDouglas Gregor 18164ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadDependentDecltypeType::DependentDecltypeType(const ASTContext &Context, Expr *E) 18179d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor : DecltypeType(E, Context.DependentTy), Context(Context) { } 18189d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor 18191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpvoid DependentDecltypeType::Profile(llvm::FoldingSetNodeID &ID, 18204ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad const ASTContext &Context, Expr *E) { 18219d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor E->Profile(ID, Context, true); 18229d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor} 18239d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor 182419c8576b7328f4dc2d07682f5da552875c1912efJohn McCallTagType::TagType(TypeClass TC, const TagDecl *D, QualType can) 1825561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor : Type(TC, can, D->isDependentType(), 1826561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /*InstantiationDependent=*/D->isDependentType(), 1827561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /*VariablyModified=*/false, 1828d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /*ContainsUnexpandedParameterPack=*/false), 1829ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl decl(const_cast<TagDecl*>(D)) {} 1830ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl 1831ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redlstatic TagDecl *getInterestingTagDecl(TagDecl *decl) { 1832ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl for (TagDecl::redecl_iterator I = decl->redecls_begin(), 1833ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl E = decl->redecls_end(); 1834ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl I != E; ++I) { 18355e1cdac63c3d9c9b32fa41fa0b2d242a58a20d49John McCall if (I->isCompleteDefinition() || I->isBeingDefined()) 1836ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl return *I; 1837ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl } 1838ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl // If there's no definition (not even in progress), return what we have. 1839ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl return decl; 1840ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl} 1841ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl 1842ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean HuntUnaryTransformType::UnaryTransformType(QualType BaseType, 1843ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt QualType UnderlyingType, 1844ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt UTTKind UKind, 1845ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt QualType CanonicalType) 1846ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt : Type(UnaryTransform, CanonicalType, UnderlyingType->isDependentType(), 1847561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor UnderlyingType->isInstantiationDependentType(), 1848ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt UnderlyingType->isVariablyModifiedType(), 1849ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt BaseType->containsUnexpandedParameterPack()) 1850ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt , BaseType(BaseType), UnderlyingType(UnderlyingType), UKind(UKind) 1851ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt{} 1852ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt 1853ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian RedlTagDecl *TagType::getDecl() const { 1854ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl return getInterestingTagDecl(decl); 1855ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl} 1856ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl 1857ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redlbool TagType::isBeingDefined() const { 1858ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl return getDecl()->isBeingDefined(); 1859ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl} 1860ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl 1861ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian RedlCXXRecordDecl *InjectedClassNameType::getDecl() const { 1862ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl return cast<CXXRecordDecl>(getInterestingTagDecl(Decl)); 1863ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl} 18647da97d0f31e1ec16998d3de2cfd2e88fe3736673Douglas Gregor 1865b7efff4bae117604f442bb6859c844f90b15f3ffChandler CarruthIdentifierInfo *TemplateTypeParmType::getIdentifier() const { 18664fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth return isCanonicalUnqualified() ? 0 : getDecl()->getIdentifier(); 18674fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth} 18684fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth 1869c3069d618f4661d923cb1b5c4525b082fce73b04Douglas GregorSubstTemplateTypeParmPackType:: 1870c3069d618f4661d923cb1b5c4525b082fce73b04Douglas GregorSubstTemplateTypeParmPackType(const TemplateTypeParmType *Param, 1871c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor QualType Canon, 1872c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor const TemplateArgument &ArgPack) 1873561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor : Type(SubstTemplateTypeParmPack, Canon, true, true, false, true), 1874561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor Replaced(Param), 1875c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor Arguments(ArgPack.pack_begin()), NumArguments(ArgPack.pack_size()) 1876c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor{ 1877c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor} 1878c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor 1879c3069d618f4661d923cb1b5c4525b082fce73b04Douglas GregorTemplateArgument SubstTemplateTypeParmPackType::getArgumentPack() const { 1880c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor return TemplateArgument(Arguments, NumArguments); 1881c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor} 1882c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor 1883c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregorvoid SubstTemplateTypeParmPackType::Profile(llvm::FoldingSetNodeID &ID) { 1884c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor Profile(ID, getReplacedParameter(), getArgumentPack()); 1885c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor} 1886c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor 1887c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregorvoid SubstTemplateTypeParmPackType::Profile(llvm::FoldingSetNodeID &ID, 1888c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor const TemplateTypeParmType *Replaced, 1889c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor const TemplateArgument &ArgPack) { 1890c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor ID.AddPointer(Replaced); 1891c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor ID.AddInteger(ArgPack.pack_size()); 1892c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor for (TemplateArgument::pack_iterator P = ArgPack.pack_begin(), 1893c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor PEnd = ArgPack.pack_end(); 1894c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor P != PEnd; ++P) 1895c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor ID.AddPointer(P->getAsType().getAsOpaquePtr()); 1896c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor} 1897c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor 1898833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallbool TemplateSpecializationType:: 1899561f81243f665cf2001caadc45df505f826b72d6Douglas GregoranyDependentTemplateArguments(const TemplateArgumentListInfo &Args, 1900561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor bool &InstantiationDependent) { 1901561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor return anyDependentTemplateArguments(Args.getArgumentArray(), Args.size(), 1902561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor InstantiationDependent); 1903d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall} 1904d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall 1905d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCallbool TemplateSpecializationType:: 1906561f81243f665cf2001caadc45df505f826b72d6Douglas GregoranyDependentTemplateArguments(const TemplateArgumentLoc *Args, unsigned N, 1907561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor bool &InstantiationDependent) { 1908561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor for (unsigned i = 0; i != N; ++i) { 1909561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (Args[i].getArgument().isDependent()) { 1910561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor InstantiationDependent = true; 1911833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return true; 1912561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor } 1913561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor 1914561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (Args[i].getArgument().isInstantiationDependent()) 1915561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor InstantiationDependent = true; 1916561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor } 1917833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return false; 1918833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall} 1919833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 1920833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallbool TemplateSpecializationType:: 1921561f81243f665cf2001caadc45df505f826b72d6Douglas GregoranyDependentTemplateArguments(const TemplateArgument *Args, unsigned N, 1922561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor bool &InstantiationDependent) { 1923561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor for (unsigned i = 0; i != N; ++i) { 1924561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (Args[i].isDependent()) { 1925561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor InstantiationDependent = true; 1926833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return true; 1927561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor } 1928561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor 1929561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (Args[i].isInstantiationDependent()) 1930561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor InstantiationDependent = true; 1931561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor } 1932833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return false; 1933833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall} 1934833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 19357532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas GregorTemplateSpecializationType:: 1936ef99001908e799c388f1363b1e607dad5f5b57d3John McCallTemplateSpecializationType(TemplateName T, 19373e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith const TemplateArgument *Args, unsigned NumArgs, 19383e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith QualType Canon, QualType AliasedType) 19391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : Type(TemplateSpecialization, 194040808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor Canon.isNull()? QualType(this, 0) : Canon, 19413e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith Canon.isNull()? T.isDependent() : Canon->isDependentType(), 1942561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor Canon.isNull()? T.isDependent() 1943561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor : Canon->isInstantiationDependentType(), 1944c0536c8294fc4453f0f1d1cf24a62bfc725fd492Richard Smith false, 1945d8672ef2d343a0dbfe838724fb2d9fb4efea6041Richard Smith T.containsUnexpandedParameterPack()), 1946b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor Template(T), NumArgs(NumArgs), TypeAlias(!AliasedType.isNull()) { 1947a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor assert(!T.getAsDependentTemplateName() && 1948a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor "Use DependentTemplateSpecializationType for dependent template-name"); 19491901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall assert((T.getKind() == TemplateName::Template || 1950146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall T.getKind() == TemplateName::SubstTemplateTemplateParm || 19511901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall T.getKind() == TemplateName::SubstTemplateTemplateParmPack) && 19521901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall "Unexpected template name for TemplateSpecializationType"); 1953561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor bool InstantiationDependent; 1954561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (void)InstantiationDependent; 19551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump assert((!Canon.isNull() || 1956561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor T.isDependent() || 1957561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor anyDependentTemplateArguments(Args, NumArgs, 1958561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor InstantiationDependent)) && 195940808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor "No canonical type for non-dependent class template specialization"); 196055f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 19611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TemplateArgument *TemplateArgs 196240808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor = reinterpret_cast<TemplateArgument *>(this + 1); 196335495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor for (unsigned Arg = 0; Arg < NumArgs; ++Arg) { 196435495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor // Update dependent and variably-modified bits. 19653e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith // If the canonical type exists and is non-dependent, the template 19663e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith // specialization type can be non-dependent even if one of the type 19673e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith // arguments is. Given: 19683e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith // template<typename T> using U = int; 19693e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith // U<T> is always non-dependent, irrespective of the type T. 1970d8672ef2d343a0dbfe838724fb2d9fb4efea6041Richard Smith // However, U<Ts> contains an unexpanded parameter pack, even though 1971d8672ef2d343a0dbfe838724fb2d9fb4efea6041Richard Smith // its expansion (and thus its desugared type) doesn't. 19723e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith if (Canon.isNull() && Args[Arg].isDependent()) 197335495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor setDependent(); 1974561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor else if (Args[Arg].isInstantiationDependent()) 1975561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor setInstantiationDependent(); 1976561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor 197735495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor if (Args[Arg].getKind() == TemplateArgument::Type && 197835495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor Args[Arg].getAsType()->isVariablyModifiedType()) 197935495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor setVariablyModified(); 1980d8672ef2d343a0dbfe838724fb2d9fb4efea6041Richard Smith if (Args[Arg].containsUnexpandedParameterPack()) 1981d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor setContainsUnexpandedParameterPack(); 1982d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 198340808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor new (&TemplateArgs[Arg]) TemplateArgument(Args[Arg]); 198435495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor } 19853e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith 19863e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith // Store the aliased type if this is a type alias template specialization. 1987b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor if (TypeAlias) { 19883e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith TemplateArgument *Begin = reinterpret_cast<TemplateArgument *>(this + 1); 19893e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith *reinterpret_cast<QualType*>(Begin + getNumArgs()) = AliasedType; 19903e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith } 199155f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor} 199255f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 19931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpvoid 19941eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTemplateSpecializationType::Profile(llvm::FoldingSetNodeID &ID, 19951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TemplateName T, 19961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const TemplateArgument *Args, 1997828e226ab7ed08b3eb766549e9d3306432137460Douglas Gregor unsigned NumArgs, 19984ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad const ASTContext &Context) { 19997532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor T.Profile(ID); 200040808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor for (unsigned Idx = 0; Idx < NumArgs; ++Idx) 2001828e226ab7ed08b3eb766549e9d3306432137460Douglas Gregor Args[Idx].Profile(ID, Context); 200255f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor} 200397e0179f1ae545e07d9f5e7c1d2ef5c5bab06676Anders Carlsson 20044ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualType 20054ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualifierCollector::apply(const ASTContext &Context, QualType QT) const { 20060953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (!hasNonFastQualifiers()) 20070953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return QT.withFastQualifiers(getFastQualifiers()); 20081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 200949f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall return Context.getQualifiedType(QT, *this); 20105e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor} 20115e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor 20124ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualType 20134ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualifierCollector::apply(const ASTContext &Context, const Type *T) const { 20140953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (!hasNonFastQualifiers()) 20150953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return QualType(T, getFastQualifiers()); 20160953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 201749f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall return Context.getQualifiedType(T, *this); 20185e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor} 20195e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor 2020c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallvoid ObjCObjectTypeImpl::Profile(llvm::FoldingSetNodeID &ID, 2021c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall QualType BaseType, 2022c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCProtocolDecl * const *Protocols, 2023c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall unsigned NumProtocols) { 2024c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ID.AddPointer(BaseType.getAsOpaquePtr()); 2025c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff for (unsigned i = 0; i != NumProtocols; i++) 2026c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ID.AddPointer(Protocols[i]); 2027c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff} 2028c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff 2029c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallvoid ObjCObjectTypeImpl::Profile(llvm::FoldingSetNodeID &ID) { 2030c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall Profile(ID, getBaseType(), qual_begin(), getNumProtocols()); 2031c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff} 20320b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 2033b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCallnamespace { 20341fb0caaa7bef765b85972274e3b434af2572c141John McCall 2035b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall/// \brief The cached properties of a type. 2036b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCallclass CachedProperties { 2037a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola Linkage L; 2038b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall bool local; 20392beda12c3fbaa9125831b7f818680978c596b205Rafael Espindola 2040b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCallpublic: 2041a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola CachedProperties(Linkage L, bool local) : L(L), local(local) {} 20422beda12c3fbaa9125831b7f818680978c596b205Rafael Espindola 2043a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola Linkage getLinkage() const { return L; } 2044b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall bool hasLocalOrUnnamedType() const { return local; } 20452beda12c3fbaa9125831b7f818680978c596b205Rafael Espindola 2046b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall friend CachedProperties merge(CachedProperties L, CachedProperties R) { 2047a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola Linkage MergedLinkage = minLinkage(L.L, R.L); 2048a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola return CachedProperties(MergedLinkage, 2049b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall L.hasLocalOrUnnamedType() | R.hasLocalOrUnnamedType()); 2050b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall } 2051b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall}; 20521fb0caaa7bef765b85972274e3b434af2572c141John McCall} 20531fb0caaa7bef765b85972274e3b434af2572c141John McCall 2054b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCallstatic CachedProperties computeCachedProperties(const Type *T); 20550b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 2056b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCallnamespace clang { 2057b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall/// The type-property cache. This is templated so as to be 2058b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall/// instantiated at an internal type to prevent unnecessary symbol 2059b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall/// leakage. 2060b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCalltemplate <class Private> class TypePropertyCache { 2061b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCallpublic: 2062b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall static CachedProperties get(QualType T) { 2063b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return get(T.getTypePtr()); 2064b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall } 20651fb0caaa7bef765b85972274e3b434af2572c141John McCall 2066b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall static CachedProperties get(const Type *T) { 2067b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall ensure(T); 2068a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola return CachedProperties(T->TypeBits.getLinkage(), 2069a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola T->TypeBits.hasLocalOrUnnamedType()); 2070b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall } 2071db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor 2072b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall static void ensure(const Type *T) { 2073b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall // If the cache is valid, we're okay. 2074b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall if (T->TypeBits.isCacheValid()) return; 2075b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall 2076b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall // If this type is non-canonical, ask its canonical type for the 2077b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall // relevant information. 20783b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (!T->isCanonicalUnqualified()) { 20793b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall const Type *CT = T->getCanonicalTypeInternal().getTypePtr(); 2080b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall ensure(CT); 2081a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola T->TypeBits.CacheValid = true; 2082b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall T->TypeBits.CachedLinkage = CT->TypeBits.CachedLinkage; 2083b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall T->TypeBits.CachedLocalOrUnnamed = CT->TypeBits.CachedLocalOrUnnamed; 2084b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return; 2085b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall } 20861fb0caaa7bef765b85972274e3b434af2572c141John McCall 2087b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall // Compute the cached properties and then set the cache. 2088b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall CachedProperties Result = computeCachedProperties(T); 2089a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola T->TypeBits.CacheValid = true; 2090b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall T->TypeBits.CachedLinkage = Result.getLinkage(); 2091b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall T->TypeBits.CachedLocalOrUnnamed = Result.hasLocalOrUnnamedType(); 2092b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall } 2093b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall}; 20941fb0caaa7bef765b85972274e3b434af2572c141John McCall} 20951fb0caaa7bef765b85972274e3b434af2572c141John McCall 2096b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall// Instantiate the friend template at a private class. In a 2097b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall// reasonable implementation, these symbols will be internal. 2098b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall// It is terrible that this is the best way to accomplish this. 2099b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCallnamespace { class Private {}; } 2100b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCalltypedef TypePropertyCache<Private> Cache; 21011fb0caaa7bef765b85972274e3b434af2572c141John McCall 2102b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCallstatic CachedProperties computeCachedProperties(const Type *T) { 2103b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall switch (T->getTypeClass()) { 2104b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall#define TYPE(Class,Base) 2105b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall#define NON_CANONICAL_TYPE(Class,Base) case Type::Class: 2106b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall#include "clang/AST/TypeNodes.def" 2107b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall llvm_unreachable("didn't expect a non-canonical type here"); 210860e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor 2109b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall#define TYPE(Class,Base) 2110b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall#define DEPENDENT_TYPE(Class,Base) case Type::Class: 2111b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall#define NON_CANONICAL_UNLESS_DEPENDENT_TYPE(Class,Base) case Type::Class: 2112b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall#include "clang/AST/TypeNodes.def" 21135e78cd43a033b3dedf741fca4fa1652f9cb3e41cDouglas Gregor // Treat instantiation-dependent types as external. 21145e78cd43a033b3dedf741fca4fa1652f9cb3e41cDouglas Gregor assert(T->isInstantiationDependentType()); 2115a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola return CachedProperties(ExternalLinkage, false); 21161fb0caaa7bef765b85972274e3b434af2572c141John McCall 2117dc7a4f5d7a7e3b60d4dc4a80338d7a2728540998Richard Smith case Type::Auto: 2118dc7a4f5d7a7e3b60d4dc4a80338d7a2728540998Richard Smith // Give non-deduced 'auto' types external linkage. We should only see them 2119dc7a4f5d7a7e3b60d4dc4a80338d7a2728540998Richard Smith // here in error recovery. 2120dc7a4f5d7a7e3b60d4dc4a80338d7a2728540998Richard Smith return CachedProperties(ExternalLinkage, false); 2121dc7a4f5d7a7e3b60d4dc4a80338d7a2728540998Richard Smith 2122b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::Builtin: 2123b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall // C++ [basic.link]p8: 2124b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall // A type is said to have linkage if and only if: 2125b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall // - it is a fundamental type (3.9.1); or 2126a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola return CachedProperties(ExternalLinkage, false); 21270b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 2128b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::Record: 2129b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::Enum: { 2130b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall const TagDecl *Tag = cast<TagType>(T)->getDecl(); 2131b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall 2132b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall // C++ [basic.link]p8: 2133b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall // - it is a class or enumeration type that is named (or has a name 2134b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall // for linkage purposes (7.1.3)) and the name has linkage; or 2135b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall // - it is a specialization of a class template (14); or 2136181e3ecc0907ae0103586a9f4db52241995a8267Rafael Espindola Linkage L = Tag->getLinkageInternal(); 2137b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall bool IsLocalOrUnnamed = 2138b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall Tag->getDeclContext()->isFunctionOrMethod() || 213983972f128e9218c051692bf96361327a701aeb79John McCall !Tag->hasNameForLinkage(); 2140a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola return CachedProperties(L, IsLocalOrUnnamed); 2141b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall } 21420b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 2143b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall // C++ [basic.link]p8: 2144b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall // - it is a compound type (3.9.2) other than a class or enumeration, 2145b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall // compounded exclusively from types that have linkage; or 2146b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::Complex: 2147b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return Cache::get(cast<ComplexType>(T)->getElementType()); 2148b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::Pointer: 2149b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return Cache::get(cast<PointerType>(T)->getPointeeType()); 2150b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::BlockPointer: 2151b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return Cache::get(cast<BlockPointerType>(T)->getPointeeType()); 2152b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::LValueReference: 2153b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::RValueReference: 2154b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return Cache::get(cast<ReferenceType>(T)->getPointeeType()); 2155b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::MemberPointer: { 2156b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall const MemberPointerType *MPT = cast<MemberPointerType>(T); 2157b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return merge(Cache::get(MPT->getClass()), 2158b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall Cache::get(MPT->getPointeeType())); 2159b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall } 2160b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::ConstantArray: 2161b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::IncompleteArray: 2162b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::VariableArray: 2163b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return Cache::get(cast<ArrayType>(T)->getElementType()); 2164b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::Vector: 2165b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::ExtVector: 2166b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return Cache::get(cast<VectorType>(T)->getElementType()); 2167b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::FunctionNoProto: 2168b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return Cache::get(cast<FunctionType>(T)->getResultType()); 2169b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::FunctionProto: { 2170b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall const FunctionProtoType *FPT = cast<FunctionProtoType>(T); 2171b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall CachedProperties result = Cache::get(FPT->getResultType()); 2172b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall for (FunctionProtoType::arg_type_iterator ai = FPT->arg_type_begin(), 2173b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall ae = FPT->arg_type_end(); ai != ae; ++ai) 2174b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall result = merge(result, Cache::get(*ai)); 2175b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return result; 2176b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall } 2177b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::ObjCInterface: { 2178181e3ecc0907ae0103586a9f4db52241995a8267Rafael Espindola Linkage L = cast<ObjCInterfaceType>(T)->getDecl()->getLinkageInternal(); 2179a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola return CachedProperties(L, false); 2180b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall } 2181b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::ObjCObject: 2182b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return Cache::get(cast<ObjCObjectType>(T)->getBaseType()); 2183b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::ObjCObjectPointer: 2184b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return Cache::get(cast<ObjCObjectPointerType>(T)->getPointeeType()); 2185b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman case Type::Atomic: 2186b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman return Cache::get(cast<AtomicType>(T)->getValueType()); 2187b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall } 21880b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 2189b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall llvm_unreachable("unhandled type class"); 21900b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor} 21910b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 2192b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall/// \brief Determine the linkage of this type. 2193b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCallLinkage Type::getLinkage() const { 2194b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall Cache::ensure(this); 2195b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return TypeBits.getLinkage(); 21960b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor} 21970b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 2198b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCallbool Type::hasUnnamedOrLocalType() const { 2199b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall Cache::ensure(this); 2200b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return TypeBits.hasLocalOrUnnamedType(); 22010b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor} 22020b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 2203a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindolastatic LinkageInfo computeLinkageInfo(QualType T); 2204a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola 2205a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindolastatic LinkageInfo computeLinkageInfo(const Type *T) { 2206a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola switch (T->getTypeClass()) { 2207a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola#define TYPE(Class,Base) 2208a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola#define NON_CANONICAL_TYPE(Class,Base) case Type::Class: 2209a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola#include "clang/AST/TypeNodes.def" 2210a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola llvm_unreachable("didn't expect a non-canonical type here"); 2211a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola 2212a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola#define TYPE(Class,Base) 2213a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola#define DEPENDENT_TYPE(Class,Base) case Type::Class: 2214a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola#define NON_CANONICAL_UNLESS_DEPENDENT_TYPE(Class,Base) case Type::Class: 2215a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola#include "clang/AST/TypeNodes.def" 2216a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola // Treat instantiation-dependent types as external. 2217a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola assert(T->isInstantiationDependentType()); 2218a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola return LinkageInfo::external(); 2219a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola 2220a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola case Type::Builtin: 2221a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola return LinkageInfo::external(); 2222a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola 2223dc7a4f5d7a7e3b60d4dc4a80338d7a2728540998Richard Smith case Type::Auto: 2224dc7a4f5d7a7e3b60d4dc4a80338d7a2728540998Richard Smith return LinkageInfo::external(); 2225dc7a4f5d7a7e3b60d4dc4a80338d7a2728540998Richard Smith 2226a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola case Type::Record: 2227a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola case Type::Enum: 2228a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola return cast<TagType>(T)->getDecl()->getLinkageAndVisibility(); 2229a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola 2230a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola case Type::Complex: 2231a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola return computeLinkageInfo(cast<ComplexType>(T)->getElementType()); 2232a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola case Type::Pointer: 2233a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola return computeLinkageInfo(cast<PointerType>(T)->getPointeeType()); 2234a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola case Type::BlockPointer: 2235a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola return computeLinkageInfo(cast<BlockPointerType>(T)->getPointeeType()); 2236a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola case Type::LValueReference: 2237a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola case Type::RValueReference: 2238a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola return computeLinkageInfo(cast<ReferenceType>(T)->getPointeeType()); 2239a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola case Type::MemberPointer: { 2240a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola const MemberPointerType *MPT = cast<MemberPointerType>(T); 2241a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola LinkageInfo LV = computeLinkageInfo(MPT->getClass()); 2242a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola LV.merge(computeLinkageInfo(MPT->getPointeeType())); 2243a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola return LV; 2244a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola } 2245a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola case Type::ConstantArray: 2246a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola case Type::IncompleteArray: 2247a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola case Type::VariableArray: 2248a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola return computeLinkageInfo(cast<ArrayType>(T)->getElementType()); 2249a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola case Type::Vector: 2250a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola case Type::ExtVector: 2251a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola return computeLinkageInfo(cast<VectorType>(T)->getElementType()); 2252a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola case Type::FunctionNoProto: 2253a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola return computeLinkageInfo(cast<FunctionType>(T)->getResultType()); 2254a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola case Type::FunctionProto: { 2255a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola const FunctionProtoType *FPT = cast<FunctionProtoType>(T); 2256a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola LinkageInfo LV = computeLinkageInfo(FPT->getResultType()); 2257a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola for (FunctionProtoType::arg_type_iterator ai = FPT->arg_type_begin(), 2258a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola ae = FPT->arg_type_end(); ai != ae; ++ai) 2259a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola LV.merge(computeLinkageInfo(*ai)); 2260a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola return LV; 2261a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola } 2262a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola case Type::ObjCInterface: 2263a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola return cast<ObjCInterfaceType>(T)->getDecl()->getLinkageAndVisibility(); 2264a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola case Type::ObjCObject: 2265a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola return computeLinkageInfo(cast<ObjCObjectType>(T)->getBaseType()); 2266a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola case Type::ObjCObjectPointer: 2267a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola return computeLinkageInfo(cast<ObjCObjectPointerType>(T)->getPointeeType()); 2268a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola case Type::Atomic: 2269a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola return computeLinkageInfo(cast<AtomicType>(T)->getValueType()); 2270a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola } 2271a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola 2272a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola llvm_unreachable("unhandled type class"); 2273a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola} 2274a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola 2275a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindolastatic LinkageInfo computeLinkageInfo(QualType T) { 2276a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola return computeLinkageInfo(T.getTypePtr()); 2277a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola} 2278a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola 22792d1b09641ecf2e754bf3fd244dc45dbf3e460c1bRafael Espindolabool Type::isLinkageValid() const { 22802d1b09641ecf2e754bf3fd244dc45dbf3e460c1bRafael Espindola if (!TypeBits.isCacheValid()) 22812d1b09641ecf2e754bf3fd244dc45dbf3e460c1bRafael Espindola return true; 22822d1b09641ecf2e754bf3fd244dc45dbf3e460c1bRafael Espindola 22832d1b09641ecf2e754bf3fd244dc45dbf3e460c1bRafael Espindola return computeLinkageInfo(getCanonicalTypeInternal()).getLinkage() == 22842d1b09641ecf2e754bf3fd244dc45dbf3e460c1bRafael Espindola TypeBits.getLinkage(); 22852d1b09641ecf2e754bf3fd244dc45dbf3e460c1bRafael Espindola} 22862d1b09641ecf2e754bf3fd244dc45dbf3e460c1bRafael Espindola 228718895dc4fd29f0071eeb591be820338f16407906Rafael EspindolaLinkageInfo Type::getLinkageAndVisibility() const { 2288a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola if (!isCanonicalUnqualified()) 2289a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola return computeLinkageInfo(getCanonicalTypeInternal()); 2290a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola 2291a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola LinkageInfo LV = computeLinkageInfo(this); 2292a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola assert(LV.getLinkage() == getLinkage()); 229318895dc4fd29f0071eeb591be820338f16407906Rafael Espindola return LV; 22940b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor} 22950b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 2296f85e193739c953358c865005855253af4f68a497John McCallQualifiers::ObjCLifetime Type::getObjCARCImplicitLifetime() const { 2297f85e193739c953358c865005855253af4f68a497John McCall if (isObjCARCImplicitlyUnretainedType()) 2298f85e193739c953358c865005855253af4f68a497John McCall return Qualifiers::OCL_ExplicitNone; 2299f85e193739c953358c865005855253af4f68a497John McCall return Qualifiers::OCL_Strong; 2300f85e193739c953358c865005855253af4f68a497John McCall} 2301f85e193739c953358c865005855253af4f68a497John McCall 2302f85e193739c953358c865005855253af4f68a497John McCallbool Type::isObjCARCImplicitlyUnretainedType() const { 2303f85e193739c953358c865005855253af4f68a497John McCall assert(isObjCLifetimeType() && 2304f85e193739c953358c865005855253af4f68a497John McCall "cannot query implicit lifetime for non-inferrable type"); 2305f85e193739c953358c865005855253af4f68a497John McCall 2306f85e193739c953358c865005855253af4f68a497John McCall const Type *canon = getCanonicalTypeInternal().getTypePtr(); 2307f85e193739c953358c865005855253af4f68a497John McCall 2308f85e193739c953358c865005855253af4f68a497John McCall // Walk down to the base type. We don't care about qualifiers for this. 2309f85e193739c953358c865005855253af4f68a497John McCall while (const ArrayType *array = dyn_cast<ArrayType>(canon)) 2310f85e193739c953358c865005855253af4f68a497John McCall canon = array->getElementType().getTypePtr(); 2311f85e193739c953358c865005855253af4f68a497John McCall 2312f85e193739c953358c865005855253af4f68a497John McCall if (const ObjCObjectPointerType *opt 2313f85e193739c953358c865005855253af4f68a497John McCall = dyn_cast<ObjCObjectPointerType>(canon)) { 2314f85e193739c953358c865005855253af4f68a497John McCall // Class and Class<Protocol> don't require retension. 2315f85e193739c953358c865005855253af4f68a497John McCall if (opt->getObjectType()->isObjCClass()) 2316f85e193739c953358c865005855253af4f68a497John McCall return true; 2317f85e193739c953358c865005855253af4f68a497John McCall } 2318f85e193739c953358c865005855253af4f68a497John McCall 2319f85e193739c953358c865005855253af4f68a497John McCall return false; 2320f85e193739c953358c865005855253af4f68a497John McCall} 2321f85e193739c953358c865005855253af4f68a497John McCall 2322f85e193739c953358c865005855253af4f68a497John McCallbool Type::isObjCNSObjectType() const { 2323f85e193739c953358c865005855253af4f68a497John McCall if (const TypedefType *typedefType = dyn_cast<TypedefType>(this)) 2324f85e193739c953358c865005855253af4f68a497John McCall return typedefType->getDecl()->hasAttr<ObjCNSObjectAttr>(); 2325f85e193739c953358c865005855253af4f68a497John McCall return false; 2326f85e193739c953358c865005855253af4f68a497John McCall} 2327f85e193739c953358c865005855253af4f68a497John McCallbool Type::isObjCRetainableType() const { 2328f85e193739c953358c865005855253af4f68a497John McCall return isObjCObjectPointerType() || 2329f85e193739c953358c865005855253af4f68a497John McCall isBlockPointerType() || 2330f85e193739c953358c865005855253af4f68a497John McCall isObjCNSObjectType(); 2331f85e193739c953358c865005855253af4f68a497John McCall} 2332f85e193739c953358c865005855253af4f68a497John McCallbool Type::isObjCIndirectLifetimeType() const { 2333f85e193739c953358c865005855253af4f68a497John McCall if (isObjCLifetimeType()) 2334f85e193739c953358c865005855253af4f68a497John McCall return true; 2335f85e193739c953358c865005855253af4f68a497John McCall if (const PointerType *OPT = getAs<PointerType>()) 2336f85e193739c953358c865005855253af4f68a497John McCall return OPT->getPointeeType()->isObjCIndirectLifetimeType(); 2337f85e193739c953358c865005855253af4f68a497John McCall if (const ReferenceType *Ref = getAs<ReferenceType>()) 2338f85e193739c953358c865005855253af4f68a497John McCall return Ref->getPointeeType()->isObjCIndirectLifetimeType(); 2339f85e193739c953358c865005855253af4f68a497John McCall if (const MemberPointerType *MemPtr = getAs<MemberPointerType>()) 2340f85e193739c953358c865005855253af4f68a497John McCall return MemPtr->getPointeeType()->isObjCIndirectLifetimeType(); 2341f85e193739c953358c865005855253af4f68a497John McCall return false; 2342f85e193739c953358c865005855253af4f68a497John McCall} 2343f85e193739c953358c865005855253af4f68a497John McCall 2344f85e193739c953358c865005855253af4f68a497John McCall/// Returns true if objects of this type have lifetime semantics under 2345f85e193739c953358c865005855253af4f68a497John McCall/// ARC. 2346f85e193739c953358c865005855253af4f68a497John McCallbool Type::isObjCLifetimeType() const { 2347f85e193739c953358c865005855253af4f68a497John McCall const Type *type = this; 2348f85e193739c953358c865005855253af4f68a497John McCall while (const ArrayType *array = type->getAsArrayTypeUnsafe()) 2349f85e193739c953358c865005855253af4f68a497John McCall type = array->getElementType().getTypePtr(); 2350f85e193739c953358c865005855253af4f68a497John McCall return type->isObjCRetainableType(); 2351f85e193739c953358c865005855253af4f68a497John McCall} 2352f85e193739c953358c865005855253af4f68a497John McCall 2353f85e193739c953358c865005855253af4f68a497John McCall/// \brief Determine whether the given type T is a "bridgable" Objective-C type, 2354f85e193739c953358c865005855253af4f68a497John McCall/// which is either an Objective-C object pointer type or an 2355f85e193739c953358c865005855253af4f68a497John McCallbool Type::isObjCARCBridgableType() const { 2356f85e193739c953358c865005855253af4f68a497John McCall return isObjCObjectPointerType() || isBlockPointerType(); 2357f85e193739c953358c865005855253af4f68a497John McCall} 2358f85e193739c953358c865005855253af4f68a497John McCall 2359f85e193739c953358c865005855253af4f68a497John McCall/// \brief Determine whether the given type T is a "bridgeable" C type. 2360f85e193739c953358c865005855253af4f68a497John McCallbool Type::isCARCBridgableType() const { 2361f85e193739c953358c865005855253af4f68a497John McCall const PointerType *Pointer = getAs<PointerType>(); 2362f85e193739c953358c865005855253af4f68a497John McCall if (!Pointer) 2363f85e193739c953358c865005855253af4f68a497John McCall return false; 2364f85e193739c953358c865005855253af4f68a497John McCall 2365f85e193739c953358c865005855253af4f68a497John McCall QualType Pointee = Pointer->getPointeeType(); 2366f85e193739c953358c865005855253af4f68a497John McCall return Pointee->isVoidType() || Pointee->isRecordType(); 2367f85e193739c953358c865005855253af4f68a497John McCall} 2368f85e193739c953358c865005855253af4f68a497John McCall 23693b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallbool Type::hasSizedVLAType() const { 23703b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (!isVariablyModifiedType()) return false; 23713b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 23723b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (const PointerType *ptr = getAs<PointerType>()) 23733b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return ptr->getPointeeType()->hasSizedVLAType(); 23743b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (const ReferenceType *ref = getAs<ReferenceType>()) 23753b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return ref->getPointeeType()->hasSizedVLAType(); 23763b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (const ArrayType *arr = getAsArrayTypeUnsafe()) { 23773b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (isa<VariableArrayType>(arr) && 23783b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall cast<VariableArrayType>(arr)->getSizeExpr()) 23793b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return true; 23803b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 23813b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return arr->getElementType()->hasSizedVLAType(); 23823b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall } 23833b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 23843b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return false; 23853b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall} 23860d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall 23870d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCallQualType::DestructionKind QualType::isDestructedTypeImpl(QualType type) { 2388f85e193739c953358c865005855253af4f68a497John McCall switch (type.getObjCLifetime()) { 2389f85e193739c953358c865005855253af4f68a497John McCall case Qualifiers::OCL_None: 2390f85e193739c953358c865005855253af4f68a497John McCall case Qualifiers::OCL_ExplicitNone: 2391f85e193739c953358c865005855253af4f68a497John McCall case Qualifiers::OCL_Autoreleasing: 2392f85e193739c953358c865005855253af4f68a497John McCall break; 2393f85e193739c953358c865005855253af4f68a497John McCall 2394f85e193739c953358c865005855253af4f68a497John McCall case Qualifiers::OCL_Strong: 2395f85e193739c953358c865005855253af4f68a497John McCall return DK_objc_strong_lifetime; 2396f85e193739c953358c865005855253af4f68a497John McCall case Qualifiers::OCL_Weak: 2397f85e193739c953358c865005855253af4f68a497John McCall return DK_objc_weak_lifetime; 2398f85e193739c953358c865005855253af4f68a497John McCall } 2399f85e193739c953358c865005855253af4f68a497John McCall 24000d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall /// Currently, the only destruction kind we recognize is C++ objects 24010d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall /// with non-trivial destructors. 24020d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall const CXXRecordDecl *record = 24030d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall type->getBaseElementTypeUnsafe()->getAsCXXRecordDecl(); 240491873b72bf01b7170f80154f3118300ff2eacd34Eli Friedman if (record && record->hasDefinition() && !record->hasTrivialDestructor()) 24050d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall return DK_cxx_destructor; 24060d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall 24070d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall return DK_none; 24080d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall} 2409