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(); 486bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines NamedDecl *ND = nullptr; 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(); 636bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines return nullptr; 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 114e8caa30d6124b915fb6bfb3fb2d0eb4857381d08Serge Pavlov // Limit the number of bits in size_t so that maximal bit size fits 64 bit 115e8caa30d6124b915fb6bfb3fb2d0eb4857381d08Serge Pavlov // integer (see PR8256). We can do this as currently there is no hardware 116e8caa30d6124b915fb6bfb3fb2d0eb4857381d08Serge Pavlov // that supports full 64-bit virtual space. 117e8caa30d6124b915fb6bfb3fb2d0eb4857381d08Serge Pavlov if (Bits > 61) 118e8caa30d6124b915fb6bfb3fb2d0eb4857381d08Serge Pavlov Bits = 61; 119e8caa30d6124b915fb6bfb3fb2d0eb4857381d08Serge Pavlov 1202767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor return Bits; 1212767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor} 1222767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor 1234ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadDependentSizedArrayType::DependentSizedArrayType(const ASTContext &Context, 124d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor QualType et, QualType can, 125d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor Expr *e, ArraySizeModifier sm, 126d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor unsigned tq, 127d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor SourceRange brackets) 128d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor : ArrayType(DependentSizedArray, et, can, sm, tq, 129d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor (et->containsUnexpandedParameterPack() || 130d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor (e && e->containsUnexpandedParameterPack()))), 131d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor Context(Context), SizeExpr((Stmt*) e), Brackets(brackets) 132d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor{ 133d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor} 134d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 1351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpvoid DependentSizedArrayType::Profile(llvm::FoldingSetNodeID &ID, 1364ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad const ASTContext &Context, 13704d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor QualType ET, 13804d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor ArraySizeModifier SizeMod, 13904d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor unsigned TypeQuals, 14004d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor Expr *E) { 14104d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor ID.AddPointer(ET.getAsOpaquePtr()); 14204d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor ID.AddInteger(SizeMod); 14304d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor ID.AddInteger(TypeQuals); 14404d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor E->Profile(ID, Context, true); 14504d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor} 14604d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor 1474ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadDependentSizedExtVectorType::DependentSizedExtVectorType(const 1484ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad ASTContext &Context, 149d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor QualType ElementType, 150d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor QualType can, 151d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor Expr *SizeExpr, 152d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor SourceLocation loc) 153d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor : Type(DependentSizedExtVector, can, /*Dependent=*/true, 154561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /*InstantiationDependent=*/true, 155d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor ElementType->isVariablyModifiedType(), 156d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor (ElementType->containsUnexpandedParameterPack() || 157d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor (SizeExpr && SizeExpr->containsUnexpandedParameterPack()))), 158d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor Context(Context), SizeExpr(SizeExpr), ElementType(ElementType), 159d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor loc(loc) 160d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor{ 161d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor} 162d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 1631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpvoid 1641eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpDependentSizedExtVectorType::Profile(llvm::FoldingSetNodeID &ID, 1654ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad const ASTContext &Context, 1662ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor QualType ElementType, Expr *SizeExpr) { 1672ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor ID.AddPointer(ElementType.getAsOpaquePtr()); 1682ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor SizeExpr->Profile(ID, Context, true); 1692ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor} 1702ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor 171d0937224f383c7cc72c947119380f9713a070c73Douglas GregorVectorType::VectorType(QualType vecType, unsigned nElements, QualType canonType, 172d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor VectorKind vecKind) 173d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor : Type(Vector, canonType, vecType->isDependentType(), 174561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor vecType->isInstantiationDependentType(), 175d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor vecType->isVariablyModifiedType(), 176d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor vecType->containsUnexpandedParameterPack()), 177d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor ElementType(vecType) 178d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor{ 179d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor VectorTypeBits.VecKind = vecKind; 180d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor VectorTypeBits.NumElements = nElements; 181d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor} 182d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 183d0937224f383c7cc72c947119380f9713a070c73Douglas GregorVectorType::VectorType(TypeClass tc, QualType vecType, unsigned nElements, 184d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor QualType canonType, VectorKind vecKind) 185d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor : Type(tc, canonType, vecType->isDependentType(), 186561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor vecType->isInstantiationDependentType(), 187d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor vecType->isVariablyModifiedType(), 188d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor vecType->containsUnexpandedParameterPack()), 189d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor ElementType(vecType) 190d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor{ 191d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor VectorTypeBits.VecKind = vecKind; 192d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor VectorTypeBits.NumElements = nElements; 193d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor} 194d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 195c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner/// getArrayElementTypeNoTypeQual - If this is an array type, return the 196c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner/// element type of the array, potentially with type qualifiers missing. 197c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner/// This method should never be used when type qualifiers are meaningful. 198c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattnerconst Type *Type::getArrayElementTypeNoTypeQual() const { 199c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // If this is directly an array type, return it. 200c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner if (const ArrayType *ATy = dyn_cast<ArrayType>(this)) 201c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return ATy->getElementType().getTypePtr(); 2021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 203c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // If the canonical form of this type isn't the right kind, reject it. 2040953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (!isa<ArrayType>(CanonicalType)) 2056bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines return nullptr; 2061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 207c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // If this is a typedef for an array type, strip the typedef off without 208c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // losing all typedef information. 209bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall return cast<ArrayType>(getUnqualifiedDesugaredType()) 210bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall ->getElementType().getTypePtr(); 2112fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner} 2122fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner 2132fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner/// getDesugaredType - Return the specified type with any "sugar" removed from 2142fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner/// the type. This takes off typedefs, typeof's etc. If the outer level of 2152fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner/// the type is already concrete, it returns it unmodified. This is similar 2162fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner/// to getting the canonical type, but it doesn't remove *all* typedefs. For 2172fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner/// example, it returns "T*" as "T*", (not as "int*"), because the pointer is 2182fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner/// concrete. 2194ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualType QualType::getDesugaredType(QualType T, const ASTContext &Context) { 22049f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall SplitQualType split = getSplitDesugaredType(T); 221200fa53fd420aa8369586f569dbece04930ad6a3John McCall return Context.getQualifiedType(split.Ty, split.Quals); 22249f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall} 22349f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall 224200fa53fd420aa8369586f569dbece04930ad6a3John McCallQualType QualType::getSingleStepDesugaredTypeImpl(QualType type, 225200fa53fd420aa8369586f569dbece04930ad6a3John McCall const ASTContext &Context) { 226200fa53fd420aa8369586f569dbece04930ad6a3John McCall SplitQualType split = type.split(); 227200fa53fd420aa8369586f569dbece04930ad6a3John McCall QualType desugar = split.Ty->getLocallyUnqualifiedSingleStepDesugaredType(); 228200fa53fd420aa8369586f569dbece04930ad6a3John McCall return Context.getQualifiedType(desugar, split.Quals); 229200fa53fd420aa8369586f569dbece04930ad6a3John McCall} 230200fa53fd420aa8369586f569dbece04930ad6a3John McCall 231200fa53fd420aa8369586f569dbece04930ad6a3John McCallQualType Type::getLocallyUnqualifiedSingleStepDesugaredType() const { 232200fa53fd420aa8369586f569dbece04930ad6a3John McCall switch (getTypeClass()) { 233f1588660c109610e6a79c786b83b7c9bbd6ed31eDouglas Gregor#define ABSTRACT_TYPE(Class, Parent) 234f1588660c109610e6a79c786b83b7c9bbd6ed31eDouglas Gregor#define TYPE(Class, Parent) \ 235f1588660c109610e6a79c786b83b7c9bbd6ed31eDouglas Gregor case Type::Class: { \ 236200fa53fd420aa8369586f569dbece04930ad6a3John McCall const Class##Type *ty = cast<Class##Type>(this); \ 237200fa53fd420aa8369586f569dbece04930ad6a3John McCall if (!ty->isSugared()) return QualType(ty, 0); \ 238200fa53fd420aa8369586f569dbece04930ad6a3John McCall return ty->desugar(); \ 239f1588660c109610e6a79c786b83b7c9bbd6ed31eDouglas Gregor } 240f1588660c109610e6a79c786b83b7c9bbd6ed31eDouglas Gregor#include "clang/AST/TypeNodes.def" 241f1588660c109610e6a79c786b83b7c9bbd6ed31eDouglas Gregor } 242200fa53fd420aa8369586f569dbece04930ad6a3John McCall llvm_unreachable("bad type kind!"); 243f1588660c109610e6a79c786b83b7c9bbd6ed31eDouglas Gregor} 244f1588660c109610e6a79c786b83b7c9bbd6ed31eDouglas Gregor 24549f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCallSplitQualType QualType::getSplitDesugaredType(QualType T) { 2460953e767ff7817f97b3ab20896b229891eeff45bJohn McCall QualifierCollector Qs; 247c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner 248bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType Cur = T; 249bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall while (true) { 250bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall const Type *CurTy = Qs.strip(Cur); 251bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall switch (CurTy->getTypeClass()) { 252bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall#define ABSTRACT_TYPE(Class, Parent) 253bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall#define TYPE(Class, Parent) \ 254bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall case Type::Class: { \ 255bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall const Class##Type *Ty = cast<Class##Type>(CurTy); \ 256bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall if (!Ty->isSugared()) \ 25749f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall return SplitQualType(Ty, Qs); \ 258bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall Cur = Ty->desugar(); \ 259bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall break; \ 260bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall } 261bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall#include "clang/AST/TypeNodes.def" 262bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall } 263969c689d893a248eca4f049f5b89f747e66e4bffDouglas Gregor } 264bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall} 2655cdf82164dd7c2b2320d6735c63ace4331e0716dDouglas Gregor 26662c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCallSplitQualType QualType::getSplitUnqualifiedTypeImpl(QualType type) { 26762c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall SplitQualType split = type.split(); 26862c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall 26962c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall // All the qualifiers we've seen so far. 270200fa53fd420aa8369586f569dbece04930ad6a3John McCall Qualifiers quals = split.Quals; 27162c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall 27262c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall // The last type node we saw with any nodes inside it. 273200fa53fd420aa8369586f569dbece04930ad6a3John McCall const Type *lastTypeWithQuals = split.Ty; 27462c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall 27562c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall while (true) { 27662c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall QualType next; 27762c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall 27862c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall // Do a single-step desugar, aborting the loop if the type isn't 27962c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall // sugared. 280200fa53fd420aa8369586f569dbece04930ad6a3John McCall switch (split.Ty->getTypeClass()) { 28162c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall#define ABSTRACT_TYPE(Class, Parent) 28262c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall#define TYPE(Class, Parent) \ 28362c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall case Type::Class: { \ 284200fa53fd420aa8369586f569dbece04930ad6a3John McCall const Class##Type *ty = cast<Class##Type>(split.Ty); \ 28562c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall if (!ty->isSugared()) goto done; \ 28662c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall next = ty->desugar(); \ 28762c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall break; \ 28862c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall } 28962c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall#include "clang/AST/TypeNodes.def" 29062c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall } 29162c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall 29262c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall // Otherwise, split the underlying type. If that yields qualifiers, 29362c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall // update the information. 29462c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall split = next.split(); 295200fa53fd420aa8369586f569dbece04930ad6a3John McCall if (!split.Quals.empty()) { 296200fa53fd420aa8369586f569dbece04930ad6a3John McCall lastTypeWithQuals = split.Ty; 297200fa53fd420aa8369586f569dbece04930ad6a3John McCall quals.addConsistentQualifiers(split.Quals); 29862c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall } 29962c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall } 30062c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall 30162c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall done: 30262c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall return SplitQualType(lastTypeWithQuals, quals); 30362c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall} 30462c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall 305075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo BagnaraQualType QualType::IgnoreParens(QualType T) { 30662c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall // FIXME: this seems inherently un-qualifiers-safe. 307075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara while (const ParenType *PT = T->getAs<ParenType>()) 308075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara T = PT->getInnerType(); 309075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara return T; 310075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara} 311075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 312073819806ba2441e2a3e550107f1e756a6ee3ad0Richard Smith/// \brief This will check for a T (which should be a Type which can act as 313073819806ba2441e2a3e550107f1e756a6ee3ad0Richard Smith/// sugar, such as a TypedefType) by removing any existing sugar until it 314073819806ba2441e2a3e550107f1e756a6ee3ad0Richard Smith/// reaches a T or a non-sugared type. 315073819806ba2441e2a3e550107f1e756a6ee3ad0Richard Smithtemplate<typename T> static const T *getAsSugar(const Type *Cur) { 3162df1a5819fd98708ff3b4772f3477f6c1a8da59aArgyrios Kyrtzidis while (true) { 317073819806ba2441e2a3e550107f1e756a6ee3ad0Richard Smith if (const T *Sugar = dyn_cast<T>(Cur)) 318073819806ba2441e2a3e550107f1e756a6ee3ad0Richard Smith return Sugar; 3192df1a5819fd98708ff3b4772f3477f6c1a8da59aArgyrios Kyrtzidis switch (Cur->getTypeClass()) { 3202df1a5819fd98708ff3b4772f3477f6c1a8da59aArgyrios Kyrtzidis#define ABSTRACT_TYPE(Class, Parent) 3212df1a5819fd98708ff3b4772f3477f6c1a8da59aArgyrios Kyrtzidis#define TYPE(Class, Parent) \ 322073819806ba2441e2a3e550107f1e756a6ee3ad0Richard Smith case Type::Class: { \ 3232df1a5819fd98708ff3b4772f3477f6c1a8da59aArgyrios Kyrtzidis const Class##Type *Ty = cast<Class##Type>(Cur); \ 3242df1a5819fd98708ff3b4772f3477f6c1a8da59aArgyrios Kyrtzidis if (!Ty->isSugared()) return 0; \ 3252df1a5819fd98708ff3b4772f3477f6c1a8da59aArgyrios Kyrtzidis Cur = Ty->desugar().getTypePtr(); \ 3262df1a5819fd98708ff3b4772f3477f6c1a8da59aArgyrios Kyrtzidis break; \ 3272df1a5819fd98708ff3b4772f3477f6c1a8da59aArgyrios Kyrtzidis } 3282df1a5819fd98708ff3b4772f3477f6c1a8da59aArgyrios Kyrtzidis#include "clang/AST/TypeNodes.def" 3292df1a5819fd98708ff3b4772f3477f6c1a8da59aArgyrios Kyrtzidis } 3302df1a5819fd98708ff3b4772f3477f6c1a8da59aArgyrios Kyrtzidis } 3312df1a5819fd98708ff3b4772f3477f6c1a8da59aArgyrios Kyrtzidis} 3322df1a5819fd98708ff3b4772f3477f6c1a8da59aArgyrios Kyrtzidis 333073819806ba2441e2a3e550107f1e756a6ee3ad0Richard Smithtemplate <> const TypedefType *Type::getAs() const { 334073819806ba2441e2a3e550107f1e756a6ee3ad0Richard Smith return getAsSugar<TypedefType>(this); 335073819806ba2441e2a3e550107f1e756a6ee3ad0Richard Smith} 336073819806ba2441e2a3e550107f1e756a6ee3ad0Richard Smith 337073819806ba2441e2a3e550107f1e756a6ee3ad0Richard Smithtemplate <> const TemplateSpecializationType *Type::getAs() const { 338073819806ba2441e2a3e550107f1e756a6ee3ad0Richard Smith return getAsSugar<TemplateSpecializationType>(this); 339073819806ba2441e2a3e550107f1e756a6ee3ad0Richard Smith} 340073819806ba2441e2a3e550107f1e756a6ee3ad0Richard Smith 341ef072033876e295ec5d3402f8730a3ae358ad815Reid Klecknertemplate <> const AttributedType *Type::getAs() const { 342ef072033876e295ec5d3402f8730a3ae358ad815Reid Kleckner return getAsSugar<AttributedType>(this); 343ef072033876e295ec5d3402f8730a3ae358ad815Reid Kleckner} 344ef072033876e295ec5d3402f8730a3ae358ad815Reid Kleckner 345bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall/// getUnqualifiedDesugaredType - Pull any qualifiers and syntactic 346bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall/// sugar off the given type. This should produce an object of the 347bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall/// same dynamic type as the canonical type. 348bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCallconst Type *Type::getUnqualifiedDesugaredType() const { 349bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall const Type *Cur = this; 350bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 351bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall while (true) { 352bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall switch (Cur->getTypeClass()) { 353bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall#define ABSTRACT_TYPE(Class, Parent) 354bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall#define TYPE(Class, Parent) \ 355bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall case Class: { \ 356bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall const Class##Type *Ty = cast<Class##Type>(Cur); \ 357bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall if (!Ty->isSugared()) return Cur; \ 358bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall Cur = Ty->desugar().getTypePtr(); \ 359bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall break; \ 360bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall } 361bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall#include "clang/AST/TypeNodes.def" 362bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall } 363bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall } 364c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner} 36599dc91422144483c20d1c7381bc9ac634b646b04Chris Lattnerbool Type::isClassType() const { 3666217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const RecordType *RT = getAs<RecordType>()) 367f728a4a05df2455e1c6e62173ab720a92cd4a074Chris Lattner return RT->getDecl()->isClass(); 36899dc91422144483c20d1c7381bc9ac634b646b04Chris Lattner return false; 36999dc91422144483c20d1c7381bc9ac634b646b04Chris Lattner} 370c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattnerbool Type::isStructureType() const { 3716217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const RecordType *RT = getAs<RecordType>()) 372f728a4a05df2455e1c6e62173ab720a92cd4a074Chris Lattner return RT->getDecl()->isStruct(); 373c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner return false; 374c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner} 3756666ed4ed2e2bc13da5ac5d0a4947019137d45beJoao Matosbool Type::isInterfaceType() const { 3766666ed4ed2e2bc13da5ac5d0a4947019137d45beJoao Matos if (const RecordType *RT = getAs<RecordType>()) 3776666ed4ed2e2bc13da5ac5d0a4947019137d45beJoao Matos return RT->getDecl()->isInterface(); 3786666ed4ed2e2bc13da5ac5d0a4947019137d45beJoao Matos return false; 3796666ed4ed2e2bc13da5ac5d0a4947019137d45beJoao Matos} 380fb87b89fc9eb103e19fb8e4b925c23f0bd091b99Douglas Gregorbool Type::isStructureOrClassType() const { 381fb87b89fc9eb103e19fb8e4b925c23f0bd091b99Douglas Gregor if (const RecordType *RT = getAs<RecordType>()) 3826666ed4ed2e2bc13da5ac5d0a4947019137d45beJoao Matos return RT->getDecl()->isStruct() || RT->getDecl()->isClass() || 3836666ed4ed2e2bc13da5ac5d0a4947019137d45beJoao Matos RT->getDecl()->isInterface(); 384fb87b89fc9eb103e19fb8e4b925c23f0bd091b99Douglas Gregor return false; 385fb87b89fc9eb103e19fb8e4b925c23f0bd091b99Douglas Gregor} 3867154a77e7c1f23418342d3b72836ab504aa7821eSteve Naroffbool Type::isVoidPointerType() const { 3876217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const PointerType *PT = getAs<PointerType>()) 3887154a77e7c1f23418342d3b72836ab504aa7821eSteve Naroff return PT->getPointeeType()->isVoidType(); 3897154a77e7c1f23418342d3b72836ab504aa7821eSteve Naroff return false; 3907154a77e7c1f23418342d3b72836ab504aa7821eSteve Naroff} 3917154a77e7c1f23418342d3b72836ab504aa7821eSteve Naroff 392c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattnerbool Type::isUnionType() const { 3936217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const RecordType *RT = getAs<RecordType>()) 394f728a4a05df2455e1c6e62173ab720a92cd4a074Chris Lattner return RT->getDecl()->isUnion(); 395c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner return false; 396c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner} 397c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner 398c6fb90a7246c2d5d3233e70107bf9d8c7c9e535bChris Lattnerbool Type::isComplexType() const { 39902f62a9fedbc370fba081303399410a3afdde29fSteve Naroff if (const ComplexType *CT = dyn_cast<ComplexType>(CanonicalType)) 40002f62a9fedbc370fba081303399410a3afdde29fSteve Naroff return CT->getElementType()->isFloatingType(); 40102f62a9fedbc370fba081303399410a3afdde29fSteve Naroff return false; 402c6fb90a7246c2d5d3233e70107bf9d8c7c9e535bChris Lattner} 403c6fb90a7246c2d5d3233e70107bf9d8c7c9e535bChris Lattner 4044cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroffbool Type::isComplexIntegerType() const { 4054cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroff // Check for GCC complex integer extension. 4060953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return getAsComplexIntegerType(); 4074cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroff} 4084cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroff 4094cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroffconst ComplexType *Type::getAsComplexIntegerType() const { 4100953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (const ComplexType *Complex = getAs<ComplexType>()) 4110953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (Complex->getElementType()->isIntegerType()) 4120953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return Complex; 4136bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines return nullptr; 4144cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroff} 4154cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroff 41614108da7f7fc059772711e4ffee1322a27b152a7Steve NaroffQualType Type::getPointeeType() const { 4176217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const PointerType *PT = getAs<PointerType>()) 41814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return PT->getPointeeType(); 419183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) 42014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return OPT->getPointeeType(); 4216217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const BlockPointerType *BPT = getAs<BlockPointerType>()) 42214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return BPT->getPointeeType(); 4239c21289a866b677d21ed3d5ecfdfd5ced5a55410Mike Stump if (const ReferenceType *RT = getAs<ReferenceType>()) 4249c21289a866b677d21ed3d5ecfdfd5ced5a55410Mike Stump return RT->getPointeeType(); 425651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines if (const MemberPointerType *MPT = getAs<MemberPointerType>()) 426651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines return MPT->getPointeeType(); 427651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines if (const DecayedType *DT = getAs<DecayedType>()) 428651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines return DT->getPointeeType(); 42914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return QualType(); 43014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff} 431b77792eabf5882cf9af8cc810599b20432fda6c2Chris Lattner 432c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattnerconst RecordType *Type::getAsStructureType() const { 4337064f5c95bbdb17680d0ea658d4090898c2592d3Steve Naroff // If this is directly a structure type, return it. 434c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner if (const RecordType *RT = dyn_cast<RecordType>(this)) { 43539ba4aeca296b1c9f04bde7d9d3cbbf129f1abd3Argyrios Kyrtzidis if (RT->getDecl()->isStruct()) 436c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner return RT; 4377064f5c95bbdb17680d0ea658d4090898c2592d3Steve Naroff } 438dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner 439dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner // If the canonical form of this type isn't the right kind, reject it. 440c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner if (const RecordType *RT = dyn_cast<RecordType>(CanonicalType)) { 44139ba4aeca296b1c9f04bde7d9d3cbbf129f1abd3Argyrios Kyrtzidis if (!RT->getDecl()->isStruct()) 4426bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines return nullptr; 4431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 444dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner // If this is a typedef for a structure type, strip the typedef off without 445dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner // losing all typedef information. 446bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall return cast<RecordType>(getUnqualifiedDesugaredType()); 4475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 4486bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines return nullptr; 4495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 4505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpconst RecordType *Type::getAsUnionType() const { 4527064f5c95bbdb17680d0ea658d4090898c2592d3Steve Naroff // If this is directly a union type, return it. 453c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner if (const RecordType *RT = dyn_cast<RecordType>(this)) { 45439ba4aeca296b1c9f04bde7d9d3cbbf129f1abd3Argyrios Kyrtzidis if (RT->getDecl()->isUnion()) 455c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner return RT; 4567064f5c95bbdb17680d0ea658d4090898c2592d3Steve Naroff } 4571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 458dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner // If the canonical form of this type isn't the right kind, reject it. 459c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner if (const RecordType *RT = dyn_cast<RecordType>(CanonicalType)) { 46039ba4aeca296b1c9f04bde7d9d3cbbf129f1abd3Argyrios Kyrtzidis if (!RT->getDecl()->isUnion()) 4616bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines return nullptr; 462dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner 463dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner // If this is a typedef for a union type, strip the typedef off without 464dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner // losing all typedef information. 465bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall return cast<RecordType>(getUnqualifiedDesugaredType()); 4665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 4671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4686bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines return nullptr; 4695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 4705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 471c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallObjCObjectType::ObjCObjectType(QualType Canonical, QualType Base, 472c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCProtocolDecl * const *Protocols, 473c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall unsigned NumProtocols) 474561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor : Type(ObjCObject, Canonical, false, false, false, false), 475d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor BaseType(Base) 476d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor{ 477b870b88df784c2940efce448ebfaf54dece14666John McCall ObjCObjectTypeBits.NumProtocols = NumProtocols; 47871c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall assert(getNumProtocols() == NumProtocols && 479c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall "bitfield overflow in protocol count"); 480fd6a0887a099256c35a5b23e9afd517ffe95fa0aDouglas Gregor if (NumProtocols) 481c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall memcpy(getProtocolStorage(), Protocols, 482c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall NumProtocols * sizeof(ObjCProtocolDecl*)); 48371842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek} 48471842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek 485c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallconst ObjCObjectType *Type::getAsObjCQualifiedInterfaceType() const { 486c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall // There is no sugar for ObjCObjectType's, just return the canonical 487c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff // type pointer if it is the right class. There is no typedef information to 488c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff // return and these cannot be Address-space qualified. 489c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall if (const ObjCObjectType *T = getAs<ObjCObjectType>()) 490c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall if (T->getNumProtocols() && T->getInterface()) 491c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return T; 4926bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines return nullptr; 493c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff} 494c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff 495c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroffbool Type::isObjCQualifiedInterfaceType() const { 4966bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines return getAsObjCQualifiedInterfaceType() != nullptr; 497c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff} 498c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff 499d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroffconst ObjCObjectPointerType *Type::getAsObjCQualifiedIdType() const { 500eca7be6b7ebd93682eeaab2c71d59f2995dacdccChris Lattner // There is no sugar for ObjCQualifiedIdType's, just return the canonical 501eca7be6b7ebd93682eeaab2c71d59f2995dacdccChris Lattner // type pointer if it is the right class. 502183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) { 503d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff if (OPT->isObjCQualifiedIdType()) 504d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff return OPT; 505d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff } 5066bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines return nullptr; 507368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner} 508368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner 509759abb4d9ec14ae32104a9677b60f0542b60d1d8Fariborz Jahanianconst ObjCObjectPointerType *Type::getAsObjCQualifiedClassType() const { 510759abb4d9ec14ae32104a9677b60f0542b60d1d8Fariborz Jahanian // There is no sugar for ObjCQualifiedClassType's, just return the canonical 511759abb4d9ec14ae32104a9677b60f0542b60d1d8Fariborz Jahanian // type pointer if it is the right class. 512759abb4d9ec14ae32104a9677b60f0542b60d1d8Fariborz Jahanian if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) { 513759abb4d9ec14ae32104a9677b60f0542b60d1d8Fariborz Jahanian if (OPT->isObjCQualifiedClassType()) 514759abb4d9ec14ae32104a9677b60f0542b60d1d8Fariborz Jahanian return OPT; 515759abb4d9ec14ae32104a9677b60f0542b60d1d8Fariborz Jahanian } 5166bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines return nullptr; 517759abb4d9ec14ae32104a9677b60f0542b60d1d8Fariborz Jahanian} 518759abb4d9ec14ae32104a9677b60f0542b60d1d8Fariborz Jahanian 51914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroffconst ObjCObjectPointerType *Type::getAsObjCInterfacePointerType() const { 520183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) { 52114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff if (OPT->getInterfaceType()) 52214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return OPT; 52314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff } 5246bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines return nullptr; 52514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff} 52614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff 527041ce8e00afd1185549a25d5c2b97d219ae032d9Jordan Roseconst CXXRecordDecl *Type::getPointeeCXXRecordDecl() const { 528041ce8e00afd1185549a25d5c2b97d219ae032d9Jordan Rose QualType PointeeType; 5296217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const PointerType *PT = getAs<PointerType>()) 530041ce8e00afd1185549a25d5c2b97d219ae032d9Jordan Rose PointeeType = PT->getPointeeType(); 531041ce8e00afd1185549a25d5c2b97d219ae032d9Jordan Rose else if (const ReferenceType *RT = getAs<ReferenceType>()) 532041ce8e00afd1185549a25d5c2b97d219ae032d9Jordan Rose PointeeType = RT->getPointeeType(); 533041ce8e00afd1185549a25d5c2b97d219ae032d9Jordan Rose else 5346bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines return nullptr; 535041ce8e00afd1185549a25d5c2b97d219ae032d9Jordan Rose 536041ce8e00afd1185549a25d5c2b97d219ae032d9Jordan Rose if (const RecordType *RT = PointeeType->getAs<RecordType>()) 537041ce8e00afd1185549a25d5c2b97d219ae032d9Jordan Rose return dyn_cast<CXXRecordDecl>(RT->getDecl()); 538041ce8e00afd1185549a25d5c2b97d219ae032d9Jordan Rose 5396bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines return nullptr; 540a91d6a6619a91d0ca7102d8ab5678d855f04d850Fariborz Jahanian} 541a91d6a6619a91d0ca7102d8ab5678d855f04d850Fariborz Jahanian 542c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas GregorCXXRecordDecl *Type::getAsCXXRecordDecl() const { 543c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor if (const RecordType *RT = getAs<RecordType>()) 544c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor return dyn_cast<CXXRecordDecl>(RT->getDecl()); 545c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor else if (const InjectedClassNameType *Injected 546c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor = getAs<InjectedClassNameType>()) 547c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor return Injected->getDecl(); 5486bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 5496bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines return nullptr; 550c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor} 551c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor 55234b41d939a1328f484511c6002ba2456db879a29Richard Smithnamespace { 55334b41d939a1328f484511c6002ba2456db879a29Richard Smith class GetContainedAutoVisitor : 55434b41d939a1328f484511c6002ba2456db879a29Richard Smith public TypeVisitor<GetContainedAutoVisitor, AutoType*> { 55534b41d939a1328f484511c6002ba2456db879a29Richard Smith public: 55634b41d939a1328f484511c6002ba2456db879a29Richard Smith using TypeVisitor<GetContainedAutoVisitor, AutoType*>::Visit; 55734b41d939a1328f484511c6002ba2456db879a29Richard Smith AutoType *Visit(QualType T) { 55834b41d939a1328f484511c6002ba2456db879a29Richard Smith if (T.isNull()) 5596bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines return nullptr; 56034b41d939a1328f484511c6002ba2456db879a29Richard Smith return Visit(T.getTypePtr()); 56134b41d939a1328f484511c6002ba2456db879a29Richard Smith } 56234b41d939a1328f484511c6002ba2456db879a29Richard Smith 56334b41d939a1328f484511c6002ba2456db879a29Richard Smith // The 'auto' type itself. 56434b41d939a1328f484511c6002ba2456db879a29Richard Smith AutoType *VisitAutoType(const AutoType *AT) { 56534b41d939a1328f484511c6002ba2456db879a29Richard Smith return const_cast<AutoType*>(AT); 56634b41d939a1328f484511c6002ba2456db879a29Richard Smith } 56734b41d939a1328f484511c6002ba2456db879a29Richard Smith 56834b41d939a1328f484511c6002ba2456db879a29Richard Smith // Only these types can contain the desired 'auto' type. 56934b41d939a1328f484511c6002ba2456db879a29Richard Smith AutoType *VisitPointerType(const PointerType *T) { 57034b41d939a1328f484511c6002ba2456db879a29Richard Smith return Visit(T->getPointeeType()); 57134b41d939a1328f484511c6002ba2456db879a29Richard Smith } 57234b41d939a1328f484511c6002ba2456db879a29Richard Smith AutoType *VisitBlockPointerType(const BlockPointerType *T) { 57334b41d939a1328f484511c6002ba2456db879a29Richard Smith return Visit(T->getPointeeType()); 57434b41d939a1328f484511c6002ba2456db879a29Richard Smith } 57534b41d939a1328f484511c6002ba2456db879a29Richard Smith AutoType *VisitReferenceType(const ReferenceType *T) { 57634b41d939a1328f484511c6002ba2456db879a29Richard Smith return Visit(T->getPointeeTypeAsWritten()); 57734b41d939a1328f484511c6002ba2456db879a29Richard Smith } 57834b41d939a1328f484511c6002ba2456db879a29Richard Smith AutoType *VisitMemberPointerType(const MemberPointerType *T) { 57934b41d939a1328f484511c6002ba2456db879a29Richard Smith return Visit(T->getPointeeType()); 58034b41d939a1328f484511c6002ba2456db879a29Richard Smith } 58134b41d939a1328f484511c6002ba2456db879a29Richard Smith AutoType *VisitArrayType(const ArrayType *T) { 58234b41d939a1328f484511c6002ba2456db879a29Richard Smith return Visit(T->getElementType()); 58334b41d939a1328f484511c6002ba2456db879a29Richard Smith } 58434b41d939a1328f484511c6002ba2456db879a29Richard Smith AutoType *VisitDependentSizedExtVectorType( 58534b41d939a1328f484511c6002ba2456db879a29Richard Smith const DependentSizedExtVectorType *T) { 58634b41d939a1328f484511c6002ba2456db879a29Richard Smith return Visit(T->getElementType()); 58734b41d939a1328f484511c6002ba2456db879a29Richard Smith } 58834b41d939a1328f484511c6002ba2456db879a29Richard Smith AutoType *VisitVectorType(const VectorType *T) { 58934b41d939a1328f484511c6002ba2456db879a29Richard Smith return Visit(T->getElementType()); 59034b41d939a1328f484511c6002ba2456db879a29Richard Smith } 59134b41d939a1328f484511c6002ba2456db879a29Richard Smith AutoType *VisitFunctionType(const FunctionType *T) { 592651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines return Visit(T->getReturnType()); 59334b41d939a1328f484511c6002ba2456db879a29Richard Smith } 59434b41d939a1328f484511c6002ba2456db879a29Richard Smith AutoType *VisitParenType(const ParenType *T) { 59534b41d939a1328f484511c6002ba2456db879a29Richard Smith return Visit(T->getInnerType()); 59634b41d939a1328f484511c6002ba2456db879a29Richard Smith } 59734b41d939a1328f484511c6002ba2456db879a29Richard Smith AutoType *VisitAttributedType(const AttributedType *T) { 59834b41d939a1328f484511c6002ba2456db879a29Richard Smith return Visit(T->getModifiedType()); 59934b41d939a1328f484511c6002ba2456db879a29Richard Smith } 600651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines AutoType *VisitAdjustedType(const AdjustedType *T) { 601651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines return Visit(T->getOriginalType()); 602651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines } 60334b41d939a1328f484511c6002ba2456db879a29Richard Smith }; 60434b41d939a1328f484511c6002ba2456db879a29Richard Smith} 60534b41d939a1328f484511c6002ba2456db879a29Richard Smith 60634b41d939a1328f484511c6002ba2456db879a29Richard SmithAutoType *Type::getContainedAutoType() const { 60734b41d939a1328f484511c6002ba2456db879a29Richard Smith return GetContainedAutoVisitor().Visit(this); 60834b41d939a1328f484511c6002ba2456db879a29Richard Smith} 60934b41d939a1328f484511c6002ba2456db879a29Richard Smith 610f60946222721d9ba3c059563935c17b84703187aDouglas Gregorbool Type::hasIntegerRepresentation() const { 611c63b96ad706e054a1390dd2ab53af9f05d33bbb1Steve Naroff if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType)) 612c63b96ad706e054a1390dd2ab53af9f05d33bbb1Steve Naroff return VT->getElementType()->isIntegerType(); 613f60946222721d9ba3c059563935c17b84703187aDouglas Gregor else 614f60946222721d9ba3c059563935c17b84703187aDouglas Gregor return isIntegerType(); 6155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 6165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6179d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// \brief Determine whether this type is an integral type. 6189d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// 6199d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// This routine determines whether the given type is an integral type per 6209d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// C++ [basic.fundamental]p7. Although the C standard does not define the 6219d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// term "integral type", it has a similar term "integer type", and in C++ 6229d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// the two terms are equivalent. However, C's "integer type" includes 6239d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// enumeration types, while C++'s "integer type" does not. The \c ASTContext 6249d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// parameter is used to determine whether we should be following the C or 6259d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// C++ rules when determining whether this type is an integral/integer type. 6269d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// 6279d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// For cases where C permits "an integer type" and C++ permits "an integral 6289d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// type", use this routine. 6299d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// 6309d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// For cases where C permits "an integer type" and C++ permits "an integral 6319d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// or enumeration type", use \c isIntegralOrEnumerationType() instead. 6329d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// 6339d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// \param Ctx The context in which this type occurs. 6349d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// 6359d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// \returns true if the type is considered an integral type, false otherwise. 6369d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregorbool Type::isIntegralType(ASTContext &Ctx) const { 63733e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 63833e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian return BT->getKind() >= BuiltinType::Bool && 639f5f7d864f5067d1ea4bff7fcf41b53a43b7b48baAnders Carlsson BT->getKind() <= BuiltinType::Int128; 6409d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor 6414e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie if (!Ctx.getLangOpts().CPlusPlus) 6421274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) 6431274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor return ET->getDecl()->isComplete(); // Complete enum types are integral in C. 6449d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor 64533e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian return false; 64633e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian} 64733e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian 6482ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor 6491274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregorbool Type::isIntegralOrUnscopedEnumerationType() const { 6501274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 6511274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor return BT->getKind() >= BuiltinType::Bool && 6521274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor BT->getKind() <= BuiltinType::Int128; 6531274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor 6541274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor // Check for a complete enum type; incomplete enum types are not properly an 6551274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor // enumeration type in the sense required here. 6561274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor // C++0x: However, if the underlying type of the enum is fixed, it is 6571274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor // considered complete. 6581274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) 6591274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor return ET->getDecl()->isComplete() && !ET->getDecl()->isScoped(); 6601274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor 6611274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor return false; 6621274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor} 6631274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor 6641274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor 665f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbar 66613b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroffbool Type::isCharType() const { 66713b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 66813b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff return BT->getKind() == BuiltinType::Char_U || 66913b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff BT->getKind() == BuiltinType::UChar || 670c67ad5f299bb2c09e4567def8ff0d34bd15a42fdAnders Carlsson BT->getKind() == BuiltinType::Char_S || 671c67ad5f299bb2c09e4567def8ff0d34bd15a42fdAnders Carlsson BT->getKind() == BuiltinType::SChar; 67213b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff return false; 67313b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff} 67413b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff 67577a52233f7c0f162672652051bfe78b65ad4f789Douglas Gregorbool Type::isWideCharType() const { 67677a52233f7c0f162672652051bfe78b65ad4f789Douglas Gregor if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 6773f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner return BT->getKind() == BuiltinType::WChar_S || 6783f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner BT->getKind() == BuiltinType::WChar_U; 67977a52233f7c0f162672652051bfe78b65ad4f789Douglas Gregor return false; 68077a52233f7c0f162672652051bfe78b65ad4f789Douglas Gregor} 68177a52233f7c0f162672652051bfe78b65ad4f789Douglas Gregor 6825cee1195584fa8672253139c86e922daeda69b9eDouglas Gregorbool Type::isChar16Type() const { 6835cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 6845cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor return BT->getKind() == BuiltinType::Char16; 6855cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor return false; 6865cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor} 6875cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor 6885cee1195584fa8672253139c86e922daeda69b9eDouglas Gregorbool Type::isChar32Type() const { 6895cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 6905cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor return BT->getKind() == BuiltinType::Char32; 6915cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor return false; 6925cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor} 6935cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor 69420093b4bf698f292c664676987541d5103b65b15Douglas Gregor/// \brief Determine whether this type is any of the built-in character 69520093b4bf698f292c664676987541d5103b65b15Douglas Gregor/// types. 69620093b4bf698f292c664676987541d5103b65b15Douglas Gregorbool Type::isAnyCharacterType() const { 6973f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType); 6986bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines if (!BT) return false; 6993f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner switch (BT->getKind()) { 7003f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner default: return false; 7013f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner case BuiltinType::Char_U: 7023f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner case BuiltinType::UChar: 7033f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner case BuiltinType::WChar_U: 7043f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner case BuiltinType::Char16: 7053f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner case BuiltinType::Char32: 7063f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner case BuiltinType::Char_S: 7073f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner case BuiltinType::SChar: 7083f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner case BuiltinType::WChar_S: 7093f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner return true; 7103f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner } 71120093b4bf698f292c664676987541d5103b65b15Douglas Gregor} 71220093b4bf698f292c664676987541d5103b65b15Douglas Gregor 713d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner/// isSignedIntegerType - Return true if this is an integer type that is 714d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner/// signed, according to C99 6.2.5p4 [char, signed char, short, int, long..], 715f60946222721d9ba3c059563935c17b84703187aDouglas Gregor/// an enum decl which has a signed representation 7165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isSignedIntegerType() const { 7175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) { 7185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return BT->getKind() >= BuiltinType::Char_S && 719f5f7d864f5067d1ea4bff7fcf41b53a43b7b48baAnders Carlsson BT->getKind() <= BuiltinType::Int128; 7205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 7211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 722bbd340717422bf011d56cd0164d2576601368111Fariborz Jahanian if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) { 723bbd340717422bf011d56cd0164d2576601368111Fariborz Jahanian // Incomplete enum types are not treated as integer types. 724bbd340717422bf011d56cd0164d2576601368111Fariborz Jahanian // FIXME: In C++, enum types are never integer types. 725b6adf2c889bb17c1be44e6c8e67e3b2762e9ceccDouglas Gregor if (ET->getDecl()->isComplete() && !ET->getDecl()->isScoped()) 726bbd340717422bf011d56cd0164d2576601368111Fariborz Jahanian return ET->getDecl()->getIntegerType()->isSignedIntegerType(); 727bbd340717422bf011d56cd0164d2576601368111Fariborz Jahanian } 7281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 729f60946222721d9ba3c059563935c17b84703187aDouglas Gregor return false; 730f60946222721d9ba3c059563935c17b84703187aDouglas Gregor} 731f60946222721d9ba3c059563935c17b84703187aDouglas Gregor 732575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregorbool Type::isSignedIntegerOrEnumerationType() const { 733575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) { 734575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor return BT->getKind() >= BuiltinType::Char_S && 735575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor BT->getKind() <= BuiltinType::Int128; 736575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor } 737575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor 738575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) { 739575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor if (ET->getDecl()->isComplete()) 740575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor return ET->getDecl()->getIntegerType()->isSignedIntegerType(); 741575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor } 742575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor 743575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor return false; 744575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor} 745575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor 746f60946222721d9ba3c059563935c17b84703187aDouglas Gregorbool Type::hasSignedIntegerRepresentation() const { 747c63b96ad706e054a1390dd2ab53af9f05d33bbb1Steve Naroff if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType)) 748e7eb0c4f6e728bb62c7d7304949b8a697153ba90Richard Smith return VT->getElementType()->isSignedIntegerOrEnumerationType(); 749f60946222721d9ba3c059563935c17b84703187aDouglas Gregor else 750e7eb0c4f6e728bb62c7d7304949b8a697153ba90Richard Smith return isSignedIntegerOrEnumerationType(); 7515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 7525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 753d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner/// isUnsignedIntegerType - Return true if this is an integer type that is 754d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner/// unsigned, according to C99 6.2.5p6 [which returns true for _Bool], an enum 755f60946222721d9ba3c059563935c17b84703187aDouglas Gregor/// decl which has an unsigned representation 7565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isUnsignedIntegerType() const { 7575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) { 7585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return BT->getKind() >= BuiltinType::Bool && 7591c03ca30ae962199ef702324b48550f6af7fdc32Anders Carlsson BT->getKind() <= BuiltinType::UInt128; 7605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 761d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner 762bbd340717422bf011d56cd0164d2576601368111Fariborz Jahanian if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) { 763bbd340717422bf011d56cd0164d2576601368111Fariborz Jahanian // Incomplete enum types are not treated as integer types. 764bbd340717422bf011d56cd0164d2576601368111Fariborz Jahanian // FIXME: In C++, enum types are never integer types. 765b6adf2c889bb17c1be44e6c8e67e3b2762e9ceccDouglas Gregor if (ET->getDecl()->isComplete() && !ET->getDecl()->isScoped()) 766bbd340717422bf011d56cd0164d2576601368111Fariborz Jahanian return ET->getDecl()->getIntegerType()->isUnsignedIntegerType(); 767bbd340717422bf011d56cd0164d2576601368111Fariborz Jahanian } 768d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner 769f60946222721d9ba3c059563935c17b84703187aDouglas Gregor return false; 770f60946222721d9ba3c059563935c17b84703187aDouglas Gregor} 771f60946222721d9ba3c059563935c17b84703187aDouglas Gregor 772575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregorbool Type::isUnsignedIntegerOrEnumerationType() const { 773575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) { 774575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor return BT->getKind() >= BuiltinType::Bool && 775575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor BT->getKind() <= BuiltinType::UInt128; 776575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor } 777575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor 778575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) { 779575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor if (ET->getDecl()->isComplete()) 780575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor return ET->getDecl()->getIntegerType()->isUnsignedIntegerType(); 781575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor } 782575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor 783575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor return false; 784575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor} 785575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor 786f60946222721d9ba3c059563935c17b84703187aDouglas Gregorbool Type::hasUnsignedIntegerRepresentation() const { 787c63b96ad706e054a1390dd2ab53af9f05d33bbb1Steve Naroff if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType)) 788e7eb0c4f6e728bb62c7d7304949b8a697153ba90Richard Smith return VT->getElementType()->isUnsignedIntegerOrEnumerationType(); 789f60946222721d9ba3c059563935c17b84703187aDouglas Gregor else 790e7eb0c4f6e728bb62c7d7304949b8a697153ba90Richard Smith return isUnsignedIntegerOrEnumerationType(); 7915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 7925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isFloatingType() const { 7945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 795aa4a99b4a62615db243f7a5c433169f2fc704420Anton Korobeynikov return BT->getKind() >= BuiltinType::Half && 7965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer BT->getKind() <= BuiltinType::LongDouble; 7975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (const ComplexType *CT = dyn_cast<ComplexType>(CanonicalType)) 798729a2131228cb7fcbc00bd8af36bc6f14d12317dChris Lattner return CT->getElementType()->isFloatingType(); 7998eee119bf4f1693dde17b8552c1f9f81bf2b681eDouglas Gregor return false; 8008eee119bf4f1693dde17b8552c1f9f81bf2b681eDouglas Gregor} 8018eee119bf4f1693dde17b8552c1f9f81bf2b681eDouglas Gregor 8028eee119bf4f1693dde17b8552c1f9f81bf2b681eDouglas Gregorbool Type::hasFloatingRepresentation() const { 803c63b96ad706e054a1390dd2ab53af9f05d33bbb1Steve Naroff if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType)) 804c63b96ad706e054a1390dd2ab53af9f05d33bbb1Steve Naroff return VT->getElementType()->isFloatingType(); 8058eee119bf4f1693dde17b8552c1f9f81bf2b681eDouglas Gregor else 8068eee119bf4f1693dde17b8552c1f9f81bf2b681eDouglas Gregor return isFloatingType(); 8075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 8085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isRealFloatingType() const { 8105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 811680523a91dd3351389667c8de17121ba7ae82673John McCall return BT->isFloatingPoint(); 8125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return false; 8135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 8145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isRealType() const { 8165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 8175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return BT->getKind() >= BuiltinType::Bool && 8185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer BT->getKind() <= BuiltinType::LongDouble; 8191274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) 8201274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor return ET->getDecl()->isComplete() && !ET->getDecl()->isScoped(); 8215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return false; 8225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 8235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isArithmeticType() const { 8255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 826a7fbf7282eadebaf1293d9f970b01fb57f4b0ae4Douglas Gregor return BT->getKind() >= BuiltinType::Bool && 827a7fbf7282eadebaf1293d9f970b01fb57f4b0ae4Douglas Gregor BT->getKind() <= BuiltinType::LongDouble; 82837c1b78a20a09b0456aa5caa15e159027010ca22Chris Lattner if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) 82937c1b78a20a09b0456aa5caa15e159027010ca22Chris Lattner // GCC allows forward declaration of enum types (forbid by C99 6.7.2.3p2). 83037c1b78a20a09b0456aa5caa15e159027010ca22Chris Lattner // If a body isn't seen by the time we get here, return false. 8311274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor // 8321274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor // C++0x: Enumerations are not arithmetic types. For now, just return 8331274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor // false for scoped enumerations since that will disable any 8341274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor // unwanted implicit conversions. 8351274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor return !ET->getDecl()->isScoped() && ET->getDecl()->isComplete(); 83600619623af0b9d3271e31402ec1a95e84c2c4526Douglas Gregor return isa<ComplexType>(CanonicalType); 8375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 8385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 839daa8e4e888758d55a7a759dd4a91b83921cef222John McCallType::ScalarTypeKind Type::getScalarTypeKind() const { 840daa8e4e888758d55a7a759dd4a91b83921cef222John McCall assert(isScalarType()); 841daa8e4e888758d55a7a759dd4a91b83921cef222John McCall 842daa8e4e888758d55a7a759dd4a91b83921cef222John McCall const Type *T = CanonicalType.getTypePtr(); 843daa8e4e888758d55a7a759dd4a91b83921cef222John McCall if (const BuiltinType *BT = dyn_cast<BuiltinType>(T)) { 844daa8e4e888758d55a7a759dd4a91b83921cef222John McCall if (BT->getKind() == BuiltinType::Bool) return STK_Bool; 8451d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall if (BT->getKind() == BuiltinType::NullPtr) return STK_CPointer; 846daa8e4e888758d55a7a759dd4a91b83921cef222John McCall if (BT->isInteger()) return STK_Integral; 847daa8e4e888758d55a7a759dd4a91b83921cef222John McCall if (BT->isFloatingPoint()) return STK_Floating; 848daa8e4e888758d55a7a759dd4a91b83921cef222John McCall llvm_unreachable("unknown scalar builtin type"); 8491d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall } else if (isa<PointerType>(T)) { 8501d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall return STK_CPointer; 8511d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall } else if (isa<BlockPointerType>(T)) { 8521d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall return STK_BlockPointer; 8531d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall } else if (isa<ObjCObjectPointerType>(T)) { 8541d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall return STK_ObjCObjectPointer; 855daa8e4e888758d55a7a759dd4a91b83921cef222John McCall } else if (isa<MemberPointerType>(T)) { 856daa8e4e888758d55a7a759dd4a91b83921cef222John McCall return STK_MemberPointer; 857daa8e4e888758d55a7a759dd4a91b83921cef222John McCall } else if (isa<EnumType>(T)) { 858daa8e4e888758d55a7a759dd4a91b83921cef222John McCall assert(cast<EnumType>(T)->getDecl()->isComplete()); 859daa8e4e888758d55a7a759dd4a91b83921cef222John McCall return STK_Integral; 860daa8e4e888758d55a7a759dd4a91b83921cef222John McCall } else if (const ComplexType *CT = dyn_cast<ComplexType>(T)) { 861daa8e4e888758d55a7a759dd4a91b83921cef222John McCall if (CT->getElementType()->isRealFloatingType()) 862daa8e4e888758d55a7a759dd4a91b83921cef222John McCall return STK_FloatingComplex; 863daa8e4e888758d55a7a759dd4a91b83921cef222John McCall return STK_IntegralComplex; 864daa8e4e888758d55a7a759dd4a91b83921cef222John McCall } 865daa8e4e888758d55a7a759dd4a91b83921cef222John McCall 866daa8e4e888758d55a7a759dd4a91b83921cef222John McCall llvm_unreachable("unknown scalar type"); 867daa8e4e888758d55a7a759dd4a91b83921cef222John McCall} 868daa8e4e888758d55a7a759dd4a91b83921cef222John McCall 869d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor/// \brief Determines whether the type is a C++ aggregate type or C 870d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor/// aggregate or union type. 871d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor/// 872d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor/// An aggregate type is an array or a class type (struct, union, or 873d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor/// class) that has no user-declared constructors, no private or 874d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor/// protected non-static data members, no base classes, and no virtual 875d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor/// functions (C++ [dcl.init.aggr]p1). The notion of an aggregate type 876d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor/// subsumes the notion of C aggregates (C99 6.2.5p21) because it also 877d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor/// includes union types. 8785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isAggregateType() const { 879c1efaecf0373f1a55c5ef4c234357cf726fc0600Douglas Gregor if (const RecordType *Record = dyn_cast<RecordType>(CanonicalType)) { 880c1efaecf0373f1a55c5ef4c234357cf726fc0600Douglas Gregor if (CXXRecordDecl *ClassDecl = dyn_cast<CXXRecordDecl>(Record->getDecl())) 881c1efaecf0373f1a55c5ef4c234357cf726fc0600Douglas Gregor return ClassDecl->isAggregate(); 882c1efaecf0373f1a55c5ef4c234357cf726fc0600Douglas Gregor 883d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor return true; 884c1efaecf0373f1a55c5ef4c234357cf726fc0600Douglas Gregor } 885c1efaecf0373f1a55c5ef4c234357cf726fc0600Douglas Gregor 886c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman return isa<ArrayType>(CanonicalType); 8875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 8885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8899bfa73c5ab7bf4b0e749d04f29da6884e8d5bd9fChris Lattner/// isConstantSizeType - Return true if this is not a variable sized type, 8909bfa73c5ab7bf4b0e749d04f29da6884e8d5bd9fChris Lattner/// according to the rules of C99 6.7.5p3. It is not legal to call this on 891898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// incomplete types or dependent types. 8923c2b3170041f69a92904e3bab9b6d654eaf260acEli Friedmanbool Type::isConstantSizeType() const { 893d52a4578144ab2887912e52eabec58a857a44adbChris Lattner assert(!isIncompleteType() && "This doesn't make sense for incomplete types"); 894898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor assert(!isDependentType() && "This doesn't make sense for dependent types"); 8959bfa73c5ab7bf4b0e749d04f29da6884e8d5bd9fChris Lattner // The VAT must have a size, as it is known to be complete. 8969bfa73c5ab7bf4b0e749d04f29da6884e8d5bd9fChris Lattner return !isa<VariableArrayType>(CanonicalType); 8975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 8985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// isIncompleteType - Return true if this is an incomplete type (C99 6.2.5p1) 9005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// - a type that can describe objects, but which lacks information needed to 9015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// determine its size. 902d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregorbool Type::isIncompleteType(NamedDecl **Def) const { 903d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor if (Def) 9046bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines *Def = nullptr; 9056bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 9061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump switch (CanonicalType->getTypeClass()) { 9075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer default: return false; 9085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Builtin: 9095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Void is the only incomplete builtin type. Per C99 6.2.5p19, it can never 9105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // be completed. 9115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return isVoidType(); 912d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor case Enum: { 913d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor EnumDecl *EnumD = cast<EnumType>(CanonicalType)->getDecl(); 914d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor if (Def) 915d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor *Def = EnumD; 916d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor 9171274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor // An enumeration with fixed underlying type is complete (C++0x 7.2p3). 918d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor if (EnumD->isFixed()) 919d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor return false; 920d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor 921d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor return !EnumD->isCompleteDefinition(); 922d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor } 923d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor case Record: { 9245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // A tagged type (struct/union/enum/class) is incomplete if the decl is a 9255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // forward declaration, but not a full definition (C99 6.2.5p22). 926d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor RecordDecl *Rec = cast<RecordType>(CanonicalType)->getDecl(); 927d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor if (Def) 928d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor *Def = Rec; 929d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor return !Rec->isCompleteDefinition(); 930d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor } 931923d56d436f750bc1f29db50e641078725558a1bSebastian Redl case ConstantArray: 932923d56d436f750bc1f29db50e641078725558a1bSebastian Redl // An array is incomplete if its element type is incomplete 933923d56d436f750bc1f29db50e641078725558a1bSebastian Redl // (C++ [dcl.array]p1). 934923d56d436f750bc1f29db50e641078725558a1bSebastian Redl // We don't handle variable arrays (they're not allowed in C++) or 935923d56d436f750bc1f29db50e641078725558a1bSebastian Redl // dependent-sized arrays (dependent types are never treated as incomplete). 936d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor return cast<ArrayType>(CanonicalType)->getElementType() 937d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor ->isIncompleteType(Def); 938c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman case IncompleteArray: 9395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // An array of unknown size is an incomplete type (C99 6.2.5p22). 940c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman return true; 941c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall case ObjCObject: 942d0221526bcc81f49eff5c992978176e83ada3bc7Douglas Gregor return cast<ObjCObjectType>(CanonicalType)->getBaseType() 943d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor ->isIncompleteType(Def); 944d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor case ObjCInterface: { 9451efaa9594a81709a17658fd80ae7e783e1026407Chris Lattner // ObjC interfaces are incomplete if they are @class, not @interface. 946d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor ObjCInterfaceDecl *Interface 947d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor = cast<ObjCInterfaceType>(CanonicalType)->getDecl(); 948d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor if (Def) 949d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor *Def = Interface; 950d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor return !Interface->hasDefinition(); 951d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor } 9525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 9535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 9545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 955f85e193739c953358c865005855253af4f68a497John McCallbool QualType::isPODType(ASTContext &Context) const { 956152f6b7be508fbc61543f3736ebd390d7ac84bd1Benjamin Kramer // C++11 has a more relaxed definition of POD. 95780ad52f327b532bded5c5b0ee38779d841c6cd35Richard Smith if (Context.getLangOpts().CPlusPlus11) 958152f6b7be508fbc61543f3736ebd390d7ac84bd1Benjamin Kramer return isCXX11PODType(Context); 959152f6b7be508fbc61543f3736ebd390d7ac84bd1Benjamin Kramer 960152f6b7be508fbc61543f3736ebd390d7ac84bd1Benjamin Kramer return isCXX98PODType(Context); 961152f6b7be508fbc61543f3736ebd390d7ac84bd1Benjamin Kramer} 962152f6b7be508fbc61543f3736ebd390d7ac84bd1Benjamin Kramer 963152f6b7be508fbc61543f3736ebd390d7ac84bd1Benjamin Kramerbool QualType::isCXX98PODType(ASTContext &Context) const { 96464b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl // The compiler shouldn't query this for incomplete types, but the user might. 965607a1788d9529c8e8494ac528764aa2c678a1a97Sebastian Redl // We return false for that case. Except for incomplete arrays of PODs, which 966607a1788d9529c8e8494ac528764aa2c678a1a97Sebastian Redl // are PODs according to the standard. 967f85e193739c953358c865005855253af4f68a497John McCall if (isNull()) 968f85e193739c953358c865005855253af4f68a497John McCall return 0; 969f85e193739c953358c865005855253af4f68a497John McCall 970f85e193739c953358c865005855253af4f68a497John McCall if ((*this)->isIncompleteArrayType()) 9718907832ddee33d8a0b0d8432d4c7470360353d67Benjamin Kramer return Context.getBaseElementType(*this).isCXX98PODType(Context); 972f85e193739c953358c865005855253af4f68a497John McCall 973f85e193739c953358c865005855253af4f68a497John McCall if ((*this)->isIncompleteType()) 97464b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl return false; 97564b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 9764e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie if (Context.getLangOpts().ObjCAutoRefCount) { 977f85e193739c953358c865005855253af4f68a497John McCall switch (getObjCLifetime()) { 978f85e193739c953358c865005855253af4f68a497John McCall case Qualifiers::OCL_ExplicitNone: 979f85e193739c953358c865005855253af4f68a497John McCall return true; 980f85e193739c953358c865005855253af4f68a497John McCall 981f85e193739c953358c865005855253af4f68a497John McCall case Qualifiers::OCL_Strong: 982f85e193739c953358c865005855253af4f68a497John McCall case Qualifiers::OCL_Weak: 983f85e193739c953358c865005855253af4f68a497John McCall case Qualifiers::OCL_Autoreleasing: 984f85e193739c953358c865005855253af4f68a497John McCall return false; 985f85e193739c953358c865005855253af4f68a497John McCall 986f85e193739c953358c865005855253af4f68a497John McCall case Qualifiers::OCL_None: 987f85e193739c953358c865005855253af4f68a497John McCall break; 988f85e193739c953358c865005855253af4f68a497John McCall } 989f85e193739c953358c865005855253af4f68a497John McCall } 990f85e193739c953358c865005855253af4f68a497John McCall 991f85e193739c953358c865005855253af4f68a497John McCall QualType CanonicalType = getTypePtr()->CanonicalType; 99264b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl switch (CanonicalType->getTypeClass()) { 99364b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl // Everything not explicitly mentioned is not POD. 99464b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl default: return false; 995f85e193739c953358c865005855253af4f68a497John McCall case Type::VariableArray: 996f85e193739c953358c865005855253af4f68a497John McCall case Type::ConstantArray: 997607a1788d9529c8e8494ac528764aa2c678a1a97Sebastian Redl // IncompleteArray is handled above. 9988907832ddee33d8a0b0d8432d4c7470360353d67Benjamin Kramer return Context.getBaseElementType(*this).isCXX98PODType(Context); 999f85e193739c953358c865005855253af4f68a497John McCall 1000f85e193739c953358c865005855253af4f68a497John McCall case Type::ObjCObjectPointer: 1001f85e193739c953358c865005855253af4f68a497John McCall case Type::BlockPointer: 1002f85e193739c953358c865005855253af4f68a497John McCall case Type::Builtin: 1003f85e193739c953358c865005855253af4f68a497John McCall case Type::Complex: 1004f85e193739c953358c865005855253af4f68a497John McCall case Type::Pointer: 1005f85e193739c953358c865005855253af4f68a497John McCall case Type::MemberPointer: 1006f85e193739c953358c865005855253af4f68a497John McCall case Type::Vector: 1007f85e193739c953358c865005855253af4f68a497John McCall case Type::ExtVector: 100864b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl return true; 100964b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 1010f85e193739c953358c865005855253af4f68a497John McCall case Type::Enum: 101172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor return true; 101272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor 1013f85e193739c953358c865005855253af4f68a497John McCall case Type::Record: 10141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (CXXRecordDecl *ClassDecl 1015c1efaecf0373f1a55c5ef4c234357cf726fc0600Douglas Gregor = dyn_cast<CXXRecordDecl>(cast<RecordType>(CanonicalType)->getDecl())) 1016c1efaecf0373f1a55c5ef4c234357cf726fc0600Douglas Gregor return ClassDecl->isPOD(); 1017c1efaecf0373f1a55c5ef4c234357cf726fc0600Douglas Gregor 101864b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl // C struct/union is POD. 101964b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl return true; 102064b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl } 102164b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl} 102264b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 1023f85e193739c953358c865005855253af4f68a497John McCallbool QualType::isTrivialType(ASTContext &Context) const { 1024f85e193739c953358c865005855253af4f68a497John McCall // The compiler shouldn't query this for incomplete types, but the user might. 1025f85e193739c953358c865005855253af4f68a497John McCall // We return false for that case. Except for incomplete arrays of PODs, which 1026f85e193739c953358c865005855253af4f68a497John McCall // are PODs according to the standard. 1027f85e193739c953358c865005855253af4f68a497John McCall if (isNull()) 1028f85e193739c953358c865005855253af4f68a497John McCall return 0; 1029f85e193739c953358c865005855253af4f68a497John McCall 1030f85e193739c953358c865005855253af4f68a497John McCall if ((*this)->isArrayType()) 1031f85e193739c953358c865005855253af4f68a497John McCall return Context.getBaseElementType(*this).isTrivialType(Context); 1032f85e193739c953358c865005855253af4f68a497John McCall 1033f85e193739c953358c865005855253af4f68a497John McCall // Return false for incomplete types after skipping any incomplete array 1034f85e193739c953358c865005855253af4f68a497John McCall // types which are expressly allowed by the standard and thus our API. 1035f85e193739c953358c865005855253af4f68a497John McCall if ((*this)->isIncompleteType()) 1036f85e193739c953358c865005855253af4f68a497John McCall return false; 1037f85e193739c953358c865005855253af4f68a497John McCall 10384e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie if (Context.getLangOpts().ObjCAutoRefCount) { 1039f85e193739c953358c865005855253af4f68a497John McCall switch (getObjCLifetime()) { 1040f85e193739c953358c865005855253af4f68a497John McCall case Qualifiers::OCL_ExplicitNone: 1041f85e193739c953358c865005855253af4f68a497John McCall return true; 1042f85e193739c953358c865005855253af4f68a497John McCall 1043f85e193739c953358c865005855253af4f68a497John McCall case Qualifiers::OCL_Strong: 1044f85e193739c953358c865005855253af4f68a497John McCall case Qualifiers::OCL_Weak: 1045f85e193739c953358c865005855253af4f68a497John McCall case Qualifiers::OCL_Autoreleasing: 1046f85e193739c953358c865005855253af4f68a497John McCall return false; 1047f85e193739c953358c865005855253af4f68a497John McCall 1048f85e193739c953358c865005855253af4f68a497John McCall case Qualifiers::OCL_None: 1049f85e193739c953358c865005855253af4f68a497John McCall if ((*this)->isObjCLifetimeType()) 1050f85e193739c953358c865005855253af4f68a497John McCall return false; 1051f85e193739c953358c865005855253af4f68a497John McCall break; 1052f85e193739c953358c865005855253af4f68a497John McCall } 1053f85e193739c953358c865005855253af4f68a497John McCall } 1054f85e193739c953358c865005855253af4f68a497John McCall 1055f85e193739c953358c865005855253af4f68a497John McCall QualType CanonicalType = getTypePtr()->CanonicalType; 1056f85e193739c953358c865005855253af4f68a497John McCall if (CanonicalType->isDependentType()) 1057f85e193739c953358c865005855253af4f68a497John McCall return false; 1058f85e193739c953358c865005855253af4f68a497John McCall 1059f85e193739c953358c865005855253af4f68a497John McCall // C++0x [basic.types]p9: 1060f85e193739c953358c865005855253af4f68a497John McCall // Scalar types, trivial class types, arrays of such types, and 1061f85e193739c953358c865005855253af4f68a497John McCall // cv-qualified versions of these types are collectively called trivial 1062f85e193739c953358c865005855253af4f68a497John McCall // types. 1063f85e193739c953358c865005855253af4f68a497John McCall 1064f85e193739c953358c865005855253af4f68a497John McCall // As an extension, Clang treats vector types as Scalar types. 1065f85e193739c953358c865005855253af4f68a497John McCall if (CanonicalType->isScalarType() || CanonicalType->isVectorType()) 1066f85e193739c953358c865005855253af4f68a497John McCall return true; 1067f85e193739c953358c865005855253af4f68a497John McCall if (const RecordType *RT = CanonicalType->getAs<RecordType>()) { 1068f85e193739c953358c865005855253af4f68a497John McCall if (const CXXRecordDecl *ClassDecl = 1069f85e193739c953358c865005855253af4f68a497John McCall dyn_cast<CXXRecordDecl>(RT->getDecl())) { 1070426391cd51af86f9d59eceb0fb1c42153eccbb9aRichard Smith // C++11 [class]p6: 1071426391cd51af86f9d59eceb0fb1c42153eccbb9aRichard Smith // A trivial class is a class that has a default constructor, 1072426391cd51af86f9d59eceb0fb1c42153eccbb9aRichard Smith // has no non-trivial default constructors, and is trivially 1073426391cd51af86f9d59eceb0fb1c42153eccbb9aRichard Smith // copyable. 1074426391cd51af86f9d59eceb0fb1c42153eccbb9aRichard Smith return ClassDecl->hasDefaultConstructor() && 1075426391cd51af86f9d59eceb0fb1c42153eccbb9aRichard Smith !ClassDecl->hasNonTrivialDefaultConstructor() && 1076426391cd51af86f9d59eceb0fb1c42153eccbb9aRichard Smith ClassDecl->isTriviallyCopyable(); 1077f85e193739c953358c865005855253af4f68a497John McCall } 1078f85e193739c953358c865005855253af4f68a497John McCall 1079f85e193739c953358c865005855253af4f68a497John McCall return true; 1080f85e193739c953358c865005855253af4f68a497John McCall } 1081f85e193739c953358c865005855253af4f68a497John McCall 1082f85e193739c953358c865005855253af4f68a497John McCall // No other types can match. 1083f85e193739c953358c865005855253af4f68a497John McCall return false; 1084f85e193739c953358c865005855253af4f68a497John McCall} 1085f85e193739c953358c865005855253af4f68a497John McCall 1086f85e193739c953358c865005855253af4f68a497John McCallbool QualType::isTriviallyCopyableType(ASTContext &Context) const { 1087f85e193739c953358c865005855253af4f68a497John McCall if ((*this)->isArrayType()) 1088f85e193739c953358c865005855253af4f68a497John McCall return Context.getBaseElementType(*this).isTrivialType(Context); 1089f85e193739c953358c865005855253af4f68a497John McCall 10904e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie if (Context.getLangOpts().ObjCAutoRefCount) { 1091f85e193739c953358c865005855253af4f68a497John McCall switch (getObjCLifetime()) { 1092f85e193739c953358c865005855253af4f68a497John McCall case Qualifiers::OCL_ExplicitNone: 1093f85e193739c953358c865005855253af4f68a497John McCall return true; 1094f85e193739c953358c865005855253af4f68a497John McCall 1095f85e193739c953358c865005855253af4f68a497John McCall case Qualifiers::OCL_Strong: 1096f85e193739c953358c865005855253af4f68a497John McCall case Qualifiers::OCL_Weak: 1097f85e193739c953358c865005855253af4f68a497John McCall case Qualifiers::OCL_Autoreleasing: 1098f85e193739c953358c865005855253af4f68a497John McCall return false; 1099f85e193739c953358c865005855253af4f68a497John McCall 1100f85e193739c953358c865005855253af4f68a497John McCall case Qualifiers::OCL_None: 1101f85e193739c953358c865005855253af4f68a497John McCall if ((*this)->isObjCLifetimeType()) 1102f85e193739c953358c865005855253af4f68a497John McCall return false; 1103f85e193739c953358c865005855253af4f68a497John McCall break; 1104f85e193739c953358c865005855253af4f68a497John McCall } 1105f85e193739c953358c865005855253af4f68a497John McCall } 1106f85e193739c953358c865005855253af4f68a497John McCall 1107a3d727ba775eaecd4fd69e1c90b81732394716a6Eli Friedman // C++11 [basic.types]p9 1108f85e193739c953358c865005855253af4f68a497John McCall // Scalar types, trivially copyable class types, arrays of such types, and 1109a3d727ba775eaecd4fd69e1c90b81732394716a6Eli Friedman // non-volatile const-qualified versions of these types are collectively 1110a3d727ba775eaecd4fd69e1c90b81732394716a6Eli Friedman // called trivially copyable types. 1111f85e193739c953358c865005855253af4f68a497John McCall 1112f85e193739c953358c865005855253af4f68a497John McCall QualType CanonicalType = getCanonicalType(); 1113f85e193739c953358c865005855253af4f68a497John McCall if (CanonicalType->isDependentType()) 1114f85e193739c953358c865005855253af4f68a497John McCall return false; 1115f85e193739c953358c865005855253af4f68a497John McCall 1116a3d727ba775eaecd4fd69e1c90b81732394716a6Eli Friedman if (CanonicalType.isVolatileQualified()) 1117a3d727ba775eaecd4fd69e1c90b81732394716a6Eli Friedman return false; 1118a3d727ba775eaecd4fd69e1c90b81732394716a6Eli Friedman 1119f85e193739c953358c865005855253af4f68a497John McCall // Return false for incomplete types after skipping any incomplete array types 1120f85e193739c953358c865005855253af4f68a497John McCall // which are expressly allowed by the standard and thus our API. 1121f85e193739c953358c865005855253af4f68a497John McCall if (CanonicalType->isIncompleteType()) 1122f85e193739c953358c865005855253af4f68a497John McCall return false; 1123f85e193739c953358c865005855253af4f68a497John McCall 1124f85e193739c953358c865005855253af4f68a497John McCall // As an extension, Clang treats vector types as Scalar types. 1125f85e193739c953358c865005855253af4f68a497John McCall if (CanonicalType->isScalarType() || CanonicalType->isVectorType()) 1126f85e193739c953358c865005855253af4f68a497John McCall return true; 1127f85e193739c953358c865005855253af4f68a497John McCall 1128f85e193739c953358c865005855253af4f68a497John McCall if (const RecordType *RT = CanonicalType->getAs<RecordType>()) { 1129f85e193739c953358c865005855253af4f68a497John McCall if (const CXXRecordDecl *ClassDecl = 1130f85e193739c953358c865005855253af4f68a497John McCall dyn_cast<CXXRecordDecl>(RT->getDecl())) { 1131f85e193739c953358c865005855253af4f68a497John McCall if (!ClassDecl->isTriviallyCopyable()) return false; 1132f85e193739c953358c865005855253af4f68a497John McCall } 1133f85e193739c953358c865005855253af4f68a497John McCall 1134f85e193739c953358c865005855253af4f68a497John McCall return true; 1135f85e193739c953358c865005855253af4f68a497John McCall } 1136f85e193739c953358c865005855253af4f68a497John McCall 1137f85e193739c953358c865005855253af4f68a497John McCall // No other types can match. 1138f85e193739c953358c865005855253af4f68a497John McCall return false; 1139f85e193739c953358c865005855253af4f68a497John McCall} 1140f85e193739c953358c865005855253af4f68a497John McCall 1141f85e193739c953358c865005855253af4f68a497John McCall 1142f85e193739c953358c865005855253af4f68a497John McCall 11439db7a7eb4e23758e041752c9c0c0ec1663d5a0afCraig Topperbool Type::isLiteralType(const ASTContext &Ctx) const { 1144018a088b3b30e500efa9173f7cd4b1b1f6a065a8Chandler Carruth if (isDependentType()) 1145ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl return false; 1146ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl 1147a10b97898ee6339c3110e6ca33f178ff52f05238Richard Smith // C++1y [basic.types]p10: 1148a10b97898ee6339c3110e6ca33f178ff52f05238Richard Smith // A type is a literal type if it is: 1149a10b97898ee6339c3110e6ca33f178ff52f05238Richard Smith // -- cv void; or 1150a10b97898ee6339c3110e6ca33f178ff52f05238Richard Smith if (Ctx.getLangOpts().CPlusPlus1y && isVoidType()) 1151a10b97898ee6339c3110e6ca33f178ff52f05238Richard Smith return true; 1152a10b97898ee6339c3110e6ca33f178ff52f05238Richard Smith 1153a10b97898ee6339c3110e6ca33f178ff52f05238Richard Smith // C++11 [basic.types]p10: 1154ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl // A type is a literal type if it is: 11559b6347cd410be55425f7062d22fd6e4ecb4e1a58Chandler Carruth // [...] 1156a10b97898ee6339c3110e6ca33f178ff52f05238Richard Smith // -- an array of literal type other than an array of runtime bound; or 1157018a088b3b30e500efa9173f7cd4b1b1f6a065a8Chandler Carruth if (isVariableArrayType()) 1158ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl return false; 11599b6347cd410be55425f7062d22fd6e4ecb4e1a58Chandler Carruth const Type *BaseTy = getBaseElementTypeUnsafe(); 11609b6347cd410be55425f7062d22fd6e4ecb4e1a58Chandler Carruth assert(BaseTy && "NULL element type"); 1161ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl 1162018a088b3b30e500efa9173f7cd4b1b1f6a065a8Chandler Carruth // Return false for incomplete types after skipping any incomplete array 1163018a088b3b30e500efa9173f7cd4b1b1f6a065a8Chandler Carruth // types; those are expressly allowed by the standard and thus our API. 1164018a088b3b30e500efa9173f7cd4b1b1f6a065a8Chandler Carruth if (BaseTy->isIncompleteType()) 1165018a088b3b30e500efa9173f7cd4b1b1f6a065a8Chandler Carruth return false; 1166018a088b3b30e500efa9173f7cd4b1b1f6a065a8Chandler Carruth 1167a10b97898ee6339c3110e6ca33f178ff52f05238Richard Smith // C++11 [basic.types]p10: 11689b6347cd410be55425f7062d22fd6e4ecb4e1a58Chandler Carruth // A type is a literal type if it is: 11699b6347cd410be55425f7062d22fd6e4ecb4e1a58Chandler Carruth // -- a scalar type; or 11707ead5c7b6fd48cf549e55b4db499c26ecf88ae75Eli Friedman // As an extension, Clang treats vector types and complex types as 11717ead5c7b6fd48cf549e55b4db499c26ecf88ae75Eli Friedman // literal types. 11727ead5c7b6fd48cf549e55b4db499c26ecf88ae75Eli Friedman if (BaseTy->isScalarType() || BaseTy->isVectorType() || 11737ead5c7b6fd48cf549e55b4db499c26ecf88ae75Eli Friedman BaseTy->isAnyComplexType()) 1174af1fc7af351758b0ea0d285bdfe5640128109a4eRichard Smith return true; 11759b6347cd410be55425f7062d22fd6e4ecb4e1a58Chandler Carruth // -- a reference type; or 1176af1fc7af351758b0ea0d285bdfe5640128109a4eRichard Smith if (BaseTy->isReferenceType()) 1177af1fc7af351758b0ea0d285bdfe5640128109a4eRichard Smith return true; 11789b6347cd410be55425f7062d22fd6e4ecb4e1a58Chandler Carruth // -- a class type that has all of the following properties: 11799b6347cd410be55425f7062d22fd6e4ecb4e1a58Chandler Carruth if (const RecordType *RT = BaseTy->getAs<RecordType>()) { 11809f569cca2a4c5fb6026005434e27025b9e71309dRichard Smith // -- a trivial destructor, 11819f569cca2a4c5fb6026005434e27025b9e71309dRichard Smith // -- every constructor call and full-expression in the 11829f569cca2a4c5fb6026005434e27025b9e71309dRichard Smith // brace-or-equal-initializers for non-static data members (if any) 11839f569cca2a4c5fb6026005434e27025b9e71309dRichard Smith // is a constant expression, 11849f569cca2a4c5fb6026005434e27025b9e71309dRichard Smith // -- it is an aggregate type or has at least one constexpr 11859f569cca2a4c5fb6026005434e27025b9e71309dRichard Smith // constructor or constructor template that is not a copy or move 11869f569cca2a4c5fb6026005434e27025b9e71309dRichard Smith // constructor, and 11879f569cca2a4c5fb6026005434e27025b9e71309dRichard Smith // -- all non-static data members and base classes of literal types 11889f569cca2a4c5fb6026005434e27025b9e71309dRichard Smith // 11899f569cca2a4c5fb6026005434e27025b9e71309dRichard Smith // We resolve DR1361 by ignoring the second bullet. 11905751838965eefa1c08e4fc545498a3ee45cd9611Chandler Carruth if (const CXXRecordDecl *ClassDecl = 11919f569cca2a4c5fb6026005434e27025b9e71309dRichard Smith dyn_cast<CXXRecordDecl>(RT->getDecl())) 11929f569cca2a4c5fb6026005434e27025b9e71309dRichard Smith return ClassDecl->isLiteral(); 11939b6347cd410be55425f7062d22fd6e4ecb4e1a58Chandler Carruth 11949b6347cd410be55425f7062d22fd6e4ecb4e1a58Chandler Carruth return true; 1195ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl } 1196af1fc7af351758b0ea0d285bdfe5640128109a4eRichard Smith 11975705f211472f19fc38e58d81365f9261024b3ba3Richard Smith // We treat _Atomic T as a literal type if T is a literal type. 11985705f211472f19fc38e58d81365f9261024b3ba3Richard Smith if (const AtomicType *AT = BaseTy->getAs<AtomicType>()) 11995705f211472f19fc38e58d81365f9261024b3ba3Richard Smith return AT->getValueType()->isLiteralType(Ctx); 12005705f211472f19fc38e58d81365f9261024b3ba3Richard Smith 1201bdaeaed3e3293f1915cdf336f406d4d391331039Richard Smith // If this type hasn't been deduced yet, then conservatively assume that 1202bdaeaed3e3293f1915cdf336f406d4d391331039Richard Smith // it'll work out to be a literal type. 1203bdaeaed3e3293f1915cdf336f406d4d391331039Richard Smith if (isa<AutoType>(BaseTy->getCanonicalTypeInternal())) 1204bdaeaed3e3293f1915cdf336f406d4d391331039Richard Smith return true; 1205bdaeaed3e3293f1915cdf336f406d4d391331039Richard Smith 12069b6347cd410be55425f7062d22fd6e4ecb4e1a58Chandler Carruth return false; 1207ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl} 1208ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl 1209636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruthbool Type::isStandardLayoutType() const { 1210018a088b3b30e500efa9173f7cd4b1b1f6a065a8Chandler Carruth if (isDependentType()) 1211636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth return false; 1212636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth 1213636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth // C++0x [basic.types]p9: 1214636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth // Scalar types, standard-layout class types, arrays of such types, and 1215636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth // cv-qualified versions of these types are collectively called 1216636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth // standard-layout types. 1217636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth const Type *BaseTy = getBaseElementTypeUnsafe(); 1218636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth assert(BaseTy && "NULL element type"); 1219018a088b3b30e500efa9173f7cd4b1b1f6a065a8Chandler Carruth 1220018a088b3b30e500efa9173f7cd4b1b1f6a065a8Chandler Carruth // Return false for incomplete types after skipping any incomplete array 1221018a088b3b30e500efa9173f7cd4b1b1f6a065a8Chandler Carruth // types which are expressly allowed by the standard and thus our API. 1222018a088b3b30e500efa9173f7cd4b1b1f6a065a8Chandler Carruth if (BaseTy->isIncompleteType()) 1223018a088b3b30e500efa9173f7cd4b1b1f6a065a8Chandler Carruth return false; 1224018a088b3b30e500efa9173f7cd4b1b1f6a065a8Chandler Carruth 122525df423cfc6689cf21d51a66af84ea1e70d489dfChandler Carruth // As an extension, Clang treats vector types as Scalar types. 122625df423cfc6689cf21d51a66af84ea1e70d489dfChandler Carruth if (BaseTy->isScalarType() || BaseTy->isVectorType()) return true; 1227636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth if (const RecordType *RT = BaseTy->getAs<RecordType>()) { 1228636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth if (const CXXRecordDecl *ClassDecl = 1229636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth dyn_cast<CXXRecordDecl>(RT->getDecl())) 1230ec997dc66627957bcdcd3db7906a68c1e14a279cChandler Carruth if (!ClassDecl->isStandardLayout()) 1231636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth return false; 1232636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth 1233636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth // Default to 'true' for non-C++ class types. 1234636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth // FIXME: This is a bit dubious, but plain C structs should trivially meet 1235636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth // all the requirements of standard layout classes. 1236636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth return true; 1237636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth } 1238636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth 1239636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth // No other types can match. 1240636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth return false; 1241636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth} 1242636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth 1243636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth// This is effectively the intersection of isTrivialType and 12447426f793844407021ffeb5afcf917fff1a57f196Richard Smith// isStandardLayoutType. We implement it directly to avoid redundant 1245636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth// conversions from a type to a CXXRecordDecl. 1246f85e193739c953358c865005855253af4f68a497John McCallbool QualType::isCXX11PODType(ASTContext &Context) const { 1247f85e193739c953358c865005855253af4f68a497John McCall const Type *ty = getTypePtr(); 1248f85e193739c953358c865005855253af4f68a497John McCall if (ty->isDependentType()) 124943fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth return false; 125043fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth 12514e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie if (Context.getLangOpts().ObjCAutoRefCount) { 1252f85e193739c953358c865005855253af4f68a497John McCall switch (getObjCLifetime()) { 1253f85e193739c953358c865005855253af4f68a497John McCall case Qualifiers::OCL_ExplicitNone: 1254f85e193739c953358c865005855253af4f68a497John McCall return true; 1255f85e193739c953358c865005855253af4f68a497John McCall 1256f85e193739c953358c865005855253af4f68a497John McCall case Qualifiers::OCL_Strong: 1257f85e193739c953358c865005855253af4f68a497John McCall case Qualifiers::OCL_Weak: 1258f85e193739c953358c865005855253af4f68a497John McCall case Qualifiers::OCL_Autoreleasing: 1259f85e193739c953358c865005855253af4f68a497John McCall return false; 1260f85e193739c953358c865005855253af4f68a497John McCall 1261f85e193739c953358c865005855253af4f68a497John McCall case Qualifiers::OCL_None: 1262f85e193739c953358c865005855253af4f68a497John McCall break; 1263f85e193739c953358c865005855253af4f68a497John McCall } 1264f85e193739c953358c865005855253af4f68a497John McCall } 1265f85e193739c953358c865005855253af4f68a497John McCall 126643fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth // C++11 [basic.types]p9: 126743fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth // Scalar types, POD classes, arrays of such types, and cv-qualified 126843fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth // versions of these types are collectively called trivial types. 1269f85e193739c953358c865005855253af4f68a497John McCall const Type *BaseTy = ty->getBaseElementTypeUnsafe(); 127043fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth assert(BaseTy && "NULL element type"); 1271018a088b3b30e500efa9173f7cd4b1b1f6a065a8Chandler Carruth 1272018a088b3b30e500efa9173f7cd4b1b1f6a065a8Chandler Carruth // Return false for incomplete types after skipping any incomplete array 1273018a088b3b30e500efa9173f7cd4b1b1f6a065a8Chandler Carruth // types which are expressly allowed by the standard and thus our API. 1274018a088b3b30e500efa9173f7cd4b1b1f6a065a8Chandler Carruth if (BaseTy->isIncompleteType()) 1275018a088b3b30e500efa9173f7cd4b1b1f6a065a8Chandler Carruth return false; 1276018a088b3b30e500efa9173f7cd4b1b1f6a065a8Chandler Carruth 127725df423cfc6689cf21d51a66af84ea1e70d489dfChandler Carruth // As an extension, Clang treats vector types as Scalar types. 127825df423cfc6689cf21d51a66af84ea1e70d489dfChandler Carruth if (BaseTy->isScalarType() || BaseTy->isVectorType()) return true; 127943fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth if (const RecordType *RT = BaseTy->getAs<RecordType>()) { 128043fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth if (const CXXRecordDecl *ClassDecl = 128143fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth dyn_cast<CXXRecordDecl>(RT->getDecl())) { 128243fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth // C++11 [class]p10: 128343fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth // A POD struct is a non-union class that is both a trivial class [...] 1284023df37c27ee8035664fb62f206ca58f4e2a169dSean Hunt if (!ClassDecl->isTrivial()) return false; 128543fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth 128643fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth // C++11 [class]p10: 128743fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth // A POD struct is a non-union class that is both a trivial class and 128843fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth // a standard-layout class [...] 1289ec997dc66627957bcdcd3db7906a68c1e14a279cChandler Carruth if (!ClassDecl->isStandardLayout()) return false; 129043fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth 129143fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth // C++11 [class]p10: 129243fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth // A POD struct is a non-union class that is both a trivial class and 129343fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth // a standard-layout class, and has no non-static data members of type 129443fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth // non-POD struct, non-POD union (or array of such types). [...] 129543fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth // 129643fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth // We don't directly query the recursive aspect as the requiremets for 129743fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth // both standard-layout classes and trivial classes apply recursively 129843fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth // already. 129943fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth } 130043fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth 130143fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth return true; 130243fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth } 130343fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth 130443fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth // No other types can match. 130543fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth return false; 130643fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth} 130743fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth 13085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isPromotableIntegerType() const { 1309183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const BuiltinType *BT = getAs<BuiltinType>()) 13102a18dfe292cf3c406a769c3672080970ac586345Chris Lattner switch (BT->getKind()) { 13112a18dfe292cf3c406a769c3672080970ac586345Chris Lattner case BuiltinType::Bool: 13122a18dfe292cf3c406a769c3672080970ac586345Chris Lattner case BuiltinType::Char_S: 13132a18dfe292cf3c406a769c3672080970ac586345Chris Lattner case BuiltinType::Char_U: 13142a18dfe292cf3c406a769c3672080970ac586345Chris Lattner case BuiltinType::SChar: 13152a18dfe292cf3c406a769c3672080970ac586345Chris Lattner case BuiltinType::UChar: 13162a18dfe292cf3c406a769c3672080970ac586345Chris Lattner case BuiltinType::Short: 13172a18dfe292cf3c406a769c3672080970ac586345Chris Lattner case BuiltinType::UShort: 131868a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman case BuiltinType::WChar_S: 131968a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman case BuiltinType::WChar_U: 132068a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman case BuiltinType::Char16: 132168a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman case BuiltinType::Char32: 13222a18dfe292cf3c406a769c3672080970ac586345Chris Lattner return true; 13231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump default: 13242a18dfe292cf3c406a769c3672080970ac586345Chris Lattner return false; 13252a18dfe292cf3c406a769c3672080970ac586345Chris Lattner } 1326aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor 1327aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor // Enumerated types are promotable to their compatible integer types 1328aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor // (C99 6.3.1.1) a.k.a. its underlying type (C++ [conv.prom]p2). 1329aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor if (const EnumType *ET = getAs<EnumType>()){ 13301274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor if (this->isDependentType() || ET->getDecl()->getPromotionType().isNull() 13311274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor || ET->getDecl()->isScoped()) 1332aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor return false; 1333aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor 133468a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman return true; 1335aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor } 1336aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor 13372a18dfe292cf3c406a769c3672080970ac586345Chris Lattner return false; 13385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 13395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 134022b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedmanbool Type::isSpecifierType() const { 134122b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman // Note that this intentionally does not use the canonical type. 134222b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman switch (getTypeClass()) { 134322b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman case Builtin: 134422b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman case Record: 134522b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman case Enum: 134622b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman case Typedef: 1347c8f2c61f4f667c2bc3e4e74b274fa397a4232393Eli Friedman case Complex: 1348c8f2c61f4f667c2bc3e4e74b274fa397a4232393Eli Friedman case TypeOfExpr: 1349c8f2c61f4f667c2bc3e4e74b274fa397a4232393Eli Friedman case TypeOf: 1350c8f2c61f4f667c2bc3e4e74b274fa397a4232393Eli Friedman case TemplateTypeParm: 135149a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall case SubstTemplateTypeParm: 1352c8f2c61f4f667c2bc3e4e74b274fa397a4232393Eli Friedman case TemplateSpecialization: 1353465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case Elaborated: 13544714c12a1ab759156b78be8f109ea4c12213af57Douglas Gregor case DependentName: 135533500955d731c73717af52088b7fc0e7a85681e7John McCall case DependentTemplateSpecialization: 1356c8f2c61f4f667c2bc3e4e74b274fa397a4232393Eli Friedman case ObjCInterface: 1357c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall case ObjCObject: 1358c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall case ObjCObjectPointer: // FIXME: object pointers aren't really specifiers 135922b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman return true; 136022b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman default: 136122b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman return false; 136222b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman } 136322b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman} 136422b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman 1365465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraElaboratedTypeKeyword 1366465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraTypeWithKeyword::getKeywordForTypeSpec(unsigned TypeSpec) { 1367465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara switch (TypeSpec) { 1368465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara default: return ETK_None; 1369465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TST_typename: return ETK_Typename; 1370465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TST_class: return ETK_Class; 1371465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TST_struct: return ETK_Struct; 13726666ed4ed2e2bc13da5ac5d0a4947019137d45beJoao Matos case TST_interface: return ETK_Interface; 1373465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TST_union: return ETK_Union; 1374465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TST_enum: return ETK_Enum; 1375465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara } 1376465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara} 1377465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 1378465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraTagTypeKind 1379465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraTypeWithKeyword::getTagTypeKindForTypeSpec(unsigned TypeSpec) { 1380465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara switch(TypeSpec) { 1381465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TST_class: return TTK_Class; 1382465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TST_struct: return TTK_Struct; 13836666ed4ed2e2bc13da5ac5d0a4947019137d45beJoao Matos case TST_interface: return TTK_Interface; 1384465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TST_union: return TTK_Union; 1385465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TST_enum: return TTK_Enum; 1386465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara } 13877907fad723a0f4764a2396df620d9c58725b3053Douglas Gregor 13887907fad723a0f4764a2396df620d9c58725b3053Douglas Gregor llvm_unreachable("Type specifier is not a tag type kind."); 1389465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara} 1390465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 1391465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraElaboratedTypeKeyword 1392465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraTypeWithKeyword::getKeywordForTagTypeKind(TagTypeKind Kind) { 1393465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara switch (Kind) { 1394465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TTK_Class: return ETK_Class; 1395465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TTK_Struct: return ETK_Struct; 13966666ed4ed2e2bc13da5ac5d0a4947019137d45beJoao Matos case TTK_Interface: return ETK_Interface; 1397465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TTK_Union: return ETK_Union; 1398465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TTK_Enum: return ETK_Enum; 1399465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara } 1400465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara llvm_unreachable("Unknown tag type kind."); 1401465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara} 1402465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 1403465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraTagTypeKind 1404465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraTypeWithKeyword::getTagTypeKindForKeyword(ElaboratedTypeKeyword Keyword) { 1405465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara switch (Keyword) { 1406465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Class: return TTK_Class; 1407465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Struct: return TTK_Struct; 14086666ed4ed2e2bc13da5ac5d0a4947019137d45beJoao Matos case ETK_Interface: return TTK_Interface; 1409465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Union: return TTK_Union; 1410465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Enum: return TTK_Enum; 1411465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_None: // Fall through. 1412465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Typename: 1413465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara llvm_unreachable("Elaborated type keyword is not a tag type kind."); 1414465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara } 1415465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara llvm_unreachable("Unknown elaborated type keyword."); 1416465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara} 1417465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 1418465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnarabool 1419465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraTypeWithKeyword::KeywordIsTagTypeKind(ElaboratedTypeKeyword Keyword) { 1420465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara switch (Keyword) { 1421465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_None: 1422465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Typename: 1423465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara return false; 1424465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Class: 1425465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Struct: 14266666ed4ed2e2bc13da5ac5d0a4947019137d45beJoao Matos case ETK_Interface: 1427465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Union: 1428465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Enum: 14294033642464e8ba0982f88f34cffad808d247b393Douglas Gregor return true; 14304033642464e8ba0982f88f34cffad808d247b393Douglas Gregor } 1431465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara llvm_unreachable("Unknown elaborated type keyword."); 1432465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara} 1433465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 14346bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen HinesStringRef TypeWithKeyword::getKeywordName(ElaboratedTypeKeyword Keyword) { 1435465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara switch (Keyword) { 1436465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_None: return ""; 1437465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Typename: return "typename"; 1438465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Class: return "class"; 1439465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Struct: return "struct"; 14406666ed4ed2e2bc13da5ac5d0a4947019137d45beJoao Matos case ETK_Interface: return "__interface"; 1441465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Union: return "union"; 1442465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Enum: return "enum"; 1443465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara } 14447907fad723a0f4764a2396df620d9c58725b3053Douglas Gregor 14457907fad723a0f4764a2396df620d9c58725b3053Douglas Gregor llvm_unreachable("Unknown elaborated type keyword."); 1446465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara} 1447465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 144833500955d731c73717af52088b7fc0e7a85681e7John McCallDependentTemplateSpecializationType::DependentTemplateSpecializationType( 1449ef99001908e799c388f1363b1e607dad5f5b57d3John McCall ElaboratedTypeKeyword Keyword, 145033500955d731c73717af52088b7fc0e7a85681e7John McCall NestedNameSpecifier *NNS, const IdentifierInfo *Name, 145133500955d731c73717af52088b7fc0e7a85681e7John McCall unsigned NumArgs, const TemplateArgument *Args, 145233500955d731c73717af52088b7fc0e7a85681e7John McCall QualType Canon) 1453561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor : TypeWithKeyword(Keyword, DependentTemplateSpecialization, Canon, true, true, 1454d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /*VariablyModified=*/false, 1455aa2187de137e5b809dcbbe14f3b61ae907a3d8aaDouglas Gregor NNS && NNS->containsUnexpandedParameterPack()), 1456ef99001908e799c388f1363b1e607dad5f5b57d3John McCall NNS(NNS), Name(Name), NumArgs(NumArgs) { 1457aa2187de137e5b809dcbbe14f3b61ae907a3d8aaDouglas Gregor assert((!NNS || NNS->isDependent()) && 145833500955d731c73717af52088b7fc0e7a85681e7John McCall "DependentTemplateSpecializatonType requires dependent qualifier"); 1459d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor for (unsigned I = 0; I != NumArgs; ++I) { 1460d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor if (Args[I].containsUnexpandedParameterPack()) 1461d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor setContainsUnexpandedParameterPack(); 1462d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 146333500955d731c73717af52088b7fc0e7a85681e7John McCall new (&getArgBuffer()[I]) TemplateArgument(Args[I]); 1464d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor } 146533500955d731c73717af52088b7fc0e7a85681e7John McCall} 146633500955d731c73717af52088b7fc0e7a85681e7John McCall 146733500955d731c73717af52088b7fc0e7a85681e7John McCallvoid 146833500955d731c73717af52088b7fc0e7a85681e7John McCallDependentTemplateSpecializationType::Profile(llvm::FoldingSetNodeID &ID, 14694ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad const ASTContext &Context, 147033500955d731c73717af52088b7fc0e7a85681e7John McCall ElaboratedTypeKeyword Keyword, 147133500955d731c73717af52088b7fc0e7a85681e7John McCall NestedNameSpecifier *Qualifier, 147233500955d731c73717af52088b7fc0e7a85681e7John McCall const IdentifierInfo *Name, 147333500955d731c73717af52088b7fc0e7a85681e7John McCall unsigned NumArgs, 147433500955d731c73717af52088b7fc0e7a85681e7John McCall const TemplateArgument *Args) { 147533500955d731c73717af52088b7fc0e7a85681e7John McCall ID.AddInteger(Keyword); 147633500955d731c73717af52088b7fc0e7a85681e7John McCall ID.AddPointer(Qualifier); 147733500955d731c73717af52088b7fc0e7a85681e7John McCall ID.AddPointer(Name); 147833500955d731c73717af52088b7fc0e7a85681e7John McCall for (unsigned Idx = 0; Idx < NumArgs; ++Idx) 147933500955d731c73717af52088b7fc0e7a85681e7John McCall Args[Idx].Profile(ID, Context); 148033500955d731c73717af52088b7fc0e7a85681e7John McCall} 148133500955d731c73717af52088b7fc0e7a85681e7John McCall 1482465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnarabool Type::isElaboratedTypeSpecifier() const { 1483465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara ElaboratedTypeKeyword Keyword; 1484465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara if (const ElaboratedType *Elab = dyn_cast<ElaboratedType>(this)) 1485465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara Keyword = Elab->getKeyword(); 1486465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara else if (const DependentNameType *DepName = dyn_cast<DependentNameType>(this)) 1487465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara Keyword = DepName->getKeyword(); 148833500955d731c73717af52088b7fc0e7a85681e7John McCall else if (const DependentTemplateSpecializationType *DepTST = 148933500955d731c73717af52088b7fc0e7a85681e7John McCall dyn_cast<DependentTemplateSpecializationType>(this)) 149033500955d731c73717af52088b7fc0e7a85681e7John McCall Keyword = DepTST->getKeyword(); 1491465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara else 1492465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara return false; 1493465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 1494465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara return TypeWithKeyword::KeywordIsTagTypeKind(Keyword); 14954033642464e8ba0982f88f34cffad808d247b393Douglas Gregor} 14964033642464e8ba0982f88f34cffad808d247b393Douglas Gregor 1497cd01f17358dc8ef19338c0e2321138dd0a6160d9Argyrios Kyrtzidisconst char *Type::getTypeClassName() const { 1498b870b88df784c2940efce448ebfaf54dece14666John McCall switch (TypeBits.TC) { 1499cd01f17358dc8ef19338c0e2321138dd0a6160d9Argyrios Kyrtzidis#define ABSTRACT_TYPE(Derived, Base) 1500cd01f17358dc8ef19338c0e2321138dd0a6160d9Argyrios Kyrtzidis#define TYPE(Derived, Base) case Derived: return #Derived; 1501cd01f17358dc8ef19338c0e2321138dd0a6160d9Argyrios Kyrtzidis#include "clang/AST/TypeNodes.def" 1502cd01f17358dc8ef19338c0e2321138dd0a6160d9Argyrios Kyrtzidis } 15037907fad723a0f4764a2396df620d9c58725b3053Douglas Gregor 15047907fad723a0f4764a2396df620d9c58725b3053Douglas Gregor llvm_unreachable("Invalid type class."); 1505cd01f17358dc8ef19338c0e2321138dd0a6160d9Argyrios Kyrtzidis} 1506cd01f17358dc8ef19338c0e2321138dd0a6160d9Argyrios Kyrtzidis 150727a00970bf4ababdc115e54383e6252cc3276dfaArgyrios KyrtzidisStringRef BuiltinType::getName(const PrintingPolicy &Policy) const { 15085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer switch (getKind()) { 15095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Void: return "void"; 151030c42404202d2e2512e51efc6066bd614cfdb5a4Douglas Gregor case Bool: return Policy.Bool ? "bool" : "_Bool"; 15115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Char_S: return "char"; 15125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Char_U: return "char"; 15135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case SChar: return "signed char"; 15145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Short: return "short"; 15155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Int: return "int"; 15165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Long: return "long"; 15175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case LongLong: return "long long"; 15185a5a971908a1fd064454db44c42333a3aecf3d5bRichard Smith case Int128: return "__int128"; 15195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case UChar: return "unsigned char"; 15205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case UShort: return "unsigned short"; 15215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case UInt: return "unsigned int"; 15225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case ULong: return "unsigned long"; 15235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case ULongLong: return "unsigned long long"; 15245a5a971908a1fd064454db44c42333a3aecf3d5bRichard Smith case UInt128: return "unsigned __int128"; 1525651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines case Half: return Policy.Half ? "half" : "__fp16"; 15265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Float: return "float"; 15275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Double: return "double"; 15285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case LongDouble: return "long double"; 15293f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner case WChar_S: 153015f92bad58c8650b1306729744b1a1230197497aHans Wennborg case WChar_U: return Policy.MSWChar ? "__wchar_t" : "wchar_t"; 1531f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith case Char16: return "char16_t"; 1532f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith case Char32: return "char32_t"; 15336e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl case NullPtr: return "nullptr_t"; 15348e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor case Overload: return "<overloaded function type>"; 1535864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall case BoundMember: return "<bound member function type>"; 15363c3b7f90a863af43fa63043d396553ecf205351cJohn McCall case PseudoObject: return "<pseudo-object type>"; 1537898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor case Dependent: return "<dependent type>"; 15381de4d4e8cb2e9c88809fea8092bc6e835a5473d2John McCall case UnknownAny: return "<unknown type>"; 15390ddaeb9b031070ec64afe92d9892875ac44df427John McCall case ARCUnbridgedCast: return "<ARC unbridged cast type>"; 1540a6c66cedc022c9e5d45a937d6b8cff491a6bf81bEli Friedman case BuiltinFn: return "<builtin fn type>"; 1541de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff case ObjCId: return "id"; 1542de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff case ObjCClass: return "Class"; 1543bef0efd11bc4430a3ee437a3213cec5c18af855aChris Lattner case ObjCSel: return "SEL"; 1544b13621d08e20ac7aa550e05896de8a57ee99c1e8Guy Benyei case OCLImage1d: return "image1d_t"; 1545b13621d08e20ac7aa550e05896de8a57ee99c1e8Guy Benyei case OCLImage1dArray: return "image1d_array_t"; 1546b13621d08e20ac7aa550e05896de8a57ee99c1e8Guy Benyei case OCLImage1dBuffer: return "image1d_buffer_t"; 1547b13621d08e20ac7aa550e05896de8a57ee99c1e8Guy Benyei case OCLImage2d: return "image2d_t"; 1548b13621d08e20ac7aa550e05896de8a57ee99c1e8Guy Benyei case OCLImage2dArray: return "image2d_array_t"; 1549b13621d08e20ac7aa550e05896de8a57ee99c1e8Guy Benyei case OCLImage3d: return "image3d_t"; 155021f18c4fda167dc5f72feddbd6a7ac1b63200a0dGuy Benyei case OCLSampler: return "sampler_t"; 1551e6b9d802fb7b16d93474c4f1c179ab36202e8a8bGuy Benyei case OCLEvent: return "event_t"; 15525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 15537907fad723a0f4764a2396df620d9c58725b3053Douglas Gregor 1554aab440b2cb0e583aeaf21f08c8247456f3142a23Nick Lewycky llvm_unreachable("Invalid builtin type."); 15555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 15565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 155732b5a1e82f535d43e94332183cd330f4a39b2dbdCraig TopperQualType QualType::getNonLValueExprType(const ASTContext &Context) const { 15585291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor if (const ReferenceType *RefType = getTypePtr()->getAs<ReferenceType>()) 15595291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor return RefType->getPointeeType(); 15605291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor 15615291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor // C++0x [basic.lval]: 15625291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor // Class prvalues can have cv-qualified types; non-class prvalues always 15635291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor // have cv-unqualified types. 15645291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor // 15655291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor // See also C99 6.3.2.1p2. 15664e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie if (!Context.getLangOpts().CPlusPlus || 15676dc1ef87044e6b177d4df0d2b593a94616180b3dChandler Carruth (!getTypePtr()->isDependentType() && !getTypePtr()->isRecordType())) 15685291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor return getUnqualifiedType(); 15695291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor 15705291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor return *this; 15715291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor} 15725291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor 15735f9e272e632e951b1efe824cd16acb4d96077930Chris LattnerStringRef FunctionType::getNameForCallConv(CallingConv CC) { 157404a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall switch (CC) { 157504a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall case CC_C: return "cdecl"; 157604a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall case CC_X86StdCall: return "stdcall"; 157704a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall case CC_X86FastCall: return "fastcall"; 1578f813a2c03fcb05381b3252010435f557eb6b3cdeDouglas Gregor case CC_X86ThisCall: return "thiscall"; 157952fc314e1b5e1baee6305067cf831763d02bd243Dawn Perchik case CC_X86Pascal: return "pascal"; 1580e8519c31a6ef853b627d557702ac1890f18ce2c9Charles Davis case CC_X86_64Win64: return "ms_abi"; 1581e8519c31a6ef853b627d557702ac1890f18ce2c9Charles Davis case CC_X86_64SysV: return "sysv_abi"; 1582414d8967e1d760ea1e19a4aca96b13777a8cf8c5Anton Korobeynikov case CC_AAPCS: return "aapcs"; 1583414d8967e1d760ea1e19a4aca96b13777a8cf8c5Anton Korobeynikov case CC_AAPCS_VFP: return "aapcs-vfp"; 1584263366f9241366f29ba65b703120f302490c39ffDerek Schuff case CC_PnaclCall: return "pnaclcall"; 158538980086c0f791e8c23cc882574f18e5b4a87db6Guy Benyei case CC_IntelOclBicc: return "intel_ocl_bicc"; 158604a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall } 15877907fad723a0f4764a2396df620d9c58725b3053Douglas Gregor 15887907fad723a0f4764a2396df620d9c58725b3053Douglas Gregor llvm_unreachable("Invalid calling convention."); 158904a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall} 159004a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall 1591651f13cea278ec967336033dd032faef0e9fc2ecStephen HinesFunctionProtoType::FunctionProtoType(QualType result, ArrayRef<QualType> params, 1592bea522ff43a3f11c7a2bc7949119dbb9fce19e39Jordan Rose QualType canonical, 15938026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redl const ExtProtoInfo &epi) 1594651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines : FunctionType(FunctionProto, result, epi.TypeQuals, canonical, 1595651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines result->isDependentType(), 1596651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines result->isInstantiationDependentType(), 1597651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines result->isVariablyModifiedType(), 1598651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines result->containsUnexpandedParameterPack(), epi.ExtInfo), 1599651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines NumParams(params.size()), NumExceptions(epi.NumExceptions), 1600651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines ExceptionSpecType(epi.ExceptionSpecType), 16016bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines HasAnyConsumedParams(epi.ConsumedParameters != nullptr), 16026bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines Variadic(epi.Variadic), HasTrailingReturn(epi.HasTrailingReturn), 16036bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines RefQualifier(epi.RefQualifier) { 1604651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines assert(NumParams == params.size() && "function has too many parameters"); 1605aa46d513f47280a9786e8e9aa77f7089b3f8fee6Richard Smith 160635495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor // Fill in the trailing argument array. 1607e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall QualType *argSlot = reinterpret_cast<QualType*>(this+1); 1608651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines for (unsigned i = 0; i != NumParams; ++i) { 1609651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines if (params[i]->isDependentType()) 161035495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor setDependent(); 1611651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines else if (params[i]->isInstantiationDependentType()) 1612561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor setInstantiationDependent(); 1613651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 1614651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines if (params[i]->containsUnexpandedParameterPack()) 1615d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor setContainsUnexpandedParameterPack(); 1616d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 1617651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines argSlot[i] = params[i]; 161835495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor } 1619e186269a8a41dbff1ebea2c251048892979d1078Douglas Gregor 162060618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl if (getExceptionSpecType() == EST_Dynamic) { 162160618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl // Fill in the exception array. 1622651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines QualType *exnSlot = argSlot + NumParams; 162360618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl for (unsigned i = 0, e = epi.NumExceptions; i != e; ++i) { 162460618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl if (epi.Exceptions[i]->isDependentType()) 162560618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl setDependent(); 1626561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor else if (epi.Exceptions[i]->isInstantiationDependentType()) 1627561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor setInstantiationDependent(); 1628561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor 162960618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl if (epi.Exceptions[i]->containsUnexpandedParameterPack()) 163060618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl setContainsUnexpandedParameterPack(); 163160618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl 163260618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl exnSlot[i] = epi.Exceptions[i]; 163360618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl } 163460618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl } else if (getExceptionSpecType() == EST_ComputedNoexcept) { 163560618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl // Store the noexcept expression and context. 1636651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines Expr **noexSlot = reinterpret_cast<Expr **>(argSlot + NumParams); 163760618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl *noexSlot = epi.NoexceptExpr; 1638561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor 1639561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (epi.NoexceptExpr) { 1640561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (epi.NoexceptExpr->isValueDependent() 1641561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor || epi.NoexceptExpr->isTypeDependent()) 1642561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor setDependent(); 1643561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor else if (epi.NoexceptExpr->isInstantiationDependent()) 1644561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor setInstantiationDependent(); 1645561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor } 1646e6975e9b0985ad7f7ff9187e38d95bfe9ac4181bRichard Smith } else if (getExceptionSpecType() == EST_Uninstantiated) { 1647e6975e9b0985ad7f7ff9187e38d95bfe9ac4181bRichard Smith // Store the function decl from which we will resolve our 1648e6975e9b0985ad7f7ff9187e38d95bfe9ac4181bRichard Smith // exception specification. 1649651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines FunctionDecl **slot = 1650651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines reinterpret_cast<FunctionDecl **>(argSlot + NumParams); 165113bffc532bafd45d4a77867993c1afb83c7661beRichard Smith slot[0] = epi.ExceptionSpecDecl; 165213bffc532bafd45d4a77867993c1afb83c7661beRichard Smith slot[1] = epi.ExceptionSpecTemplate; 1653e6975e9b0985ad7f7ff9187e38d95bfe9ac4181bRichard Smith // This exception specification doesn't make the type dependent, because 1654e6975e9b0985ad7f7ff9187e38d95bfe9ac4181bRichard Smith // it's not instantiated as part of instantiating the type. 1655b9d0b76e42fd2d4cdfd135220302458d03ad09feRichard Smith } else if (getExceptionSpecType() == EST_Unevaluated) { 1656b9d0b76e42fd2d4cdfd135220302458d03ad09feRichard Smith // Store the function decl from which we will resolve our 1657b9d0b76e42fd2d4cdfd135220302458d03ad09feRichard Smith // exception specification. 1658651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines FunctionDecl **slot = 1659651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines reinterpret_cast<FunctionDecl **>(argSlot + NumParams); 1660b9d0b76e42fd2d4cdfd135220302458d03ad09feRichard Smith slot[0] = epi.ExceptionSpecDecl; 1661e186269a8a41dbff1ebea2c251048892979d1078Douglas Gregor } 1662f85e193739c953358c865005855253af4f68a497John McCall 1663651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines if (epi.ConsumedParameters) { 1664651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines bool *consumedParams = const_cast<bool *>(getConsumedParamsBuffer()); 1665651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines for (unsigned i = 0; i != NumParams; ++i) 1666651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines consumedParams[i] = epi.ConsumedParameters[i]; 1667f85e193739c953358c865005855253af4f68a497John McCall } 166835495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor} 166935495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor 167060618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian RedlFunctionProtoType::NoexceptResult 167132b5a1e82f535d43e94332183cd330f4a39b2dbdCraig TopperFunctionProtoType::getNoexceptSpec(const ASTContext &ctx) const { 167260618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl ExceptionSpecificationType est = getExceptionSpecType(); 167360618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl if (est == EST_BasicNoexcept) 167460618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl return NR_Nothrow; 167560618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl 167660618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl if (est != EST_ComputedNoexcept) 167760618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl return NR_NoNoexcept; 167860618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl 167960618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl Expr *noexceptExpr = getNoexceptExpr(); 168060618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl if (!noexceptExpr) 168160618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl return NR_BadNoexcept; 168260618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl if (noexceptExpr->isValueDependent()) 168360618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl return NR_Dependent; 168460618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl 168560618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl llvm::APSInt value; 16866bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines bool isICE = noexceptExpr->isIntegerConstantExpr(value, ctx, nullptr, 168760618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl /*evaluated*/false); 168860618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl (void)isICE; 168960618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl assert(isICE && "AST should not contain bad noexcept expressions."); 169060618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl 169160618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl return value.getBoolValue() ? NR_Nothrow : NR_Throw; 169260618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl} 169360618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl 1694651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinesbool FunctionProtoType::isNothrow(const ASTContext &Ctx, 1695651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines bool ResultIfDependent) const { 1696651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines ExceptionSpecificationType EST = getExceptionSpecType(); 1697651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines assert(EST != EST_Unevaluated && EST != EST_Uninstantiated); 1698651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines if (EST == EST_DynamicNone || EST == EST_BasicNoexcept) 1699651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines return true; 1700651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 1701651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines if (EST == EST_Dynamic && ResultIfDependent == true) { 1702651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines // A dynamic exception specification is throwing unless every exception 1703651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines // type is an (unexpanded) pack expansion type. 1704651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines for (unsigned I = 0, N = NumExceptions; I != N; ++I) 1705651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines if (!getExceptionType(I)->getAs<PackExpansionType>()) 1706651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines return false; 1707651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines return ResultIfDependent; 1708651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines } 1709651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 1710651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines if (EST != EST_ComputedNoexcept) 1711651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines return false; 1712651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 1713651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines NoexceptResult NR = getNoexceptSpec(Ctx); 1714651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines if (NR == NR_Dependent) 1715651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines return ResultIfDependent; 1716651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines return NR == NR_Nothrow; 1717651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines} 1718651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 1719f5c65ffbd7374b6c8d9f1e361041578640cab320Douglas Gregorbool FunctionProtoType::isTemplateVariadic() const { 1720651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines for (unsigned ArgIdx = getNumParams(); ArgIdx; --ArgIdx) 1721651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines if (isa<PackExpansionType>(getParamType(ArgIdx - 1))) 17227d5c0c1273bdc1cb3dff1cb5a62d07b1439e82c7Douglas Gregor return true; 17237d5c0c1273bdc1cb3dff1cb5a62d07b1439e82c7Douglas Gregor 17247d5c0c1273bdc1cb3dff1cb5a62d07b1439e82c7Douglas Gregor return false; 1725f5c65ffbd7374b6c8d9f1e361041578640cab320Douglas Gregor} 172635495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor 172772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregorvoid FunctionProtoType::Profile(llvm::FoldingSetNodeID &ID, QualType Result, 1728651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines const QualType *ArgTys, unsigned NumParams, 172960618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl const ExtProtoInfo &epi, 17308026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redl const ASTContext &Context) { 1731f85e193739c953358c865005855253af4f68a497John McCall 1732f85e193739c953358c865005855253af4f68a497John McCall // We have to be careful not to get ambiguous profile encodings. 1733f85e193739c953358c865005855253af4f68a497John McCall // Note that valid type pointers are never ambiguous with anything else. 1734f85e193739c953358c865005855253af4f68a497John McCall // 1735f85e193739c953358c865005855253af4f68a497John McCall // The encoding grammar begins: 1736f85e193739c953358c865005855253af4f68a497John McCall // type type* bool int bool 1737f85e193739c953358c865005855253af4f68a497John McCall // If that final bool is true, then there is a section for the EH spec: 1738f85e193739c953358c865005855253af4f68a497John McCall // bool type* 1739f85e193739c953358c865005855253af4f68a497John McCall // This is followed by an optional "consumed argument" section of the 1740f85e193739c953358c865005855253af4f68a497John McCall // same length as the first type sequence: 1741f85e193739c953358c865005855253af4f68a497John McCall // bool* 1742eefb3d5b49c844347f212073a7e975b8118fe8e9Richard Smith // Finally, we have the ext info and trailing return type flag: 1743eefb3d5b49c844347f212073a7e975b8118fe8e9Richard Smith // int bool 1744f85e193739c953358c865005855253af4f68a497John McCall // 1745f85e193739c953358c865005855253af4f68a497John McCall // There is no ambiguity between the consumed arguments and an empty EH 1746f85e193739c953358c865005855253af4f68a497John McCall // spec because of the leading 'bool' which unambiguously indicates 1747f85e193739c953358c865005855253af4f68a497John McCall // whether the following bool is the EH spec or part of the arguments. 1748f85e193739c953358c865005855253af4f68a497John McCall 17495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddPointer(Result.getAsOpaquePtr()); 1750651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines for (unsigned i = 0; i != NumParams; ++i) 17515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddPointer(ArgTys[i].getAsOpaquePtr()); 17520c051221bd06fe1b24b9459292584e5264a131c5Eli Friedman // This method is relatively performance sensitive, so as a performance 17530c051221bd06fe1b24b9459292584e5264a131c5Eli Friedman // shortcut, use one AddInteger call instead of four for the next four 17540c051221bd06fe1b24b9459292584e5264a131c5Eli Friedman // fields. 17550c051221bd06fe1b24b9459292584e5264a131c5Eli Friedman assert(!(unsigned(epi.Variadic) & ~1) && 17560c051221bd06fe1b24b9459292584e5264a131c5Eli Friedman !(unsigned(epi.TypeQuals) & ~255) && 17570c051221bd06fe1b24b9459292584e5264a131c5Eli Friedman !(unsigned(epi.RefQualifier) & ~3) && 17580c051221bd06fe1b24b9459292584e5264a131c5Eli Friedman !(unsigned(epi.ExceptionSpecType) & ~7) && 17590c051221bd06fe1b24b9459292584e5264a131c5Eli Friedman "Values larger than expected."); 17600c051221bd06fe1b24b9459292584e5264a131c5Eli Friedman ID.AddInteger(unsigned(epi.Variadic) + 17610c051221bd06fe1b24b9459292584e5264a131c5Eli Friedman (epi.TypeQuals << 1) + 17620c051221bd06fe1b24b9459292584e5264a131c5Eli Friedman (epi.RefQualifier << 9) + 17630c051221bd06fe1b24b9459292584e5264a131c5Eli Friedman (epi.ExceptionSpecType << 11)); 176460618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl if (epi.ExceptionSpecType == EST_Dynamic) { 1765e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall for (unsigned i = 0; i != epi.NumExceptions; ++i) 1766e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall ID.AddPointer(epi.Exceptions[i].getAsOpaquePtr()); 176760618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl } else if (epi.ExceptionSpecType == EST_ComputedNoexcept && epi.NoexceptExpr){ 17681abd35950bcb0761887dca0995c68b8a9dc8916fDouglas Gregor epi.NoexceptExpr->Profile(ID, Context, false); 1769b9d0b76e42fd2d4cdfd135220302458d03ad09feRichard Smith } else if (epi.ExceptionSpecType == EST_Uninstantiated || 1770b9d0b76e42fd2d4cdfd135220302458d03ad09feRichard Smith epi.ExceptionSpecType == EST_Unevaluated) { 1771e6975e9b0985ad7f7ff9187e38d95bfe9ac4181bRichard Smith ID.AddPointer(epi.ExceptionSpecDecl->getCanonicalDecl()); 1772465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl } 1773651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines if (epi.ConsumedParameters) { 1774651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines for (unsigned i = 0; i != NumParams; ++i) 1775651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines ID.AddBoolean(epi.ConsumedParameters[i]); 1776f85e193739c953358c865005855253af4f68a497John McCall } 1777e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall epi.ExtInfo.Profile(ID); 1778eefb3d5b49c844347f212073a7e975b8118fe8e9Richard Smith ID.AddBoolean(epi.HasTrailingReturn); 17795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 17805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 17818026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redlvoid FunctionProtoType::Profile(llvm::FoldingSetNodeID &ID, 17828026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redl const ASTContext &Ctx) { 1783651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines Profile(ID, getReturnType(), param_type_begin(), NumParams, getExtProtoInfo(), 17848026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redl Ctx); 17855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 17865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1787bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCallQualType TypedefType::desugar() const { 1788bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall return getDecl()->getUnderlyingType(); 1789bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall} 1790bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 179172564e73277e29f6db3305d1f27ba408abb7ed88Douglas GregorTypeOfExprType::TypeOfExprType(Expr *E, QualType can) 179235495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor : Type(TypeOfExpr, can, E->isTypeDependent(), 1793561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor E->isInstantiationDependent(), 1794d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor E->getType()->isVariablyModifiedType(), 1795d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor E->containsUnexpandedParameterPack()), 1796d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor TOExpr(E) { 1797898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor} 1798898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 17996af9f3ca25157379efd5c1caad82e9d01c17b9ffDouglas Gregorbool TypeOfExprType::isSugared() const { 18006af9f3ca25157379efd5c1caad82e9d01c17b9ffDouglas Gregor return !TOExpr->isTypeDependent(); 18016af9f3ca25157379efd5c1caad82e9d01c17b9ffDouglas Gregor} 18026af9f3ca25157379efd5c1caad82e9d01c17b9ffDouglas Gregor 1803bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCallQualType TypeOfExprType::desugar() const { 1804c910d4cfa5042f2c9da1eb4e0b6ed59240c0eeeeReid Kleckner if (isSugared()) 1805c910d4cfa5042f2c9da1eb4e0b6ed59240c0eeeeReid Kleckner return getUnderlyingExpr()->getType(); 18066af9f3ca25157379efd5c1caad82e9d01c17b9ffDouglas Gregor 18076af9f3ca25157379efd5c1caad82e9d01c17b9ffDouglas Gregor return QualType(this, 0); 1808bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall} 1809bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 18101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpvoid DependentTypeOfExprType::Profile(llvm::FoldingSetNodeID &ID, 18114ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad const ASTContext &Context, Expr *E) { 1812b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor E->Profile(ID, Context, true); 1813b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor} 1814b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor 1815563a03b1338d31c2462def43253a722bc885d384Anders CarlssonDecltypeType::DecltypeType(Expr *E, QualType underlyingType, QualType can) 1816fa16125aaf667c2bd80efcea403a7a71aa65da14Richard Smith // C++11 [temp.type]p2: "If an expression e involves a template parameter, 1817fa16125aaf667c2bd80efcea403a7a71aa65da14Richard Smith // decltype(e) denotes a unique dependent type." Hence a decltype type is 1818fa16125aaf667c2bd80efcea403a7a71aa65da14Richard Smith // type-dependent even if its expression is only instantiation-dependent. 1819fa16125aaf667c2bd80efcea403a7a71aa65da14Richard Smith : Type(Decltype, can, E->isInstantiationDependent(), 1820561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor E->isInstantiationDependent(), 1821d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor E->getType()->isVariablyModifiedType(), 1822d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor E->containsUnexpandedParameterPack()), 1823d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor E(E), 1824563a03b1338d31c2462def43253a722bc885d384Anders Carlsson UnderlyingType(underlyingType) { 1825395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson} 1826395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson 18276af9f3ca25157379efd5c1caad82e9d01c17b9ffDouglas Gregorbool DecltypeType::isSugared() const { return !E->isInstantiationDependent(); } 18286af9f3ca25157379efd5c1caad82e9d01c17b9ffDouglas Gregor 18296af9f3ca25157379efd5c1caad82e9d01c17b9ffDouglas GregorQualType DecltypeType::desugar() const { 18306af9f3ca25157379efd5c1caad82e9d01c17b9ffDouglas Gregor if (isSugared()) 18316af9f3ca25157379efd5c1caad82e9d01c17b9ffDouglas Gregor return getUnderlyingType(); 18326af9f3ca25157379efd5c1caad82e9d01c17b9ffDouglas Gregor 18336af9f3ca25157379efd5c1caad82e9d01c17b9ffDouglas Gregor return QualType(this, 0); 18346af9f3ca25157379efd5c1caad82e9d01c17b9ffDouglas Gregor} 18356af9f3ca25157379efd5c1caad82e9d01c17b9ffDouglas Gregor 18364ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadDependentDecltypeType::DependentDecltypeType(const ASTContext &Context, Expr *E) 18379d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor : DecltypeType(E, Context.DependentTy), Context(Context) { } 18389d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor 18391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpvoid DependentDecltypeType::Profile(llvm::FoldingSetNodeID &ID, 18404ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad const ASTContext &Context, Expr *E) { 18419d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor E->Profile(ID, Context, true); 18429d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor} 18439d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor 184419c8576b7328f4dc2d07682f5da552875c1912efJohn McCallTagType::TagType(TypeClass TC, const TagDecl *D, QualType can) 1845561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor : Type(TC, can, D->isDependentType(), 1846561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /*InstantiationDependent=*/D->isDependentType(), 1847561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /*VariablyModified=*/false, 1848d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /*ContainsUnexpandedParameterPack=*/false), 1849ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl decl(const_cast<TagDecl*>(D)) {} 1850ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl 1851ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redlstatic TagDecl *getInterestingTagDecl(TagDecl *decl) { 1852651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines for (auto I : decl->redecls()) { 18535e1cdac63c3d9c9b32fa41fa0b2d242a58a20d49John McCall if (I->isCompleteDefinition() || I->isBeingDefined()) 1854651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines return I; 1855ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl } 1856ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl // If there's no definition (not even in progress), return what we have. 1857ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl return decl; 1858ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl} 1859ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl 1860ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean HuntUnaryTransformType::UnaryTransformType(QualType BaseType, 1861ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt QualType UnderlyingType, 1862ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt UTTKind UKind, 1863ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt QualType CanonicalType) 1864ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt : Type(UnaryTransform, CanonicalType, UnderlyingType->isDependentType(), 1865561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor UnderlyingType->isInstantiationDependentType(), 1866ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt UnderlyingType->isVariablyModifiedType(), 1867ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt BaseType->containsUnexpandedParameterPack()) 1868ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt , BaseType(BaseType), UnderlyingType(UnderlyingType), UKind(UKind) 1869ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt{} 1870ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt 1871ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian RedlTagDecl *TagType::getDecl() const { 1872ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl return getInterestingTagDecl(decl); 1873ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl} 1874ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl 1875ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redlbool TagType::isBeingDefined() const { 1876ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl return getDecl()->isBeingDefined(); 18775b92696c8f1f8ef943ad87397b95c031b5787305Reid Kleckner} 18785b92696c8f1f8ef943ad87397b95c031b5787305Reid Kleckner 18795b92696c8f1f8ef943ad87397b95c031b5787305Reid Klecknerbool AttributedType::isMSTypeSpec() const { 18805b92696c8f1f8ef943ad87397b95c031b5787305Reid Kleckner switch (getAttrKind()) { 18815b92696c8f1f8ef943ad87397b95c031b5787305Reid Kleckner default: return false; 18825b92696c8f1f8ef943ad87397b95c031b5787305Reid Kleckner case attr_ptr32: 18835b92696c8f1f8ef943ad87397b95c031b5787305Reid Kleckner case attr_ptr64: 18845b92696c8f1f8ef943ad87397b95c031b5787305Reid Kleckner case attr_sptr: 18855b92696c8f1f8ef943ad87397b95c031b5787305Reid Kleckner case attr_uptr: 18865b92696c8f1f8ef943ad87397b95c031b5787305Reid Kleckner return true; 18875b92696c8f1f8ef943ad87397b95c031b5787305Reid Kleckner } 18885b92696c8f1f8ef943ad87397b95c031b5787305Reid Kleckner llvm_unreachable("invalid attr kind"); 18895b92696c8f1f8ef943ad87397b95c031b5787305Reid Kleckner} 18905b92696c8f1f8ef943ad87397b95c031b5787305Reid Kleckner 18915b92696c8f1f8ef943ad87397b95c031b5787305Reid Klecknerbool AttributedType::isCallingConv() const { 18925b92696c8f1f8ef943ad87397b95c031b5787305Reid Kleckner switch (getAttrKind()) { 18935b92696c8f1f8ef943ad87397b95c031b5787305Reid Kleckner case attr_ptr32: 18945b92696c8f1f8ef943ad87397b95c031b5787305Reid Kleckner case attr_ptr64: 18955b92696c8f1f8ef943ad87397b95c031b5787305Reid Kleckner case attr_sptr: 18965b92696c8f1f8ef943ad87397b95c031b5787305Reid Kleckner case attr_uptr: 18975b92696c8f1f8ef943ad87397b95c031b5787305Reid Kleckner case attr_address_space: 18985b92696c8f1f8ef943ad87397b95c031b5787305Reid Kleckner case attr_regparm: 18995b92696c8f1f8ef943ad87397b95c031b5787305Reid Kleckner case attr_vector_size: 19005b92696c8f1f8ef943ad87397b95c031b5787305Reid Kleckner case attr_neon_vector_type: 19015b92696c8f1f8ef943ad87397b95c031b5787305Reid Kleckner case attr_neon_polyvector_type: 19025b92696c8f1f8ef943ad87397b95c031b5787305Reid Kleckner case attr_objc_gc: 19035b92696c8f1f8ef943ad87397b95c031b5787305Reid Kleckner case attr_objc_ownership: 19045b92696c8f1f8ef943ad87397b95c031b5787305Reid Kleckner case attr_noreturn: 19055b92696c8f1f8ef943ad87397b95c031b5787305Reid Kleckner return false; 19065b92696c8f1f8ef943ad87397b95c031b5787305Reid Kleckner case attr_pcs: 19075b92696c8f1f8ef943ad87397b95c031b5787305Reid Kleckner case attr_pcs_vfp: 19085b92696c8f1f8ef943ad87397b95c031b5787305Reid Kleckner case attr_cdecl: 19095b92696c8f1f8ef943ad87397b95c031b5787305Reid Kleckner case attr_fastcall: 19105b92696c8f1f8ef943ad87397b95c031b5787305Reid Kleckner case attr_stdcall: 19115b92696c8f1f8ef943ad87397b95c031b5787305Reid Kleckner case attr_thiscall: 19125b92696c8f1f8ef943ad87397b95c031b5787305Reid Kleckner case attr_pascal: 1913e8519c31a6ef853b627d557702ac1890f18ce2c9Charles Davis case attr_ms_abi: 1914e8519c31a6ef853b627d557702ac1890f18ce2c9Charles Davis case attr_sysv_abi: 19155b92696c8f1f8ef943ad87397b95c031b5787305Reid Kleckner case attr_pnaclcall: 19165b92696c8f1f8ef943ad87397b95c031b5787305Reid Kleckner case attr_inteloclbicc: 19175b92696c8f1f8ef943ad87397b95c031b5787305Reid Kleckner return true; 19185b92696c8f1f8ef943ad87397b95c031b5787305Reid Kleckner } 19195b92696c8f1f8ef943ad87397b95c031b5787305Reid Kleckner llvm_unreachable("invalid attr kind"); 1920ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl} 1921ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl 1922ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian RedlCXXRecordDecl *InjectedClassNameType::getDecl() const { 1923ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl return cast<CXXRecordDecl>(getInterestingTagDecl(Decl)); 1924ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl} 19257da97d0f31e1ec16998d3de2cfd2e88fe3736673Douglas Gregor 1926b7efff4bae117604f442bb6859c844f90b15f3ffChandler CarruthIdentifierInfo *TemplateTypeParmType::getIdentifier() const { 19276bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines return isCanonicalUnqualified() ? nullptr : getDecl()->getIdentifier(); 19284fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth} 19294fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth 1930c3069d618f4661d923cb1b5c4525b082fce73b04Douglas GregorSubstTemplateTypeParmPackType:: 1931c3069d618f4661d923cb1b5c4525b082fce73b04Douglas GregorSubstTemplateTypeParmPackType(const TemplateTypeParmType *Param, 1932c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor QualType Canon, 1933c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor const TemplateArgument &ArgPack) 1934561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor : Type(SubstTemplateTypeParmPack, Canon, true, true, false, true), 1935561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor Replaced(Param), 1936c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor Arguments(ArgPack.pack_begin()), NumArguments(ArgPack.pack_size()) 1937c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor{ 1938c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor} 1939c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor 1940c3069d618f4661d923cb1b5c4525b082fce73b04Douglas GregorTemplateArgument SubstTemplateTypeParmPackType::getArgumentPack() const { 1941c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor return TemplateArgument(Arguments, NumArguments); 1942c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor} 1943c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor 1944c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregorvoid SubstTemplateTypeParmPackType::Profile(llvm::FoldingSetNodeID &ID) { 1945c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor Profile(ID, getReplacedParameter(), getArgumentPack()); 1946c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor} 1947c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor 1948c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregorvoid SubstTemplateTypeParmPackType::Profile(llvm::FoldingSetNodeID &ID, 1949c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor const TemplateTypeParmType *Replaced, 1950c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor const TemplateArgument &ArgPack) { 1951c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor ID.AddPointer(Replaced); 1952c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor ID.AddInteger(ArgPack.pack_size()); 1953c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor for (TemplateArgument::pack_iterator P = ArgPack.pack_begin(), 1954c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor PEnd = ArgPack.pack_end(); 1955c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor P != PEnd; ++P) 1956c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor ID.AddPointer(P->getAsType().getAsOpaquePtr()); 1957c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor} 1958c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor 1959833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallbool TemplateSpecializationType:: 1960561f81243f665cf2001caadc45df505f826b72d6Douglas GregoranyDependentTemplateArguments(const TemplateArgumentListInfo &Args, 1961561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor bool &InstantiationDependent) { 1962561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor return anyDependentTemplateArguments(Args.getArgumentArray(), Args.size(), 1963561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor InstantiationDependent); 1964d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall} 1965d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall 1966d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCallbool TemplateSpecializationType:: 1967561f81243f665cf2001caadc45df505f826b72d6Douglas GregoranyDependentTemplateArguments(const TemplateArgumentLoc *Args, unsigned N, 1968561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor bool &InstantiationDependent) { 1969561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor for (unsigned i = 0; i != N; ++i) { 1970561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (Args[i].getArgument().isDependent()) { 1971561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor InstantiationDependent = true; 1972833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return true; 1973561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor } 1974561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor 1975561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (Args[i].getArgument().isInstantiationDependent()) 1976561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor InstantiationDependent = true; 1977561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor } 1978833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return false; 1979833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall} 1980833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 19810a598fd7e428b5eb28b67770a66f3976ac365e42Eli Friedman#ifndef NDEBUG 19820a598fd7e428b5eb28b67770a66f3976ac365e42Eli Friedmanstatic bool 1983561f81243f665cf2001caadc45df505f826b72d6Douglas GregoranyDependentTemplateArguments(const TemplateArgument *Args, unsigned N, 1984561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor bool &InstantiationDependent) { 1985561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor for (unsigned i = 0; i != N; ++i) { 1986561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (Args[i].isDependent()) { 1987561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor InstantiationDependent = true; 1988833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return true; 1989561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor } 1990561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor 1991561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (Args[i].isInstantiationDependent()) 1992561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor InstantiationDependent = true; 1993561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor } 1994833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return false; 1995833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall} 19960a598fd7e428b5eb28b67770a66f3976ac365e42Eli Friedman#endif 1997833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 19987532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas GregorTemplateSpecializationType:: 1999ef99001908e799c388f1363b1e607dad5f5b57d3John McCallTemplateSpecializationType(TemplateName T, 20003e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith const TemplateArgument *Args, unsigned NumArgs, 20013e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith QualType Canon, QualType AliasedType) 20021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : Type(TemplateSpecialization, 200340808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor Canon.isNull()? QualType(this, 0) : Canon, 20043e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith Canon.isNull()? T.isDependent() : Canon->isDependentType(), 2005561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor Canon.isNull()? T.isDependent() 2006561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor : Canon->isInstantiationDependentType(), 2007c0536c8294fc4453f0f1d1cf24a62bfc725fd492Richard Smith false, 2008d8672ef2d343a0dbfe838724fb2d9fb4efea6041Richard Smith T.containsUnexpandedParameterPack()), 2009b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor Template(T), NumArgs(NumArgs), TypeAlias(!AliasedType.isNull()) { 2010a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor assert(!T.getAsDependentTemplateName() && 2011a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor "Use DependentTemplateSpecializationType for dependent template-name"); 20121901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall assert((T.getKind() == TemplateName::Template || 2013146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall T.getKind() == TemplateName::SubstTemplateTemplateParm || 20141901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall T.getKind() == TemplateName::SubstTemplateTemplateParmPack) && 20151901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall "Unexpected template name for TemplateSpecializationType"); 2016561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor bool InstantiationDependent; 2017561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (void)InstantiationDependent; 20181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump assert((!Canon.isNull() || 2019561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor T.isDependent() || 20200a598fd7e428b5eb28b67770a66f3976ac365e42Eli Friedman ::anyDependentTemplateArguments(Args, NumArgs, 20210a598fd7e428b5eb28b67770a66f3976ac365e42Eli Friedman InstantiationDependent)) && 202240808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor "No canonical type for non-dependent class template specialization"); 202355f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 20241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TemplateArgument *TemplateArgs 202540808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor = reinterpret_cast<TemplateArgument *>(this + 1); 202635495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor for (unsigned Arg = 0; Arg < NumArgs; ++Arg) { 202735495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor // Update dependent and variably-modified bits. 20283e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith // If the canonical type exists and is non-dependent, the template 20293e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith // specialization type can be non-dependent even if one of the type 20303e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith // arguments is. Given: 20313e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith // template<typename T> using U = int; 20323e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith // U<T> is always non-dependent, irrespective of the type T. 2033d8672ef2d343a0dbfe838724fb2d9fb4efea6041Richard Smith // However, U<Ts> contains an unexpanded parameter pack, even though 2034d8672ef2d343a0dbfe838724fb2d9fb4efea6041Richard Smith // its expansion (and thus its desugared type) doesn't. 20353e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith if (Canon.isNull() && Args[Arg].isDependent()) 203635495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor setDependent(); 2037561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor else if (Args[Arg].isInstantiationDependent()) 2038561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor setInstantiationDependent(); 2039561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor 204035495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor if (Args[Arg].getKind() == TemplateArgument::Type && 204135495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor Args[Arg].getAsType()->isVariablyModifiedType()) 204235495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor setVariablyModified(); 2043d8672ef2d343a0dbfe838724fb2d9fb4efea6041Richard Smith if (Args[Arg].containsUnexpandedParameterPack()) 2044d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor setContainsUnexpandedParameterPack(); 2045d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 204640808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor new (&TemplateArgs[Arg]) TemplateArgument(Args[Arg]); 204735495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor } 20483e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith 20493e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith // Store the aliased type if this is a type alias template specialization. 2050b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor if (TypeAlias) { 20513e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith TemplateArgument *Begin = reinterpret_cast<TemplateArgument *>(this + 1); 20523e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith *reinterpret_cast<QualType*>(Begin + getNumArgs()) = AliasedType; 20533e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith } 205455f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor} 205555f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 20561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpvoid 20571eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTemplateSpecializationType::Profile(llvm::FoldingSetNodeID &ID, 20581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TemplateName T, 20591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const TemplateArgument *Args, 2060828e226ab7ed08b3eb766549e9d3306432137460Douglas Gregor unsigned NumArgs, 20614ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad const ASTContext &Context) { 20627532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor T.Profile(ID); 206340808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor for (unsigned Idx = 0; Idx < NumArgs; ++Idx) 2064828e226ab7ed08b3eb766549e9d3306432137460Douglas Gregor Args[Idx].Profile(ID, Context); 206555f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor} 206697e0179f1ae545e07d9f5e7c1d2ef5c5bab06676Anders Carlsson 20674ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualType 20684ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualifierCollector::apply(const ASTContext &Context, QualType QT) const { 20690953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (!hasNonFastQualifiers()) 20700953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return QT.withFastQualifiers(getFastQualifiers()); 20711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 207249f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall return Context.getQualifiedType(QT, *this); 20735e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor} 20745e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor 20754ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualType 20764ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualifierCollector::apply(const ASTContext &Context, const Type *T) const { 20770953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (!hasNonFastQualifiers()) 20780953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return QualType(T, getFastQualifiers()); 20790953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 208049f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall return Context.getQualifiedType(T, *this); 20815e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor} 20825e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor 2083c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallvoid ObjCObjectTypeImpl::Profile(llvm::FoldingSetNodeID &ID, 2084c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall QualType BaseType, 2085c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCProtocolDecl * const *Protocols, 2086c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall unsigned NumProtocols) { 2087c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ID.AddPointer(BaseType.getAsOpaquePtr()); 2088c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff for (unsigned i = 0; i != NumProtocols; i++) 2089c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ID.AddPointer(Protocols[i]); 2090c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff} 2091c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff 2092c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallvoid ObjCObjectTypeImpl::Profile(llvm::FoldingSetNodeID &ID) { 2093c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall Profile(ID, getBaseType(), qual_begin(), getNumProtocols()); 2094c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff} 20950b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 2096b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCallnamespace { 20971fb0caaa7bef765b85972274e3b434af2572c141John McCall 2098b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall/// \brief The cached properties of a type. 2099b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCallclass CachedProperties { 2100a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola Linkage L; 2101b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall bool local; 21022beda12c3fbaa9125831b7f818680978c596b205Rafael Espindola 2103b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCallpublic: 2104a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola CachedProperties(Linkage L, bool local) : L(L), local(local) {} 21052beda12c3fbaa9125831b7f818680978c596b205Rafael Espindola 2106a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola Linkage getLinkage() const { return L; } 2107b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall bool hasLocalOrUnnamedType() const { return local; } 21082beda12c3fbaa9125831b7f818680978c596b205Rafael Espindola 2109b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall friend CachedProperties merge(CachedProperties L, CachedProperties R) { 2110a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola Linkage MergedLinkage = minLinkage(L.L, R.L); 2111a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola return CachedProperties(MergedLinkage, 2112b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall L.hasLocalOrUnnamedType() | R.hasLocalOrUnnamedType()); 2113b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall } 2114b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall}; 21151fb0caaa7bef765b85972274e3b434af2572c141John McCall} 21161fb0caaa7bef765b85972274e3b434af2572c141John McCall 2117b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCallstatic CachedProperties computeCachedProperties(const Type *T); 21180b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 2119b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCallnamespace clang { 2120b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall/// The type-property cache. This is templated so as to be 2121b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall/// instantiated at an internal type to prevent unnecessary symbol 2122b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall/// leakage. 2123b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCalltemplate <class Private> class TypePropertyCache { 2124b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCallpublic: 2125b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall static CachedProperties get(QualType T) { 2126b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return get(T.getTypePtr()); 2127b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall } 21281fb0caaa7bef765b85972274e3b434af2572c141John McCall 2129b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall static CachedProperties get(const Type *T) { 2130b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall ensure(T); 2131a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola return CachedProperties(T->TypeBits.getLinkage(), 2132a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola T->TypeBits.hasLocalOrUnnamedType()); 2133b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall } 2134db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor 2135b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall static void ensure(const Type *T) { 2136b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall // If the cache is valid, we're okay. 2137b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall if (T->TypeBits.isCacheValid()) return; 2138b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall 2139b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall // If this type is non-canonical, ask its canonical type for the 2140b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall // relevant information. 21413b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (!T->isCanonicalUnqualified()) { 21423b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall const Type *CT = T->getCanonicalTypeInternal().getTypePtr(); 2143b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall ensure(CT); 2144a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola T->TypeBits.CacheValid = true; 2145b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall T->TypeBits.CachedLinkage = CT->TypeBits.CachedLinkage; 2146b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall T->TypeBits.CachedLocalOrUnnamed = CT->TypeBits.CachedLocalOrUnnamed; 2147b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return; 2148b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall } 21491fb0caaa7bef765b85972274e3b434af2572c141John McCall 2150b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall // Compute the cached properties and then set the cache. 2151b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall CachedProperties Result = computeCachedProperties(T); 2152a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola T->TypeBits.CacheValid = true; 2153b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall T->TypeBits.CachedLinkage = Result.getLinkage(); 2154b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall T->TypeBits.CachedLocalOrUnnamed = Result.hasLocalOrUnnamedType(); 2155b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall } 2156b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall}; 21571fb0caaa7bef765b85972274e3b434af2572c141John McCall} 21581fb0caaa7bef765b85972274e3b434af2572c141John McCall 2159b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall// Instantiate the friend template at a private class. In a 2160b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall// reasonable implementation, these symbols will be internal. 2161b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall// It is terrible that this is the best way to accomplish this. 2162b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCallnamespace { class Private {}; } 2163b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCalltypedef TypePropertyCache<Private> Cache; 21641fb0caaa7bef765b85972274e3b434af2572c141John McCall 2165b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCallstatic CachedProperties computeCachedProperties(const Type *T) { 2166b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall switch (T->getTypeClass()) { 2167b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall#define TYPE(Class,Base) 2168b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall#define NON_CANONICAL_TYPE(Class,Base) case Type::Class: 2169b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall#include "clang/AST/TypeNodes.def" 2170b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall llvm_unreachable("didn't expect a non-canonical type here"); 217160e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor 2172b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall#define TYPE(Class,Base) 2173b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall#define DEPENDENT_TYPE(Class,Base) case Type::Class: 2174b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall#define NON_CANONICAL_UNLESS_DEPENDENT_TYPE(Class,Base) case Type::Class: 2175b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall#include "clang/AST/TypeNodes.def" 21765e78cd43a033b3dedf741fca4fa1652f9cb3e41cDouglas Gregor // Treat instantiation-dependent types as external. 21775e78cd43a033b3dedf741fca4fa1652f9cb3e41cDouglas Gregor assert(T->isInstantiationDependentType()); 2178a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola return CachedProperties(ExternalLinkage, false); 21791fb0caaa7bef765b85972274e3b434af2572c141John McCall 2180dc7a4f5d7a7e3b60d4dc4a80338d7a2728540998Richard Smith case Type::Auto: 2181dc7a4f5d7a7e3b60d4dc4a80338d7a2728540998Richard Smith // Give non-deduced 'auto' types external linkage. We should only see them 2182dc7a4f5d7a7e3b60d4dc4a80338d7a2728540998Richard Smith // here in error recovery. 2183dc7a4f5d7a7e3b60d4dc4a80338d7a2728540998Richard Smith return CachedProperties(ExternalLinkage, false); 2184dc7a4f5d7a7e3b60d4dc4a80338d7a2728540998Richard Smith 2185b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::Builtin: 2186b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall // C++ [basic.link]p8: 2187b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall // A type is said to have linkage if and only if: 2188b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall // - it is a fundamental type (3.9.1); or 2189a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola return CachedProperties(ExternalLinkage, false); 21900b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 2191b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::Record: 2192b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::Enum: { 2193b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall const TagDecl *Tag = cast<TagType>(T)->getDecl(); 2194b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall 2195b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall // C++ [basic.link]p8: 2196b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall // - it is a class or enumeration type that is named (or has a name 2197b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall // for linkage purposes (7.1.3)) and the name has linkage; or 2198b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall // - it is a specialization of a class template (14); or 2199181e3ecc0907ae0103586a9f4db52241995a8267Rafael Espindola Linkage L = Tag->getLinkageInternal(); 2200b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall bool IsLocalOrUnnamed = 2201b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall Tag->getDeclContext()->isFunctionOrMethod() || 220283972f128e9218c051692bf96361327a701aeb79John McCall !Tag->hasNameForLinkage(); 2203a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola return CachedProperties(L, IsLocalOrUnnamed); 2204b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall } 22050b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 2206b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall // C++ [basic.link]p8: 2207b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall // - it is a compound type (3.9.2) other than a class or enumeration, 2208b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall // compounded exclusively from types that have linkage; or 2209b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::Complex: 2210b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return Cache::get(cast<ComplexType>(T)->getElementType()); 2211b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::Pointer: 2212b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return Cache::get(cast<PointerType>(T)->getPointeeType()); 2213b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::BlockPointer: 2214b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return Cache::get(cast<BlockPointerType>(T)->getPointeeType()); 2215b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::LValueReference: 2216b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::RValueReference: 2217b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return Cache::get(cast<ReferenceType>(T)->getPointeeType()); 2218b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::MemberPointer: { 2219b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall const MemberPointerType *MPT = cast<MemberPointerType>(T); 2220b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return merge(Cache::get(MPT->getClass()), 2221b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall Cache::get(MPT->getPointeeType())); 2222b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall } 2223b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::ConstantArray: 2224b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::IncompleteArray: 2225b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::VariableArray: 2226b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return Cache::get(cast<ArrayType>(T)->getElementType()); 2227b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::Vector: 2228b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::ExtVector: 2229b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return Cache::get(cast<VectorType>(T)->getElementType()); 2230b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::FunctionNoProto: 2231651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines return Cache::get(cast<FunctionType>(T)->getReturnType()); 2232b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::FunctionProto: { 2233b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall const FunctionProtoType *FPT = cast<FunctionProtoType>(T); 2234651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines CachedProperties result = Cache::get(FPT->getReturnType()); 2235651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines for (const auto &ai : FPT->param_types()) 2236651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines result = merge(result, Cache::get(ai)); 2237b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return result; 2238b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall } 2239b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::ObjCInterface: { 2240181e3ecc0907ae0103586a9f4db52241995a8267Rafael Espindola Linkage L = cast<ObjCInterfaceType>(T)->getDecl()->getLinkageInternal(); 2241a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola return CachedProperties(L, false); 2242b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall } 2243b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::ObjCObject: 2244b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return Cache::get(cast<ObjCObjectType>(T)->getBaseType()); 2245b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::ObjCObjectPointer: 2246b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return Cache::get(cast<ObjCObjectPointerType>(T)->getPointeeType()); 2247b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman case Type::Atomic: 2248b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman return Cache::get(cast<AtomicType>(T)->getValueType()); 2249b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall } 22500b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 2251b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall llvm_unreachable("unhandled type class"); 22520b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor} 22530b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 2254b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall/// \brief Determine the linkage of this type. 2255b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCallLinkage Type::getLinkage() const { 2256b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall Cache::ensure(this); 2257b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return TypeBits.getLinkage(); 22580b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor} 22590b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 2260b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCallbool Type::hasUnnamedOrLocalType() const { 2261b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall Cache::ensure(this); 2262b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return TypeBits.hasLocalOrUnnamedType(); 22630b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor} 22640b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 2265a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindolastatic LinkageInfo computeLinkageInfo(QualType T); 2266a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola 2267a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindolastatic LinkageInfo computeLinkageInfo(const Type *T) { 2268a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola switch (T->getTypeClass()) { 2269a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola#define TYPE(Class,Base) 2270a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola#define NON_CANONICAL_TYPE(Class,Base) case Type::Class: 2271a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola#include "clang/AST/TypeNodes.def" 2272a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola llvm_unreachable("didn't expect a non-canonical type here"); 2273a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola 2274a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola#define TYPE(Class,Base) 2275a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola#define DEPENDENT_TYPE(Class,Base) case Type::Class: 2276a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola#define NON_CANONICAL_UNLESS_DEPENDENT_TYPE(Class,Base) case Type::Class: 2277a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola#include "clang/AST/TypeNodes.def" 2278a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola // Treat instantiation-dependent types as external. 2279a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola assert(T->isInstantiationDependentType()); 2280a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola return LinkageInfo::external(); 2281a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola 2282a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola case Type::Builtin: 2283a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola return LinkageInfo::external(); 2284a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola 2285dc7a4f5d7a7e3b60d4dc4a80338d7a2728540998Richard Smith case Type::Auto: 2286dc7a4f5d7a7e3b60d4dc4a80338d7a2728540998Richard Smith return LinkageInfo::external(); 2287dc7a4f5d7a7e3b60d4dc4a80338d7a2728540998Richard Smith 2288a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola case Type::Record: 2289a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola case Type::Enum: 2290a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola return cast<TagType>(T)->getDecl()->getLinkageAndVisibility(); 2291a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola 2292a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola case Type::Complex: 2293a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola return computeLinkageInfo(cast<ComplexType>(T)->getElementType()); 2294a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola case Type::Pointer: 2295a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola return computeLinkageInfo(cast<PointerType>(T)->getPointeeType()); 2296a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola case Type::BlockPointer: 2297a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola return computeLinkageInfo(cast<BlockPointerType>(T)->getPointeeType()); 2298a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola case Type::LValueReference: 2299a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola case Type::RValueReference: 2300a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola return computeLinkageInfo(cast<ReferenceType>(T)->getPointeeType()); 2301a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola case Type::MemberPointer: { 2302a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola const MemberPointerType *MPT = cast<MemberPointerType>(T); 2303a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola LinkageInfo LV = computeLinkageInfo(MPT->getClass()); 2304a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola LV.merge(computeLinkageInfo(MPT->getPointeeType())); 2305a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola return LV; 2306a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola } 2307a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola case Type::ConstantArray: 2308a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola case Type::IncompleteArray: 2309a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola case Type::VariableArray: 2310a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola return computeLinkageInfo(cast<ArrayType>(T)->getElementType()); 2311a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola case Type::Vector: 2312a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola case Type::ExtVector: 2313a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola return computeLinkageInfo(cast<VectorType>(T)->getElementType()); 2314a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola case Type::FunctionNoProto: 2315651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines return computeLinkageInfo(cast<FunctionType>(T)->getReturnType()); 2316a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola case Type::FunctionProto: { 2317a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola const FunctionProtoType *FPT = cast<FunctionProtoType>(T); 2318651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines LinkageInfo LV = computeLinkageInfo(FPT->getReturnType()); 2319651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines for (const auto &ai : FPT->param_types()) 2320651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines LV.merge(computeLinkageInfo(ai)); 2321a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola return LV; 2322a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola } 2323a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola case Type::ObjCInterface: 2324a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola return cast<ObjCInterfaceType>(T)->getDecl()->getLinkageAndVisibility(); 2325a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola case Type::ObjCObject: 2326a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola return computeLinkageInfo(cast<ObjCObjectType>(T)->getBaseType()); 2327a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola case Type::ObjCObjectPointer: 2328a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola return computeLinkageInfo(cast<ObjCObjectPointerType>(T)->getPointeeType()); 2329a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola case Type::Atomic: 2330a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola return computeLinkageInfo(cast<AtomicType>(T)->getValueType()); 2331a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola } 2332a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola 2333a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola llvm_unreachable("unhandled type class"); 2334a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola} 2335a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola 2336a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindolastatic LinkageInfo computeLinkageInfo(QualType T) { 2337a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola return computeLinkageInfo(T.getTypePtr()); 2338a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola} 2339a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola 23402d1b09641ecf2e754bf3fd244dc45dbf3e460c1bRafael Espindolabool Type::isLinkageValid() const { 23412d1b09641ecf2e754bf3fd244dc45dbf3e460c1bRafael Espindola if (!TypeBits.isCacheValid()) 23422d1b09641ecf2e754bf3fd244dc45dbf3e460c1bRafael Espindola return true; 23432d1b09641ecf2e754bf3fd244dc45dbf3e460c1bRafael Espindola 23442d1b09641ecf2e754bf3fd244dc45dbf3e460c1bRafael Espindola return computeLinkageInfo(getCanonicalTypeInternal()).getLinkage() == 23452d1b09641ecf2e754bf3fd244dc45dbf3e460c1bRafael Espindola TypeBits.getLinkage(); 23462d1b09641ecf2e754bf3fd244dc45dbf3e460c1bRafael Espindola} 23472d1b09641ecf2e754bf3fd244dc45dbf3e460c1bRafael Espindola 234818895dc4fd29f0071eeb591be820338f16407906Rafael EspindolaLinkageInfo Type::getLinkageAndVisibility() const { 2349a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola if (!isCanonicalUnqualified()) 2350a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola return computeLinkageInfo(getCanonicalTypeInternal()); 2351a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola 2352a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola LinkageInfo LV = computeLinkageInfo(this); 2353a2bb8923334ecd35b8f914dff7d105330abbad22Rafael Espindola assert(LV.getLinkage() == getLinkage()); 235418895dc4fd29f0071eeb591be820338f16407906Rafael Espindola return LV; 23550b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor} 23560b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 2357f85e193739c953358c865005855253af4f68a497John McCallQualifiers::ObjCLifetime Type::getObjCARCImplicitLifetime() const { 2358f85e193739c953358c865005855253af4f68a497John McCall if (isObjCARCImplicitlyUnretainedType()) 2359f85e193739c953358c865005855253af4f68a497John McCall return Qualifiers::OCL_ExplicitNone; 2360f85e193739c953358c865005855253af4f68a497John McCall return Qualifiers::OCL_Strong; 2361f85e193739c953358c865005855253af4f68a497John McCall} 2362f85e193739c953358c865005855253af4f68a497John McCall 2363f85e193739c953358c865005855253af4f68a497John McCallbool Type::isObjCARCImplicitlyUnretainedType() const { 2364f85e193739c953358c865005855253af4f68a497John McCall assert(isObjCLifetimeType() && 2365f85e193739c953358c865005855253af4f68a497John McCall "cannot query implicit lifetime for non-inferrable type"); 2366f85e193739c953358c865005855253af4f68a497John McCall 2367f85e193739c953358c865005855253af4f68a497John McCall const Type *canon = getCanonicalTypeInternal().getTypePtr(); 2368f85e193739c953358c865005855253af4f68a497John McCall 2369f85e193739c953358c865005855253af4f68a497John McCall // Walk down to the base type. We don't care about qualifiers for this. 2370f85e193739c953358c865005855253af4f68a497John McCall while (const ArrayType *array = dyn_cast<ArrayType>(canon)) 2371f85e193739c953358c865005855253af4f68a497John McCall canon = array->getElementType().getTypePtr(); 2372f85e193739c953358c865005855253af4f68a497John McCall 2373f85e193739c953358c865005855253af4f68a497John McCall if (const ObjCObjectPointerType *opt 2374f85e193739c953358c865005855253af4f68a497John McCall = dyn_cast<ObjCObjectPointerType>(canon)) { 2375f85e193739c953358c865005855253af4f68a497John McCall // Class and Class<Protocol> don't require retension. 2376f85e193739c953358c865005855253af4f68a497John McCall if (opt->getObjectType()->isObjCClass()) 2377f85e193739c953358c865005855253af4f68a497John McCall return true; 2378f85e193739c953358c865005855253af4f68a497John McCall } 2379f85e193739c953358c865005855253af4f68a497John McCall 2380f85e193739c953358c865005855253af4f68a497John McCall return false; 2381f85e193739c953358c865005855253af4f68a497John McCall} 2382f85e193739c953358c865005855253af4f68a497John McCall 2383f85e193739c953358c865005855253af4f68a497John McCallbool Type::isObjCNSObjectType() const { 2384f85e193739c953358c865005855253af4f68a497John McCall if (const TypedefType *typedefType = dyn_cast<TypedefType>(this)) 2385f85e193739c953358c865005855253af4f68a497John McCall return typedefType->getDecl()->hasAttr<ObjCNSObjectAttr>(); 2386f85e193739c953358c865005855253af4f68a497John McCall return false; 2387f85e193739c953358c865005855253af4f68a497John McCall} 2388f85e193739c953358c865005855253af4f68a497John McCallbool Type::isObjCRetainableType() const { 2389f85e193739c953358c865005855253af4f68a497John McCall return isObjCObjectPointerType() || 2390f85e193739c953358c865005855253af4f68a497John McCall isBlockPointerType() || 2391f85e193739c953358c865005855253af4f68a497John McCall isObjCNSObjectType(); 2392f85e193739c953358c865005855253af4f68a497John McCall} 2393f85e193739c953358c865005855253af4f68a497John McCallbool Type::isObjCIndirectLifetimeType() const { 2394f85e193739c953358c865005855253af4f68a497John McCall if (isObjCLifetimeType()) 2395f85e193739c953358c865005855253af4f68a497John McCall return true; 2396f85e193739c953358c865005855253af4f68a497John McCall if (const PointerType *OPT = getAs<PointerType>()) 2397f85e193739c953358c865005855253af4f68a497John McCall return OPT->getPointeeType()->isObjCIndirectLifetimeType(); 2398f85e193739c953358c865005855253af4f68a497John McCall if (const ReferenceType *Ref = getAs<ReferenceType>()) 2399f85e193739c953358c865005855253af4f68a497John McCall return Ref->getPointeeType()->isObjCIndirectLifetimeType(); 2400f85e193739c953358c865005855253af4f68a497John McCall if (const MemberPointerType *MemPtr = getAs<MemberPointerType>()) 2401f85e193739c953358c865005855253af4f68a497John McCall return MemPtr->getPointeeType()->isObjCIndirectLifetimeType(); 2402f85e193739c953358c865005855253af4f68a497John McCall return false; 2403f85e193739c953358c865005855253af4f68a497John McCall} 2404f85e193739c953358c865005855253af4f68a497John McCall 2405f85e193739c953358c865005855253af4f68a497John McCall/// Returns true if objects of this type have lifetime semantics under 2406f85e193739c953358c865005855253af4f68a497John McCall/// ARC. 2407f85e193739c953358c865005855253af4f68a497John McCallbool Type::isObjCLifetimeType() const { 2408f85e193739c953358c865005855253af4f68a497John McCall const Type *type = this; 2409f85e193739c953358c865005855253af4f68a497John McCall while (const ArrayType *array = type->getAsArrayTypeUnsafe()) 2410f85e193739c953358c865005855253af4f68a497John McCall type = array->getElementType().getTypePtr(); 2411f85e193739c953358c865005855253af4f68a497John McCall return type->isObjCRetainableType(); 2412f85e193739c953358c865005855253af4f68a497John McCall} 2413f85e193739c953358c865005855253af4f68a497John McCall 2414f85e193739c953358c865005855253af4f68a497John McCall/// \brief Determine whether the given type T is a "bridgable" Objective-C type, 2415f85e193739c953358c865005855253af4f68a497John McCall/// which is either an Objective-C object pointer type or an 2416f85e193739c953358c865005855253af4f68a497John McCallbool Type::isObjCARCBridgableType() const { 2417f85e193739c953358c865005855253af4f68a497John McCall return isObjCObjectPointerType() || isBlockPointerType(); 2418f85e193739c953358c865005855253af4f68a497John McCall} 2419f85e193739c953358c865005855253af4f68a497John McCall 2420f85e193739c953358c865005855253af4f68a497John McCall/// \brief Determine whether the given type T is a "bridgeable" C type. 2421f85e193739c953358c865005855253af4f68a497John McCallbool Type::isCARCBridgableType() const { 2422f85e193739c953358c865005855253af4f68a497John McCall const PointerType *Pointer = getAs<PointerType>(); 2423f85e193739c953358c865005855253af4f68a497John McCall if (!Pointer) 2424f85e193739c953358c865005855253af4f68a497John McCall return false; 2425f85e193739c953358c865005855253af4f68a497John McCall 2426f85e193739c953358c865005855253af4f68a497John McCall QualType Pointee = Pointer->getPointeeType(); 2427f85e193739c953358c865005855253af4f68a497John McCall return Pointee->isVoidType() || Pointee->isRecordType(); 2428f85e193739c953358c865005855253af4f68a497John McCall} 2429f85e193739c953358c865005855253af4f68a497John McCall 24303b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallbool Type::hasSizedVLAType() const { 24313b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (!isVariablyModifiedType()) return false; 24323b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 24333b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (const PointerType *ptr = getAs<PointerType>()) 24343b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return ptr->getPointeeType()->hasSizedVLAType(); 24353b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (const ReferenceType *ref = getAs<ReferenceType>()) 24363b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return ref->getPointeeType()->hasSizedVLAType(); 24373b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (const ArrayType *arr = getAsArrayTypeUnsafe()) { 24383b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (isa<VariableArrayType>(arr) && 24393b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall cast<VariableArrayType>(arr)->getSizeExpr()) 24403b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return true; 24413b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 24423b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return arr->getElementType()->hasSizedVLAType(); 24433b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall } 24443b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 24453b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return false; 24463b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall} 24470d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall 24480d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCallQualType::DestructionKind QualType::isDestructedTypeImpl(QualType type) { 2449f85e193739c953358c865005855253af4f68a497John McCall switch (type.getObjCLifetime()) { 2450f85e193739c953358c865005855253af4f68a497John McCall case Qualifiers::OCL_None: 2451f85e193739c953358c865005855253af4f68a497John McCall case Qualifiers::OCL_ExplicitNone: 2452f85e193739c953358c865005855253af4f68a497John McCall case Qualifiers::OCL_Autoreleasing: 2453f85e193739c953358c865005855253af4f68a497John McCall break; 2454f85e193739c953358c865005855253af4f68a497John McCall 2455f85e193739c953358c865005855253af4f68a497John McCall case Qualifiers::OCL_Strong: 2456f85e193739c953358c865005855253af4f68a497John McCall return DK_objc_strong_lifetime; 2457f85e193739c953358c865005855253af4f68a497John McCall case Qualifiers::OCL_Weak: 2458f85e193739c953358c865005855253af4f68a497John McCall return DK_objc_weak_lifetime; 2459f85e193739c953358c865005855253af4f68a497John McCall } 2460f85e193739c953358c865005855253af4f68a497John McCall 24610d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall /// Currently, the only destruction kind we recognize is C++ objects 24620d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall /// with non-trivial destructors. 24630d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall const CXXRecordDecl *record = 24640d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall type->getBaseElementTypeUnsafe()->getAsCXXRecordDecl(); 246591873b72bf01b7170f80154f3118300ff2eacd34Eli Friedman if (record && record->hasDefinition() && !record->hasTrivialDestructor()) 24660d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall return DK_cxx_destructor; 24670d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall 24680d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall return DK_none; 24690d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall} 2470651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 2471651f13cea278ec967336033dd032faef0e9fc2ecStephen HinesCXXRecordDecl *MemberPointerType::getMostRecentCXXRecordDecl() const { 2472651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines return getClass()->getAsCXXRecordDecl()->getMostRecentDecl(); 2473651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines} 2474