Type.cpp revision 18895dc4fd29f0071eeb591be820338f16407906
15f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===--- Type.cpp - Type representation and manipulation ------------------===// 25f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 35f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// The LLVM Compiler Infrastructure 45f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 50bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// This file is distributed under the University of Illinois Open Source 60bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// License. See LICENSE.TXT for details. 75f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 85f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 95f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// This file implements type-related functionality. 115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 14b381aac9bae6d608c72267dd0ed08ec6369e94e4Nuno Lopes#include "clang/AST/ASTContext.h" 152fa67efeaf66a9332c30a026dc1c21bef6c33a6cBenjamin Kramer#include "clang/AST/Attr.h" 162767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor#include "clang/AST/CharUnits.h" 1749aa7ff1245abd03e6e998e01302df31e4c6f8f6Argyrios Kyrtzidis#include "clang/AST/DeclCXX.h" 18980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff#include "clang/AST/DeclObjC.h" 19aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor#include "clang/AST/DeclTemplate.h" 205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "clang/AST/Expr.h" 21d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor#include "clang/AST/PrettyPrinter.h" 222fa67efeaf66a9332c30a026dc1c21bef6c33a6cBenjamin Kramer#include "clang/AST/Type.h" 23b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall#include "clang/AST/TypeVisitor.h" 24465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara#include "clang/Basic/Specifiers.h" 2560618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl#include "llvm/ADT/APSInt.h" 265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "llvm/ADT/StringExtras.h" 27bad351822117eaf280081494e3dbe4a06c0dbfcfDouglas Gregor#include "llvm/Support/raw_ostream.h" 282767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor#include <algorithm> 295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing namespace clang; 305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 31769d0cc72b1831785596d0e76f327bdb887823beDouglas Gregorbool Qualifiers::isStrictSupersetOf(Qualifiers Other) const { 32769d0cc72b1831785596d0e76f327bdb887823beDouglas Gregor return (*this != Other) && 33769d0cc72b1831785596d0e76f327bdb887823beDouglas Gregor // CVR qualifiers superset 34769d0cc72b1831785596d0e76f327bdb887823beDouglas Gregor (((Mask & CVRMask) | (Other.Mask & CVRMask)) == (Mask & CVRMask)) && 35769d0cc72b1831785596d0e76f327bdb887823beDouglas Gregor // ObjC GC qualifiers superset 36769d0cc72b1831785596d0e76f327bdb887823beDouglas Gregor ((getObjCGCAttr() == Other.getObjCGCAttr()) || 37769d0cc72b1831785596d0e76f327bdb887823beDouglas Gregor (hasObjCGCAttr() && !Other.hasObjCGCAttr())) && 38769d0cc72b1831785596d0e76f327bdb887823beDouglas Gregor // Address space superset. 39769d0cc72b1831785596d0e76f327bdb887823beDouglas Gregor ((getAddressSpace() == Other.getAddressSpace()) || 40f85e193739c953358c865005855253af4f68a497John McCall (hasAddressSpace()&& !Other.hasAddressSpace())) && 41f85e193739c953358c865005855253af4f68a497John McCall // Lifetime qualifier superset. 42f85e193739c953358c865005855253af4f68a497John McCall ((getObjCLifetime() == Other.getObjCLifetime()) || 43f85e193739c953358c865005855253af4f68a497John McCall (hasObjCLifetime() && !Other.hasObjCLifetime())); 44769d0cc72b1831785596d0e76f327bdb887823beDouglas Gregor} 45769d0cc72b1831785596d0e76f327bdb887823beDouglas Gregor 464d9d157afb35742bc6348defbe45bc6de780ec77Kaelyn Uhrainconst IdentifierInfo* QualType::getBaseTypeIdentifier() const { 474d9d157afb35742bc6348defbe45bc6de780ec77Kaelyn Uhrain const Type* ty = getTypePtr(); 484d9d157afb35742bc6348defbe45bc6de780ec77Kaelyn Uhrain NamedDecl *ND = NULL; 494d9d157afb35742bc6348defbe45bc6de780ec77Kaelyn Uhrain if (ty->isPointerType() || ty->isReferenceType()) 504d9d157afb35742bc6348defbe45bc6de780ec77Kaelyn Uhrain return ty->getPointeeType().getBaseTypeIdentifier(); 514d9d157afb35742bc6348defbe45bc6de780ec77Kaelyn Uhrain else if (ty->isRecordType()) 524d9d157afb35742bc6348defbe45bc6de780ec77Kaelyn Uhrain ND = ty->getAs<RecordType>()->getDecl(); 534d9d157afb35742bc6348defbe45bc6de780ec77Kaelyn Uhrain else if (ty->isEnumeralType()) 544d9d157afb35742bc6348defbe45bc6de780ec77Kaelyn Uhrain ND = ty->getAs<EnumType>()->getDecl(); 554d9d157afb35742bc6348defbe45bc6de780ec77Kaelyn Uhrain else if (ty->getTypeClass() == Type::Typedef) 564d9d157afb35742bc6348defbe45bc6de780ec77Kaelyn Uhrain ND = ty->getAs<TypedefType>()->getDecl(); 574d9d157afb35742bc6348defbe45bc6de780ec77Kaelyn Uhrain else if (ty->isArrayType()) 584d9d157afb35742bc6348defbe45bc6de780ec77Kaelyn Uhrain return ty->castAsArrayTypeUnsafe()-> 594d9d157afb35742bc6348defbe45bc6de780ec77Kaelyn Uhrain getElementType().getBaseTypeIdentifier(); 604d9d157afb35742bc6348defbe45bc6de780ec77Kaelyn Uhrain 614d9d157afb35742bc6348defbe45bc6de780ec77Kaelyn Uhrain if (ND) 624d9d157afb35742bc6348defbe45bc6de780ec77Kaelyn Uhrain return ND->getIdentifier(); 634d9d157afb35742bc6348defbe45bc6de780ec77Kaelyn Uhrain return NULL; 644d9d157afb35742bc6348defbe45bc6de780ec77Kaelyn Uhrain} 654d9d157afb35742bc6348defbe45bc6de780ec77Kaelyn Uhrain 66bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCallbool QualType::isConstant(QualType T, ASTContext &Ctx) { 67bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall if (T.isConstQualified()) 68b381aac9bae6d608c72267dd0ed08ec6369e94e4Nuno Lopes return true; 69b381aac9bae6d608c72267dd0ed08ec6369e94e4Nuno Lopes 70bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall if (const ArrayType *AT = Ctx.getAsArrayType(T)) 71bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall return AT->getElementType().isConstant(Ctx); 72b381aac9bae6d608c72267dd0ed08ec6369e94e4Nuno Lopes 73b381aac9bae6d608c72267dd0ed08ec6369e94e4Nuno Lopes return false; 74b381aac9bae6d608c72267dd0ed08ec6369e94e4Nuno Lopes} 75b381aac9bae6d608c72267dd0ed08ec6369e94e4Nuno Lopes 762767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregorunsigned ConstantArrayType::getNumAddressingBits(ASTContext &Context, 772767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor QualType ElementType, 782767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor const llvm::APInt &NumElements) { 792767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor llvm::APSInt SizeExtended(NumElements, true); 802767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor unsigned SizeTypeBits = Context.getTypeSize(Context.getSizeType()); 819f71a8f4c7a182a5236da9e747d57cc1d1bd24c2Jay Foad SizeExtended = SizeExtended.extend(std::max(SizeTypeBits, 829f71a8f4c7a182a5236da9e747d57cc1d1bd24c2Jay Foad SizeExtended.getBitWidth()) * 2); 832767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor 842767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor uint64_t ElementSize 852767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor = Context.getTypeSizeInChars(ElementType).getQuantity(); 862767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor llvm::APSInt TotalSize(llvm::APInt(SizeExtended.getBitWidth(), ElementSize)); 872767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor TotalSize *= SizeExtended; 882767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor 892767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor return TotalSize.getActiveBits(); 902767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor} 912767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor 922767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregorunsigned ConstantArrayType::getMaxSizeBits(ASTContext &Context) { 932767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor unsigned Bits = Context.getTypeSize(Context.getSizeType()); 942767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor 952767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor // GCC appears to only allow 63 bits worth of address space when compiling 962767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor // for 64-bit, so we do the same. 972767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor if (Bits == 64) 982767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor --Bits; 992767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor 1002767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor return Bits; 1012767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor} 1022767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor 1034ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadDependentSizedArrayType::DependentSizedArrayType(const ASTContext &Context, 104d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor QualType et, QualType can, 105d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor Expr *e, ArraySizeModifier sm, 106d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor unsigned tq, 107d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor SourceRange brackets) 108d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor : ArrayType(DependentSizedArray, et, can, sm, tq, 109d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor (et->containsUnexpandedParameterPack() || 110d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor (e && e->containsUnexpandedParameterPack()))), 111d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor Context(Context), SizeExpr((Stmt*) e), Brackets(brackets) 112d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor{ 113d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor} 114d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 1151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpvoid DependentSizedArrayType::Profile(llvm::FoldingSetNodeID &ID, 1164ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad const ASTContext &Context, 11704d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor QualType ET, 11804d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor ArraySizeModifier SizeMod, 11904d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor unsigned TypeQuals, 12004d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor Expr *E) { 12104d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor ID.AddPointer(ET.getAsOpaquePtr()); 12204d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor ID.AddInteger(SizeMod); 12304d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor ID.AddInteger(TypeQuals); 12404d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor E->Profile(ID, Context, true); 12504d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor} 12604d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor 1274ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadDependentSizedExtVectorType::DependentSizedExtVectorType(const 1284ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad ASTContext &Context, 129d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor QualType ElementType, 130d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor QualType can, 131d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor Expr *SizeExpr, 132d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor SourceLocation loc) 133d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor : Type(DependentSizedExtVector, can, /*Dependent=*/true, 134561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /*InstantiationDependent=*/true, 135d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor ElementType->isVariablyModifiedType(), 136d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor (ElementType->containsUnexpandedParameterPack() || 137d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor (SizeExpr && SizeExpr->containsUnexpandedParameterPack()))), 138d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor Context(Context), SizeExpr(SizeExpr), ElementType(ElementType), 139d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor loc(loc) 140d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor{ 141d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor} 142d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 1431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpvoid 1441eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpDependentSizedExtVectorType::Profile(llvm::FoldingSetNodeID &ID, 1454ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad const ASTContext &Context, 1462ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor QualType ElementType, Expr *SizeExpr) { 1472ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor ID.AddPointer(ElementType.getAsOpaquePtr()); 1482ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor SizeExpr->Profile(ID, Context, true); 1492ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor} 1502ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor 151d0937224f383c7cc72c947119380f9713a070c73Douglas GregorVectorType::VectorType(QualType vecType, unsigned nElements, QualType canonType, 152d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor VectorKind vecKind) 153d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor : Type(Vector, canonType, vecType->isDependentType(), 154561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor vecType->isInstantiationDependentType(), 155d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor vecType->isVariablyModifiedType(), 156d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor vecType->containsUnexpandedParameterPack()), 157d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor ElementType(vecType) 158d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor{ 159d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor VectorTypeBits.VecKind = vecKind; 160d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor VectorTypeBits.NumElements = nElements; 161d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor} 162d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 163d0937224f383c7cc72c947119380f9713a070c73Douglas GregorVectorType::VectorType(TypeClass tc, QualType vecType, unsigned nElements, 164d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor QualType canonType, VectorKind vecKind) 165d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor : Type(tc, canonType, vecType->isDependentType(), 166561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor vecType->isInstantiationDependentType(), 167d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor vecType->isVariablyModifiedType(), 168d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor vecType->containsUnexpandedParameterPack()), 169d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor ElementType(vecType) 170d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor{ 171d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor VectorTypeBits.VecKind = vecKind; 172d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor VectorTypeBits.NumElements = nElements; 173d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor} 174d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 175c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner/// getArrayElementTypeNoTypeQual - If this is an array type, return the 176c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner/// element type of the array, potentially with type qualifiers missing. 177c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner/// This method should never be used when type qualifiers are meaningful. 178c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattnerconst Type *Type::getArrayElementTypeNoTypeQual() const { 179c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // If this is directly an array type, return it. 180c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner if (const ArrayType *ATy = dyn_cast<ArrayType>(this)) 181c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return ATy->getElementType().getTypePtr(); 1821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 183c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // If the canonical form of this type isn't the right kind, reject it. 1840953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (!isa<ArrayType>(CanonicalType)) 185c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return 0; 1861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 187c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // If this is a typedef for an array type, strip the typedef off without 188c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // losing all typedef information. 189bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall return cast<ArrayType>(getUnqualifiedDesugaredType()) 190bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall ->getElementType().getTypePtr(); 1912fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner} 1922fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner 1932fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner/// getDesugaredType - Return the specified type with any "sugar" removed from 1942fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner/// the type. This takes off typedefs, typeof's etc. If the outer level of 1952fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner/// the type is already concrete, it returns it unmodified. This is similar 1962fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner/// to getting the canonical type, but it doesn't remove *all* typedefs. For 1972fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner/// example, it returns "T*" as "T*", (not as "int*"), because the pointer is 1982fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner/// concrete. 1994ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualType QualType::getDesugaredType(QualType T, const ASTContext &Context) { 20049f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall SplitQualType split = getSplitDesugaredType(T); 201200fa53fd420aa8369586f569dbece04930ad6a3John McCall return Context.getQualifiedType(split.Ty, split.Quals); 20249f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall} 20349f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall 204200fa53fd420aa8369586f569dbece04930ad6a3John McCallQualType QualType::getSingleStepDesugaredTypeImpl(QualType type, 205200fa53fd420aa8369586f569dbece04930ad6a3John McCall const ASTContext &Context) { 206200fa53fd420aa8369586f569dbece04930ad6a3John McCall SplitQualType split = type.split(); 207200fa53fd420aa8369586f569dbece04930ad6a3John McCall QualType desugar = split.Ty->getLocallyUnqualifiedSingleStepDesugaredType(); 208200fa53fd420aa8369586f569dbece04930ad6a3John McCall return Context.getQualifiedType(desugar, split.Quals); 209200fa53fd420aa8369586f569dbece04930ad6a3John McCall} 210200fa53fd420aa8369586f569dbece04930ad6a3John McCall 211200fa53fd420aa8369586f569dbece04930ad6a3John McCallQualType Type::getLocallyUnqualifiedSingleStepDesugaredType() const { 212200fa53fd420aa8369586f569dbece04930ad6a3John McCall switch (getTypeClass()) { 213f1588660c109610e6a79c786b83b7c9bbd6ed31eDouglas Gregor#define ABSTRACT_TYPE(Class, Parent) 214f1588660c109610e6a79c786b83b7c9bbd6ed31eDouglas Gregor#define TYPE(Class, Parent) \ 215f1588660c109610e6a79c786b83b7c9bbd6ed31eDouglas Gregor case Type::Class: { \ 216200fa53fd420aa8369586f569dbece04930ad6a3John McCall const Class##Type *ty = cast<Class##Type>(this); \ 217200fa53fd420aa8369586f569dbece04930ad6a3John McCall if (!ty->isSugared()) return QualType(ty, 0); \ 218200fa53fd420aa8369586f569dbece04930ad6a3John McCall return ty->desugar(); \ 219f1588660c109610e6a79c786b83b7c9bbd6ed31eDouglas Gregor } 220f1588660c109610e6a79c786b83b7c9bbd6ed31eDouglas Gregor#include "clang/AST/TypeNodes.def" 221f1588660c109610e6a79c786b83b7c9bbd6ed31eDouglas Gregor } 222200fa53fd420aa8369586f569dbece04930ad6a3John McCall llvm_unreachable("bad type kind!"); 223f1588660c109610e6a79c786b83b7c9bbd6ed31eDouglas Gregor} 224f1588660c109610e6a79c786b83b7c9bbd6ed31eDouglas Gregor 22549f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCallSplitQualType QualType::getSplitDesugaredType(QualType T) { 2260953e767ff7817f97b3ab20896b229891eeff45bJohn McCall QualifierCollector Qs; 227c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner 228bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType Cur = T; 229bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall while (true) { 230bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall const Type *CurTy = Qs.strip(Cur); 231bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall switch (CurTy->getTypeClass()) { 232bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall#define ABSTRACT_TYPE(Class, Parent) 233bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall#define TYPE(Class, Parent) \ 234bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall case Type::Class: { \ 235bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall const Class##Type *Ty = cast<Class##Type>(CurTy); \ 236bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall if (!Ty->isSugared()) \ 23749f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall return SplitQualType(Ty, Qs); \ 238bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall Cur = Ty->desugar(); \ 239bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall break; \ 240bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall } 241bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall#include "clang/AST/TypeNodes.def" 242bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall } 243969c689d893a248eca4f049f5b89f747e66e4bffDouglas Gregor } 244bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall} 2455cdf82164dd7c2b2320d6735c63ace4331e0716dDouglas Gregor 24662c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCallSplitQualType QualType::getSplitUnqualifiedTypeImpl(QualType type) { 24762c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall SplitQualType split = type.split(); 24862c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall 24962c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall // All the qualifiers we've seen so far. 250200fa53fd420aa8369586f569dbece04930ad6a3John McCall Qualifiers quals = split.Quals; 25162c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall 25262c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall // The last type node we saw with any nodes inside it. 253200fa53fd420aa8369586f569dbece04930ad6a3John McCall const Type *lastTypeWithQuals = split.Ty; 25462c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall 25562c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall while (true) { 25662c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall QualType next; 25762c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall 25862c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall // Do a single-step desugar, aborting the loop if the type isn't 25962c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall // sugared. 260200fa53fd420aa8369586f569dbece04930ad6a3John McCall switch (split.Ty->getTypeClass()) { 26162c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall#define ABSTRACT_TYPE(Class, Parent) 26262c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall#define TYPE(Class, Parent) \ 26362c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall case Type::Class: { \ 264200fa53fd420aa8369586f569dbece04930ad6a3John McCall const Class##Type *ty = cast<Class##Type>(split.Ty); \ 26562c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall if (!ty->isSugared()) goto done; \ 26662c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall next = ty->desugar(); \ 26762c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall break; \ 26862c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall } 26962c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall#include "clang/AST/TypeNodes.def" 27062c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall } 27162c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall 27262c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall // Otherwise, split the underlying type. If that yields qualifiers, 27362c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall // update the information. 27462c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall split = next.split(); 275200fa53fd420aa8369586f569dbece04930ad6a3John McCall if (!split.Quals.empty()) { 276200fa53fd420aa8369586f569dbece04930ad6a3John McCall lastTypeWithQuals = split.Ty; 277200fa53fd420aa8369586f569dbece04930ad6a3John McCall quals.addConsistentQualifiers(split.Quals); 27862c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall } 27962c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall } 28062c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall 28162c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall done: 28262c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall return SplitQualType(lastTypeWithQuals, quals); 28362c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall} 28462c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall 285075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo BagnaraQualType QualType::IgnoreParens(QualType T) { 28662c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall // FIXME: this seems inherently un-qualifiers-safe. 287075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara while (const ParenType *PT = T->getAs<ParenType>()) 288075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara T = PT->getInnerType(); 289075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara return T; 290075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara} 291075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 292073819806ba2441e2a3e550107f1e756a6ee3ad0Richard Smith/// \brief This will check for a T (which should be a Type which can act as 293073819806ba2441e2a3e550107f1e756a6ee3ad0Richard Smith/// sugar, such as a TypedefType) by removing any existing sugar until it 294073819806ba2441e2a3e550107f1e756a6ee3ad0Richard Smith/// reaches a T or a non-sugared type. 295073819806ba2441e2a3e550107f1e756a6ee3ad0Richard Smithtemplate<typename T> static const T *getAsSugar(const Type *Cur) { 2962df1a5819fd98708ff3b4772f3477f6c1a8da59aArgyrios Kyrtzidis while (true) { 297073819806ba2441e2a3e550107f1e756a6ee3ad0Richard Smith if (const T *Sugar = dyn_cast<T>(Cur)) 298073819806ba2441e2a3e550107f1e756a6ee3ad0Richard Smith return Sugar; 2992df1a5819fd98708ff3b4772f3477f6c1a8da59aArgyrios Kyrtzidis switch (Cur->getTypeClass()) { 3002df1a5819fd98708ff3b4772f3477f6c1a8da59aArgyrios Kyrtzidis#define ABSTRACT_TYPE(Class, Parent) 3012df1a5819fd98708ff3b4772f3477f6c1a8da59aArgyrios Kyrtzidis#define TYPE(Class, Parent) \ 302073819806ba2441e2a3e550107f1e756a6ee3ad0Richard Smith case Type::Class: { \ 3032df1a5819fd98708ff3b4772f3477f6c1a8da59aArgyrios Kyrtzidis const Class##Type *Ty = cast<Class##Type>(Cur); \ 3042df1a5819fd98708ff3b4772f3477f6c1a8da59aArgyrios Kyrtzidis if (!Ty->isSugared()) return 0; \ 3052df1a5819fd98708ff3b4772f3477f6c1a8da59aArgyrios Kyrtzidis Cur = Ty->desugar().getTypePtr(); \ 3062df1a5819fd98708ff3b4772f3477f6c1a8da59aArgyrios Kyrtzidis break; \ 3072df1a5819fd98708ff3b4772f3477f6c1a8da59aArgyrios Kyrtzidis } 3082df1a5819fd98708ff3b4772f3477f6c1a8da59aArgyrios Kyrtzidis#include "clang/AST/TypeNodes.def" 3092df1a5819fd98708ff3b4772f3477f6c1a8da59aArgyrios Kyrtzidis } 3102df1a5819fd98708ff3b4772f3477f6c1a8da59aArgyrios Kyrtzidis } 3112df1a5819fd98708ff3b4772f3477f6c1a8da59aArgyrios Kyrtzidis} 3122df1a5819fd98708ff3b4772f3477f6c1a8da59aArgyrios Kyrtzidis 313073819806ba2441e2a3e550107f1e756a6ee3ad0Richard Smithtemplate <> const TypedefType *Type::getAs() const { 314073819806ba2441e2a3e550107f1e756a6ee3ad0Richard Smith return getAsSugar<TypedefType>(this); 315073819806ba2441e2a3e550107f1e756a6ee3ad0Richard Smith} 316073819806ba2441e2a3e550107f1e756a6ee3ad0Richard Smith 317073819806ba2441e2a3e550107f1e756a6ee3ad0Richard Smithtemplate <> const TemplateSpecializationType *Type::getAs() const { 318073819806ba2441e2a3e550107f1e756a6ee3ad0Richard Smith return getAsSugar<TemplateSpecializationType>(this); 319073819806ba2441e2a3e550107f1e756a6ee3ad0Richard Smith} 320073819806ba2441e2a3e550107f1e756a6ee3ad0Richard Smith 321bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall/// getUnqualifiedDesugaredType - Pull any qualifiers and syntactic 322bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall/// sugar off the given type. This should produce an object of the 323bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall/// same dynamic type as the canonical type. 324bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCallconst Type *Type::getUnqualifiedDesugaredType() const { 325bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall const Type *Cur = this; 326bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 327bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall while (true) { 328bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall switch (Cur->getTypeClass()) { 329bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall#define ABSTRACT_TYPE(Class, Parent) 330bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall#define TYPE(Class, Parent) \ 331bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall case Class: { \ 332bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall const Class##Type *Ty = cast<Class##Type>(Cur); \ 333bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall if (!Ty->isSugared()) return Cur; \ 334bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall Cur = Ty->desugar().getTypePtr(); \ 335bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall break; \ 336bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall } 337bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall#include "clang/AST/TypeNodes.def" 338bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall } 339bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall } 340c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner} 341c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner 3425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isDerivedType() const { 3435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer switch (CanonicalType->getTypeClass()) { 3445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Pointer: 345fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff case VariableArray: 346fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff case ConstantArray: 347c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman case IncompleteArray: 3485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case FunctionProto: 3495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case FunctionNoProto: 3507c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl case LValueReference: 3517c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl case RValueReference: 35272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor case Record: 3535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return true; 3545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer default: 3555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return false; 3565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 3575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 35899dc91422144483c20d1c7381bc9ac634b646b04Chris Lattnerbool Type::isClassType() const { 3596217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const RecordType *RT = getAs<RecordType>()) 360f728a4a05df2455e1c6e62173ab720a92cd4a074Chris Lattner return RT->getDecl()->isClass(); 36199dc91422144483c20d1c7381bc9ac634b646b04Chris Lattner return false; 36299dc91422144483c20d1c7381bc9ac634b646b04Chris Lattner} 363c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattnerbool Type::isStructureType() const { 3646217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const RecordType *RT = getAs<RecordType>()) 365f728a4a05df2455e1c6e62173ab720a92cd4a074Chris Lattner return RT->getDecl()->isStruct(); 366c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner return false; 367c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner} 3686666ed4ed2e2bc13da5ac5d0a4947019137d45beJoao Matosbool Type::isInterfaceType() const { 3696666ed4ed2e2bc13da5ac5d0a4947019137d45beJoao Matos if (const RecordType *RT = getAs<RecordType>()) 3706666ed4ed2e2bc13da5ac5d0a4947019137d45beJoao Matos return RT->getDecl()->isInterface(); 3716666ed4ed2e2bc13da5ac5d0a4947019137d45beJoao Matos return false; 3726666ed4ed2e2bc13da5ac5d0a4947019137d45beJoao Matos} 373fb87b89fc9eb103e19fb8e4b925c23f0bd091b99Douglas Gregorbool Type::isStructureOrClassType() const { 374fb87b89fc9eb103e19fb8e4b925c23f0bd091b99Douglas Gregor if (const RecordType *RT = getAs<RecordType>()) 3756666ed4ed2e2bc13da5ac5d0a4947019137d45beJoao Matos return RT->getDecl()->isStruct() || RT->getDecl()->isClass() || 3766666ed4ed2e2bc13da5ac5d0a4947019137d45beJoao Matos RT->getDecl()->isInterface(); 377fb87b89fc9eb103e19fb8e4b925c23f0bd091b99Douglas Gregor return false; 378fb87b89fc9eb103e19fb8e4b925c23f0bd091b99Douglas Gregor} 3797154a77e7c1f23418342d3b72836ab504aa7821eSteve Naroffbool Type::isVoidPointerType() const { 3806217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const PointerType *PT = getAs<PointerType>()) 3817154a77e7c1f23418342d3b72836ab504aa7821eSteve Naroff return PT->getPointeeType()->isVoidType(); 3827154a77e7c1f23418342d3b72836ab504aa7821eSteve Naroff return false; 3837154a77e7c1f23418342d3b72836ab504aa7821eSteve Naroff} 3847154a77e7c1f23418342d3b72836ab504aa7821eSteve Naroff 385c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattnerbool Type::isUnionType() const { 3866217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const RecordType *RT = getAs<RecordType>()) 387f728a4a05df2455e1c6e62173ab720a92cd4a074Chris Lattner return RT->getDecl()->isUnion(); 388c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner return false; 389c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner} 390c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner 391c6fb90a7246c2d5d3233e70107bf9d8c7c9e535bChris Lattnerbool Type::isComplexType() const { 39202f62a9fedbc370fba081303399410a3afdde29fSteve Naroff if (const ComplexType *CT = dyn_cast<ComplexType>(CanonicalType)) 39302f62a9fedbc370fba081303399410a3afdde29fSteve Naroff return CT->getElementType()->isFloatingType(); 39402f62a9fedbc370fba081303399410a3afdde29fSteve Naroff return false; 395c6fb90a7246c2d5d3233e70107bf9d8c7c9e535bChris Lattner} 396c6fb90a7246c2d5d3233e70107bf9d8c7c9e535bChris Lattner 3974cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroffbool Type::isComplexIntegerType() const { 3984cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroff // Check for GCC complex integer extension. 3990953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return getAsComplexIntegerType(); 4004cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroff} 4014cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroff 4024cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroffconst ComplexType *Type::getAsComplexIntegerType() const { 4030953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (const ComplexType *Complex = getAs<ComplexType>()) 4040953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (Complex->getElementType()->isIntegerType()) 4050953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return Complex; 4060953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return 0; 4074cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroff} 4084cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroff 40914108da7f7fc059772711e4ffee1322a27b152a7Steve NaroffQualType Type::getPointeeType() const { 4106217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const PointerType *PT = getAs<PointerType>()) 41114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return PT->getPointeeType(); 412183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) 41314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return OPT->getPointeeType(); 4146217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const BlockPointerType *BPT = getAs<BlockPointerType>()) 41514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return BPT->getPointeeType(); 4169c21289a866b677d21ed3d5ecfdfd5ced5a55410Mike Stump if (const ReferenceType *RT = getAs<ReferenceType>()) 4179c21289a866b677d21ed3d5ecfdfd5ced5a55410Mike Stump return RT->getPointeeType(); 41814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return QualType(); 41914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff} 420b77792eabf5882cf9af8cc810599b20432fda6c2Chris Lattner 421c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattnerconst RecordType *Type::getAsStructureType() const { 4227064f5c95bbdb17680d0ea658d4090898c2592d3Steve Naroff // If this is directly a structure type, return it. 423c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner if (const RecordType *RT = dyn_cast<RecordType>(this)) { 42439ba4aeca296b1c9f04bde7d9d3cbbf129f1abd3Argyrios Kyrtzidis if (RT->getDecl()->isStruct()) 425c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner return RT; 4267064f5c95bbdb17680d0ea658d4090898c2592d3Steve Naroff } 427dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner 428dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner // If the canonical form of this type isn't the right kind, reject it. 429c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner if (const RecordType *RT = dyn_cast<RecordType>(CanonicalType)) { 43039ba4aeca296b1c9f04bde7d9d3cbbf129f1abd3Argyrios Kyrtzidis if (!RT->getDecl()->isStruct()) 431dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner return 0; 4321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 433dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner // If this is a typedef for a structure type, strip the typedef off without 434dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner // losing all typedef information. 435bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall return cast<RecordType>(getUnqualifiedDesugaredType()); 4365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 4377064f5c95bbdb17680d0ea658d4090898c2592d3Steve Naroff return 0; 4385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 4395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpconst RecordType *Type::getAsUnionType() const { 4417064f5c95bbdb17680d0ea658d4090898c2592d3Steve Naroff // If this is directly a union type, return it. 442c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner if (const RecordType *RT = dyn_cast<RecordType>(this)) { 44339ba4aeca296b1c9f04bde7d9d3cbbf129f1abd3Argyrios Kyrtzidis if (RT->getDecl()->isUnion()) 444c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner return RT; 4457064f5c95bbdb17680d0ea658d4090898c2592d3Steve Naroff } 4461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 447dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner // If the canonical form of this type isn't the right kind, reject it. 448c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner if (const RecordType *RT = dyn_cast<RecordType>(CanonicalType)) { 44939ba4aeca296b1c9f04bde7d9d3cbbf129f1abd3Argyrios Kyrtzidis if (!RT->getDecl()->isUnion()) 450dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner return 0; 451dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner 452dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner // If this is a typedef for a union type, strip the typedef off without 453dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner // losing all typedef information. 454bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall return cast<RecordType>(getUnqualifiedDesugaredType()); 4555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 4561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4577064f5c95bbdb17680d0ea658d4090898c2592d3Steve Naroff return 0; 4585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 4595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 460c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallObjCObjectType::ObjCObjectType(QualType Canonical, QualType Base, 461c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCProtocolDecl * const *Protocols, 462c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall unsigned NumProtocols) 463561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor : Type(ObjCObject, Canonical, false, false, false, false), 464d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor BaseType(Base) 465d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor{ 466b870b88df784c2940efce448ebfaf54dece14666John McCall ObjCObjectTypeBits.NumProtocols = NumProtocols; 46771c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall assert(getNumProtocols() == NumProtocols && 468c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall "bitfield overflow in protocol count"); 469fd6a0887a099256c35a5b23e9afd517ffe95fa0aDouglas Gregor if (NumProtocols) 470c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall memcpy(getProtocolStorage(), Protocols, 471c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall NumProtocols * sizeof(ObjCProtocolDecl*)); 47271842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek} 47371842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek 474c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallconst ObjCObjectType *Type::getAsObjCQualifiedInterfaceType() const { 475c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall // There is no sugar for ObjCObjectType's, just return the canonical 476c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff // type pointer if it is the right class. There is no typedef information to 477c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff // return and these cannot be Address-space qualified. 478c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall if (const ObjCObjectType *T = getAs<ObjCObjectType>()) 479c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall if (T->getNumProtocols() && T->getInterface()) 480c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return T; 481c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff return 0; 482c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff} 483c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff 484c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroffbool Type::isObjCQualifiedInterfaceType() const { 485e61ad0b7063fcd97204b1cce5558685144267eb6Steve Naroff return getAsObjCQualifiedInterfaceType() != 0; 486c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff} 487c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff 488d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroffconst ObjCObjectPointerType *Type::getAsObjCQualifiedIdType() const { 489eca7be6b7ebd93682eeaab2c71d59f2995dacdccChris Lattner // There is no sugar for ObjCQualifiedIdType's, just return the canonical 490eca7be6b7ebd93682eeaab2c71d59f2995dacdccChris Lattner // type pointer if it is the right class. 491183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) { 492d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff if (OPT->isObjCQualifiedIdType()) 493d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff return OPT; 494d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff } 495d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff return 0; 496368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner} 497368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner 498759abb4d9ec14ae32104a9677b60f0542b60d1d8Fariborz Jahanianconst ObjCObjectPointerType *Type::getAsObjCQualifiedClassType() const { 499759abb4d9ec14ae32104a9677b60f0542b60d1d8Fariborz Jahanian // There is no sugar for ObjCQualifiedClassType's, just return the canonical 500759abb4d9ec14ae32104a9677b60f0542b60d1d8Fariborz Jahanian // type pointer if it is the right class. 501759abb4d9ec14ae32104a9677b60f0542b60d1d8Fariborz Jahanian if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) { 502759abb4d9ec14ae32104a9677b60f0542b60d1d8Fariborz Jahanian if (OPT->isObjCQualifiedClassType()) 503759abb4d9ec14ae32104a9677b60f0542b60d1d8Fariborz Jahanian return OPT; 504759abb4d9ec14ae32104a9677b60f0542b60d1d8Fariborz Jahanian } 505759abb4d9ec14ae32104a9677b60f0542b60d1d8Fariborz Jahanian return 0; 506759abb4d9ec14ae32104a9677b60f0542b60d1d8Fariborz Jahanian} 507759abb4d9ec14ae32104a9677b60f0542b60d1d8Fariborz Jahanian 50814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroffconst ObjCObjectPointerType *Type::getAsObjCInterfacePointerType() const { 509183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) { 51014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff if (OPT->getInterfaceType()) 51114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return OPT; 51214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff } 51314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return 0; 51414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff} 51514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff 516041ce8e00afd1185549a25d5c2b97d219ae032d9Jordan Roseconst CXXRecordDecl *Type::getPointeeCXXRecordDecl() const { 517041ce8e00afd1185549a25d5c2b97d219ae032d9Jordan Rose QualType PointeeType; 5186217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const PointerType *PT = getAs<PointerType>()) 519041ce8e00afd1185549a25d5c2b97d219ae032d9Jordan Rose PointeeType = PT->getPointeeType(); 520041ce8e00afd1185549a25d5c2b97d219ae032d9Jordan Rose else if (const ReferenceType *RT = getAs<ReferenceType>()) 521041ce8e00afd1185549a25d5c2b97d219ae032d9Jordan Rose PointeeType = RT->getPointeeType(); 522041ce8e00afd1185549a25d5c2b97d219ae032d9Jordan Rose else 523041ce8e00afd1185549a25d5c2b97d219ae032d9Jordan Rose return 0; 524041ce8e00afd1185549a25d5c2b97d219ae032d9Jordan Rose 525041ce8e00afd1185549a25d5c2b97d219ae032d9Jordan Rose if (const RecordType *RT = PointeeType->getAs<RecordType>()) 526041ce8e00afd1185549a25d5c2b97d219ae032d9Jordan Rose return dyn_cast<CXXRecordDecl>(RT->getDecl()); 527041ce8e00afd1185549a25d5c2b97d219ae032d9Jordan Rose 528a91d6a6619a91d0ca7102d8ab5678d855f04d850Fariborz Jahanian return 0; 529a91d6a6619a91d0ca7102d8ab5678d855f04d850Fariborz Jahanian} 530a91d6a6619a91d0ca7102d8ab5678d855f04d850Fariborz Jahanian 531c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas GregorCXXRecordDecl *Type::getAsCXXRecordDecl() const { 532c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor if (const RecordType *RT = getAs<RecordType>()) 533c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor return dyn_cast<CXXRecordDecl>(RT->getDecl()); 534c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor else if (const InjectedClassNameType *Injected 535c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor = getAs<InjectedClassNameType>()) 536c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor return Injected->getDecl(); 537c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor 538c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor return 0; 539c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor} 540c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor 54134b41d939a1328f484511c6002ba2456db879a29Richard Smithnamespace { 54234b41d939a1328f484511c6002ba2456db879a29Richard Smith class GetContainedAutoVisitor : 54334b41d939a1328f484511c6002ba2456db879a29Richard Smith public TypeVisitor<GetContainedAutoVisitor, AutoType*> { 54434b41d939a1328f484511c6002ba2456db879a29Richard Smith public: 54534b41d939a1328f484511c6002ba2456db879a29Richard Smith using TypeVisitor<GetContainedAutoVisitor, AutoType*>::Visit; 54634b41d939a1328f484511c6002ba2456db879a29Richard Smith AutoType *Visit(QualType T) { 54734b41d939a1328f484511c6002ba2456db879a29Richard Smith if (T.isNull()) 54834b41d939a1328f484511c6002ba2456db879a29Richard Smith return 0; 54934b41d939a1328f484511c6002ba2456db879a29Richard Smith return Visit(T.getTypePtr()); 55034b41d939a1328f484511c6002ba2456db879a29Richard Smith } 55134b41d939a1328f484511c6002ba2456db879a29Richard Smith 55234b41d939a1328f484511c6002ba2456db879a29Richard Smith // The 'auto' type itself. 55334b41d939a1328f484511c6002ba2456db879a29Richard Smith AutoType *VisitAutoType(const AutoType *AT) { 55434b41d939a1328f484511c6002ba2456db879a29Richard Smith return const_cast<AutoType*>(AT); 55534b41d939a1328f484511c6002ba2456db879a29Richard Smith } 55634b41d939a1328f484511c6002ba2456db879a29Richard Smith 55734b41d939a1328f484511c6002ba2456db879a29Richard Smith // Only these types can contain the desired 'auto' type. 55834b41d939a1328f484511c6002ba2456db879a29Richard Smith AutoType *VisitPointerType(const PointerType *T) { 55934b41d939a1328f484511c6002ba2456db879a29Richard Smith return Visit(T->getPointeeType()); 56034b41d939a1328f484511c6002ba2456db879a29Richard Smith } 56134b41d939a1328f484511c6002ba2456db879a29Richard Smith AutoType *VisitBlockPointerType(const BlockPointerType *T) { 56234b41d939a1328f484511c6002ba2456db879a29Richard Smith return Visit(T->getPointeeType()); 56334b41d939a1328f484511c6002ba2456db879a29Richard Smith } 56434b41d939a1328f484511c6002ba2456db879a29Richard Smith AutoType *VisitReferenceType(const ReferenceType *T) { 56534b41d939a1328f484511c6002ba2456db879a29Richard Smith return Visit(T->getPointeeTypeAsWritten()); 56634b41d939a1328f484511c6002ba2456db879a29Richard Smith } 56734b41d939a1328f484511c6002ba2456db879a29Richard Smith AutoType *VisitMemberPointerType(const MemberPointerType *T) { 56834b41d939a1328f484511c6002ba2456db879a29Richard Smith return Visit(T->getPointeeType()); 56934b41d939a1328f484511c6002ba2456db879a29Richard Smith } 57034b41d939a1328f484511c6002ba2456db879a29Richard Smith AutoType *VisitArrayType(const ArrayType *T) { 57134b41d939a1328f484511c6002ba2456db879a29Richard Smith return Visit(T->getElementType()); 57234b41d939a1328f484511c6002ba2456db879a29Richard Smith } 57334b41d939a1328f484511c6002ba2456db879a29Richard Smith AutoType *VisitDependentSizedExtVectorType( 57434b41d939a1328f484511c6002ba2456db879a29Richard Smith const DependentSizedExtVectorType *T) { 57534b41d939a1328f484511c6002ba2456db879a29Richard Smith return Visit(T->getElementType()); 57634b41d939a1328f484511c6002ba2456db879a29Richard Smith } 57734b41d939a1328f484511c6002ba2456db879a29Richard Smith AutoType *VisitVectorType(const VectorType *T) { 57834b41d939a1328f484511c6002ba2456db879a29Richard Smith return Visit(T->getElementType()); 57934b41d939a1328f484511c6002ba2456db879a29Richard Smith } 58034b41d939a1328f484511c6002ba2456db879a29Richard Smith AutoType *VisitFunctionType(const FunctionType *T) { 58134b41d939a1328f484511c6002ba2456db879a29Richard Smith return Visit(T->getResultType()); 58234b41d939a1328f484511c6002ba2456db879a29Richard Smith } 58334b41d939a1328f484511c6002ba2456db879a29Richard Smith AutoType *VisitParenType(const ParenType *T) { 58434b41d939a1328f484511c6002ba2456db879a29Richard Smith return Visit(T->getInnerType()); 58534b41d939a1328f484511c6002ba2456db879a29Richard Smith } 58634b41d939a1328f484511c6002ba2456db879a29Richard Smith AutoType *VisitAttributedType(const AttributedType *T) { 58734b41d939a1328f484511c6002ba2456db879a29Richard Smith return Visit(T->getModifiedType()); 58834b41d939a1328f484511c6002ba2456db879a29Richard Smith } 58934b41d939a1328f484511c6002ba2456db879a29Richard Smith }; 59034b41d939a1328f484511c6002ba2456db879a29Richard Smith} 59134b41d939a1328f484511c6002ba2456db879a29Richard Smith 59234b41d939a1328f484511c6002ba2456db879a29Richard SmithAutoType *Type::getContainedAutoType() const { 59334b41d939a1328f484511c6002ba2456db879a29Richard Smith return GetContainedAutoVisitor().Visit(this); 59434b41d939a1328f484511c6002ba2456db879a29Richard Smith} 59534b41d939a1328f484511c6002ba2456db879a29Richard Smith 596f60946222721d9ba3c059563935c17b84703187aDouglas Gregorbool Type::hasIntegerRepresentation() const { 597c63b96ad706e054a1390dd2ab53af9f05d33bbb1Steve Naroff if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType)) 598c63b96ad706e054a1390dd2ab53af9f05d33bbb1Steve Naroff return VT->getElementType()->isIntegerType(); 599f60946222721d9ba3c059563935c17b84703187aDouglas Gregor else 600f60946222721d9ba3c059563935c17b84703187aDouglas Gregor return isIntegerType(); 6015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 6025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6039d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// \brief Determine whether this type is an integral type. 6049d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// 6059d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// This routine determines whether the given type is an integral type per 6069d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// C++ [basic.fundamental]p7. Although the C standard does not define the 6079d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// term "integral type", it has a similar term "integer type", and in C++ 6089d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// the two terms are equivalent. However, C's "integer type" includes 6099d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// enumeration types, while C++'s "integer type" does not. The \c ASTContext 6109d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// parameter is used to determine whether we should be following the C or 6119d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// C++ rules when determining whether this type is an integral/integer type. 6129d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// 6139d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// For cases where C permits "an integer type" and C++ permits "an integral 6149d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// type", use this routine. 6159d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// 6169d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// For cases where C permits "an integer type" and C++ permits "an integral 6179d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// or enumeration type", use \c isIntegralOrEnumerationType() instead. 6189d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// 6199d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// \param Ctx The context in which this type occurs. 6209d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// 6219d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// \returns true if the type is considered an integral type, false otherwise. 6229d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregorbool Type::isIntegralType(ASTContext &Ctx) const { 62333e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 62433e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian return BT->getKind() >= BuiltinType::Bool && 625f5f7d864f5067d1ea4bff7fcf41b53a43b7b48baAnders Carlsson BT->getKind() <= BuiltinType::Int128; 6269d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor 6274e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie if (!Ctx.getLangOpts().CPlusPlus) 6281274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) 6291274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor return ET->getDecl()->isComplete(); // Complete enum types are integral in C. 6309d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor 63133e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian return false; 63233e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian} 63333e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian 6342ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor 6351274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregorbool Type::isIntegralOrUnscopedEnumerationType() const { 6361274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 6371274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor return BT->getKind() >= BuiltinType::Bool && 6381274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor BT->getKind() <= BuiltinType::Int128; 6391274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor 6401274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor // Check for a complete enum type; incomplete enum types are not properly an 6411274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor // enumeration type in the sense required here. 6421274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor // C++0x: However, if the underlying type of the enum is fixed, it is 6431274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor // considered complete. 6441274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) 6451274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor return ET->getDecl()->isComplete() && !ET->getDecl()->isScoped(); 6461274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor 6471274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor return false; 6481274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor} 6491274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor 6501274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor 651f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbar 65213b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroffbool Type::isCharType() const { 65313b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 65413b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff return BT->getKind() == BuiltinType::Char_U || 65513b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff BT->getKind() == BuiltinType::UChar || 656c67ad5f299bb2c09e4567def8ff0d34bd15a42fdAnders Carlsson BT->getKind() == BuiltinType::Char_S || 657c67ad5f299bb2c09e4567def8ff0d34bd15a42fdAnders Carlsson BT->getKind() == BuiltinType::SChar; 65813b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff return false; 65913b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff} 66013b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff 66177a52233f7c0f162672652051bfe78b65ad4f789Douglas Gregorbool Type::isWideCharType() const { 66277a52233f7c0f162672652051bfe78b65ad4f789Douglas Gregor if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 6633f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner return BT->getKind() == BuiltinType::WChar_S || 6643f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner BT->getKind() == BuiltinType::WChar_U; 66577a52233f7c0f162672652051bfe78b65ad4f789Douglas Gregor return false; 66677a52233f7c0f162672652051bfe78b65ad4f789Douglas Gregor} 66777a52233f7c0f162672652051bfe78b65ad4f789Douglas Gregor 6685cee1195584fa8672253139c86e922daeda69b9eDouglas Gregorbool Type::isChar16Type() const { 6695cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 6705cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor return BT->getKind() == BuiltinType::Char16; 6715cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor return false; 6725cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor} 6735cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor 6745cee1195584fa8672253139c86e922daeda69b9eDouglas Gregorbool Type::isChar32Type() const { 6755cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 6765cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor return BT->getKind() == BuiltinType::Char32; 6775cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor return false; 6785cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor} 6795cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor 68020093b4bf698f292c664676987541d5103b65b15Douglas Gregor/// \brief Determine whether this type is any of the built-in character 68120093b4bf698f292c664676987541d5103b65b15Douglas Gregor/// types. 68220093b4bf698f292c664676987541d5103b65b15Douglas Gregorbool Type::isAnyCharacterType() const { 6833f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType); 6843f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner if (BT == 0) return false; 6853f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner switch (BT->getKind()) { 6863f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner default: return false; 6873f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner case BuiltinType::Char_U: 6883f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner case BuiltinType::UChar: 6893f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner case BuiltinType::WChar_U: 6903f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner case BuiltinType::Char16: 6913f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner case BuiltinType::Char32: 6923f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner case BuiltinType::Char_S: 6933f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner case BuiltinType::SChar: 6943f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner case BuiltinType::WChar_S: 6953f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner return true; 6963f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner } 69720093b4bf698f292c664676987541d5103b65b15Douglas Gregor} 69820093b4bf698f292c664676987541d5103b65b15Douglas Gregor 699d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner/// isSignedIntegerType - Return true if this is an integer type that is 700d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner/// signed, according to C99 6.2.5p4 [char, signed char, short, int, long..], 701f60946222721d9ba3c059563935c17b84703187aDouglas Gregor/// an enum decl which has a signed representation 7025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isSignedIntegerType() const { 7035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) { 7045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return BT->getKind() >= BuiltinType::Char_S && 705f5f7d864f5067d1ea4bff7fcf41b53a43b7b48baAnders Carlsson BT->getKind() <= BuiltinType::Int128; 7065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 7071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 708bbd340717422bf011d56cd0164d2576601368111Fariborz Jahanian if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) { 709bbd340717422bf011d56cd0164d2576601368111Fariborz Jahanian // Incomplete enum types are not treated as integer types. 710bbd340717422bf011d56cd0164d2576601368111Fariborz Jahanian // FIXME: In C++, enum types are never integer types. 711b6adf2c889bb17c1be44e6c8e67e3b2762e9ceccDouglas Gregor if (ET->getDecl()->isComplete() && !ET->getDecl()->isScoped()) 712bbd340717422bf011d56cd0164d2576601368111Fariborz Jahanian return ET->getDecl()->getIntegerType()->isSignedIntegerType(); 713bbd340717422bf011d56cd0164d2576601368111Fariborz Jahanian } 7141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 715f60946222721d9ba3c059563935c17b84703187aDouglas Gregor return false; 716f60946222721d9ba3c059563935c17b84703187aDouglas Gregor} 717f60946222721d9ba3c059563935c17b84703187aDouglas Gregor 718575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregorbool Type::isSignedIntegerOrEnumerationType() const { 719575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) { 720575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor return BT->getKind() >= BuiltinType::Char_S && 721575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor BT->getKind() <= BuiltinType::Int128; 722575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor } 723575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor 724575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) { 725575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor if (ET->getDecl()->isComplete()) 726575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor return ET->getDecl()->getIntegerType()->isSignedIntegerType(); 727575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor } 728575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor 729575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor return false; 730575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor} 731575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor 732f60946222721d9ba3c059563935c17b84703187aDouglas Gregorbool Type::hasSignedIntegerRepresentation() const { 733c63b96ad706e054a1390dd2ab53af9f05d33bbb1Steve Naroff if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType)) 734c63b96ad706e054a1390dd2ab53af9f05d33bbb1Steve Naroff return VT->getElementType()->isSignedIntegerType(); 735f60946222721d9ba3c059563935c17b84703187aDouglas Gregor else 736f60946222721d9ba3c059563935c17b84703187aDouglas Gregor return isSignedIntegerType(); 7375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 7385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 739d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner/// isUnsignedIntegerType - Return true if this is an integer type that is 740d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner/// unsigned, according to C99 6.2.5p6 [which returns true for _Bool], an enum 741f60946222721d9ba3c059563935c17b84703187aDouglas Gregor/// decl which has an unsigned representation 7425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isUnsignedIntegerType() const { 7435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) { 7445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return BT->getKind() >= BuiltinType::Bool && 7451c03ca30ae962199ef702324b48550f6af7fdc32Anders Carlsson BT->getKind() <= BuiltinType::UInt128; 7465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 747d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner 748bbd340717422bf011d56cd0164d2576601368111Fariborz Jahanian if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) { 749bbd340717422bf011d56cd0164d2576601368111Fariborz Jahanian // Incomplete enum types are not treated as integer types. 750bbd340717422bf011d56cd0164d2576601368111Fariborz Jahanian // FIXME: In C++, enum types are never integer types. 751b6adf2c889bb17c1be44e6c8e67e3b2762e9ceccDouglas Gregor if (ET->getDecl()->isComplete() && !ET->getDecl()->isScoped()) 752bbd340717422bf011d56cd0164d2576601368111Fariborz Jahanian return ET->getDecl()->getIntegerType()->isUnsignedIntegerType(); 753bbd340717422bf011d56cd0164d2576601368111Fariborz Jahanian } 754d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner 755f60946222721d9ba3c059563935c17b84703187aDouglas Gregor return false; 756f60946222721d9ba3c059563935c17b84703187aDouglas Gregor} 757f60946222721d9ba3c059563935c17b84703187aDouglas Gregor 758575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregorbool Type::isUnsignedIntegerOrEnumerationType() const { 759575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) { 760575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor return BT->getKind() >= BuiltinType::Bool && 761575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor BT->getKind() <= BuiltinType::UInt128; 762575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor } 763575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor 764575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) { 765575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor if (ET->getDecl()->isComplete()) 766575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor return ET->getDecl()->getIntegerType()->isUnsignedIntegerType(); 767575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor } 768575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor 769575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor return false; 770575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor} 771575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor 772f60946222721d9ba3c059563935c17b84703187aDouglas Gregorbool Type::hasUnsignedIntegerRepresentation() const { 773c63b96ad706e054a1390dd2ab53af9f05d33bbb1Steve Naroff if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType)) 774c63b96ad706e054a1390dd2ab53af9f05d33bbb1Steve Naroff return VT->getElementType()->isUnsignedIntegerType(); 775f60946222721d9ba3c059563935c17b84703187aDouglas Gregor else 776f60946222721d9ba3c059563935c17b84703187aDouglas Gregor return isUnsignedIntegerType(); 7775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 7785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isFloatingType() const { 7805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 781aa4a99b4a62615db243f7a5c433169f2fc704420Anton Korobeynikov return BT->getKind() >= BuiltinType::Half && 7825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer BT->getKind() <= BuiltinType::LongDouble; 7835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (const ComplexType *CT = dyn_cast<ComplexType>(CanonicalType)) 784729a2131228cb7fcbc00bd8af36bc6f14d12317dChris Lattner return CT->getElementType()->isFloatingType(); 7858eee119bf4f1693dde17b8552c1f9f81bf2b681eDouglas Gregor return false; 7868eee119bf4f1693dde17b8552c1f9f81bf2b681eDouglas Gregor} 7878eee119bf4f1693dde17b8552c1f9f81bf2b681eDouglas Gregor 7888eee119bf4f1693dde17b8552c1f9f81bf2b681eDouglas Gregorbool Type::hasFloatingRepresentation() const { 789c63b96ad706e054a1390dd2ab53af9f05d33bbb1Steve Naroff if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType)) 790c63b96ad706e054a1390dd2ab53af9f05d33bbb1Steve Naroff return VT->getElementType()->isFloatingType(); 7918eee119bf4f1693dde17b8552c1f9f81bf2b681eDouglas Gregor else 7928eee119bf4f1693dde17b8552c1f9f81bf2b681eDouglas Gregor return isFloatingType(); 7935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 7945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isRealFloatingType() const { 7965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 797680523a91dd3351389667c8de17121ba7ae82673John McCall return BT->isFloatingPoint(); 7985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return false; 7995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 8005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isRealType() const { 8025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 8035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return BT->getKind() >= BuiltinType::Bool && 8045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer BT->getKind() <= BuiltinType::LongDouble; 8051274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) 8061274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor return ET->getDecl()->isComplete() && !ET->getDecl()->isScoped(); 8075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return false; 8085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 8095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isArithmeticType() const { 8115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 812a7fbf7282eadebaf1293d9f970b01fb57f4b0ae4Douglas Gregor return BT->getKind() >= BuiltinType::Bool && 813a7fbf7282eadebaf1293d9f970b01fb57f4b0ae4Douglas Gregor BT->getKind() <= BuiltinType::LongDouble; 81437c1b78a20a09b0456aa5caa15e159027010ca22Chris Lattner if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) 81537c1b78a20a09b0456aa5caa15e159027010ca22Chris Lattner // GCC allows forward declaration of enum types (forbid by C99 6.7.2.3p2). 81637c1b78a20a09b0456aa5caa15e159027010ca22Chris Lattner // If a body isn't seen by the time we get here, return false. 8171274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor // 8181274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor // C++0x: Enumerations are not arithmetic types. For now, just return 8191274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor // false for scoped enumerations since that will disable any 8201274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor // unwanted implicit conversions. 8211274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor return !ET->getDecl()->isScoped() && ET->getDecl()->isComplete(); 82200619623af0b9d3271e31402ec1a95e84c2c4526Douglas Gregor return isa<ComplexType>(CanonicalType); 8235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 8245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 825daa8e4e888758d55a7a759dd4a91b83921cef222John McCallType::ScalarTypeKind Type::getScalarTypeKind() const { 826daa8e4e888758d55a7a759dd4a91b83921cef222John McCall assert(isScalarType()); 827daa8e4e888758d55a7a759dd4a91b83921cef222John McCall 828daa8e4e888758d55a7a759dd4a91b83921cef222John McCall const Type *T = CanonicalType.getTypePtr(); 829daa8e4e888758d55a7a759dd4a91b83921cef222John McCall if (const BuiltinType *BT = dyn_cast<BuiltinType>(T)) { 830daa8e4e888758d55a7a759dd4a91b83921cef222John McCall if (BT->getKind() == BuiltinType::Bool) return STK_Bool; 8311d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall if (BT->getKind() == BuiltinType::NullPtr) return STK_CPointer; 832daa8e4e888758d55a7a759dd4a91b83921cef222John McCall if (BT->isInteger()) return STK_Integral; 833daa8e4e888758d55a7a759dd4a91b83921cef222John McCall if (BT->isFloatingPoint()) return STK_Floating; 834daa8e4e888758d55a7a759dd4a91b83921cef222John McCall llvm_unreachable("unknown scalar builtin type"); 8351d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall } else if (isa<PointerType>(T)) { 8361d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall return STK_CPointer; 8371d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall } else if (isa<BlockPointerType>(T)) { 8381d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall return STK_BlockPointer; 8391d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall } else if (isa<ObjCObjectPointerType>(T)) { 8401d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall return STK_ObjCObjectPointer; 841daa8e4e888758d55a7a759dd4a91b83921cef222John McCall } else if (isa<MemberPointerType>(T)) { 842daa8e4e888758d55a7a759dd4a91b83921cef222John McCall return STK_MemberPointer; 843daa8e4e888758d55a7a759dd4a91b83921cef222John McCall } else if (isa<EnumType>(T)) { 844daa8e4e888758d55a7a759dd4a91b83921cef222John McCall assert(cast<EnumType>(T)->getDecl()->isComplete()); 845daa8e4e888758d55a7a759dd4a91b83921cef222John McCall return STK_Integral; 846daa8e4e888758d55a7a759dd4a91b83921cef222John McCall } else if (const ComplexType *CT = dyn_cast<ComplexType>(T)) { 847daa8e4e888758d55a7a759dd4a91b83921cef222John McCall if (CT->getElementType()->isRealFloatingType()) 848daa8e4e888758d55a7a759dd4a91b83921cef222John McCall return STK_FloatingComplex; 849daa8e4e888758d55a7a759dd4a91b83921cef222John McCall return STK_IntegralComplex; 850daa8e4e888758d55a7a759dd4a91b83921cef222John McCall } 851daa8e4e888758d55a7a759dd4a91b83921cef222John McCall 852daa8e4e888758d55a7a759dd4a91b83921cef222John McCall llvm_unreachable("unknown scalar type"); 853daa8e4e888758d55a7a759dd4a91b83921cef222John McCall} 854daa8e4e888758d55a7a759dd4a91b83921cef222John McCall 855d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor/// \brief Determines whether the type is a C++ aggregate type or C 856d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor/// aggregate or union type. 857d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor/// 858d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor/// An aggregate type is an array or a class type (struct, union, or 859d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor/// class) that has no user-declared constructors, no private or 860d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor/// protected non-static data members, no base classes, and no virtual 861d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor/// functions (C++ [dcl.init.aggr]p1). The notion of an aggregate type 862d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor/// subsumes the notion of C aggregates (C99 6.2.5p21) because it also 863d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor/// includes union types. 8645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isAggregateType() const { 865c1efaecf0373f1a55c5ef4c234357cf726fc0600Douglas Gregor if (const RecordType *Record = dyn_cast<RecordType>(CanonicalType)) { 866c1efaecf0373f1a55c5ef4c234357cf726fc0600Douglas Gregor if (CXXRecordDecl *ClassDecl = dyn_cast<CXXRecordDecl>(Record->getDecl())) 867c1efaecf0373f1a55c5ef4c234357cf726fc0600Douglas Gregor return ClassDecl->isAggregate(); 868c1efaecf0373f1a55c5ef4c234357cf726fc0600Douglas Gregor 869d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor return true; 870c1efaecf0373f1a55c5ef4c234357cf726fc0600Douglas Gregor } 871c1efaecf0373f1a55c5ef4c234357cf726fc0600Douglas Gregor 872c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman return isa<ArrayType>(CanonicalType); 8735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 8745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8759bfa73c5ab7bf4b0e749d04f29da6884e8d5bd9fChris Lattner/// isConstantSizeType - Return true if this is not a variable sized type, 8769bfa73c5ab7bf4b0e749d04f29da6884e8d5bd9fChris Lattner/// according to the rules of C99 6.7.5p3. It is not legal to call this on 877898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// incomplete types or dependent types. 8783c2b3170041f69a92904e3bab9b6d654eaf260acEli Friedmanbool Type::isConstantSizeType() const { 879d52a4578144ab2887912e52eabec58a857a44adbChris Lattner assert(!isIncompleteType() && "This doesn't make sense for incomplete types"); 880898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor assert(!isDependentType() && "This doesn't make sense for dependent types"); 8819bfa73c5ab7bf4b0e749d04f29da6884e8d5bd9fChris Lattner // The VAT must have a size, as it is known to be complete. 8829bfa73c5ab7bf4b0e749d04f29da6884e8d5bd9fChris Lattner return !isa<VariableArrayType>(CanonicalType); 8835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 8845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// isIncompleteType - Return true if this is an incomplete type (C99 6.2.5p1) 8865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// - a type that can describe objects, but which lacks information needed to 8875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// determine its size. 888d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregorbool Type::isIncompleteType(NamedDecl **Def) const { 889d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor if (Def) 890d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor *Def = 0; 891d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor 8921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump switch (CanonicalType->getTypeClass()) { 8935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer default: return false; 8945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Builtin: 8955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Void is the only incomplete builtin type. Per C99 6.2.5p19, it can never 8965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // be completed. 8975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return isVoidType(); 898d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor case Enum: { 899d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor EnumDecl *EnumD = cast<EnumType>(CanonicalType)->getDecl(); 900d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor if (Def) 901d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor *Def = EnumD; 902d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor 9031274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor // An enumeration with fixed underlying type is complete (C++0x 7.2p3). 904d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor if (EnumD->isFixed()) 905d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor return false; 906d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor 907d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor return !EnumD->isCompleteDefinition(); 908d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor } 909d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor case Record: { 9105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // A tagged type (struct/union/enum/class) is incomplete if the decl is a 9115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // forward declaration, but not a full definition (C99 6.2.5p22). 912d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor RecordDecl *Rec = cast<RecordType>(CanonicalType)->getDecl(); 913d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor if (Def) 914d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor *Def = Rec; 915d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor return !Rec->isCompleteDefinition(); 916d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor } 917923d56d436f750bc1f29db50e641078725558a1bSebastian Redl case ConstantArray: 918923d56d436f750bc1f29db50e641078725558a1bSebastian Redl // An array is incomplete if its element type is incomplete 919923d56d436f750bc1f29db50e641078725558a1bSebastian Redl // (C++ [dcl.array]p1). 920923d56d436f750bc1f29db50e641078725558a1bSebastian Redl // We don't handle variable arrays (they're not allowed in C++) or 921923d56d436f750bc1f29db50e641078725558a1bSebastian Redl // dependent-sized arrays (dependent types are never treated as incomplete). 922d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor return cast<ArrayType>(CanonicalType)->getElementType() 923d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor ->isIncompleteType(Def); 924c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman case IncompleteArray: 9255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // An array of unknown size is an incomplete type (C99 6.2.5p22). 926c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman return true; 927c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall case ObjCObject: 928d0221526bcc81f49eff5c992978176e83ada3bc7Douglas Gregor return cast<ObjCObjectType>(CanonicalType)->getBaseType() 929d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor ->isIncompleteType(Def); 930d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor case ObjCInterface: { 9311efaa9594a81709a17658fd80ae7e783e1026407Chris Lattner // ObjC interfaces are incomplete if they are @class, not @interface. 932d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor ObjCInterfaceDecl *Interface 933d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor = cast<ObjCInterfaceType>(CanonicalType)->getDecl(); 934d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor if (Def) 935d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor *Def = Interface; 936d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor return !Interface->hasDefinition(); 937d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor } 9385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 9395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 9405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 941f85e193739c953358c865005855253af4f68a497John McCallbool QualType::isPODType(ASTContext &Context) const { 942152f6b7be508fbc61543f3736ebd390d7ac84bd1Benjamin Kramer // C++11 has a more relaxed definition of POD. 94380ad52f327b532bded5c5b0ee38779d841c6cd35Richard Smith if (Context.getLangOpts().CPlusPlus11) 944152f6b7be508fbc61543f3736ebd390d7ac84bd1Benjamin Kramer return isCXX11PODType(Context); 945152f6b7be508fbc61543f3736ebd390d7ac84bd1Benjamin Kramer 946152f6b7be508fbc61543f3736ebd390d7ac84bd1Benjamin Kramer return isCXX98PODType(Context); 947152f6b7be508fbc61543f3736ebd390d7ac84bd1Benjamin Kramer} 948152f6b7be508fbc61543f3736ebd390d7ac84bd1Benjamin Kramer 949152f6b7be508fbc61543f3736ebd390d7ac84bd1Benjamin Kramerbool QualType::isCXX98PODType(ASTContext &Context) const { 95064b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl // The compiler shouldn't query this for incomplete types, but the user might. 951607a1788d9529c8e8494ac528764aa2c678a1a97Sebastian Redl // We return false for that case. Except for incomplete arrays of PODs, which 952607a1788d9529c8e8494ac528764aa2c678a1a97Sebastian Redl // are PODs according to the standard. 953f85e193739c953358c865005855253af4f68a497John McCall if (isNull()) 954f85e193739c953358c865005855253af4f68a497John McCall return 0; 955f85e193739c953358c865005855253af4f68a497John McCall 956f85e193739c953358c865005855253af4f68a497John McCall if ((*this)->isIncompleteArrayType()) 9578907832ddee33d8a0b0d8432d4c7470360353d67Benjamin Kramer return Context.getBaseElementType(*this).isCXX98PODType(Context); 958f85e193739c953358c865005855253af4f68a497John McCall 959f85e193739c953358c865005855253af4f68a497John McCall if ((*this)->isIncompleteType()) 96064b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl return false; 96164b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 9624e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie if (Context.getLangOpts().ObjCAutoRefCount) { 963f85e193739c953358c865005855253af4f68a497John McCall switch (getObjCLifetime()) { 964f85e193739c953358c865005855253af4f68a497John McCall case Qualifiers::OCL_ExplicitNone: 965f85e193739c953358c865005855253af4f68a497John McCall return true; 966f85e193739c953358c865005855253af4f68a497John McCall 967f85e193739c953358c865005855253af4f68a497John McCall case Qualifiers::OCL_Strong: 968f85e193739c953358c865005855253af4f68a497John McCall case Qualifiers::OCL_Weak: 969f85e193739c953358c865005855253af4f68a497John McCall case Qualifiers::OCL_Autoreleasing: 970f85e193739c953358c865005855253af4f68a497John McCall return false; 971f85e193739c953358c865005855253af4f68a497John McCall 972f85e193739c953358c865005855253af4f68a497John McCall case Qualifiers::OCL_None: 973f85e193739c953358c865005855253af4f68a497John McCall break; 974f85e193739c953358c865005855253af4f68a497John McCall } 975f85e193739c953358c865005855253af4f68a497John McCall } 976f85e193739c953358c865005855253af4f68a497John McCall 977f85e193739c953358c865005855253af4f68a497John McCall QualType CanonicalType = getTypePtr()->CanonicalType; 97864b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl switch (CanonicalType->getTypeClass()) { 97964b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl // Everything not explicitly mentioned is not POD. 98064b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl default: return false; 981f85e193739c953358c865005855253af4f68a497John McCall case Type::VariableArray: 982f85e193739c953358c865005855253af4f68a497John McCall case Type::ConstantArray: 983607a1788d9529c8e8494ac528764aa2c678a1a97Sebastian Redl // IncompleteArray is handled above. 9848907832ddee33d8a0b0d8432d4c7470360353d67Benjamin Kramer return Context.getBaseElementType(*this).isCXX98PODType(Context); 985f85e193739c953358c865005855253af4f68a497John McCall 986f85e193739c953358c865005855253af4f68a497John McCall case Type::ObjCObjectPointer: 987f85e193739c953358c865005855253af4f68a497John McCall case Type::BlockPointer: 988f85e193739c953358c865005855253af4f68a497John McCall case Type::Builtin: 989f85e193739c953358c865005855253af4f68a497John McCall case Type::Complex: 990f85e193739c953358c865005855253af4f68a497John McCall case Type::Pointer: 991f85e193739c953358c865005855253af4f68a497John McCall case Type::MemberPointer: 992f85e193739c953358c865005855253af4f68a497John McCall case Type::Vector: 993f85e193739c953358c865005855253af4f68a497John McCall case Type::ExtVector: 99464b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl return true; 99564b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 996f85e193739c953358c865005855253af4f68a497John McCall case Type::Enum: 99772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor return true; 99872564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor 999f85e193739c953358c865005855253af4f68a497John McCall case Type::Record: 10001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (CXXRecordDecl *ClassDecl 1001c1efaecf0373f1a55c5ef4c234357cf726fc0600Douglas Gregor = dyn_cast<CXXRecordDecl>(cast<RecordType>(CanonicalType)->getDecl())) 1002c1efaecf0373f1a55c5ef4c234357cf726fc0600Douglas Gregor return ClassDecl->isPOD(); 1003c1efaecf0373f1a55c5ef4c234357cf726fc0600Douglas Gregor 100464b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl // C struct/union is POD. 100564b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl return true; 100664b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl } 100764b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl} 100864b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 1009f85e193739c953358c865005855253af4f68a497John McCallbool QualType::isTrivialType(ASTContext &Context) const { 1010f85e193739c953358c865005855253af4f68a497John McCall // The compiler shouldn't query this for incomplete types, but the user might. 1011f85e193739c953358c865005855253af4f68a497John McCall // We return false for that case. Except for incomplete arrays of PODs, which 1012f85e193739c953358c865005855253af4f68a497John McCall // are PODs according to the standard. 1013f85e193739c953358c865005855253af4f68a497John McCall if (isNull()) 1014f85e193739c953358c865005855253af4f68a497John McCall return 0; 1015f85e193739c953358c865005855253af4f68a497John McCall 1016f85e193739c953358c865005855253af4f68a497John McCall if ((*this)->isArrayType()) 1017f85e193739c953358c865005855253af4f68a497John McCall return Context.getBaseElementType(*this).isTrivialType(Context); 1018f85e193739c953358c865005855253af4f68a497John McCall 1019f85e193739c953358c865005855253af4f68a497John McCall // Return false for incomplete types after skipping any incomplete array 1020f85e193739c953358c865005855253af4f68a497John McCall // types which are expressly allowed by the standard and thus our API. 1021f85e193739c953358c865005855253af4f68a497John McCall if ((*this)->isIncompleteType()) 1022f85e193739c953358c865005855253af4f68a497John McCall return false; 1023f85e193739c953358c865005855253af4f68a497John McCall 10244e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie if (Context.getLangOpts().ObjCAutoRefCount) { 1025f85e193739c953358c865005855253af4f68a497John McCall switch (getObjCLifetime()) { 1026f85e193739c953358c865005855253af4f68a497John McCall case Qualifiers::OCL_ExplicitNone: 1027f85e193739c953358c865005855253af4f68a497John McCall return true; 1028f85e193739c953358c865005855253af4f68a497John McCall 1029f85e193739c953358c865005855253af4f68a497John McCall case Qualifiers::OCL_Strong: 1030f85e193739c953358c865005855253af4f68a497John McCall case Qualifiers::OCL_Weak: 1031f85e193739c953358c865005855253af4f68a497John McCall case Qualifiers::OCL_Autoreleasing: 1032f85e193739c953358c865005855253af4f68a497John McCall return false; 1033f85e193739c953358c865005855253af4f68a497John McCall 1034f85e193739c953358c865005855253af4f68a497John McCall case Qualifiers::OCL_None: 1035f85e193739c953358c865005855253af4f68a497John McCall if ((*this)->isObjCLifetimeType()) 1036f85e193739c953358c865005855253af4f68a497John McCall return false; 1037f85e193739c953358c865005855253af4f68a497John McCall break; 1038f85e193739c953358c865005855253af4f68a497John McCall } 1039f85e193739c953358c865005855253af4f68a497John McCall } 1040f85e193739c953358c865005855253af4f68a497John McCall 1041f85e193739c953358c865005855253af4f68a497John McCall QualType CanonicalType = getTypePtr()->CanonicalType; 1042f85e193739c953358c865005855253af4f68a497John McCall if (CanonicalType->isDependentType()) 1043f85e193739c953358c865005855253af4f68a497John McCall return false; 1044f85e193739c953358c865005855253af4f68a497John McCall 1045f85e193739c953358c865005855253af4f68a497John McCall // C++0x [basic.types]p9: 1046f85e193739c953358c865005855253af4f68a497John McCall // Scalar types, trivial class types, arrays of such types, and 1047f85e193739c953358c865005855253af4f68a497John McCall // cv-qualified versions of these types are collectively called trivial 1048f85e193739c953358c865005855253af4f68a497John McCall // types. 1049f85e193739c953358c865005855253af4f68a497John McCall 1050f85e193739c953358c865005855253af4f68a497John McCall // As an extension, Clang treats vector types as Scalar types. 1051f85e193739c953358c865005855253af4f68a497John McCall if (CanonicalType->isScalarType() || CanonicalType->isVectorType()) 1052f85e193739c953358c865005855253af4f68a497John McCall return true; 1053f85e193739c953358c865005855253af4f68a497John McCall if (const RecordType *RT = CanonicalType->getAs<RecordType>()) { 1054f85e193739c953358c865005855253af4f68a497John McCall if (const CXXRecordDecl *ClassDecl = 1055f85e193739c953358c865005855253af4f68a497John McCall dyn_cast<CXXRecordDecl>(RT->getDecl())) { 1056426391cd51af86f9d59eceb0fb1c42153eccbb9aRichard Smith // C++11 [class]p6: 1057426391cd51af86f9d59eceb0fb1c42153eccbb9aRichard Smith // A trivial class is a class that has a default constructor, 1058426391cd51af86f9d59eceb0fb1c42153eccbb9aRichard Smith // has no non-trivial default constructors, and is trivially 1059426391cd51af86f9d59eceb0fb1c42153eccbb9aRichard Smith // copyable. 1060426391cd51af86f9d59eceb0fb1c42153eccbb9aRichard Smith return ClassDecl->hasDefaultConstructor() && 1061426391cd51af86f9d59eceb0fb1c42153eccbb9aRichard Smith !ClassDecl->hasNonTrivialDefaultConstructor() && 1062426391cd51af86f9d59eceb0fb1c42153eccbb9aRichard Smith ClassDecl->isTriviallyCopyable(); 1063f85e193739c953358c865005855253af4f68a497John McCall } 1064f85e193739c953358c865005855253af4f68a497John McCall 1065f85e193739c953358c865005855253af4f68a497John McCall return true; 1066f85e193739c953358c865005855253af4f68a497John McCall } 1067f85e193739c953358c865005855253af4f68a497John McCall 1068f85e193739c953358c865005855253af4f68a497John McCall // No other types can match. 1069f85e193739c953358c865005855253af4f68a497John McCall return false; 1070f85e193739c953358c865005855253af4f68a497John McCall} 1071f85e193739c953358c865005855253af4f68a497John McCall 1072f85e193739c953358c865005855253af4f68a497John McCallbool QualType::isTriviallyCopyableType(ASTContext &Context) const { 1073f85e193739c953358c865005855253af4f68a497John McCall if ((*this)->isArrayType()) 1074f85e193739c953358c865005855253af4f68a497John McCall return Context.getBaseElementType(*this).isTrivialType(Context); 1075f85e193739c953358c865005855253af4f68a497John McCall 10764e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie if (Context.getLangOpts().ObjCAutoRefCount) { 1077f85e193739c953358c865005855253af4f68a497John McCall switch (getObjCLifetime()) { 1078f85e193739c953358c865005855253af4f68a497John McCall case Qualifiers::OCL_ExplicitNone: 1079f85e193739c953358c865005855253af4f68a497John McCall return true; 1080f85e193739c953358c865005855253af4f68a497John McCall 1081f85e193739c953358c865005855253af4f68a497John McCall case Qualifiers::OCL_Strong: 1082f85e193739c953358c865005855253af4f68a497John McCall case Qualifiers::OCL_Weak: 1083f85e193739c953358c865005855253af4f68a497John McCall case Qualifiers::OCL_Autoreleasing: 1084f85e193739c953358c865005855253af4f68a497John McCall return false; 1085f85e193739c953358c865005855253af4f68a497John McCall 1086f85e193739c953358c865005855253af4f68a497John McCall case Qualifiers::OCL_None: 1087f85e193739c953358c865005855253af4f68a497John McCall if ((*this)->isObjCLifetimeType()) 1088f85e193739c953358c865005855253af4f68a497John McCall return false; 1089f85e193739c953358c865005855253af4f68a497John McCall break; 1090f85e193739c953358c865005855253af4f68a497John McCall } 1091f85e193739c953358c865005855253af4f68a497John McCall } 1092f85e193739c953358c865005855253af4f68a497John McCall 1093f85e193739c953358c865005855253af4f68a497John McCall // C++0x [basic.types]p9 1094f85e193739c953358c865005855253af4f68a497John McCall // Scalar types, trivially copyable class types, arrays of such types, and 1095f85e193739c953358c865005855253af4f68a497John McCall // cv-qualified versions of these types are collectively called trivial 1096f85e193739c953358c865005855253af4f68a497John McCall // types. 1097f85e193739c953358c865005855253af4f68a497John McCall 1098f85e193739c953358c865005855253af4f68a497John McCall QualType CanonicalType = getCanonicalType(); 1099f85e193739c953358c865005855253af4f68a497John McCall if (CanonicalType->isDependentType()) 1100f85e193739c953358c865005855253af4f68a497John McCall return false; 1101f85e193739c953358c865005855253af4f68a497John McCall 1102f85e193739c953358c865005855253af4f68a497John McCall // Return false for incomplete types after skipping any incomplete array types 1103f85e193739c953358c865005855253af4f68a497John McCall // which are expressly allowed by the standard and thus our API. 1104f85e193739c953358c865005855253af4f68a497John McCall if (CanonicalType->isIncompleteType()) 1105f85e193739c953358c865005855253af4f68a497John McCall return false; 1106f85e193739c953358c865005855253af4f68a497John McCall 1107f85e193739c953358c865005855253af4f68a497John McCall // As an extension, Clang treats vector types as Scalar types. 1108f85e193739c953358c865005855253af4f68a497John McCall if (CanonicalType->isScalarType() || CanonicalType->isVectorType()) 1109f85e193739c953358c865005855253af4f68a497John McCall return true; 1110f85e193739c953358c865005855253af4f68a497John McCall 1111f85e193739c953358c865005855253af4f68a497John McCall if (const RecordType *RT = CanonicalType->getAs<RecordType>()) { 1112f85e193739c953358c865005855253af4f68a497John McCall if (const CXXRecordDecl *ClassDecl = 1113f85e193739c953358c865005855253af4f68a497John McCall dyn_cast<CXXRecordDecl>(RT->getDecl())) { 1114f85e193739c953358c865005855253af4f68a497John McCall if (!ClassDecl->isTriviallyCopyable()) return false; 1115f85e193739c953358c865005855253af4f68a497John McCall } 1116f85e193739c953358c865005855253af4f68a497John McCall 1117f85e193739c953358c865005855253af4f68a497John McCall return true; 1118f85e193739c953358c865005855253af4f68a497John McCall } 1119f85e193739c953358c865005855253af4f68a497John McCall 1120f85e193739c953358c865005855253af4f68a497John McCall // No other types can match. 1121f85e193739c953358c865005855253af4f68a497John McCall return false; 1122f85e193739c953358c865005855253af4f68a497John McCall} 1123f85e193739c953358c865005855253af4f68a497John McCall 1124f85e193739c953358c865005855253af4f68a497John McCall 1125f85e193739c953358c865005855253af4f68a497John McCall 1126ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redlbool Type::isLiteralType() const { 1127018a088b3b30e500efa9173f7cd4b1b1f6a065a8Chandler Carruth if (isDependentType()) 1128ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl return false; 1129ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl 1130ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl // C++0x [basic.types]p10: 1131ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl // A type is a literal type if it is: 11329b6347cd410be55425f7062d22fd6e4ecb4e1a58Chandler Carruth // [...] 1133af1fc7af351758b0ea0d285bdfe5640128109a4eRichard Smith // -- an array of literal type. 11349b6347cd410be55425f7062d22fd6e4ecb4e1a58Chandler Carruth // Extension: variable arrays cannot be literal types, since they're 11359b6347cd410be55425f7062d22fd6e4ecb4e1a58Chandler Carruth // runtime-sized. 1136018a088b3b30e500efa9173f7cd4b1b1f6a065a8Chandler Carruth if (isVariableArrayType()) 1137ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl return false; 11389b6347cd410be55425f7062d22fd6e4ecb4e1a58Chandler Carruth const Type *BaseTy = getBaseElementTypeUnsafe(); 11399b6347cd410be55425f7062d22fd6e4ecb4e1a58Chandler Carruth assert(BaseTy && "NULL element type"); 1140ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl 1141018a088b3b30e500efa9173f7cd4b1b1f6a065a8Chandler Carruth // Return false for incomplete types after skipping any incomplete array 1142018a088b3b30e500efa9173f7cd4b1b1f6a065a8Chandler Carruth // types; those are expressly allowed by the standard and thus our API. 1143018a088b3b30e500efa9173f7cd4b1b1f6a065a8Chandler Carruth if (BaseTy->isIncompleteType()) 1144018a088b3b30e500efa9173f7cd4b1b1f6a065a8Chandler Carruth return false; 1145018a088b3b30e500efa9173f7cd4b1b1f6a065a8Chandler Carruth 11469b6347cd410be55425f7062d22fd6e4ecb4e1a58Chandler Carruth // C++0x [basic.types]p10: 11479b6347cd410be55425f7062d22fd6e4ecb4e1a58Chandler Carruth // A type is a literal type if it is: 11489b6347cd410be55425f7062d22fd6e4ecb4e1a58Chandler Carruth // -- a scalar type; or 11497ead5c7b6fd48cf549e55b4db499c26ecf88ae75Eli Friedman // As an extension, Clang treats vector types and complex types as 11507ead5c7b6fd48cf549e55b4db499c26ecf88ae75Eli Friedman // literal types. 11517ead5c7b6fd48cf549e55b4db499c26ecf88ae75Eli Friedman if (BaseTy->isScalarType() || BaseTy->isVectorType() || 11527ead5c7b6fd48cf549e55b4db499c26ecf88ae75Eli Friedman BaseTy->isAnyComplexType()) 1153af1fc7af351758b0ea0d285bdfe5640128109a4eRichard Smith return true; 11549b6347cd410be55425f7062d22fd6e4ecb4e1a58Chandler Carruth // -- a reference type; or 1155af1fc7af351758b0ea0d285bdfe5640128109a4eRichard Smith if (BaseTy->isReferenceType()) 1156af1fc7af351758b0ea0d285bdfe5640128109a4eRichard Smith return true; 11579b6347cd410be55425f7062d22fd6e4ecb4e1a58Chandler Carruth // -- a class type that has all of the following properties: 11589b6347cd410be55425f7062d22fd6e4ecb4e1a58Chandler Carruth if (const RecordType *RT = BaseTy->getAs<RecordType>()) { 11599f569cca2a4c5fb6026005434e27025b9e71309dRichard Smith // -- a trivial destructor, 11609f569cca2a4c5fb6026005434e27025b9e71309dRichard Smith // -- every constructor call and full-expression in the 11619f569cca2a4c5fb6026005434e27025b9e71309dRichard Smith // brace-or-equal-initializers for non-static data members (if any) 11629f569cca2a4c5fb6026005434e27025b9e71309dRichard Smith // is a constant expression, 11639f569cca2a4c5fb6026005434e27025b9e71309dRichard Smith // -- it is an aggregate type or has at least one constexpr 11649f569cca2a4c5fb6026005434e27025b9e71309dRichard Smith // constructor or constructor template that is not a copy or move 11659f569cca2a4c5fb6026005434e27025b9e71309dRichard Smith // constructor, and 11669f569cca2a4c5fb6026005434e27025b9e71309dRichard Smith // -- all non-static data members and base classes of literal types 11679f569cca2a4c5fb6026005434e27025b9e71309dRichard Smith // 11689f569cca2a4c5fb6026005434e27025b9e71309dRichard Smith // We resolve DR1361 by ignoring the second bullet. 11695751838965eefa1c08e4fc545498a3ee45cd9611Chandler Carruth if (const CXXRecordDecl *ClassDecl = 11709f569cca2a4c5fb6026005434e27025b9e71309dRichard Smith dyn_cast<CXXRecordDecl>(RT->getDecl())) 11719f569cca2a4c5fb6026005434e27025b9e71309dRichard Smith return ClassDecl->isLiteral(); 11729b6347cd410be55425f7062d22fd6e4ecb4e1a58Chandler Carruth 11739b6347cd410be55425f7062d22fd6e4ecb4e1a58Chandler Carruth return true; 1174ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl } 1175af1fc7af351758b0ea0d285bdfe5640128109a4eRichard Smith 11769b6347cd410be55425f7062d22fd6e4ecb4e1a58Chandler Carruth return false; 1177ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl} 1178ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl 1179636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruthbool Type::isStandardLayoutType() const { 1180018a088b3b30e500efa9173f7cd4b1b1f6a065a8Chandler Carruth if (isDependentType()) 1181636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth return false; 1182636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth 1183636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth // C++0x [basic.types]p9: 1184636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth // Scalar types, standard-layout class types, arrays of such types, and 1185636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth // cv-qualified versions of these types are collectively called 1186636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth // standard-layout types. 1187636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth const Type *BaseTy = getBaseElementTypeUnsafe(); 1188636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth assert(BaseTy && "NULL element type"); 1189018a088b3b30e500efa9173f7cd4b1b1f6a065a8Chandler Carruth 1190018a088b3b30e500efa9173f7cd4b1b1f6a065a8Chandler Carruth // Return false for incomplete types after skipping any incomplete array 1191018a088b3b30e500efa9173f7cd4b1b1f6a065a8Chandler Carruth // types which are expressly allowed by the standard and thus our API. 1192018a088b3b30e500efa9173f7cd4b1b1f6a065a8Chandler Carruth if (BaseTy->isIncompleteType()) 1193018a088b3b30e500efa9173f7cd4b1b1f6a065a8Chandler Carruth return false; 1194018a088b3b30e500efa9173f7cd4b1b1f6a065a8Chandler Carruth 119525df423cfc6689cf21d51a66af84ea1e70d489dfChandler Carruth // As an extension, Clang treats vector types as Scalar types. 119625df423cfc6689cf21d51a66af84ea1e70d489dfChandler Carruth if (BaseTy->isScalarType() || BaseTy->isVectorType()) return true; 1197636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth if (const RecordType *RT = BaseTy->getAs<RecordType>()) { 1198636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth if (const CXXRecordDecl *ClassDecl = 1199636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth dyn_cast<CXXRecordDecl>(RT->getDecl())) 1200ec997dc66627957bcdcd3db7906a68c1e14a279cChandler Carruth if (!ClassDecl->isStandardLayout()) 1201636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth return false; 1202636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth 1203636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth // Default to 'true' for non-C++ class types. 1204636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth // FIXME: This is a bit dubious, but plain C structs should trivially meet 1205636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth // all the requirements of standard layout classes. 1206636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth return true; 1207636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth } 1208636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth 1209636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth // No other types can match. 1210636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth return false; 1211636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth} 1212636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth 1213636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth// This is effectively the intersection of isTrivialType and 12147426f793844407021ffeb5afcf917fff1a57f196Richard Smith// isStandardLayoutType. We implement it directly to avoid redundant 1215636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth// conversions from a type to a CXXRecordDecl. 1216f85e193739c953358c865005855253af4f68a497John McCallbool QualType::isCXX11PODType(ASTContext &Context) const { 1217f85e193739c953358c865005855253af4f68a497John McCall const Type *ty = getTypePtr(); 1218f85e193739c953358c865005855253af4f68a497John McCall if (ty->isDependentType()) 121943fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth return false; 122043fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth 12214e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie if (Context.getLangOpts().ObjCAutoRefCount) { 1222f85e193739c953358c865005855253af4f68a497John McCall switch (getObjCLifetime()) { 1223f85e193739c953358c865005855253af4f68a497John McCall case Qualifiers::OCL_ExplicitNone: 1224f85e193739c953358c865005855253af4f68a497John McCall return true; 1225f85e193739c953358c865005855253af4f68a497John McCall 1226f85e193739c953358c865005855253af4f68a497John McCall case Qualifiers::OCL_Strong: 1227f85e193739c953358c865005855253af4f68a497John McCall case Qualifiers::OCL_Weak: 1228f85e193739c953358c865005855253af4f68a497John McCall case Qualifiers::OCL_Autoreleasing: 1229f85e193739c953358c865005855253af4f68a497John McCall return false; 1230f85e193739c953358c865005855253af4f68a497John McCall 1231f85e193739c953358c865005855253af4f68a497John McCall case Qualifiers::OCL_None: 1232f85e193739c953358c865005855253af4f68a497John McCall break; 1233f85e193739c953358c865005855253af4f68a497John McCall } 1234f85e193739c953358c865005855253af4f68a497John McCall } 1235f85e193739c953358c865005855253af4f68a497John McCall 123643fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth // C++11 [basic.types]p9: 123743fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth // Scalar types, POD classes, arrays of such types, and cv-qualified 123843fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth // versions of these types are collectively called trivial types. 1239f85e193739c953358c865005855253af4f68a497John McCall const Type *BaseTy = ty->getBaseElementTypeUnsafe(); 124043fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth assert(BaseTy && "NULL element type"); 1241018a088b3b30e500efa9173f7cd4b1b1f6a065a8Chandler Carruth 1242018a088b3b30e500efa9173f7cd4b1b1f6a065a8Chandler Carruth // Return false for incomplete types after skipping any incomplete array 1243018a088b3b30e500efa9173f7cd4b1b1f6a065a8Chandler Carruth // types which are expressly allowed by the standard and thus our API. 1244018a088b3b30e500efa9173f7cd4b1b1f6a065a8Chandler Carruth if (BaseTy->isIncompleteType()) 1245018a088b3b30e500efa9173f7cd4b1b1f6a065a8Chandler Carruth return false; 1246018a088b3b30e500efa9173f7cd4b1b1f6a065a8Chandler Carruth 124725df423cfc6689cf21d51a66af84ea1e70d489dfChandler Carruth // As an extension, Clang treats vector types as Scalar types. 124825df423cfc6689cf21d51a66af84ea1e70d489dfChandler Carruth if (BaseTy->isScalarType() || BaseTy->isVectorType()) return true; 124943fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth if (const RecordType *RT = BaseTy->getAs<RecordType>()) { 125043fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth if (const CXXRecordDecl *ClassDecl = 125143fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth dyn_cast<CXXRecordDecl>(RT->getDecl())) { 125243fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth // C++11 [class]p10: 125343fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth // A POD struct is a non-union class that is both a trivial class [...] 1254023df37c27ee8035664fb62f206ca58f4e2a169dSean Hunt if (!ClassDecl->isTrivial()) return false; 125543fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth 125643fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth // C++11 [class]p10: 125743fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth // A POD struct is a non-union class that is both a trivial class and 125843fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth // a standard-layout class [...] 1259ec997dc66627957bcdcd3db7906a68c1e14a279cChandler Carruth if (!ClassDecl->isStandardLayout()) return false; 126043fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth 126143fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth // C++11 [class]p10: 126243fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth // A POD struct is a non-union class that is both a trivial class and 126343fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth // a standard-layout class, and has no non-static data members of type 126443fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth // non-POD struct, non-POD union (or array of such types). [...] 126543fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth // 126643fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth // We don't directly query the recursive aspect as the requiremets for 126743fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth // both standard-layout classes and trivial classes apply recursively 126843fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth // already. 126943fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth } 127043fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth 127143fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth return true; 127243fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth } 127343fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth 127443fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth // No other types can match. 127543fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth return false; 127643fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth} 127743fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth 12785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isPromotableIntegerType() const { 1279183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const BuiltinType *BT = getAs<BuiltinType>()) 12802a18dfe292cf3c406a769c3672080970ac586345Chris Lattner switch (BT->getKind()) { 12812a18dfe292cf3c406a769c3672080970ac586345Chris Lattner case BuiltinType::Bool: 12822a18dfe292cf3c406a769c3672080970ac586345Chris Lattner case BuiltinType::Char_S: 12832a18dfe292cf3c406a769c3672080970ac586345Chris Lattner case BuiltinType::Char_U: 12842a18dfe292cf3c406a769c3672080970ac586345Chris Lattner case BuiltinType::SChar: 12852a18dfe292cf3c406a769c3672080970ac586345Chris Lattner case BuiltinType::UChar: 12862a18dfe292cf3c406a769c3672080970ac586345Chris Lattner case BuiltinType::Short: 12872a18dfe292cf3c406a769c3672080970ac586345Chris Lattner case BuiltinType::UShort: 128868a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman case BuiltinType::WChar_S: 128968a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman case BuiltinType::WChar_U: 129068a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman case BuiltinType::Char16: 129168a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman case BuiltinType::Char32: 12922a18dfe292cf3c406a769c3672080970ac586345Chris Lattner return true; 12931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump default: 12942a18dfe292cf3c406a769c3672080970ac586345Chris Lattner return false; 12952a18dfe292cf3c406a769c3672080970ac586345Chris Lattner } 1296aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor 1297aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor // Enumerated types are promotable to their compatible integer types 1298aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor // (C99 6.3.1.1) a.k.a. its underlying type (C++ [conv.prom]p2). 1299aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor if (const EnumType *ET = getAs<EnumType>()){ 13001274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor if (this->isDependentType() || ET->getDecl()->getPromotionType().isNull() 13011274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor || ET->getDecl()->isScoped()) 1302aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor return false; 1303aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor 130468a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman return true; 1305aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor } 1306aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor 13072a18dfe292cf3c406a769c3672080970ac586345Chris Lattner return false; 13085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 13095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 131022b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedmanbool Type::isSpecifierType() const { 131122b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman // Note that this intentionally does not use the canonical type. 131222b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman switch (getTypeClass()) { 131322b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman case Builtin: 131422b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman case Record: 131522b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman case Enum: 131622b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman case Typedef: 1317c8f2c61f4f667c2bc3e4e74b274fa397a4232393Eli Friedman case Complex: 1318c8f2c61f4f667c2bc3e4e74b274fa397a4232393Eli Friedman case TypeOfExpr: 1319c8f2c61f4f667c2bc3e4e74b274fa397a4232393Eli Friedman case TypeOf: 1320c8f2c61f4f667c2bc3e4e74b274fa397a4232393Eli Friedman case TemplateTypeParm: 132149a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall case SubstTemplateTypeParm: 1322c8f2c61f4f667c2bc3e4e74b274fa397a4232393Eli Friedman case TemplateSpecialization: 1323465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case Elaborated: 13244714c12a1ab759156b78be8f109ea4c12213af57Douglas Gregor case DependentName: 132533500955d731c73717af52088b7fc0e7a85681e7John McCall case DependentTemplateSpecialization: 1326c8f2c61f4f667c2bc3e4e74b274fa397a4232393Eli Friedman case ObjCInterface: 1327c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall case ObjCObject: 1328c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall case ObjCObjectPointer: // FIXME: object pointers aren't really specifiers 132922b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman return true; 133022b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman default: 133122b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman return false; 133222b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman } 133322b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman} 133422b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman 1335465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraElaboratedTypeKeyword 1336465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraTypeWithKeyword::getKeywordForTypeSpec(unsigned TypeSpec) { 1337465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara switch (TypeSpec) { 1338465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara default: return ETK_None; 1339465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TST_typename: return ETK_Typename; 1340465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TST_class: return ETK_Class; 1341465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TST_struct: return ETK_Struct; 13426666ed4ed2e2bc13da5ac5d0a4947019137d45beJoao Matos case TST_interface: return ETK_Interface; 1343465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TST_union: return ETK_Union; 1344465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TST_enum: return ETK_Enum; 1345465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara } 1346465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara} 1347465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 1348465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraTagTypeKind 1349465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraTypeWithKeyword::getTagTypeKindForTypeSpec(unsigned TypeSpec) { 1350465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara switch(TypeSpec) { 1351465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TST_class: return TTK_Class; 1352465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TST_struct: return TTK_Struct; 13536666ed4ed2e2bc13da5ac5d0a4947019137d45beJoao Matos case TST_interface: return TTK_Interface; 1354465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TST_union: return TTK_Union; 1355465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TST_enum: return TTK_Enum; 1356465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara } 13577907fad723a0f4764a2396df620d9c58725b3053Douglas Gregor 13587907fad723a0f4764a2396df620d9c58725b3053Douglas Gregor llvm_unreachable("Type specifier is not a tag type kind."); 1359465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara} 1360465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 1361465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraElaboratedTypeKeyword 1362465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraTypeWithKeyword::getKeywordForTagTypeKind(TagTypeKind Kind) { 1363465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara switch (Kind) { 1364465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TTK_Class: return ETK_Class; 1365465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TTK_Struct: return ETK_Struct; 13666666ed4ed2e2bc13da5ac5d0a4947019137d45beJoao Matos case TTK_Interface: return ETK_Interface; 1367465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TTK_Union: return ETK_Union; 1368465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TTK_Enum: return ETK_Enum; 1369465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara } 1370465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara llvm_unreachable("Unknown tag type kind."); 1371465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara} 1372465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 1373465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraTagTypeKind 1374465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraTypeWithKeyword::getTagTypeKindForKeyword(ElaboratedTypeKeyword Keyword) { 1375465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara switch (Keyword) { 1376465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Class: return TTK_Class; 1377465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Struct: return TTK_Struct; 13786666ed4ed2e2bc13da5ac5d0a4947019137d45beJoao Matos case ETK_Interface: return TTK_Interface; 1379465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Union: return TTK_Union; 1380465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Enum: return TTK_Enum; 1381465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_None: // Fall through. 1382465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Typename: 1383465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara llvm_unreachable("Elaborated type keyword is not a tag type kind."); 1384465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara } 1385465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara llvm_unreachable("Unknown elaborated type keyword."); 1386465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara} 1387465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 1388465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnarabool 1389465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraTypeWithKeyword::KeywordIsTagTypeKind(ElaboratedTypeKeyword Keyword) { 1390465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara switch (Keyword) { 1391465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_None: 1392465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Typename: 1393465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara return false; 1394465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Class: 1395465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Struct: 13966666ed4ed2e2bc13da5ac5d0a4947019137d45beJoao Matos case ETK_Interface: 1397465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Union: 1398465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Enum: 13994033642464e8ba0982f88f34cffad808d247b393Douglas Gregor return true; 14004033642464e8ba0982f88f34cffad808d247b393Douglas Gregor } 1401465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara llvm_unreachable("Unknown elaborated type keyword."); 1402465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara} 1403465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 1404465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnaraconst char* 1405465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraTypeWithKeyword::getKeywordName(ElaboratedTypeKeyword Keyword) { 1406465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara switch (Keyword) { 1407465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_None: return ""; 1408465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Typename: return "typename"; 1409465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Class: return "class"; 1410465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Struct: return "struct"; 14116666ed4ed2e2bc13da5ac5d0a4947019137d45beJoao Matos case ETK_Interface: return "__interface"; 1412465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Union: return "union"; 1413465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Enum: return "enum"; 1414465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara } 14157907fad723a0f4764a2396df620d9c58725b3053Douglas Gregor 14167907fad723a0f4764a2396df620d9c58725b3053Douglas Gregor llvm_unreachable("Unknown elaborated type keyword."); 1417465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara} 1418465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 141933500955d731c73717af52088b7fc0e7a85681e7John McCallDependentTemplateSpecializationType::DependentTemplateSpecializationType( 1420ef99001908e799c388f1363b1e607dad5f5b57d3John McCall ElaboratedTypeKeyword Keyword, 142133500955d731c73717af52088b7fc0e7a85681e7John McCall NestedNameSpecifier *NNS, const IdentifierInfo *Name, 142233500955d731c73717af52088b7fc0e7a85681e7John McCall unsigned NumArgs, const TemplateArgument *Args, 142333500955d731c73717af52088b7fc0e7a85681e7John McCall QualType Canon) 1424561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor : TypeWithKeyword(Keyword, DependentTemplateSpecialization, Canon, true, true, 1425d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /*VariablyModified=*/false, 1426aa2187de137e5b809dcbbe14f3b61ae907a3d8aaDouglas Gregor NNS && NNS->containsUnexpandedParameterPack()), 1427ef99001908e799c388f1363b1e607dad5f5b57d3John McCall NNS(NNS), Name(Name), NumArgs(NumArgs) { 1428aa2187de137e5b809dcbbe14f3b61ae907a3d8aaDouglas Gregor assert((!NNS || NNS->isDependent()) && 142933500955d731c73717af52088b7fc0e7a85681e7John McCall "DependentTemplateSpecializatonType requires dependent qualifier"); 1430d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor for (unsigned I = 0; I != NumArgs; ++I) { 1431d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor if (Args[I].containsUnexpandedParameterPack()) 1432d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor setContainsUnexpandedParameterPack(); 1433d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 143433500955d731c73717af52088b7fc0e7a85681e7John McCall new (&getArgBuffer()[I]) TemplateArgument(Args[I]); 1435d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor } 143633500955d731c73717af52088b7fc0e7a85681e7John McCall} 143733500955d731c73717af52088b7fc0e7a85681e7John McCall 143833500955d731c73717af52088b7fc0e7a85681e7John McCallvoid 143933500955d731c73717af52088b7fc0e7a85681e7John McCallDependentTemplateSpecializationType::Profile(llvm::FoldingSetNodeID &ID, 14404ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad const ASTContext &Context, 144133500955d731c73717af52088b7fc0e7a85681e7John McCall ElaboratedTypeKeyword Keyword, 144233500955d731c73717af52088b7fc0e7a85681e7John McCall NestedNameSpecifier *Qualifier, 144333500955d731c73717af52088b7fc0e7a85681e7John McCall const IdentifierInfo *Name, 144433500955d731c73717af52088b7fc0e7a85681e7John McCall unsigned NumArgs, 144533500955d731c73717af52088b7fc0e7a85681e7John McCall const TemplateArgument *Args) { 144633500955d731c73717af52088b7fc0e7a85681e7John McCall ID.AddInteger(Keyword); 144733500955d731c73717af52088b7fc0e7a85681e7John McCall ID.AddPointer(Qualifier); 144833500955d731c73717af52088b7fc0e7a85681e7John McCall ID.AddPointer(Name); 144933500955d731c73717af52088b7fc0e7a85681e7John McCall for (unsigned Idx = 0; Idx < NumArgs; ++Idx) 145033500955d731c73717af52088b7fc0e7a85681e7John McCall Args[Idx].Profile(ID, Context); 145133500955d731c73717af52088b7fc0e7a85681e7John McCall} 145233500955d731c73717af52088b7fc0e7a85681e7John McCall 1453465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnarabool Type::isElaboratedTypeSpecifier() const { 1454465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara ElaboratedTypeKeyword Keyword; 1455465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara if (const ElaboratedType *Elab = dyn_cast<ElaboratedType>(this)) 1456465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara Keyword = Elab->getKeyword(); 1457465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara else if (const DependentNameType *DepName = dyn_cast<DependentNameType>(this)) 1458465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara Keyword = DepName->getKeyword(); 145933500955d731c73717af52088b7fc0e7a85681e7John McCall else if (const DependentTemplateSpecializationType *DepTST = 146033500955d731c73717af52088b7fc0e7a85681e7John McCall dyn_cast<DependentTemplateSpecializationType>(this)) 146133500955d731c73717af52088b7fc0e7a85681e7John McCall Keyword = DepTST->getKeyword(); 1462465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara else 1463465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara return false; 1464465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 1465465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara return TypeWithKeyword::KeywordIsTagTypeKind(Keyword); 14664033642464e8ba0982f88f34cffad808d247b393Douglas Gregor} 14674033642464e8ba0982f88f34cffad808d247b393Douglas Gregor 1468cd01f17358dc8ef19338c0e2321138dd0a6160d9Argyrios Kyrtzidisconst char *Type::getTypeClassName() const { 1469b870b88df784c2940efce448ebfaf54dece14666John McCall switch (TypeBits.TC) { 1470cd01f17358dc8ef19338c0e2321138dd0a6160d9Argyrios Kyrtzidis#define ABSTRACT_TYPE(Derived, Base) 1471cd01f17358dc8ef19338c0e2321138dd0a6160d9Argyrios Kyrtzidis#define TYPE(Derived, Base) case Derived: return #Derived; 1472cd01f17358dc8ef19338c0e2321138dd0a6160d9Argyrios Kyrtzidis#include "clang/AST/TypeNodes.def" 1473cd01f17358dc8ef19338c0e2321138dd0a6160d9Argyrios Kyrtzidis } 14747907fad723a0f4764a2396df620d9c58725b3053Douglas Gregor 14757907fad723a0f4764a2396df620d9c58725b3053Douglas Gregor llvm_unreachable("Invalid type class."); 1476cd01f17358dc8ef19338c0e2321138dd0a6160d9Argyrios Kyrtzidis} 1477cd01f17358dc8ef19338c0e2321138dd0a6160d9Argyrios Kyrtzidis 147827a00970bf4ababdc115e54383e6252cc3276dfaArgyrios KyrtzidisStringRef BuiltinType::getName(const PrintingPolicy &Policy) const { 14795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer switch (getKind()) { 14805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Void: return "void"; 148130c42404202d2e2512e51efc6066bd614cfdb5a4Douglas Gregor case Bool: return Policy.Bool ? "bool" : "_Bool"; 14825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Char_S: return "char"; 14835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Char_U: return "char"; 14845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case SChar: return "signed char"; 14855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Short: return "short"; 14865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Int: return "int"; 14875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Long: return "long"; 14885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case LongLong: return "long long"; 14895a5a971908a1fd064454db44c42333a3aecf3d5bRichard Smith case Int128: return "__int128"; 14905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case UChar: return "unsigned char"; 14915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case UShort: return "unsigned short"; 14925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case UInt: return "unsigned int"; 14935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case ULong: return "unsigned long"; 14945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case ULongLong: return "unsigned long long"; 14955a5a971908a1fd064454db44c42333a3aecf3d5bRichard Smith case UInt128: return "unsigned __int128"; 1496aa4a99b4a62615db243f7a5c433169f2fc704420Anton Korobeynikov case Half: return "half"; 14975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Float: return "float"; 14985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Double: return "double"; 14995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case LongDouble: return "long double"; 15003f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner case WChar_S: 15013f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner case WChar_U: return "wchar_t"; 1502f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith case Char16: return "char16_t"; 1503f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith case Char32: return "char32_t"; 15046e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl case NullPtr: return "nullptr_t"; 15058e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor case Overload: return "<overloaded function type>"; 1506864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall case BoundMember: return "<bound member function type>"; 15073c3b7f90a863af43fa63043d396553ecf205351cJohn McCall case PseudoObject: return "<pseudo-object type>"; 1508898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor case Dependent: return "<dependent type>"; 15091de4d4e8cb2e9c88809fea8092bc6e835a5473d2John McCall case UnknownAny: return "<unknown type>"; 15100ddaeb9b031070ec64afe92d9892875ac44df427John McCall case ARCUnbridgedCast: return "<ARC unbridged cast type>"; 1511a6c66cedc022c9e5d45a937d6b8cff491a6bf81bEli Friedman case BuiltinFn: return "<builtin fn type>"; 1512de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff case ObjCId: return "id"; 1513de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff case ObjCClass: return "Class"; 1514bef0efd11bc4430a3ee437a3213cec5c18af855aChris Lattner case ObjCSel: return "SEL"; 1515b13621d08e20ac7aa550e05896de8a57ee99c1e8Guy Benyei case OCLImage1d: return "image1d_t"; 1516b13621d08e20ac7aa550e05896de8a57ee99c1e8Guy Benyei case OCLImage1dArray: return "image1d_array_t"; 1517b13621d08e20ac7aa550e05896de8a57ee99c1e8Guy Benyei case OCLImage1dBuffer: return "image1d_buffer_t"; 1518b13621d08e20ac7aa550e05896de8a57ee99c1e8Guy Benyei case OCLImage2d: return "image2d_t"; 1519b13621d08e20ac7aa550e05896de8a57ee99c1e8Guy Benyei case OCLImage2dArray: return "image2d_array_t"; 1520b13621d08e20ac7aa550e05896de8a57ee99c1e8Guy Benyei case OCLImage3d: return "image3d_t"; 152121f18c4fda167dc5f72feddbd6a7ac1b63200a0dGuy Benyei case OCLSampler: return "sampler_t"; 1522e6b9d802fb7b16d93474c4f1c179ab36202e8a8bGuy Benyei case OCLEvent: return "event_t"; 15235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 15247907fad723a0f4764a2396df620d9c58725b3053Douglas Gregor 1525aab440b2cb0e583aeaf21f08c8247456f3142a23Nick Lewycky llvm_unreachable("Invalid builtin type."); 15265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 15275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 15286398235d7890a81b785ea5af3b6e66d86bf184ccDouglas GregorQualType QualType::getNonLValueExprType(ASTContext &Context) const { 15295291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor if (const ReferenceType *RefType = getTypePtr()->getAs<ReferenceType>()) 15305291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor return RefType->getPointeeType(); 15315291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor 15325291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor // C++0x [basic.lval]: 15335291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor // Class prvalues can have cv-qualified types; non-class prvalues always 15345291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor // have cv-unqualified types. 15355291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor // 15365291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor // See also C99 6.3.2.1p2. 15374e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie if (!Context.getLangOpts().CPlusPlus || 15386dc1ef87044e6b177d4df0d2b593a94616180b3dChandler Carruth (!getTypePtr()->isDependentType() && !getTypePtr()->isRecordType())) 15395291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor return getUnqualifiedType(); 15405291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor 15415291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor return *this; 15425291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor} 15435291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor 15445f9e272e632e951b1efe824cd16acb4d96077930Chris LattnerStringRef FunctionType::getNameForCallConv(CallingConv CC) { 154504a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall switch (CC) { 15467907fad723a0f4764a2396df620d9c58725b3053Douglas Gregor case CC_Default: 15477907fad723a0f4764a2396df620d9c58725b3053Douglas Gregor llvm_unreachable("no name for default cc"); 154804a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall 154904a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall case CC_C: return "cdecl"; 155004a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall case CC_X86StdCall: return "stdcall"; 155104a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall case CC_X86FastCall: return "fastcall"; 1552f813a2c03fcb05381b3252010435f557eb6b3cdeDouglas Gregor case CC_X86ThisCall: return "thiscall"; 155352fc314e1b5e1baee6305067cf831763d02bd243Dawn Perchik case CC_X86Pascal: return "pascal"; 1554414d8967e1d760ea1e19a4aca96b13777a8cf8c5Anton Korobeynikov case CC_AAPCS: return "aapcs"; 1555414d8967e1d760ea1e19a4aca96b13777a8cf8c5Anton Korobeynikov case CC_AAPCS_VFP: return "aapcs-vfp"; 1556263366f9241366f29ba65b703120f302490c39ffDerek Schuff case CC_PnaclCall: return "pnaclcall"; 155738980086c0f791e8c23cc882574f18e5b4a87db6Guy Benyei case CC_IntelOclBicc: return "intel_ocl_bicc"; 155804a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall } 15597907fad723a0f4764a2396df620d9c58725b3053Douglas Gregor 15607907fad723a0f4764a2396df620d9c58725b3053Douglas Gregor llvm_unreachable("Invalid calling convention."); 156104a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall} 156204a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall 1563e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCallFunctionProtoType::FunctionProtoType(QualType result, const QualType *args, 1564e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall unsigned numArgs, QualType canonical, 15658026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redl const ExtProtoInfo &epi) 1566aa46d513f47280a9786e8e9aa77f7089b3f8fee6Richard Smith : FunctionType(FunctionProto, result, epi.TypeQuals, 1567eefb3d5b49c844347f212073a7e975b8118fe8e9Richard Smith canonical, 1568e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall result->isDependentType(), 1569561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor result->isInstantiationDependentType(), 1570e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall result->isVariablyModifiedType(), 1571e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall result->containsUnexpandedParameterPack(), 1572e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall epi.ExtInfo), 1573e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall NumArgs(numArgs), NumExceptions(epi.NumExceptions), 1574f85e193739c953358c865005855253af4f68a497John McCall ExceptionSpecType(epi.ExceptionSpecType), 1575eefb3d5b49c844347f212073a7e975b8118fe8e9Richard Smith HasAnyConsumedArgs(epi.ConsumedArguments != 0), 1576aa46d513f47280a9786e8e9aa77f7089b3f8fee6Richard Smith Variadic(epi.Variadic), HasTrailingReturn(epi.HasTrailingReturn), 1577aa46d513f47280a9786e8e9aa77f7089b3f8fee6Richard Smith RefQualifier(epi.RefQualifier) 157835495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor{ 1579aa46d513f47280a9786e8e9aa77f7089b3f8fee6Richard Smith assert(NumArgs == numArgs && "function has too many parameters"); 1580aa46d513f47280a9786e8e9aa77f7089b3f8fee6Richard Smith 158135495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor // Fill in the trailing argument array. 1582e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall QualType *argSlot = reinterpret_cast<QualType*>(this+1); 158335495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor for (unsigned i = 0; i != numArgs; ++i) { 1584e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall if (args[i]->isDependentType()) 158535495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor setDependent(); 1586561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor else if (args[i]->isInstantiationDependentType()) 1587561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor setInstantiationDependent(); 1588561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor 1589e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall if (args[i]->containsUnexpandedParameterPack()) 1590d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor setContainsUnexpandedParameterPack(); 1591d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 1592e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall argSlot[i] = args[i]; 159335495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor } 1594e186269a8a41dbff1ebea2c251048892979d1078Douglas Gregor 159560618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl if (getExceptionSpecType() == EST_Dynamic) { 159660618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl // Fill in the exception array. 159760618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl QualType *exnSlot = argSlot + numArgs; 159860618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl for (unsigned i = 0, e = epi.NumExceptions; i != e; ++i) { 159960618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl if (epi.Exceptions[i]->isDependentType()) 160060618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl setDependent(); 1601561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor else if (epi.Exceptions[i]->isInstantiationDependentType()) 1602561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor setInstantiationDependent(); 1603561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor 160460618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl if (epi.Exceptions[i]->containsUnexpandedParameterPack()) 160560618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl setContainsUnexpandedParameterPack(); 160660618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl 160760618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl exnSlot[i] = epi.Exceptions[i]; 160860618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl } 160960618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl } else if (getExceptionSpecType() == EST_ComputedNoexcept) { 161060618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl // Store the noexcept expression and context. 161160618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl Expr **noexSlot = reinterpret_cast<Expr**>(argSlot + numArgs); 161260618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl *noexSlot = epi.NoexceptExpr; 1613561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor 1614561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (epi.NoexceptExpr) { 1615561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (epi.NoexceptExpr->isValueDependent() 1616561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor || epi.NoexceptExpr->isTypeDependent()) 1617561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor setDependent(); 1618561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor else if (epi.NoexceptExpr->isInstantiationDependent()) 1619561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor setInstantiationDependent(); 1620561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor } 1621e6975e9b0985ad7f7ff9187e38d95bfe9ac4181bRichard Smith } else if (getExceptionSpecType() == EST_Uninstantiated) { 1622e6975e9b0985ad7f7ff9187e38d95bfe9ac4181bRichard Smith // Store the function decl from which we will resolve our 1623e6975e9b0985ad7f7ff9187e38d95bfe9ac4181bRichard Smith // exception specification. 1624e6975e9b0985ad7f7ff9187e38d95bfe9ac4181bRichard Smith FunctionDecl **slot = reinterpret_cast<FunctionDecl**>(argSlot + numArgs); 162513bffc532bafd45d4a77867993c1afb83c7661beRichard Smith slot[0] = epi.ExceptionSpecDecl; 162613bffc532bafd45d4a77867993c1afb83c7661beRichard Smith slot[1] = epi.ExceptionSpecTemplate; 1627e6975e9b0985ad7f7ff9187e38d95bfe9ac4181bRichard Smith // This exception specification doesn't make the type dependent, because 1628e6975e9b0985ad7f7ff9187e38d95bfe9ac4181bRichard Smith // it's not instantiated as part of instantiating the type. 1629b9d0b76e42fd2d4cdfd135220302458d03ad09feRichard Smith } else if (getExceptionSpecType() == EST_Unevaluated) { 1630b9d0b76e42fd2d4cdfd135220302458d03ad09feRichard Smith // Store the function decl from which we will resolve our 1631b9d0b76e42fd2d4cdfd135220302458d03ad09feRichard Smith // exception specification. 1632b9d0b76e42fd2d4cdfd135220302458d03ad09feRichard Smith FunctionDecl **slot = reinterpret_cast<FunctionDecl**>(argSlot + numArgs); 1633b9d0b76e42fd2d4cdfd135220302458d03ad09feRichard Smith slot[0] = epi.ExceptionSpecDecl; 1634e186269a8a41dbff1ebea2c251048892979d1078Douglas Gregor } 1635f85e193739c953358c865005855253af4f68a497John McCall 1636f85e193739c953358c865005855253af4f68a497John McCall if (epi.ConsumedArguments) { 1637f85e193739c953358c865005855253af4f68a497John McCall bool *consumedArgs = const_cast<bool*>(getConsumedArgsBuffer()); 1638f85e193739c953358c865005855253af4f68a497John McCall for (unsigned i = 0; i != numArgs; ++i) 1639f85e193739c953358c865005855253af4f68a497John McCall consumedArgs[i] = epi.ConsumedArguments[i]; 1640f85e193739c953358c865005855253af4f68a497John McCall } 164135495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor} 164235495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor 164360618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian RedlFunctionProtoType::NoexceptResult 16448026f6d82f7fa544bc0453714fe94bca62a1196eSebastian RedlFunctionProtoType::getNoexceptSpec(ASTContext &ctx) const { 164560618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl ExceptionSpecificationType est = getExceptionSpecType(); 164660618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl if (est == EST_BasicNoexcept) 164760618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl return NR_Nothrow; 164860618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl 164960618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl if (est != EST_ComputedNoexcept) 165060618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl return NR_NoNoexcept; 165160618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl 165260618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl Expr *noexceptExpr = getNoexceptExpr(); 165360618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl if (!noexceptExpr) 165460618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl return NR_BadNoexcept; 165560618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl if (noexceptExpr->isValueDependent()) 165660618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl return NR_Dependent; 165760618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl 165860618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl llvm::APSInt value; 165960618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl bool isICE = noexceptExpr->isIntegerConstantExpr(value, ctx, 0, 166060618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl /*evaluated*/false); 166160618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl (void)isICE; 166260618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl assert(isICE && "AST should not contain bad noexcept expressions."); 166360618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl 166460618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl return value.getBoolValue() ? NR_Nothrow : NR_Throw; 166560618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl} 166660618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl 1667f5c65ffbd7374b6c8d9f1e361041578640cab320Douglas Gregorbool FunctionProtoType::isTemplateVariadic() const { 16687d5c0c1273bdc1cb3dff1cb5a62d07b1439e82c7Douglas Gregor for (unsigned ArgIdx = getNumArgs(); ArgIdx; --ArgIdx) 16697d5c0c1273bdc1cb3dff1cb5a62d07b1439e82c7Douglas Gregor if (isa<PackExpansionType>(getArgType(ArgIdx - 1))) 16707d5c0c1273bdc1cb3dff1cb5a62d07b1439e82c7Douglas Gregor return true; 16717d5c0c1273bdc1cb3dff1cb5a62d07b1439e82c7Douglas Gregor 16727d5c0c1273bdc1cb3dff1cb5a62d07b1439e82c7Douglas Gregor return false; 1673f5c65ffbd7374b6c8d9f1e361041578640cab320Douglas Gregor} 167435495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor 167572564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregorvoid FunctionProtoType::Profile(llvm::FoldingSetNodeID &ID, QualType Result, 1676e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall const QualType *ArgTys, unsigned NumArgs, 167760618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl const ExtProtoInfo &epi, 16788026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redl const ASTContext &Context) { 1679f85e193739c953358c865005855253af4f68a497John McCall 1680f85e193739c953358c865005855253af4f68a497John McCall // We have to be careful not to get ambiguous profile encodings. 1681f85e193739c953358c865005855253af4f68a497John McCall // Note that valid type pointers are never ambiguous with anything else. 1682f85e193739c953358c865005855253af4f68a497John McCall // 1683f85e193739c953358c865005855253af4f68a497John McCall // The encoding grammar begins: 1684f85e193739c953358c865005855253af4f68a497John McCall // type type* bool int bool 1685f85e193739c953358c865005855253af4f68a497John McCall // If that final bool is true, then there is a section for the EH spec: 1686f85e193739c953358c865005855253af4f68a497John McCall // bool type* 1687f85e193739c953358c865005855253af4f68a497John McCall // This is followed by an optional "consumed argument" section of the 1688f85e193739c953358c865005855253af4f68a497John McCall // same length as the first type sequence: 1689f85e193739c953358c865005855253af4f68a497John McCall // bool* 1690eefb3d5b49c844347f212073a7e975b8118fe8e9Richard Smith // Finally, we have the ext info and trailing return type flag: 1691eefb3d5b49c844347f212073a7e975b8118fe8e9Richard Smith // int bool 1692f85e193739c953358c865005855253af4f68a497John McCall // 1693f85e193739c953358c865005855253af4f68a497John McCall // There is no ambiguity between the consumed arguments and an empty EH 1694f85e193739c953358c865005855253af4f68a497John McCall // spec because of the leading 'bool' which unambiguously indicates 1695f85e193739c953358c865005855253af4f68a497John McCall // whether the following bool is the EH spec or part of the arguments. 1696f85e193739c953358c865005855253af4f68a497John McCall 16975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddPointer(Result.getAsOpaquePtr()); 16985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer for (unsigned i = 0; i != NumArgs; ++i) 16995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddPointer(ArgTys[i].getAsOpaquePtr()); 17000c051221bd06fe1b24b9459292584e5264a131c5Eli Friedman // This method is relatively performance sensitive, so as a performance 17010c051221bd06fe1b24b9459292584e5264a131c5Eli Friedman // shortcut, use one AddInteger call instead of four for the next four 17020c051221bd06fe1b24b9459292584e5264a131c5Eli Friedman // fields. 17030c051221bd06fe1b24b9459292584e5264a131c5Eli Friedman assert(!(unsigned(epi.Variadic) & ~1) && 17040c051221bd06fe1b24b9459292584e5264a131c5Eli Friedman !(unsigned(epi.TypeQuals) & ~255) && 17050c051221bd06fe1b24b9459292584e5264a131c5Eli Friedman !(unsigned(epi.RefQualifier) & ~3) && 17060c051221bd06fe1b24b9459292584e5264a131c5Eli Friedman !(unsigned(epi.ExceptionSpecType) & ~7) && 17070c051221bd06fe1b24b9459292584e5264a131c5Eli Friedman "Values larger than expected."); 17080c051221bd06fe1b24b9459292584e5264a131c5Eli Friedman ID.AddInteger(unsigned(epi.Variadic) + 17090c051221bd06fe1b24b9459292584e5264a131c5Eli Friedman (epi.TypeQuals << 1) + 17100c051221bd06fe1b24b9459292584e5264a131c5Eli Friedman (epi.RefQualifier << 9) + 17110c051221bd06fe1b24b9459292584e5264a131c5Eli Friedman (epi.ExceptionSpecType << 11)); 171260618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl if (epi.ExceptionSpecType == EST_Dynamic) { 1713e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall for (unsigned i = 0; i != epi.NumExceptions; ++i) 1714e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall ID.AddPointer(epi.Exceptions[i].getAsOpaquePtr()); 171560618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl } else if (epi.ExceptionSpecType == EST_ComputedNoexcept && epi.NoexceptExpr){ 17161abd35950bcb0761887dca0995c68b8a9dc8916fDouglas Gregor epi.NoexceptExpr->Profile(ID, Context, false); 1717b9d0b76e42fd2d4cdfd135220302458d03ad09feRichard Smith } else if (epi.ExceptionSpecType == EST_Uninstantiated || 1718b9d0b76e42fd2d4cdfd135220302458d03ad09feRichard Smith epi.ExceptionSpecType == EST_Unevaluated) { 1719e6975e9b0985ad7f7ff9187e38d95bfe9ac4181bRichard Smith ID.AddPointer(epi.ExceptionSpecDecl->getCanonicalDecl()); 1720465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl } 1721f85e193739c953358c865005855253af4f68a497John McCall if (epi.ConsumedArguments) { 1722f85e193739c953358c865005855253af4f68a497John McCall for (unsigned i = 0; i != NumArgs; ++i) 1723f85e193739c953358c865005855253af4f68a497John McCall ID.AddBoolean(epi.ConsumedArguments[i]); 1724f85e193739c953358c865005855253af4f68a497John McCall } 1725e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall epi.ExtInfo.Profile(ID); 1726eefb3d5b49c844347f212073a7e975b8118fe8e9Richard Smith ID.AddBoolean(epi.HasTrailingReturn); 17275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 17285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 17298026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redlvoid FunctionProtoType::Profile(llvm::FoldingSetNodeID &ID, 17308026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redl const ASTContext &Ctx) { 173160618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl Profile(ID, getResultType(), arg_type_begin(), NumArgs, getExtProtoInfo(), 17328026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redl Ctx); 17335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 17345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1735bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCallQualType TypedefType::desugar() const { 1736bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall return getDecl()->getUnderlyingType(); 1737bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall} 1738bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 173972564e73277e29f6db3305d1f27ba408abb7ed88Douglas GregorTypeOfExprType::TypeOfExprType(Expr *E, QualType can) 174035495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor : Type(TypeOfExpr, can, E->isTypeDependent(), 1741561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor E->isInstantiationDependent(), 1742d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor E->getType()->isVariablyModifiedType(), 1743d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor E->containsUnexpandedParameterPack()), 1744d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor TOExpr(E) { 1745898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor} 1746898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 17476af9f3ca25157379efd5c1caad82e9d01c17b9ffDouglas Gregorbool TypeOfExprType::isSugared() const { 17486af9f3ca25157379efd5c1caad82e9d01c17b9ffDouglas Gregor return !TOExpr->isTypeDependent(); 17496af9f3ca25157379efd5c1caad82e9d01c17b9ffDouglas Gregor} 17506af9f3ca25157379efd5c1caad82e9d01c17b9ffDouglas Gregor 1751bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCallQualType TypeOfExprType::desugar() const { 17526af9f3ca25157379efd5c1caad82e9d01c17b9ffDouglas Gregor if (isSugared()) 17536af9f3ca25157379efd5c1caad82e9d01c17b9ffDouglas Gregor return getUnderlyingExpr()->getType(); 17546af9f3ca25157379efd5c1caad82e9d01c17b9ffDouglas Gregor 17556af9f3ca25157379efd5c1caad82e9d01c17b9ffDouglas Gregor return QualType(this, 0); 1756bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall} 1757bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 17581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpvoid DependentTypeOfExprType::Profile(llvm::FoldingSetNodeID &ID, 17594ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad const ASTContext &Context, Expr *E) { 1760b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor E->Profile(ID, Context, true); 1761b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor} 1762b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor 1763563a03b1338d31c2462def43253a722bc885d384Anders CarlssonDecltypeType::DecltypeType(Expr *E, QualType underlyingType, QualType can) 1764fa16125aaf667c2bd80efcea403a7a71aa65da14Richard Smith // C++11 [temp.type]p2: "If an expression e involves a template parameter, 1765fa16125aaf667c2bd80efcea403a7a71aa65da14Richard Smith // decltype(e) denotes a unique dependent type." Hence a decltype type is 1766fa16125aaf667c2bd80efcea403a7a71aa65da14Richard Smith // type-dependent even if its expression is only instantiation-dependent. 1767fa16125aaf667c2bd80efcea403a7a71aa65da14Richard Smith : Type(Decltype, can, E->isInstantiationDependent(), 1768561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor E->isInstantiationDependent(), 1769d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor E->getType()->isVariablyModifiedType(), 1770d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor E->containsUnexpandedParameterPack()), 1771d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor E(E), 1772563a03b1338d31c2462def43253a722bc885d384Anders Carlsson UnderlyingType(underlyingType) { 1773395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson} 1774395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson 17756af9f3ca25157379efd5c1caad82e9d01c17b9ffDouglas Gregorbool DecltypeType::isSugared() const { return !E->isInstantiationDependent(); } 17766af9f3ca25157379efd5c1caad82e9d01c17b9ffDouglas Gregor 17776af9f3ca25157379efd5c1caad82e9d01c17b9ffDouglas GregorQualType DecltypeType::desugar() const { 17786af9f3ca25157379efd5c1caad82e9d01c17b9ffDouglas Gregor if (isSugared()) 17796af9f3ca25157379efd5c1caad82e9d01c17b9ffDouglas Gregor return getUnderlyingType(); 17806af9f3ca25157379efd5c1caad82e9d01c17b9ffDouglas Gregor 17816af9f3ca25157379efd5c1caad82e9d01c17b9ffDouglas Gregor return QualType(this, 0); 17826af9f3ca25157379efd5c1caad82e9d01c17b9ffDouglas Gregor} 17836af9f3ca25157379efd5c1caad82e9d01c17b9ffDouglas Gregor 17844ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadDependentDecltypeType::DependentDecltypeType(const ASTContext &Context, Expr *E) 17859d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor : DecltypeType(E, Context.DependentTy), Context(Context) { } 17869d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor 17871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpvoid DependentDecltypeType::Profile(llvm::FoldingSetNodeID &ID, 17884ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad const ASTContext &Context, Expr *E) { 17899d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor E->Profile(ID, Context, true); 17909d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor} 17919d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor 179219c8576b7328f4dc2d07682f5da552875c1912efJohn McCallTagType::TagType(TypeClass TC, const TagDecl *D, QualType can) 1793561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor : Type(TC, can, D->isDependentType(), 1794561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /*InstantiationDependent=*/D->isDependentType(), 1795561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /*VariablyModified=*/false, 1796d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /*ContainsUnexpandedParameterPack=*/false), 1797ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl decl(const_cast<TagDecl*>(D)) {} 1798ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl 1799ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redlstatic TagDecl *getInterestingTagDecl(TagDecl *decl) { 1800ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl for (TagDecl::redecl_iterator I = decl->redecls_begin(), 1801ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl E = decl->redecls_end(); 1802ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl I != E; ++I) { 18035e1cdac63c3d9c9b32fa41fa0b2d242a58a20d49John McCall if (I->isCompleteDefinition() || I->isBeingDefined()) 1804ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl return *I; 1805ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl } 1806ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl // If there's no definition (not even in progress), return what we have. 1807ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl return decl; 1808ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl} 1809ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl 1810ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean HuntUnaryTransformType::UnaryTransformType(QualType BaseType, 1811ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt QualType UnderlyingType, 1812ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt UTTKind UKind, 1813ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt QualType CanonicalType) 1814ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt : Type(UnaryTransform, CanonicalType, UnderlyingType->isDependentType(), 1815561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor UnderlyingType->isInstantiationDependentType(), 1816ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt UnderlyingType->isVariablyModifiedType(), 1817ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt BaseType->containsUnexpandedParameterPack()) 1818ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt , BaseType(BaseType), UnderlyingType(UnderlyingType), UKind(UKind) 1819ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt{} 1820ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt 1821ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian RedlTagDecl *TagType::getDecl() const { 1822ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl return getInterestingTagDecl(decl); 1823ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl} 1824ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl 1825ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redlbool TagType::isBeingDefined() const { 1826ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl return getDecl()->isBeingDefined(); 1827ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl} 1828ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl 1829ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian RedlCXXRecordDecl *InjectedClassNameType::getDecl() const { 1830ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl return cast<CXXRecordDecl>(getInterestingTagDecl(Decl)); 1831ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl} 18327da97d0f31e1ec16998d3de2cfd2e88fe3736673Douglas Gregor 1833b7efff4bae117604f442bb6859c844f90b15f3ffChandler CarruthIdentifierInfo *TemplateTypeParmType::getIdentifier() const { 18344fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth return isCanonicalUnqualified() ? 0 : getDecl()->getIdentifier(); 18354fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth} 18364fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth 1837c3069d618f4661d923cb1b5c4525b082fce73b04Douglas GregorSubstTemplateTypeParmPackType:: 1838c3069d618f4661d923cb1b5c4525b082fce73b04Douglas GregorSubstTemplateTypeParmPackType(const TemplateTypeParmType *Param, 1839c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor QualType Canon, 1840c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor const TemplateArgument &ArgPack) 1841561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor : Type(SubstTemplateTypeParmPack, Canon, true, true, false, true), 1842561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor Replaced(Param), 1843c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor Arguments(ArgPack.pack_begin()), NumArguments(ArgPack.pack_size()) 1844c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor{ 1845c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor} 1846c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor 1847c3069d618f4661d923cb1b5c4525b082fce73b04Douglas GregorTemplateArgument SubstTemplateTypeParmPackType::getArgumentPack() const { 1848c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor return TemplateArgument(Arguments, NumArguments); 1849c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor} 1850c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor 1851c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregorvoid SubstTemplateTypeParmPackType::Profile(llvm::FoldingSetNodeID &ID) { 1852c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor Profile(ID, getReplacedParameter(), getArgumentPack()); 1853c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor} 1854c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor 1855c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregorvoid SubstTemplateTypeParmPackType::Profile(llvm::FoldingSetNodeID &ID, 1856c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor const TemplateTypeParmType *Replaced, 1857c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor const TemplateArgument &ArgPack) { 1858c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor ID.AddPointer(Replaced); 1859c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor ID.AddInteger(ArgPack.pack_size()); 1860c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor for (TemplateArgument::pack_iterator P = ArgPack.pack_begin(), 1861c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor PEnd = ArgPack.pack_end(); 1862c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor P != PEnd; ++P) 1863c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor ID.AddPointer(P->getAsType().getAsOpaquePtr()); 1864c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor} 1865c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor 1866833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallbool TemplateSpecializationType:: 1867561f81243f665cf2001caadc45df505f826b72d6Douglas GregoranyDependentTemplateArguments(const TemplateArgumentListInfo &Args, 1868561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor bool &InstantiationDependent) { 1869561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor return anyDependentTemplateArguments(Args.getArgumentArray(), Args.size(), 1870561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor InstantiationDependent); 1871d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall} 1872d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall 1873d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCallbool TemplateSpecializationType:: 1874561f81243f665cf2001caadc45df505f826b72d6Douglas GregoranyDependentTemplateArguments(const TemplateArgumentLoc *Args, unsigned N, 1875561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor bool &InstantiationDependent) { 1876561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor for (unsigned i = 0; i != N; ++i) { 1877561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (Args[i].getArgument().isDependent()) { 1878561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor InstantiationDependent = true; 1879833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return true; 1880561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor } 1881561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor 1882561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (Args[i].getArgument().isInstantiationDependent()) 1883561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor InstantiationDependent = true; 1884561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor } 1885833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return false; 1886833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall} 1887833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 1888833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallbool TemplateSpecializationType:: 1889561f81243f665cf2001caadc45df505f826b72d6Douglas GregoranyDependentTemplateArguments(const TemplateArgument *Args, unsigned N, 1890561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor bool &InstantiationDependent) { 1891561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor for (unsigned i = 0; i != N; ++i) { 1892561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (Args[i].isDependent()) { 1893561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor InstantiationDependent = true; 1894833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return true; 1895561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor } 1896561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor 1897561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (Args[i].isInstantiationDependent()) 1898561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor InstantiationDependent = true; 1899561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor } 1900833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return false; 1901833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall} 1902833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 19037532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas GregorTemplateSpecializationType:: 1904ef99001908e799c388f1363b1e607dad5f5b57d3John McCallTemplateSpecializationType(TemplateName T, 19053e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith const TemplateArgument *Args, unsigned NumArgs, 19063e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith QualType Canon, QualType AliasedType) 19071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : Type(TemplateSpecialization, 190840808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor Canon.isNull()? QualType(this, 0) : Canon, 19093e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith Canon.isNull()? T.isDependent() : Canon->isDependentType(), 1910561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor Canon.isNull()? T.isDependent() 1911561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor : Canon->isInstantiationDependentType(), 1912c0536c8294fc4453f0f1d1cf24a62bfc725fd492Richard Smith false, 1913d8672ef2d343a0dbfe838724fb2d9fb4efea6041Richard Smith T.containsUnexpandedParameterPack()), 1914b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor Template(T), NumArgs(NumArgs), TypeAlias(!AliasedType.isNull()) { 1915a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor assert(!T.getAsDependentTemplateName() && 1916a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor "Use DependentTemplateSpecializationType for dependent template-name"); 19171901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall assert((T.getKind() == TemplateName::Template || 1918146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall T.getKind() == TemplateName::SubstTemplateTemplateParm || 19191901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall T.getKind() == TemplateName::SubstTemplateTemplateParmPack) && 19201901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall "Unexpected template name for TemplateSpecializationType"); 1921561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor bool InstantiationDependent; 1922561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (void)InstantiationDependent; 19231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump assert((!Canon.isNull() || 1924561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor T.isDependent() || 1925561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor anyDependentTemplateArguments(Args, NumArgs, 1926561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor InstantiationDependent)) && 192740808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor "No canonical type for non-dependent class template specialization"); 192855f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 19291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TemplateArgument *TemplateArgs 193040808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor = reinterpret_cast<TemplateArgument *>(this + 1); 193135495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor for (unsigned Arg = 0; Arg < NumArgs; ++Arg) { 193235495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor // Update dependent and variably-modified bits. 19333e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith // If the canonical type exists and is non-dependent, the template 19343e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith // specialization type can be non-dependent even if one of the type 19353e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith // arguments is. Given: 19363e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith // template<typename T> using U = int; 19373e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith // U<T> is always non-dependent, irrespective of the type T. 1938d8672ef2d343a0dbfe838724fb2d9fb4efea6041Richard Smith // However, U<Ts> contains an unexpanded parameter pack, even though 1939d8672ef2d343a0dbfe838724fb2d9fb4efea6041Richard Smith // its expansion (and thus its desugared type) doesn't. 19403e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith if (Canon.isNull() && Args[Arg].isDependent()) 194135495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor setDependent(); 1942561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor else if (Args[Arg].isInstantiationDependent()) 1943561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor setInstantiationDependent(); 1944561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor 194535495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor if (Args[Arg].getKind() == TemplateArgument::Type && 194635495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor Args[Arg].getAsType()->isVariablyModifiedType()) 194735495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor setVariablyModified(); 1948d8672ef2d343a0dbfe838724fb2d9fb4efea6041Richard Smith if (Args[Arg].containsUnexpandedParameterPack()) 1949d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor setContainsUnexpandedParameterPack(); 1950d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 195140808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor new (&TemplateArgs[Arg]) TemplateArgument(Args[Arg]); 195235495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor } 19533e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith 19543e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith // Store the aliased type if this is a type alias template specialization. 1955b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor if (TypeAlias) { 19563e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith TemplateArgument *Begin = reinterpret_cast<TemplateArgument *>(this + 1); 19573e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith *reinterpret_cast<QualType*>(Begin + getNumArgs()) = AliasedType; 19583e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith } 195955f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor} 196055f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 19611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpvoid 19621eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTemplateSpecializationType::Profile(llvm::FoldingSetNodeID &ID, 19631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TemplateName T, 19641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const TemplateArgument *Args, 1965828e226ab7ed08b3eb766549e9d3306432137460Douglas Gregor unsigned NumArgs, 19664ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad const ASTContext &Context) { 19677532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor T.Profile(ID); 196840808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor for (unsigned Idx = 0; Idx < NumArgs; ++Idx) 1969828e226ab7ed08b3eb766549e9d3306432137460Douglas Gregor Args[Idx].Profile(ID, Context); 197055f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor} 197197e0179f1ae545e07d9f5e7c1d2ef5c5bab06676Anders Carlsson 19724ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualType 19734ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualifierCollector::apply(const ASTContext &Context, QualType QT) const { 19740953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (!hasNonFastQualifiers()) 19750953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return QT.withFastQualifiers(getFastQualifiers()); 19761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 197749f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall return Context.getQualifiedType(QT, *this); 19785e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor} 19795e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor 19804ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualType 19814ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualifierCollector::apply(const ASTContext &Context, const Type *T) const { 19820953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (!hasNonFastQualifiers()) 19830953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return QualType(T, getFastQualifiers()); 19840953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 198549f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall return Context.getQualifiedType(T, *this); 19865e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor} 19875e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor 1988c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallvoid ObjCObjectTypeImpl::Profile(llvm::FoldingSetNodeID &ID, 1989c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall QualType BaseType, 1990c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCProtocolDecl * const *Protocols, 1991c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall unsigned NumProtocols) { 1992c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ID.AddPointer(BaseType.getAsOpaquePtr()); 1993c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff for (unsigned i = 0; i != NumProtocols; i++) 1994c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ID.AddPointer(Protocols[i]); 1995c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff} 1996c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff 1997c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallvoid ObjCObjectTypeImpl::Profile(llvm::FoldingSetNodeID &ID) { 1998c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall Profile(ID, getBaseType(), qual_begin(), getNumProtocols()); 1999c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff} 20000b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 2001b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCallnamespace { 20021fb0caaa7bef765b85972274e3b434af2572c141John McCall 2003b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall/// \brief The cached properties of a type. 2004b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCallclass CachedProperties { 20052beda12c3fbaa9125831b7f818680978c596b205Rafael Espindola LinkageInfo LV; 2006b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall bool local; 20072beda12c3fbaa9125831b7f818680978c596b205Rafael Espindola 2008b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCallpublic: 20092beda12c3fbaa9125831b7f818680978c596b205Rafael Espindola CachedProperties(LinkageInfo LV, bool local) : LV(LV), local(local) {} 20102beda12c3fbaa9125831b7f818680978c596b205Rafael Espindola 2011093ecc92afb70f6125d249eef31f40c0c57b7d24Rafael Espindola Linkage getLinkage() const { return LV.linkage(); } 2012093ecc92afb70f6125d249eef31f40c0c57b7d24Rafael Espindola Visibility getVisibility() const { return LV.visibility(); } 2013093ecc92afb70f6125d249eef31f40c0c57b7d24Rafael Espindola bool isVisibilityExplicit() const { return LV.visibilityExplicit(); } 2014b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall bool hasLocalOrUnnamedType() const { return local; } 20152beda12c3fbaa9125831b7f818680978c596b205Rafael Espindola 2016b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall friend CachedProperties merge(CachedProperties L, CachedProperties R) { 20172beda12c3fbaa9125831b7f818680978c596b205Rafael Espindola LinkageInfo MergedLV = L.LV; 2018093ecc92afb70f6125d249eef31f40c0c57b7d24Rafael Espindola MergedLV.merge(R.LV); 2019093ecc92afb70f6125d249eef31f40c0c57b7d24Rafael Espindola return CachedProperties(MergedLV, 2020b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall L.hasLocalOrUnnamedType() | R.hasLocalOrUnnamedType()); 2021b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall } 2022b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall}; 20231fb0caaa7bef765b85972274e3b434af2572c141John McCall} 20241fb0caaa7bef765b85972274e3b434af2572c141John McCall 2025b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCallstatic CachedProperties computeCachedProperties(const Type *T); 20260b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 2027b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCallnamespace clang { 2028b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall/// The type-property cache. This is templated so as to be 2029b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall/// instantiated at an internal type to prevent unnecessary symbol 2030b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall/// leakage. 2031b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCalltemplate <class Private> class TypePropertyCache { 2032b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCallpublic: 2033b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall static CachedProperties get(QualType T) { 2034b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return get(T.getTypePtr()); 2035b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall } 20361fb0caaa7bef765b85972274e3b434af2572c141John McCall 2037b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall static CachedProperties get(const Type *T) { 2038b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall ensure(T); 20392beda12c3fbaa9125831b7f818680978c596b205Rafael Espindola LinkageInfo LV(T->TypeBits.getLinkage(), 20402beda12c3fbaa9125831b7f818680978c596b205Rafael Espindola T->TypeBits.getVisibility(), 20412beda12c3fbaa9125831b7f818680978c596b205Rafael Espindola T->TypeBits.isVisibilityExplicit()); 2042093ecc92afb70f6125d249eef31f40c0c57b7d24Rafael Espindola return CachedProperties(LV, T->TypeBits.hasLocalOrUnnamedType()); 2043b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall } 2044db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor 2045b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall static void ensure(const Type *T) { 2046b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall // If the cache is valid, we're okay. 2047b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall if (T->TypeBits.isCacheValid()) return; 2048b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall 2049b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall // If this type is non-canonical, ask its canonical type for the 2050b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall // relevant information. 20513b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (!T->isCanonicalUnqualified()) { 20523b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall const Type *CT = T->getCanonicalTypeInternal().getTypePtr(); 2053b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall ensure(CT); 2054b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall T->TypeBits.CacheValidAndVisibility = 2055b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall CT->TypeBits.CacheValidAndVisibility; 2056093ecc92afb70f6125d249eef31f40c0c57b7d24Rafael Espindola T->TypeBits.CachedExplicitVisibility = 2057093ecc92afb70f6125d249eef31f40c0c57b7d24Rafael Espindola CT->TypeBits.CachedExplicitVisibility; 2058b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall T->TypeBits.CachedLinkage = CT->TypeBits.CachedLinkage; 2059b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall T->TypeBits.CachedLocalOrUnnamed = CT->TypeBits.CachedLocalOrUnnamed; 2060b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return; 2061b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall } 20621fb0caaa7bef765b85972274e3b434af2572c141John McCall 2063b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall // Compute the cached properties and then set the cache. 2064b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall CachedProperties Result = computeCachedProperties(T); 2065b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall T->TypeBits.CacheValidAndVisibility = Result.getVisibility() + 1U; 2066093ecc92afb70f6125d249eef31f40c0c57b7d24Rafael Espindola T->TypeBits.CachedExplicitVisibility = Result.isVisibilityExplicit(); 2067b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall assert(T->TypeBits.isCacheValid() && 2068b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall T->TypeBits.getVisibility() == Result.getVisibility()); 2069b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall T->TypeBits.CachedLinkage = Result.getLinkage(); 2070b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall T->TypeBits.CachedLocalOrUnnamed = Result.hasLocalOrUnnamedType(); 2071b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall } 2072b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall}; 20731fb0caaa7bef765b85972274e3b434af2572c141John McCall} 20741fb0caaa7bef765b85972274e3b434af2572c141John McCall 2075b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall// Instantiate the friend template at a private class. In a 2076b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall// reasonable implementation, these symbols will be internal. 2077b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall// It is terrible that this is the best way to accomplish this. 2078b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCallnamespace { class Private {}; } 2079b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCalltypedef TypePropertyCache<Private> Cache; 20801fb0caaa7bef765b85972274e3b434af2572c141John McCall 2081b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCallstatic CachedProperties computeCachedProperties(const Type *T) { 2082b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall switch (T->getTypeClass()) { 2083b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall#define TYPE(Class,Base) 2084b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall#define NON_CANONICAL_TYPE(Class,Base) case Type::Class: 2085b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall#include "clang/AST/TypeNodes.def" 2086b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall llvm_unreachable("didn't expect a non-canonical type here"); 208760e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor 2088b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall#define TYPE(Class,Base) 2089b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall#define DEPENDENT_TYPE(Class,Base) case Type::Class: 2090b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall#define NON_CANONICAL_UNLESS_DEPENDENT_TYPE(Class,Base) case Type::Class: 2091b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall#include "clang/AST/TypeNodes.def" 20925e78cd43a033b3dedf741fca4fa1652f9cb3e41cDouglas Gregor // Treat instantiation-dependent types as external. 20935e78cd43a033b3dedf741fca4fa1652f9cb3e41cDouglas Gregor assert(T->isInstantiationDependentType()); 20942beda12c3fbaa9125831b7f818680978c596b205Rafael Espindola return CachedProperties(LinkageInfo(), false); 20951fb0caaa7bef765b85972274e3b434af2572c141John McCall 2096b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::Builtin: 2097b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall // C++ [basic.link]p8: 2098b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall // A type is said to have linkage if and only if: 2099b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall // - it is a fundamental type (3.9.1); or 21002beda12c3fbaa9125831b7f818680978c596b205Rafael Espindola return CachedProperties(LinkageInfo(), false); 21010b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 2102b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::Record: 2103b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::Enum: { 2104b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall const TagDecl *Tag = cast<TagType>(T)->getDecl(); 2105b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall 2106b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall // C++ [basic.link]p8: 2107b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall // - it is a class or enumeration type that is named (or has a name 2108b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall // for linkage purposes (7.1.3)) and the name has linkage; or 2109b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall // - it is a specialization of a class template (14); or 21102beda12c3fbaa9125831b7f818680978c596b205Rafael Espindola LinkageInfo LV = Tag->getLinkageAndVisibility(); 2111b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall bool IsLocalOrUnnamed = 2112b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall Tag->getDeclContext()->isFunctionOrMethod() || 2113162e1c1b487352434552147967c3dd296ebee2f7Richard Smith (!Tag->getIdentifier() && !Tag->getTypedefNameForAnonDecl()); 2114093ecc92afb70f6125d249eef31f40c0c57b7d24Rafael Espindola return CachedProperties(LV, IsLocalOrUnnamed); 2115b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall } 21160b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 2117b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall // C++ [basic.link]p8: 2118b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall // - it is a compound type (3.9.2) other than a class or enumeration, 2119b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall // compounded exclusively from types that have linkage; or 2120b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::Complex: 2121b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return Cache::get(cast<ComplexType>(T)->getElementType()); 2122b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::Pointer: 2123b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return Cache::get(cast<PointerType>(T)->getPointeeType()); 2124b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::BlockPointer: 2125b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return Cache::get(cast<BlockPointerType>(T)->getPointeeType()); 2126b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::LValueReference: 2127b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::RValueReference: 2128b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return Cache::get(cast<ReferenceType>(T)->getPointeeType()); 2129b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::MemberPointer: { 2130b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall const MemberPointerType *MPT = cast<MemberPointerType>(T); 2131b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return merge(Cache::get(MPT->getClass()), 2132b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall Cache::get(MPT->getPointeeType())); 2133b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall } 2134b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::ConstantArray: 2135b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::IncompleteArray: 2136b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::VariableArray: 2137b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return Cache::get(cast<ArrayType>(T)->getElementType()); 2138b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::Vector: 2139b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::ExtVector: 2140b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return Cache::get(cast<VectorType>(T)->getElementType()); 2141b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::FunctionNoProto: 2142b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return Cache::get(cast<FunctionType>(T)->getResultType()); 2143b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::FunctionProto: { 2144b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall const FunctionProtoType *FPT = cast<FunctionProtoType>(T); 2145b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall CachedProperties result = Cache::get(FPT->getResultType()); 2146b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall for (FunctionProtoType::arg_type_iterator ai = FPT->arg_type_begin(), 2147b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall ae = FPT->arg_type_end(); ai != ae; ++ai) 2148b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall result = merge(result, Cache::get(*ai)); 2149b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return result; 2150b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall } 2151b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::ObjCInterface: { 21522beda12c3fbaa9125831b7f818680978c596b205Rafael Espindola LinkageInfo LV = 2153b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall cast<ObjCInterfaceType>(T)->getDecl()->getLinkageAndVisibility(); 2154093ecc92afb70f6125d249eef31f40c0c57b7d24Rafael Espindola return CachedProperties(LV, false); 2155b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall } 2156b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::ObjCObject: 2157b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return Cache::get(cast<ObjCObjectType>(T)->getBaseType()); 2158b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::ObjCObjectPointer: 2159b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return Cache::get(cast<ObjCObjectPointerType>(T)->getPointeeType()); 2160b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman case Type::Atomic: 2161b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman return Cache::get(cast<AtomicType>(T)->getValueType()); 2162b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall } 21630b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 2164b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall llvm_unreachable("unhandled type class"); 21650b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor} 21660b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 2167b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall/// \brief Determine the linkage of this type. 2168b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCallLinkage Type::getLinkage() const { 2169b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall Cache::ensure(this); 2170b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return TypeBits.getLinkage(); 21710b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor} 21720b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 2173b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCallbool Type::hasUnnamedOrLocalType() const { 2174b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall Cache::ensure(this); 2175b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return TypeBits.hasLocalOrUnnamedType(); 21760b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor} 21770b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 217818895dc4fd29f0071eeb591be820338f16407906Rafael EspindolaLinkageInfo Type::getLinkageAndVisibility() const { 2179b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall Cache::ensure(this); 218018895dc4fd29f0071eeb591be820338f16407906Rafael Espindola LinkageInfo LV(TypeBits.getLinkage(), TypeBits.getVisibility(), 218118895dc4fd29f0071eeb591be820338f16407906Rafael Espindola TypeBits.isVisibilityExplicit()); 218218895dc4fd29f0071eeb591be820338f16407906Rafael Espindola return LV; 21830b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor} 21840b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 2185838dc597e25614c653a062a124b06a04d6b7f5ebRafael Espindolavoid Type::ClearLinkageCache() { 2186b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall TypeBits.CacheValidAndVisibility = 0; 2187b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall if (QualType(this, 0) != CanonicalType) 2188b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall CanonicalType->TypeBits.CacheValidAndVisibility = 0; 21890b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor} 21903b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 2191f85e193739c953358c865005855253af4f68a497John McCallQualifiers::ObjCLifetime Type::getObjCARCImplicitLifetime() const { 2192f85e193739c953358c865005855253af4f68a497John McCall if (isObjCARCImplicitlyUnretainedType()) 2193f85e193739c953358c865005855253af4f68a497John McCall return Qualifiers::OCL_ExplicitNone; 2194f85e193739c953358c865005855253af4f68a497John McCall return Qualifiers::OCL_Strong; 2195f85e193739c953358c865005855253af4f68a497John McCall} 2196f85e193739c953358c865005855253af4f68a497John McCall 2197f85e193739c953358c865005855253af4f68a497John McCallbool Type::isObjCARCImplicitlyUnretainedType() const { 2198f85e193739c953358c865005855253af4f68a497John McCall assert(isObjCLifetimeType() && 2199f85e193739c953358c865005855253af4f68a497John McCall "cannot query implicit lifetime for non-inferrable type"); 2200f85e193739c953358c865005855253af4f68a497John McCall 2201f85e193739c953358c865005855253af4f68a497John McCall const Type *canon = getCanonicalTypeInternal().getTypePtr(); 2202f85e193739c953358c865005855253af4f68a497John McCall 2203f85e193739c953358c865005855253af4f68a497John McCall // Walk down to the base type. We don't care about qualifiers for this. 2204f85e193739c953358c865005855253af4f68a497John McCall while (const ArrayType *array = dyn_cast<ArrayType>(canon)) 2205f85e193739c953358c865005855253af4f68a497John McCall canon = array->getElementType().getTypePtr(); 2206f85e193739c953358c865005855253af4f68a497John McCall 2207f85e193739c953358c865005855253af4f68a497John McCall if (const ObjCObjectPointerType *opt 2208f85e193739c953358c865005855253af4f68a497John McCall = dyn_cast<ObjCObjectPointerType>(canon)) { 2209f85e193739c953358c865005855253af4f68a497John McCall // Class and Class<Protocol> don't require retension. 2210f85e193739c953358c865005855253af4f68a497John McCall if (opt->getObjectType()->isObjCClass()) 2211f85e193739c953358c865005855253af4f68a497John McCall return true; 2212f85e193739c953358c865005855253af4f68a497John McCall } 2213f85e193739c953358c865005855253af4f68a497John McCall 2214f85e193739c953358c865005855253af4f68a497John McCall return false; 2215f85e193739c953358c865005855253af4f68a497John McCall} 2216f85e193739c953358c865005855253af4f68a497John McCall 2217f85e193739c953358c865005855253af4f68a497John McCallbool Type::isObjCNSObjectType() const { 2218f85e193739c953358c865005855253af4f68a497John McCall if (const TypedefType *typedefType = dyn_cast<TypedefType>(this)) 2219f85e193739c953358c865005855253af4f68a497John McCall return typedefType->getDecl()->hasAttr<ObjCNSObjectAttr>(); 2220f85e193739c953358c865005855253af4f68a497John McCall return false; 2221f85e193739c953358c865005855253af4f68a497John McCall} 2222f85e193739c953358c865005855253af4f68a497John McCallbool Type::isObjCRetainableType() const { 2223f85e193739c953358c865005855253af4f68a497John McCall return isObjCObjectPointerType() || 2224f85e193739c953358c865005855253af4f68a497John McCall isBlockPointerType() || 2225f85e193739c953358c865005855253af4f68a497John McCall isObjCNSObjectType(); 2226f85e193739c953358c865005855253af4f68a497John McCall} 2227f85e193739c953358c865005855253af4f68a497John McCallbool Type::isObjCIndirectLifetimeType() const { 2228f85e193739c953358c865005855253af4f68a497John McCall if (isObjCLifetimeType()) 2229f85e193739c953358c865005855253af4f68a497John McCall return true; 2230f85e193739c953358c865005855253af4f68a497John McCall if (const PointerType *OPT = getAs<PointerType>()) 2231f85e193739c953358c865005855253af4f68a497John McCall return OPT->getPointeeType()->isObjCIndirectLifetimeType(); 2232f85e193739c953358c865005855253af4f68a497John McCall if (const ReferenceType *Ref = getAs<ReferenceType>()) 2233f85e193739c953358c865005855253af4f68a497John McCall return Ref->getPointeeType()->isObjCIndirectLifetimeType(); 2234f85e193739c953358c865005855253af4f68a497John McCall if (const MemberPointerType *MemPtr = getAs<MemberPointerType>()) 2235f85e193739c953358c865005855253af4f68a497John McCall return MemPtr->getPointeeType()->isObjCIndirectLifetimeType(); 2236f85e193739c953358c865005855253af4f68a497John McCall return false; 2237f85e193739c953358c865005855253af4f68a497John McCall} 2238f85e193739c953358c865005855253af4f68a497John McCall 2239f85e193739c953358c865005855253af4f68a497John McCall/// Returns true if objects of this type have lifetime semantics under 2240f85e193739c953358c865005855253af4f68a497John McCall/// ARC. 2241f85e193739c953358c865005855253af4f68a497John McCallbool Type::isObjCLifetimeType() const { 2242f85e193739c953358c865005855253af4f68a497John McCall const Type *type = this; 2243f85e193739c953358c865005855253af4f68a497John McCall while (const ArrayType *array = type->getAsArrayTypeUnsafe()) 2244f85e193739c953358c865005855253af4f68a497John McCall type = array->getElementType().getTypePtr(); 2245f85e193739c953358c865005855253af4f68a497John McCall return type->isObjCRetainableType(); 2246f85e193739c953358c865005855253af4f68a497John McCall} 2247f85e193739c953358c865005855253af4f68a497John McCall 2248f85e193739c953358c865005855253af4f68a497John McCall/// \brief Determine whether the given type T is a "bridgable" Objective-C type, 2249f85e193739c953358c865005855253af4f68a497John McCall/// which is either an Objective-C object pointer type or an 2250f85e193739c953358c865005855253af4f68a497John McCallbool Type::isObjCARCBridgableType() const { 2251f85e193739c953358c865005855253af4f68a497John McCall return isObjCObjectPointerType() || isBlockPointerType(); 2252f85e193739c953358c865005855253af4f68a497John McCall} 2253f85e193739c953358c865005855253af4f68a497John McCall 2254f85e193739c953358c865005855253af4f68a497John McCall/// \brief Determine whether the given type T is a "bridgeable" C type. 2255f85e193739c953358c865005855253af4f68a497John McCallbool Type::isCARCBridgableType() const { 2256f85e193739c953358c865005855253af4f68a497John McCall const PointerType *Pointer = getAs<PointerType>(); 2257f85e193739c953358c865005855253af4f68a497John McCall if (!Pointer) 2258f85e193739c953358c865005855253af4f68a497John McCall return false; 2259f85e193739c953358c865005855253af4f68a497John McCall 2260f85e193739c953358c865005855253af4f68a497John McCall QualType Pointee = Pointer->getPointeeType(); 2261f85e193739c953358c865005855253af4f68a497John McCall return Pointee->isVoidType() || Pointee->isRecordType(); 2262f85e193739c953358c865005855253af4f68a497John McCall} 2263f85e193739c953358c865005855253af4f68a497John McCall 22643b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallbool Type::hasSizedVLAType() const { 22653b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (!isVariablyModifiedType()) return false; 22663b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 22673b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (const PointerType *ptr = getAs<PointerType>()) 22683b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return ptr->getPointeeType()->hasSizedVLAType(); 22693b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (const ReferenceType *ref = getAs<ReferenceType>()) 22703b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return ref->getPointeeType()->hasSizedVLAType(); 22713b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (const ArrayType *arr = getAsArrayTypeUnsafe()) { 22723b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (isa<VariableArrayType>(arr) && 22733b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall cast<VariableArrayType>(arr)->getSizeExpr()) 22743b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return true; 22753b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 22763b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return arr->getElementType()->hasSizedVLAType(); 22773b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall } 22783b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 22793b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return false; 22803b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall} 22810d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall 22820d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCallQualType::DestructionKind QualType::isDestructedTypeImpl(QualType type) { 2283f85e193739c953358c865005855253af4f68a497John McCall switch (type.getObjCLifetime()) { 2284f85e193739c953358c865005855253af4f68a497John McCall case Qualifiers::OCL_None: 2285f85e193739c953358c865005855253af4f68a497John McCall case Qualifiers::OCL_ExplicitNone: 2286f85e193739c953358c865005855253af4f68a497John McCall case Qualifiers::OCL_Autoreleasing: 2287f85e193739c953358c865005855253af4f68a497John McCall break; 2288f85e193739c953358c865005855253af4f68a497John McCall 2289f85e193739c953358c865005855253af4f68a497John McCall case Qualifiers::OCL_Strong: 2290f85e193739c953358c865005855253af4f68a497John McCall return DK_objc_strong_lifetime; 2291f85e193739c953358c865005855253af4f68a497John McCall case Qualifiers::OCL_Weak: 2292f85e193739c953358c865005855253af4f68a497John McCall return DK_objc_weak_lifetime; 2293f85e193739c953358c865005855253af4f68a497John McCall } 2294f85e193739c953358c865005855253af4f68a497John McCall 22950d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall /// Currently, the only destruction kind we recognize is C++ objects 22960d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall /// with non-trivial destructors. 22970d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall const CXXRecordDecl *record = 22980d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall type->getBaseElementTypeUnsafe()->getAsCXXRecordDecl(); 229991873b72bf01b7170f80154f3118300ff2eacd34Eli Friedman if (record && record->hasDefinition() && !record->hasTrivialDestructor()) 23000d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall return DK_cxx_destructor; 23010d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall 23020d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall return DK_none; 23030d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall} 2304