Type.cpp revision 3e4c6c4c79a03f5cb0c4671d7c282d623c6dc35e
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" 152767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor#include "clang/AST/CharUnits.h" 165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "clang/AST/Type.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" 22b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall#include "clang/AST/TypeVisitor.h" 23465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara#include "clang/Basic/Specifiers.h" 2460618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl#include "llvm/ADT/APSInt.h" 255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "llvm/ADT/StringExtras.h" 26bad351822117eaf280081494e3dbe4a06c0dbfcfDouglas Gregor#include "llvm/Support/raw_ostream.h" 272767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor#include <algorithm> 285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing namespace clang; 295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 30769d0cc72b1831785596d0e76f327bdb887823beDouglas Gregorbool Qualifiers::isStrictSupersetOf(Qualifiers Other) const { 31769d0cc72b1831785596d0e76f327bdb887823beDouglas Gregor return (*this != Other) && 32769d0cc72b1831785596d0e76f327bdb887823beDouglas Gregor // CVR qualifiers superset 33769d0cc72b1831785596d0e76f327bdb887823beDouglas Gregor (((Mask & CVRMask) | (Other.Mask & CVRMask)) == (Mask & CVRMask)) && 34769d0cc72b1831785596d0e76f327bdb887823beDouglas Gregor // ObjC GC qualifiers superset 35769d0cc72b1831785596d0e76f327bdb887823beDouglas Gregor ((getObjCGCAttr() == Other.getObjCGCAttr()) || 36769d0cc72b1831785596d0e76f327bdb887823beDouglas Gregor (hasObjCGCAttr() && !Other.hasObjCGCAttr())) && 37769d0cc72b1831785596d0e76f327bdb887823beDouglas Gregor // Address space superset. 38769d0cc72b1831785596d0e76f327bdb887823beDouglas Gregor ((getAddressSpace() == Other.getAddressSpace()) || 39769d0cc72b1831785596d0e76f327bdb887823beDouglas Gregor (hasAddressSpace()&& !Other.hasAddressSpace())); 40769d0cc72b1831785596d0e76f327bdb887823beDouglas Gregor} 41769d0cc72b1831785596d0e76f327bdb887823beDouglas Gregor 42bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCallbool QualType::isConstant(QualType T, ASTContext &Ctx) { 43bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall if (T.isConstQualified()) 44b381aac9bae6d608c72267dd0ed08ec6369e94e4Nuno Lopes return true; 45b381aac9bae6d608c72267dd0ed08ec6369e94e4Nuno Lopes 46bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall if (const ArrayType *AT = Ctx.getAsArrayType(T)) 47bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall return AT->getElementType().isConstant(Ctx); 48b381aac9bae6d608c72267dd0ed08ec6369e94e4Nuno Lopes 49b381aac9bae6d608c72267dd0ed08ec6369e94e4Nuno Lopes return false; 50b381aac9bae6d608c72267dd0ed08ec6369e94e4Nuno Lopes} 51b381aac9bae6d608c72267dd0ed08ec6369e94e4Nuno Lopes 522767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregorunsigned ConstantArrayType::getNumAddressingBits(ASTContext &Context, 532767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor QualType ElementType, 542767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor const llvm::APInt &NumElements) { 552767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor llvm::APSInt SizeExtended(NumElements, true); 562767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor unsigned SizeTypeBits = Context.getTypeSize(Context.getSizeType()); 579f71a8f4c7a182a5236da9e747d57cc1d1bd24c2Jay Foad SizeExtended = SizeExtended.extend(std::max(SizeTypeBits, 589f71a8f4c7a182a5236da9e747d57cc1d1bd24c2Jay Foad SizeExtended.getBitWidth()) * 2); 592767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor 602767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor uint64_t ElementSize 612767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor = Context.getTypeSizeInChars(ElementType).getQuantity(); 622767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor llvm::APSInt TotalSize(llvm::APInt(SizeExtended.getBitWidth(), ElementSize)); 632767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor TotalSize *= SizeExtended; 642767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor 652767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor return TotalSize.getActiveBits(); 662767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor} 672767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor 682767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregorunsigned ConstantArrayType::getMaxSizeBits(ASTContext &Context) { 692767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor unsigned Bits = Context.getTypeSize(Context.getSizeType()); 702767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor 712767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor // GCC appears to only allow 63 bits worth of address space when compiling 722767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor // for 64-bit, so we do the same. 732767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor if (Bits == 64) 742767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor --Bits; 752767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor 762767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor return Bits; 772767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor} 782767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor 794ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadDependentSizedArrayType::DependentSizedArrayType(const ASTContext &Context, 80d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor QualType et, QualType can, 81d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor Expr *e, ArraySizeModifier sm, 82d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor unsigned tq, 83d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor SourceRange brackets) 84d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor : ArrayType(DependentSizedArray, et, can, sm, tq, 85d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor (et->containsUnexpandedParameterPack() || 86d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor (e && e->containsUnexpandedParameterPack()))), 87d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor Context(Context), SizeExpr((Stmt*) e), Brackets(brackets) 88d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor{ 89d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor} 90d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpvoid DependentSizedArrayType::Profile(llvm::FoldingSetNodeID &ID, 924ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad const ASTContext &Context, 9304d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor QualType ET, 9404d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor ArraySizeModifier SizeMod, 9504d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor unsigned TypeQuals, 9604d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor Expr *E) { 9704d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor ID.AddPointer(ET.getAsOpaquePtr()); 9804d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor ID.AddInteger(SizeMod); 9904d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor ID.AddInteger(TypeQuals); 10004d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor E->Profile(ID, Context, true); 10104d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor} 10204d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor 1034ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadDependentSizedExtVectorType::DependentSizedExtVectorType(const 1044ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad ASTContext &Context, 105d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor QualType ElementType, 106d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor QualType can, 107d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor Expr *SizeExpr, 108d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor SourceLocation loc) 109d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor : Type(DependentSizedExtVector, can, /*Dependent=*/true, 110d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor ElementType->isVariablyModifiedType(), 111d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor (ElementType->containsUnexpandedParameterPack() || 112d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor (SizeExpr && SizeExpr->containsUnexpandedParameterPack()))), 113d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor Context(Context), SizeExpr(SizeExpr), ElementType(ElementType), 114d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor loc(loc) 115d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor{ 116d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor} 117d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 1181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpvoid 1191eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpDependentSizedExtVectorType::Profile(llvm::FoldingSetNodeID &ID, 1204ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad const ASTContext &Context, 1212ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor QualType ElementType, Expr *SizeExpr) { 1222ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor ID.AddPointer(ElementType.getAsOpaquePtr()); 1232ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor SizeExpr->Profile(ID, Context, true); 1242ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor} 1252ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor 126d0937224f383c7cc72c947119380f9713a070c73Douglas GregorVectorType::VectorType(QualType vecType, unsigned nElements, QualType canonType, 127d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor VectorKind vecKind) 128d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor : Type(Vector, canonType, vecType->isDependentType(), 129d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor vecType->isVariablyModifiedType(), 130d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor vecType->containsUnexpandedParameterPack()), 131d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor ElementType(vecType) 132d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor{ 133d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor VectorTypeBits.VecKind = vecKind; 134d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor VectorTypeBits.NumElements = nElements; 135d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor} 136d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 137d0937224f383c7cc72c947119380f9713a070c73Douglas GregorVectorType::VectorType(TypeClass tc, QualType vecType, unsigned nElements, 138d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor QualType canonType, VectorKind vecKind) 139d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor : Type(tc, canonType, vecType->isDependentType(), 140d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor vecType->isVariablyModifiedType(), 141d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor vecType->containsUnexpandedParameterPack()), 142d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor ElementType(vecType) 143d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor{ 144d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor VectorTypeBits.VecKind = vecKind; 145d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor VectorTypeBits.NumElements = nElements; 146d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor} 147d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 148c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner/// getArrayElementTypeNoTypeQual - If this is an array type, return the 149c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner/// element type of the array, potentially with type qualifiers missing. 150c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner/// This method should never be used when type qualifiers are meaningful. 151c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattnerconst Type *Type::getArrayElementTypeNoTypeQual() const { 152c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // If this is directly an array type, return it. 153c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner if (const ArrayType *ATy = dyn_cast<ArrayType>(this)) 154c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return ATy->getElementType().getTypePtr(); 1551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 156c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // If the canonical form of this type isn't the right kind, reject it. 1570953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (!isa<ArrayType>(CanonicalType)) 158c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return 0; 1591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 160c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // If this is a typedef for an array type, strip the typedef off without 161c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // losing all typedef information. 162bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall return cast<ArrayType>(getUnqualifiedDesugaredType()) 163bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall ->getElementType().getTypePtr(); 1642fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner} 1652fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner 1662fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner/// getDesugaredType - Return the specified type with any "sugar" removed from 1672fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner/// the type. This takes off typedefs, typeof's etc. If the outer level of 1682fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner/// the type is already concrete, it returns it unmodified. This is similar 1692fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner/// to getting the canonical type, but it doesn't remove *all* typedefs. For 1702fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner/// example, it returns "T*" as "T*", (not as "int*"), because the pointer is 1712fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner/// concrete. 1724ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualType QualType::getDesugaredType(QualType T, const ASTContext &Context) { 17349f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall SplitQualType split = getSplitDesugaredType(T); 17449f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall return Context.getQualifiedType(split.first, split.second); 17549f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall} 17649f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall 17749f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCallSplitQualType QualType::getSplitDesugaredType(QualType T) { 1780953e767ff7817f97b3ab20896b229891eeff45bJohn McCall QualifierCollector Qs; 179c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner 180bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType Cur = T; 181bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall while (true) { 182bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall const Type *CurTy = Qs.strip(Cur); 183bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall switch (CurTy->getTypeClass()) { 184bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall#define ABSTRACT_TYPE(Class, Parent) 185bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall#define TYPE(Class, Parent) \ 186bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall case Type::Class: { \ 187bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall const Class##Type *Ty = cast<Class##Type>(CurTy); \ 188bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall if (!Ty->isSugared()) \ 18949f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall return SplitQualType(Ty, Qs); \ 190bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall Cur = Ty->desugar(); \ 191bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall break; \ 192bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall } 193bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall#include "clang/AST/TypeNodes.def" 194bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall } 195969c689d893a248eca4f049f5b89f747e66e4bffDouglas Gregor } 196bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall} 1975cdf82164dd7c2b2320d6735c63ace4331e0716dDouglas Gregor 19862c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCallSplitQualType QualType::getSplitUnqualifiedTypeImpl(QualType type) { 19962c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall SplitQualType split = type.split(); 20062c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall 20162c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall // All the qualifiers we've seen so far. 20262c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall Qualifiers quals = split.second; 20362c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall 20462c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall // The last type node we saw with any nodes inside it. 20562c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall const Type *lastTypeWithQuals = split.first; 20662c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall 20762c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall while (true) { 20862c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall QualType next; 20962c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall 21062c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall // Do a single-step desugar, aborting the loop if the type isn't 21162c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall // sugared. 21262c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall switch (split.first->getTypeClass()) { 21362c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall#define ABSTRACT_TYPE(Class, Parent) 21462c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall#define TYPE(Class, Parent) \ 21562c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall case Type::Class: { \ 21662c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall const Class##Type *ty = cast<Class##Type>(split.first); \ 21762c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall if (!ty->isSugared()) goto done; \ 21862c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall next = ty->desugar(); \ 21962c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall break; \ 22062c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall } 22162c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall#include "clang/AST/TypeNodes.def" 22262c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall } 22362c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall 22462c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall // Otherwise, split the underlying type. If that yields qualifiers, 22562c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall // update the information. 22662c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall split = next.split(); 22762c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall if (!split.second.empty()) { 22862c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall lastTypeWithQuals = split.first; 22962c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall quals.addConsistentQualifiers(split.second); 23062c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall } 23162c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall } 23262c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall 23362c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall done: 23462c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall return SplitQualType(lastTypeWithQuals, quals); 23562c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall} 23662c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall 237075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo BagnaraQualType QualType::IgnoreParens(QualType T) { 23862c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall // FIXME: this seems inherently un-qualifiers-safe. 239075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara while (const ParenType *PT = T->getAs<ParenType>()) 240075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara T = PT->getInnerType(); 241075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara return T; 242075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara} 243075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 244bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall/// getUnqualifiedDesugaredType - Pull any qualifiers and syntactic 245bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall/// sugar off the given type. This should produce an object of the 246bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall/// same dynamic type as the canonical type. 247bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCallconst Type *Type::getUnqualifiedDesugaredType() const { 248bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall const Type *Cur = this; 249bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 250bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall while (true) { 251bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall switch (Cur->getTypeClass()) { 252bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall#define ABSTRACT_TYPE(Class, Parent) 253bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall#define TYPE(Class, Parent) \ 254bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall case Class: { \ 255bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall const Class##Type *Ty = cast<Class##Type>(Cur); \ 256bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall if (!Ty->isSugared()) return Cur; \ 257bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall Cur = Ty->desugar().getTypePtr(); \ 258bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall break; \ 259bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall } 260bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall#include "clang/AST/TypeNodes.def" 261bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall } 262bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall } 263c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner} 264c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner 2655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// isVoidType - Helper method to determine if this is the 'void' type. 2665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isVoidType() const { 2675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 2685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return BT->getKind() == BuiltinType::Void; 2695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return false; 2705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 2715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isDerivedType() const { 2735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer switch (CanonicalType->getTypeClass()) { 2745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Pointer: 275fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff case VariableArray: 276fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff case ConstantArray: 277c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman case IncompleteArray: 2785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case FunctionProto: 2795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case FunctionNoProto: 2807c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl case LValueReference: 2817c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl case RValueReference: 28272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor case Record: 2835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return true; 2845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer default: 2855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return false; 2865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 2885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 28999dc91422144483c20d1c7381bc9ac634b646b04Chris Lattnerbool Type::isClassType() const { 2906217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const RecordType *RT = getAs<RecordType>()) 291f728a4a05df2455e1c6e62173ab720a92cd4a074Chris Lattner return RT->getDecl()->isClass(); 29299dc91422144483c20d1c7381bc9ac634b646b04Chris Lattner return false; 29399dc91422144483c20d1c7381bc9ac634b646b04Chris Lattner} 294c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattnerbool Type::isStructureType() const { 2956217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const RecordType *RT = getAs<RecordType>()) 296f728a4a05df2455e1c6e62173ab720a92cd4a074Chris Lattner return RT->getDecl()->isStruct(); 297c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner return false; 298c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner} 299fb87b89fc9eb103e19fb8e4b925c23f0bd091b99Douglas Gregorbool Type::isStructureOrClassType() const { 300fb87b89fc9eb103e19fb8e4b925c23f0bd091b99Douglas Gregor if (const RecordType *RT = getAs<RecordType>()) 301fb87b89fc9eb103e19fb8e4b925c23f0bd091b99Douglas Gregor return RT->getDecl()->isStruct() || RT->getDecl()->isClass(); 302fb87b89fc9eb103e19fb8e4b925c23f0bd091b99Douglas Gregor return false; 303fb87b89fc9eb103e19fb8e4b925c23f0bd091b99Douglas Gregor} 3047154a77e7c1f23418342d3b72836ab504aa7821eSteve Naroffbool Type::isVoidPointerType() const { 3056217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const PointerType *PT = getAs<PointerType>()) 3067154a77e7c1f23418342d3b72836ab504aa7821eSteve Naroff return PT->getPointeeType()->isVoidType(); 3077154a77e7c1f23418342d3b72836ab504aa7821eSteve Naroff return false; 3087154a77e7c1f23418342d3b72836ab504aa7821eSteve Naroff} 3097154a77e7c1f23418342d3b72836ab504aa7821eSteve Naroff 310c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattnerbool Type::isUnionType() const { 3116217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const RecordType *RT = getAs<RecordType>()) 312f728a4a05df2455e1c6e62173ab720a92cd4a074Chris Lattner return RT->getDecl()->isUnion(); 313c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner return false; 314c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner} 315c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner 316c6fb90a7246c2d5d3233e70107bf9d8c7c9e535bChris Lattnerbool Type::isComplexType() const { 31702f62a9fedbc370fba081303399410a3afdde29fSteve Naroff if (const ComplexType *CT = dyn_cast<ComplexType>(CanonicalType)) 31802f62a9fedbc370fba081303399410a3afdde29fSteve Naroff return CT->getElementType()->isFloatingType(); 31902f62a9fedbc370fba081303399410a3afdde29fSteve Naroff return false; 320c6fb90a7246c2d5d3233e70107bf9d8c7c9e535bChris Lattner} 321c6fb90a7246c2d5d3233e70107bf9d8c7c9e535bChris Lattner 3224cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroffbool Type::isComplexIntegerType() const { 3234cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroff // Check for GCC complex integer extension. 3240953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return getAsComplexIntegerType(); 3254cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroff} 3264cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroff 3274cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroffconst ComplexType *Type::getAsComplexIntegerType() const { 3280953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (const ComplexType *Complex = getAs<ComplexType>()) 3290953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (Complex->getElementType()->isIntegerType()) 3300953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return Complex; 3310953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return 0; 3324cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroff} 3334cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroff 33414108da7f7fc059772711e4ffee1322a27b152a7Steve NaroffQualType Type::getPointeeType() const { 3356217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const PointerType *PT = getAs<PointerType>()) 33614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return PT->getPointeeType(); 337183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) 33814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return OPT->getPointeeType(); 3396217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const BlockPointerType *BPT = getAs<BlockPointerType>()) 34014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return BPT->getPointeeType(); 3419c21289a866b677d21ed3d5ecfdfd5ced5a55410Mike Stump if (const ReferenceType *RT = getAs<ReferenceType>()) 3429c21289a866b677d21ed3d5ecfdfd5ced5a55410Mike Stump return RT->getPointeeType(); 34314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return QualType(); 34414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff} 345b77792eabf5882cf9af8cc810599b20432fda6c2Chris Lattner 346c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattnerconst RecordType *Type::getAsStructureType() const { 3477064f5c95bbdb17680d0ea658d4090898c2592d3Steve Naroff // If this is directly a structure type, return it. 348c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner if (const RecordType *RT = dyn_cast<RecordType>(this)) { 34939ba4aeca296b1c9f04bde7d9d3cbbf129f1abd3Argyrios Kyrtzidis if (RT->getDecl()->isStruct()) 350c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner return RT; 3517064f5c95bbdb17680d0ea658d4090898c2592d3Steve Naroff } 352dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner 353dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner // If the canonical form of this type isn't the right kind, reject it. 354c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner if (const RecordType *RT = dyn_cast<RecordType>(CanonicalType)) { 35539ba4aeca296b1c9f04bde7d9d3cbbf129f1abd3Argyrios Kyrtzidis if (!RT->getDecl()->isStruct()) 356dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner return 0; 3571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 358dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner // If this is a typedef for a structure type, strip the typedef off without 359dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner // losing all typedef information. 360bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall return cast<RecordType>(getUnqualifiedDesugaredType()); 3615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 3627064f5c95bbdb17680d0ea658d4090898c2592d3Steve Naroff return 0; 3635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 3645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpconst RecordType *Type::getAsUnionType() const { 3667064f5c95bbdb17680d0ea658d4090898c2592d3Steve Naroff // If this is directly a union type, return it. 367c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner if (const RecordType *RT = dyn_cast<RecordType>(this)) { 36839ba4aeca296b1c9f04bde7d9d3cbbf129f1abd3Argyrios Kyrtzidis if (RT->getDecl()->isUnion()) 369c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner return RT; 3707064f5c95bbdb17680d0ea658d4090898c2592d3Steve Naroff } 3711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 372dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner // If the canonical form of this type isn't the right kind, reject it. 373c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner if (const RecordType *RT = dyn_cast<RecordType>(CanonicalType)) { 37439ba4aeca296b1c9f04bde7d9d3cbbf129f1abd3Argyrios Kyrtzidis if (!RT->getDecl()->isUnion()) 375dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner return 0; 376dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner 377dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner // If this is a typedef for a union type, strip the typedef off without 378dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner // losing all typedef information. 379bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall return cast<RecordType>(getUnqualifiedDesugaredType()); 3805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 3811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3827064f5c95bbdb17680d0ea658d4090898c2592d3Steve Naroff return 0; 3835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 3845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 385c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallObjCObjectType::ObjCObjectType(QualType Canonical, QualType Base, 386c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCProtocolDecl * const *Protocols, 387c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall unsigned NumProtocols) 388d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor : Type(ObjCObject, Canonical, false, false, false), 389d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor BaseType(Base) 390d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor{ 391b870b88df784c2940efce448ebfaf54dece14666John McCall ObjCObjectTypeBits.NumProtocols = NumProtocols; 39271c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall assert(getNumProtocols() == NumProtocols && 393c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall "bitfield overflow in protocol count"); 394fd6a0887a099256c35a5b23e9afd517ffe95fa0aDouglas Gregor if (NumProtocols) 395c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall memcpy(getProtocolStorage(), Protocols, 396c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall NumProtocols * sizeof(ObjCProtocolDecl*)); 39771842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek} 39871842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek 399c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallconst ObjCObjectType *Type::getAsObjCQualifiedInterfaceType() const { 400c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall // There is no sugar for ObjCObjectType's, just return the canonical 401c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff // type pointer if it is the right class. There is no typedef information to 402c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff // return and these cannot be Address-space qualified. 403c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall if (const ObjCObjectType *T = getAs<ObjCObjectType>()) 404c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall if (T->getNumProtocols() && T->getInterface()) 405c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return T; 406c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff return 0; 407c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff} 408c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff 409c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroffbool Type::isObjCQualifiedInterfaceType() const { 410e61ad0b7063fcd97204b1cce5558685144267eb6Steve Naroff return getAsObjCQualifiedInterfaceType() != 0; 411c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff} 412c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff 413d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroffconst ObjCObjectPointerType *Type::getAsObjCQualifiedIdType() const { 414eca7be6b7ebd93682eeaab2c71d59f2995dacdccChris Lattner // There is no sugar for ObjCQualifiedIdType's, just return the canonical 415eca7be6b7ebd93682eeaab2c71d59f2995dacdccChris Lattner // type pointer if it is the right class. 416183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) { 417d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff if (OPT->isObjCQualifiedIdType()) 418d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff return OPT; 419d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff } 420d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff return 0; 421368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner} 422368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner 423759abb4d9ec14ae32104a9677b60f0542b60d1d8Fariborz Jahanianconst ObjCObjectPointerType *Type::getAsObjCQualifiedClassType() const { 424759abb4d9ec14ae32104a9677b60f0542b60d1d8Fariborz Jahanian // There is no sugar for ObjCQualifiedClassType's, just return the canonical 425759abb4d9ec14ae32104a9677b60f0542b60d1d8Fariborz Jahanian // type pointer if it is the right class. 426759abb4d9ec14ae32104a9677b60f0542b60d1d8Fariborz Jahanian if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) { 427759abb4d9ec14ae32104a9677b60f0542b60d1d8Fariborz Jahanian if (OPT->isObjCQualifiedClassType()) 428759abb4d9ec14ae32104a9677b60f0542b60d1d8Fariborz Jahanian return OPT; 429759abb4d9ec14ae32104a9677b60f0542b60d1d8Fariborz Jahanian } 430759abb4d9ec14ae32104a9677b60f0542b60d1d8Fariborz Jahanian return 0; 431759abb4d9ec14ae32104a9677b60f0542b60d1d8Fariborz Jahanian} 432759abb4d9ec14ae32104a9677b60f0542b60d1d8Fariborz Jahanian 43314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroffconst ObjCObjectPointerType *Type::getAsObjCInterfacePointerType() const { 434183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) { 43514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff if (OPT->getInterfaceType()) 43614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return OPT; 43714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff } 43814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return 0; 43914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff} 44014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff 441a91d6a6619a91d0ca7102d8ab5678d855f04d850Fariborz Jahanianconst CXXRecordDecl *Type::getCXXRecordDeclForPointerType() const { 4426217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const PointerType *PT = getAs<PointerType>()) 4436217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const RecordType *RT = PT->getPointeeType()->getAs<RecordType>()) 444a91d6a6619a91d0ca7102d8ab5678d855f04d850Fariborz Jahanian return dyn_cast<CXXRecordDecl>(RT->getDecl()); 445a91d6a6619a91d0ca7102d8ab5678d855f04d850Fariborz Jahanian return 0; 446a91d6a6619a91d0ca7102d8ab5678d855f04d850Fariborz Jahanian} 447a91d6a6619a91d0ca7102d8ab5678d855f04d850Fariborz Jahanian 448c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas GregorCXXRecordDecl *Type::getAsCXXRecordDecl() const { 449c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor if (const RecordType *RT = getAs<RecordType>()) 450c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor return dyn_cast<CXXRecordDecl>(RT->getDecl()); 451c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor else if (const InjectedClassNameType *Injected 452c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor = getAs<InjectedClassNameType>()) 453c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor return Injected->getDecl(); 454c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor 455c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor return 0; 456c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor} 457c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor 45834b41d939a1328f484511c6002ba2456db879a29Richard Smithnamespace { 45934b41d939a1328f484511c6002ba2456db879a29Richard Smith class GetContainedAutoVisitor : 46034b41d939a1328f484511c6002ba2456db879a29Richard Smith public TypeVisitor<GetContainedAutoVisitor, AutoType*> { 46134b41d939a1328f484511c6002ba2456db879a29Richard Smith public: 46234b41d939a1328f484511c6002ba2456db879a29Richard Smith using TypeVisitor<GetContainedAutoVisitor, AutoType*>::Visit; 46334b41d939a1328f484511c6002ba2456db879a29Richard Smith AutoType *Visit(QualType T) { 46434b41d939a1328f484511c6002ba2456db879a29Richard Smith if (T.isNull()) 46534b41d939a1328f484511c6002ba2456db879a29Richard Smith return 0; 46634b41d939a1328f484511c6002ba2456db879a29Richard Smith return Visit(T.getTypePtr()); 46734b41d939a1328f484511c6002ba2456db879a29Richard Smith } 46834b41d939a1328f484511c6002ba2456db879a29Richard Smith 46934b41d939a1328f484511c6002ba2456db879a29Richard Smith // The 'auto' type itself. 47034b41d939a1328f484511c6002ba2456db879a29Richard Smith AutoType *VisitAutoType(const AutoType *AT) { 47134b41d939a1328f484511c6002ba2456db879a29Richard Smith return const_cast<AutoType*>(AT); 47234b41d939a1328f484511c6002ba2456db879a29Richard Smith } 47334b41d939a1328f484511c6002ba2456db879a29Richard Smith 47434b41d939a1328f484511c6002ba2456db879a29Richard Smith // Only these types can contain the desired 'auto' type. 47534b41d939a1328f484511c6002ba2456db879a29Richard Smith AutoType *VisitPointerType(const PointerType *T) { 47634b41d939a1328f484511c6002ba2456db879a29Richard Smith return Visit(T->getPointeeType()); 47734b41d939a1328f484511c6002ba2456db879a29Richard Smith } 47834b41d939a1328f484511c6002ba2456db879a29Richard Smith AutoType *VisitBlockPointerType(const BlockPointerType *T) { 47934b41d939a1328f484511c6002ba2456db879a29Richard Smith return Visit(T->getPointeeType()); 48034b41d939a1328f484511c6002ba2456db879a29Richard Smith } 48134b41d939a1328f484511c6002ba2456db879a29Richard Smith AutoType *VisitReferenceType(const ReferenceType *T) { 48234b41d939a1328f484511c6002ba2456db879a29Richard Smith return Visit(T->getPointeeTypeAsWritten()); 48334b41d939a1328f484511c6002ba2456db879a29Richard Smith } 48434b41d939a1328f484511c6002ba2456db879a29Richard Smith AutoType *VisitMemberPointerType(const MemberPointerType *T) { 48534b41d939a1328f484511c6002ba2456db879a29Richard Smith return Visit(T->getPointeeType()); 48634b41d939a1328f484511c6002ba2456db879a29Richard Smith } 48734b41d939a1328f484511c6002ba2456db879a29Richard Smith AutoType *VisitArrayType(const ArrayType *T) { 48834b41d939a1328f484511c6002ba2456db879a29Richard Smith return Visit(T->getElementType()); 48934b41d939a1328f484511c6002ba2456db879a29Richard Smith } 49034b41d939a1328f484511c6002ba2456db879a29Richard Smith AutoType *VisitDependentSizedExtVectorType( 49134b41d939a1328f484511c6002ba2456db879a29Richard Smith const DependentSizedExtVectorType *T) { 49234b41d939a1328f484511c6002ba2456db879a29Richard Smith return Visit(T->getElementType()); 49334b41d939a1328f484511c6002ba2456db879a29Richard Smith } 49434b41d939a1328f484511c6002ba2456db879a29Richard Smith AutoType *VisitVectorType(const VectorType *T) { 49534b41d939a1328f484511c6002ba2456db879a29Richard Smith return Visit(T->getElementType()); 49634b41d939a1328f484511c6002ba2456db879a29Richard Smith } 49734b41d939a1328f484511c6002ba2456db879a29Richard Smith AutoType *VisitFunctionType(const FunctionType *T) { 49834b41d939a1328f484511c6002ba2456db879a29Richard Smith return Visit(T->getResultType()); 49934b41d939a1328f484511c6002ba2456db879a29Richard Smith } 50034b41d939a1328f484511c6002ba2456db879a29Richard Smith AutoType *VisitParenType(const ParenType *T) { 50134b41d939a1328f484511c6002ba2456db879a29Richard Smith return Visit(T->getInnerType()); 50234b41d939a1328f484511c6002ba2456db879a29Richard Smith } 50334b41d939a1328f484511c6002ba2456db879a29Richard Smith AutoType *VisitAttributedType(const AttributedType *T) { 50434b41d939a1328f484511c6002ba2456db879a29Richard Smith return Visit(T->getModifiedType()); 50534b41d939a1328f484511c6002ba2456db879a29Richard Smith } 50634b41d939a1328f484511c6002ba2456db879a29Richard Smith }; 50734b41d939a1328f484511c6002ba2456db879a29Richard Smith} 50834b41d939a1328f484511c6002ba2456db879a29Richard Smith 50934b41d939a1328f484511c6002ba2456db879a29Richard SmithAutoType *Type::getContainedAutoType() const { 51034b41d939a1328f484511c6002ba2456db879a29Richard Smith return GetContainedAutoVisitor().Visit(this); 51134b41d939a1328f484511c6002ba2456db879a29Richard Smith} 51234b41d939a1328f484511c6002ba2456db879a29Richard Smith 5135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isIntegerType() const { 5145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 5155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return BT->getKind() >= BuiltinType::Bool && 5162df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner BT->getKind() <= BuiltinType::Int128; 5171274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) 518834a72ac74cf4ff07ba6215545dba3db578f8a07Chris Lattner // Incomplete enum types are not treated as integer types. 5198e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor // FIXME: In C++, enum types are never integer types. 520b6adf2c889bb17c1be44e6c8e67e3b2762e9ceccDouglas Gregor return ET->getDecl()->isComplete() && !ET->getDecl()->isScoped(); 521f60946222721d9ba3c059563935c17b84703187aDouglas Gregor return false; 522f60946222721d9ba3c059563935c17b84703187aDouglas Gregor} 523f60946222721d9ba3c059563935c17b84703187aDouglas Gregor 524f60946222721d9ba3c059563935c17b84703187aDouglas Gregorbool Type::hasIntegerRepresentation() const { 525c63b96ad706e054a1390dd2ab53af9f05d33bbb1Steve Naroff if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType)) 526c63b96ad706e054a1390dd2ab53af9f05d33bbb1Steve Naroff return VT->getElementType()->isIntegerType(); 527f60946222721d9ba3c059563935c17b84703187aDouglas Gregor else 528f60946222721d9ba3c059563935c17b84703187aDouglas Gregor return isIntegerType(); 5295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 5305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5319d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// \brief Determine whether this type is an integral type. 5329d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// 5339d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// This routine determines whether the given type is an integral type per 5349d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// C++ [basic.fundamental]p7. Although the C standard does not define the 5359d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// term "integral type", it has a similar term "integer type", and in C++ 5369d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// the two terms are equivalent. However, C's "integer type" includes 5379d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// enumeration types, while C++'s "integer type" does not. The \c ASTContext 5389d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// parameter is used to determine whether we should be following the C or 5399d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// C++ rules when determining whether this type is an integral/integer type. 5409d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// 5419d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// For cases where C permits "an integer type" and C++ permits "an integral 5429d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// type", use this routine. 5439d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// 5449d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// For cases where C permits "an integer type" and C++ permits "an integral 5459d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// or enumeration type", use \c isIntegralOrEnumerationType() instead. 5469d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// 5479d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// \param Ctx The context in which this type occurs. 5489d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// 5499d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// \returns true if the type is considered an integral type, false otherwise. 5509d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregorbool Type::isIntegralType(ASTContext &Ctx) const { 55133e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 55233e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian return BT->getKind() >= BuiltinType::Bool && 553f5f7d864f5067d1ea4bff7fcf41b53a43b7b48baAnders Carlsson BT->getKind() <= BuiltinType::Int128; 5549d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor 5559d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor if (!Ctx.getLangOptions().CPlusPlus) 5561274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) 5571274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor return ET->getDecl()->isComplete(); // Complete enum types are integral in C. 5589d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor 55933e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian return false; 56033e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian} 56133e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian 5622ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregorbool Type::isIntegralOrEnumerationType() const { 5632ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 5642ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor return BT->getKind() >= BuiltinType::Bool && 5652ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor BT->getKind() <= BuiltinType::Int128; 56634fd628d22f54baddf30cf80c401b2f862a31b23Eli Friedman 56734fd628d22f54baddf30cf80c401b2f862a31b23Eli Friedman // Check for a complete enum type; incomplete enum types are not properly an 56834fd628d22f54baddf30cf80c401b2f862a31b23Eli Friedman // enumeration type in the sense required here. 5691274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) 5701274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor return ET->getDecl()->isComplete(); 57134fd628d22f54baddf30cf80c401b2f862a31b23Eli Friedman 5722ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor return false; 5732ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor} 5742ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor 5751274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregorbool Type::isIntegralOrUnscopedEnumerationType() const { 5761274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 5771274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor return BT->getKind() >= BuiltinType::Bool && 5781274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor BT->getKind() <= BuiltinType::Int128; 5791274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor 5801274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor // Check for a complete enum type; incomplete enum types are not properly an 5811274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor // enumeration type in the sense required here. 5821274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor // C++0x: However, if the underlying type of the enum is fixed, it is 5831274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor // considered complete. 5841274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) 5851274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor return ET->getDecl()->isComplete() && !ET->getDecl()->isScoped(); 5861274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor 5871274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor return false; 5881274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor} 5891274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor 5901274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor 59113b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroffbool Type::isBooleanType() const { 59213b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 59313b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff return BT->getKind() == BuiltinType::Bool; 59413b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff return false; 59513b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff} 59613b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff 59713b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroffbool Type::isCharType() const { 59813b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 59913b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff return BT->getKind() == BuiltinType::Char_U || 60013b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff BT->getKind() == BuiltinType::UChar || 601c67ad5f299bb2c09e4567def8ff0d34bd15a42fdAnders Carlsson BT->getKind() == BuiltinType::Char_S || 602c67ad5f299bb2c09e4567def8ff0d34bd15a42fdAnders Carlsson BT->getKind() == BuiltinType::SChar; 60313b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff return false; 60413b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff} 60513b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff 60677a52233f7c0f162672652051bfe78b65ad4f789Douglas Gregorbool Type::isWideCharType() const { 60777a52233f7c0f162672652051bfe78b65ad4f789Douglas Gregor if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 6083f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner return BT->getKind() == BuiltinType::WChar_S || 6093f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner BT->getKind() == BuiltinType::WChar_U; 61077a52233f7c0f162672652051bfe78b65ad4f789Douglas Gregor return false; 61177a52233f7c0f162672652051bfe78b65ad4f789Douglas Gregor} 61277a52233f7c0f162672652051bfe78b65ad4f789Douglas Gregor 61320093b4bf698f292c664676987541d5103b65b15Douglas Gregor/// \brief Determine whether this type is any of the built-in character 61420093b4bf698f292c664676987541d5103b65b15Douglas Gregor/// types. 61520093b4bf698f292c664676987541d5103b65b15Douglas Gregorbool Type::isAnyCharacterType() const { 6163f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType); 6173f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner if (BT == 0) return false; 6183f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner switch (BT->getKind()) { 6193f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner default: return false; 6203f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner case BuiltinType::Char_U: 6213f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner case BuiltinType::UChar: 6223f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner case BuiltinType::WChar_U: 6233f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner case BuiltinType::Char16: 6243f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner case BuiltinType::Char32: 6253f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner case BuiltinType::Char_S: 6263f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner case BuiltinType::SChar: 6273f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner case BuiltinType::WChar_S: 6283f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner return true; 6293f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner } 63020093b4bf698f292c664676987541d5103b65b15Douglas Gregor} 63120093b4bf698f292c664676987541d5103b65b15Douglas Gregor 632d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner/// isSignedIntegerType - Return true if this is an integer type that is 633d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner/// signed, according to C99 6.2.5p4 [char, signed char, short, int, long..], 634f60946222721d9ba3c059563935c17b84703187aDouglas Gregor/// an enum decl which has a signed representation 6355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isSignedIntegerType() const { 6365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) { 6375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return BT->getKind() >= BuiltinType::Char_S && 638f5f7d864f5067d1ea4bff7fcf41b53a43b7b48baAnders Carlsson BT->getKind() <= BuiltinType::Int128; 6395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 6401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 641bbd340717422bf011d56cd0164d2576601368111Fariborz Jahanian if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) { 642bbd340717422bf011d56cd0164d2576601368111Fariborz Jahanian // Incomplete enum types are not treated as integer types. 643bbd340717422bf011d56cd0164d2576601368111Fariborz Jahanian // FIXME: In C++, enum types are never integer types. 644b6adf2c889bb17c1be44e6c8e67e3b2762e9ceccDouglas Gregor if (ET->getDecl()->isComplete() && !ET->getDecl()->isScoped()) 645bbd340717422bf011d56cd0164d2576601368111Fariborz Jahanian return ET->getDecl()->getIntegerType()->isSignedIntegerType(); 646bbd340717422bf011d56cd0164d2576601368111Fariborz Jahanian } 6471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 648f60946222721d9ba3c059563935c17b84703187aDouglas Gregor return false; 649f60946222721d9ba3c059563935c17b84703187aDouglas Gregor} 650f60946222721d9ba3c059563935c17b84703187aDouglas Gregor 651f60946222721d9ba3c059563935c17b84703187aDouglas Gregorbool Type::hasSignedIntegerRepresentation() const { 652c63b96ad706e054a1390dd2ab53af9f05d33bbb1Steve Naroff if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType)) 653c63b96ad706e054a1390dd2ab53af9f05d33bbb1Steve Naroff return VT->getElementType()->isSignedIntegerType(); 654f60946222721d9ba3c059563935c17b84703187aDouglas Gregor else 655f60946222721d9ba3c059563935c17b84703187aDouglas Gregor return isSignedIntegerType(); 6565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 6575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 658d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner/// isUnsignedIntegerType - Return true if this is an integer type that is 659d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner/// unsigned, according to C99 6.2.5p6 [which returns true for _Bool], an enum 660f60946222721d9ba3c059563935c17b84703187aDouglas Gregor/// decl which has an unsigned representation 6615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isUnsignedIntegerType() const { 6625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) { 6635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return BT->getKind() >= BuiltinType::Bool && 6641c03ca30ae962199ef702324b48550f6af7fdc32Anders Carlsson BT->getKind() <= BuiltinType::UInt128; 6655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 666d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner 667bbd340717422bf011d56cd0164d2576601368111Fariborz Jahanian if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) { 668bbd340717422bf011d56cd0164d2576601368111Fariborz Jahanian // Incomplete enum types are not treated as integer types. 669bbd340717422bf011d56cd0164d2576601368111Fariborz Jahanian // FIXME: In C++, enum types are never integer types. 670b6adf2c889bb17c1be44e6c8e67e3b2762e9ceccDouglas Gregor if (ET->getDecl()->isComplete() && !ET->getDecl()->isScoped()) 671bbd340717422bf011d56cd0164d2576601368111Fariborz Jahanian return ET->getDecl()->getIntegerType()->isUnsignedIntegerType(); 672bbd340717422bf011d56cd0164d2576601368111Fariborz Jahanian } 673d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner 674f60946222721d9ba3c059563935c17b84703187aDouglas Gregor return false; 675f60946222721d9ba3c059563935c17b84703187aDouglas Gregor} 676f60946222721d9ba3c059563935c17b84703187aDouglas Gregor 677f60946222721d9ba3c059563935c17b84703187aDouglas Gregorbool Type::hasUnsignedIntegerRepresentation() const { 678c63b96ad706e054a1390dd2ab53af9f05d33bbb1Steve Naroff if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType)) 679c63b96ad706e054a1390dd2ab53af9f05d33bbb1Steve Naroff return VT->getElementType()->isUnsignedIntegerType(); 680f60946222721d9ba3c059563935c17b84703187aDouglas Gregor else 681f60946222721d9ba3c059563935c17b84703187aDouglas Gregor return isUnsignedIntegerType(); 6825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 6835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isFloatingType() const { 6855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 6865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return BT->getKind() >= BuiltinType::Float && 6875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer BT->getKind() <= BuiltinType::LongDouble; 6885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (const ComplexType *CT = dyn_cast<ComplexType>(CanonicalType)) 689729a2131228cb7fcbc00bd8af36bc6f14d12317dChris Lattner return CT->getElementType()->isFloatingType(); 6908eee119bf4f1693dde17b8552c1f9f81bf2b681eDouglas Gregor return false; 6918eee119bf4f1693dde17b8552c1f9f81bf2b681eDouglas Gregor} 6928eee119bf4f1693dde17b8552c1f9f81bf2b681eDouglas Gregor 6938eee119bf4f1693dde17b8552c1f9f81bf2b681eDouglas Gregorbool Type::hasFloatingRepresentation() const { 694c63b96ad706e054a1390dd2ab53af9f05d33bbb1Steve Naroff if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType)) 695c63b96ad706e054a1390dd2ab53af9f05d33bbb1Steve Naroff return VT->getElementType()->isFloatingType(); 6968eee119bf4f1693dde17b8552c1f9f81bf2b681eDouglas Gregor else 6978eee119bf4f1693dde17b8552c1f9f81bf2b681eDouglas Gregor return isFloatingType(); 6985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 6995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isRealFloatingType() const { 7015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 702680523a91dd3351389667c8de17121ba7ae82673John McCall return BT->isFloatingPoint(); 7035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return false; 7045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 7055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isRealType() const { 7075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 7085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return BT->getKind() >= BuiltinType::Bool && 7095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer BT->getKind() <= BuiltinType::LongDouble; 7101274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) 7111274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor return ET->getDecl()->isComplete() && !ET->getDecl()->isScoped(); 7125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return false; 7135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 7145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isArithmeticType() const { 7165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 717a7fbf7282eadebaf1293d9f970b01fb57f4b0ae4Douglas Gregor return BT->getKind() >= BuiltinType::Bool && 718a7fbf7282eadebaf1293d9f970b01fb57f4b0ae4Douglas Gregor BT->getKind() <= BuiltinType::LongDouble; 71937c1b78a20a09b0456aa5caa15e159027010ca22Chris Lattner if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) 72037c1b78a20a09b0456aa5caa15e159027010ca22Chris Lattner // GCC allows forward declaration of enum types (forbid by C99 6.7.2.3p2). 72137c1b78a20a09b0456aa5caa15e159027010ca22Chris Lattner // If a body isn't seen by the time we get here, return false. 7221274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor // 7231274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor // C++0x: Enumerations are not arithmetic types. For now, just return 7241274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor // false for scoped enumerations since that will disable any 7251274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor // unwanted implicit conversions. 7261274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor return !ET->getDecl()->isScoped() && ET->getDecl()->isComplete(); 72700619623af0b9d3271e31402ec1a95e84c2c4526Douglas Gregor return isa<ComplexType>(CanonicalType); 7285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 7295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isScalarType() const { 7315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 732daa8e4e888758d55a7a759dd4a91b83921cef222John McCall return BT->getKind() > BuiltinType::Void && 733daa8e4e888758d55a7a759dd4a91b83921cef222John McCall BT->getKind() <= BuiltinType::NullPtr; 7341274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) 735834a72ac74cf4ff07ba6215545dba3db578f8a07Chris Lattner // Enums are scalar types, but only if they are defined. Incomplete enums 736834a72ac74cf4ff07ba6215545dba3db578f8a07Chris Lattner // are not treated as scalar types. 7371274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor return ET->getDecl()->isComplete(); 7385618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff return isa<PointerType>(CanonicalType) || 7395618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff isa<BlockPointerType>(CanonicalType) || 740f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl isa<MemberPointerType>(CanonicalType) || 7415618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff isa<ComplexType>(CanonicalType) || 742d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff isa<ObjCObjectPointerType>(CanonicalType); 7435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 7445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 745daa8e4e888758d55a7a759dd4a91b83921cef222John McCallType::ScalarTypeKind Type::getScalarTypeKind() const { 746daa8e4e888758d55a7a759dd4a91b83921cef222John McCall assert(isScalarType()); 747daa8e4e888758d55a7a759dd4a91b83921cef222John McCall 748daa8e4e888758d55a7a759dd4a91b83921cef222John McCall const Type *T = CanonicalType.getTypePtr(); 749daa8e4e888758d55a7a759dd4a91b83921cef222John McCall if (const BuiltinType *BT = dyn_cast<BuiltinType>(T)) { 750daa8e4e888758d55a7a759dd4a91b83921cef222John McCall if (BT->getKind() == BuiltinType::Bool) return STK_Bool; 751daa8e4e888758d55a7a759dd4a91b83921cef222John McCall if (BT->getKind() == BuiltinType::NullPtr) return STK_Pointer; 752daa8e4e888758d55a7a759dd4a91b83921cef222John McCall if (BT->isInteger()) return STK_Integral; 753daa8e4e888758d55a7a759dd4a91b83921cef222John McCall if (BT->isFloatingPoint()) return STK_Floating; 754daa8e4e888758d55a7a759dd4a91b83921cef222John McCall llvm_unreachable("unknown scalar builtin type"); 755daa8e4e888758d55a7a759dd4a91b83921cef222John McCall } else if (isa<PointerType>(T) || 756daa8e4e888758d55a7a759dd4a91b83921cef222John McCall isa<BlockPointerType>(T) || 757daa8e4e888758d55a7a759dd4a91b83921cef222John McCall isa<ObjCObjectPointerType>(T)) { 758daa8e4e888758d55a7a759dd4a91b83921cef222John McCall return STK_Pointer; 759daa8e4e888758d55a7a759dd4a91b83921cef222John McCall } else if (isa<MemberPointerType>(T)) { 760daa8e4e888758d55a7a759dd4a91b83921cef222John McCall return STK_MemberPointer; 761daa8e4e888758d55a7a759dd4a91b83921cef222John McCall } else if (isa<EnumType>(T)) { 762daa8e4e888758d55a7a759dd4a91b83921cef222John McCall assert(cast<EnumType>(T)->getDecl()->isComplete()); 763daa8e4e888758d55a7a759dd4a91b83921cef222John McCall return STK_Integral; 764daa8e4e888758d55a7a759dd4a91b83921cef222John McCall } else if (const ComplexType *CT = dyn_cast<ComplexType>(T)) { 765daa8e4e888758d55a7a759dd4a91b83921cef222John McCall if (CT->getElementType()->isRealFloatingType()) 766daa8e4e888758d55a7a759dd4a91b83921cef222John McCall return STK_FloatingComplex; 767daa8e4e888758d55a7a759dd4a91b83921cef222John McCall return STK_IntegralComplex; 768daa8e4e888758d55a7a759dd4a91b83921cef222John McCall } 769daa8e4e888758d55a7a759dd4a91b83921cef222John McCall 770daa8e4e888758d55a7a759dd4a91b83921cef222John McCall llvm_unreachable("unknown scalar type"); 771daa8e4e888758d55a7a759dd4a91b83921cef222John McCall return STK_Pointer; 772daa8e4e888758d55a7a759dd4a91b83921cef222John McCall} 773daa8e4e888758d55a7a759dd4a91b83921cef222John McCall 774d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor/// \brief Determines whether the type is a C++ aggregate type or C 775d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor/// aggregate or union type. 776d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor/// 777d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor/// An aggregate type is an array or a class type (struct, union, or 778d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor/// class) that has no user-declared constructors, no private or 779d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor/// protected non-static data members, no base classes, and no virtual 780d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor/// functions (C++ [dcl.init.aggr]p1). The notion of an aggregate type 781d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor/// subsumes the notion of C aggregates (C99 6.2.5p21) because it also 782d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor/// includes union types. 7835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isAggregateType() const { 784c1efaecf0373f1a55c5ef4c234357cf726fc0600Douglas Gregor if (const RecordType *Record = dyn_cast<RecordType>(CanonicalType)) { 785c1efaecf0373f1a55c5ef4c234357cf726fc0600Douglas Gregor if (CXXRecordDecl *ClassDecl = dyn_cast<CXXRecordDecl>(Record->getDecl())) 786c1efaecf0373f1a55c5ef4c234357cf726fc0600Douglas Gregor return ClassDecl->isAggregate(); 787c1efaecf0373f1a55c5ef4c234357cf726fc0600Douglas Gregor 788d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor return true; 789c1efaecf0373f1a55c5ef4c234357cf726fc0600Douglas Gregor } 790c1efaecf0373f1a55c5ef4c234357cf726fc0600Douglas Gregor 791c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman return isa<ArrayType>(CanonicalType); 7925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 7935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7949bfa73c5ab7bf4b0e749d04f29da6884e8d5bd9fChris Lattner/// isConstantSizeType - Return true if this is not a variable sized type, 7959bfa73c5ab7bf4b0e749d04f29da6884e8d5bd9fChris Lattner/// according to the rules of C99 6.7.5p3. It is not legal to call this on 796898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// incomplete types or dependent types. 7973c2b3170041f69a92904e3bab9b6d654eaf260acEli Friedmanbool Type::isConstantSizeType() const { 798d52a4578144ab2887912e52eabec58a857a44adbChris Lattner assert(!isIncompleteType() && "This doesn't make sense for incomplete types"); 799898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor assert(!isDependentType() && "This doesn't make sense for dependent types"); 8009bfa73c5ab7bf4b0e749d04f29da6884e8d5bd9fChris Lattner // The VAT must have a size, as it is known to be complete. 8019bfa73c5ab7bf4b0e749d04f29da6884e8d5bd9fChris Lattner return !isa<VariableArrayType>(CanonicalType); 8025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 8035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// isIncompleteType - Return true if this is an incomplete type (C99 6.2.5p1) 8055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// - a type that can describe objects, but which lacks information needed to 8065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// determine its size. 8071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpbool Type::isIncompleteType() const { 8081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump switch (CanonicalType->getTypeClass()) { 8095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer default: return false; 8105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Builtin: 8115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Void is the only incomplete builtin type. Per C99 6.2.5p19, it can never 8125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // be completed. 8135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return isVoidType(); 81472564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor case Enum: 8151274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor // An enumeration with fixed underlying type is complete (C++0x 7.2p3). 8161274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor if (cast<EnumType>(CanonicalType)->getDecl()->isFixed()) 8171274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor return false; 8181274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor // Fall through. 8191274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor case Record: 8205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // A tagged type (struct/union/enum/class) is incomplete if the decl is a 8215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // forward declaration, but not a full definition (C99 6.2.5p22). 8225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return !cast<TagType>(CanonicalType)->getDecl()->isDefinition(); 823923d56d436f750bc1f29db50e641078725558a1bSebastian Redl case ConstantArray: 824923d56d436f750bc1f29db50e641078725558a1bSebastian Redl // An array is incomplete if its element type is incomplete 825923d56d436f750bc1f29db50e641078725558a1bSebastian Redl // (C++ [dcl.array]p1). 826923d56d436f750bc1f29db50e641078725558a1bSebastian Redl // We don't handle variable arrays (they're not allowed in C++) or 827923d56d436f750bc1f29db50e641078725558a1bSebastian Redl // dependent-sized arrays (dependent types are never treated as incomplete). 828923d56d436f750bc1f29db50e641078725558a1bSebastian Redl return cast<ArrayType>(CanonicalType)->getElementType()->isIncompleteType(); 829c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman case IncompleteArray: 8305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // An array of unknown size is an incomplete type (C99 6.2.5p22). 831c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman return true; 832c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall case ObjCObject: 833d0221526bcc81f49eff5c992978176e83ada3bc7Douglas Gregor return cast<ObjCObjectType>(CanonicalType)->getBaseType() 834d0221526bcc81f49eff5c992978176e83ada3bc7Douglas Gregor ->isIncompleteType(); 8351efaa9594a81709a17658fd80ae7e783e1026407Chris Lattner case ObjCInterface: 8361efaa9594a81709a17658fd80ae7e783e1026407Chris Lattner // ObjC interfaces are incomplete if they are @class, not @interface. 837d0221526bcc81f49eff5c992978176e83ada3bc7Douglas Gregor return cast<ObjCInterfaceType>(CanonicalType)->getDecl()->isForwardDecl(); 8385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 8395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 8405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 84164b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl/// isPODType - Return true if this is a plain-old-data type (C++ 3.9p10) 84264b45f7e0d3167f040841ac2920aead7f080730dSebastian Redlbool Type::isPODType() const { 84364b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl // The compiler shouldn't query this for incomplete types, but the user might. 844607a1788d9529c8e8494ac528764aa2c678a1a97Sebastian Redl // We return false for that case. Except for incomplete arrays of PODs, which 845607a1788d9529c8e8494ac528764aa2c678a1a97Sebastian Redl // are PODs according to the standard. 846607a1788d9529c8e8494ac528764aa2c678a1a97Sebastian Redl if (isIncompleteArrayType() && 847607a1788d9529c8e8494ac528764aa2c678a1a97Sebastian Redl cast<ArrayType>(CanonicalType)->getElementType()->isPODType()) 848607a1788d9529c8e8494ac528764aa2c678a1a97Sebastian Redl return true; 84964b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl if (isIncompleteType()) 85064b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl return false; 85164b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 85264b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl switch (CanonicalType->getTypeClass()) { 85364b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl // Everything not explicitly mentioned is not POD. 85464b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl default: return false; 85564b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl case VariableArray: 85664b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl case ConstantArray: 857607a1788d9529c8e8494ac528764aa2c678a1a97Sebastian Redl // IncompleteArray is handled above. 85864b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl return cast<ArrayType>(CanonicalType)->getElementType()->isPODType(); 85964b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 86064b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl case Builtin: 86164b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl case Complex: 86264b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl case Pointer: 863f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl case MemberPointer: 86464b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl case Vector: 86564b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl case ExtVector: 866d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff case ObjCObjectPointer: 8672263f822c31d0855ca8c48bfd9624322bf776f0bFariborz Jahanian case BlockPointer: 86864b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl return true; 86964b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 87072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor case Enum: 87172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor return true; 87272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor 87372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor case Record: 8741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (CXXRecordDecl *ClassDecl 875c1efaecf0373f1a55c5ef4c234357cf726fc0600Douglas Gregor = dyn_cast<CXXRecordDecl>(cast<RecordType>(CanonicalType)->getDecl())) 876c1efaecf0373f1a55c5ef4c234357cf726fc0600Douglas Gregor return ClassDecl->isPOD(); 877c1efaecf0373f1a55c5ef4c234357cf726fc0600Douglas Gregor 87864b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl // C struct/union is POD. 87964b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl return true; 88064b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl } 88164b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl} 88264b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 883ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redlbool Type::isLiteralType() const { 884018a088b3b30e500efa9173f7cd4b1b1f6a065a8Chandler Carruth if (isDependentType()) 885ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl return false; 886ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl 887ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl // C++0x [basic.types]p10: 888ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl // A type is a literal type if it is: 8899b6347cd410be55425f7062d22fd6e4ecb4e1a58Chandler Carruth // [...] 8909b6347cd410be55425f7062d22fd6e4ecb4e1a58Chandler Carruth // -- an array of literal type 8919b6347cd410be55425f7062d22fd6e4ecb4e1a58Chandler Carruth // Extension: variable arrays cannot be literal types, since they're 8929b6347cd410be55425f7062d22fd6e4ecb4e1a58Chandler Carruth // runtime-sized. 893018a088b3b30e500efa9173f7cd4b1b1f6a065a8Chandler Carruth if (isVariableArrayType()) 894ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl return false; 8959b6347cd410be55425f7062d22fd6e4ecb4e1a58Chandler Carruth const Type *BaseTy = getBaseElementTypeUnsafe(); 8969b6347cd410be55425f7062d22fd6e4ecb4e1a58Chandler Carruth assert(BaseTy && "NULL element type"); 897ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl 898018a088b3b30e500efa9173f7cd4b1b1f6a065a8Chandler Carruth // Return false for incomplete types after skipping any incomplete array 899018a088b3b30e500efa9173f7cd4b1b1f6a065a8Chandler Carruth // types; those are expressly allowed by the standard and thus our API. 900018a088b3b30e500efa9173f7cd4b1b1f6a065a8Chandler Carruth if (BaseTy->isIncompleteType()) 901018a088b3b30e500efa9173f7cd4b1b1f6a065a8Chandler Carruth return false; 902018a088b3b30e500efa9173f7cd4b1b1f6a065a8Chandler Carruth 9039b6347cd410be55425f7062d22fd6e4ecb4e1a58Chandler Carruth // C++0x [basic.types]p10: 9049b6347cd410be55425f7062d22fd6e4ecb4e1a58Chandler Carruth // A type is a literal type if it is: 9059b6347cd410be55425f7062d22fd6e4ecb4e1a58Chandler Carruth // -- a scalar type; or 90625df423cfc6689cf21d51a66af84ea1e70d489dfChandler Carruth // As an extension, Clang treats vector types as Scalar types. 90725df423cfc6689cf21d51a66af84ea1e70d489dfChandler Carruth if (BaseTy->isScalarType() || BaseTy->isVectorType()) return true; 9089b6347cd410be55425f7062d22fd6e4ecb4e1a58Chandler Carruth // -- a reference type; or 9099b6347cd410be55425f7062d22fd6e4ecb4e1a58Chandler Carruth if (BaseTy->isReferenceType()) return true; 9109b6347cd410be55425f7062d22fd6e4ecb4e1a58Chandler Carruth // -- a class type that has all of the following properties: 9119b6347cd410be55425f7062d22fd6e4ecb4e1a58Chandler Carruth if (const RecordType *RT = BaseTy->getAs<RecordType>()) { 9125751838965eefa1c08e4fc545498a3ee45cd9611Chandler Carruth if (const CXXRecordDecl *ClassDecl = 9135751838965eefa1c08e4fc545498a3ee45cd9611Chandler Carruth dyn_cast<CXXRecordDecl>(RT->getDecl())) { 9145751838965eefa1c08e4fc545498a3ee45cd9611Chandler Carruth // -- a trivial destructor, 9155751838965eefa1c08e4fc545498a3ee45cd9611Chandler Carruth if (!ClassDecl->hasTrivialDestructor()) return false; 9165751838965eefa1c08e4fc545498a3ee45cd9611Chandler Carruth // -- every constructor call and full-expression in the 9175751838965eefa1c08e4fc545498a3ee45cd9611Chandler Carruth // brace-or-equal-initializers for non-static data members (if any) 9185751838965eefa1c08e4fc545498a3ee45cd9611Chandler Carruth // is a constant expression, 9195751838965eefa1c08e4fc545498a3ee45cd9611Chandler Carruth // FIXME: C++0x: Clang doesn't yet support non-static data member 9205751838965eefa1c08e4fc545498a3ee45cd9611Chandler Carruth // declarations with initializers, or constexprs. 9215751838965eefa1c08e4fc545498a3ee45cd9611Chandler Carruth // -- it is an aggregate type or has at least one constexpr 9225751838965eefa1c08e4fc545498a3ee45cd9611Chandler Carruth // constructor or constructor template that is not a copy or move 9235751838965eefa1c08e4fc545498a3ee45cd9611Chandler Carruth // constructor, and 9245751838965eefa1c08e4fc545498a3ee45cd9611Chandler Carruth if (!ClassDecl->isAggregate() && 9255751838965eefa1c08e4fc545498a3ee45cd9611Chandler Carruth !ClassDecl->hasConstExprNonCopyMoveConstructor()) 9265751838965eefa1c08e4fc545498a3ee45cd9611Chandler Carruth return false; 9275751838965eefa1c08e4fc545498a3ee45cd9611Chandler Carruth // -- all non-static data members and base classes of literal types 9285751838965eefa1c08e4fc545498a3ee45cd9611Chandler Carruth if (ClassDecl->hasNonLiteralTypeFieldsOrBases()) return false; 9295751838965eefa1c08e4fc545498a3ee45cd9611Chandler Carruth } 9309b6347cd410be55425f7062d22fd6e4ecb4e1a58Chandler Carruth 9319b6347cd410be55425f7062d22fd6e4ecb4e1a58Chandler Carruth return true; 932ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl } 9339b6347cd410be55425f7062d22fd6e4ecb4e1a58Chandler Carruth return false; 934ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl} 935ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl 936b7e9589bce9852b4db9575f55ac9137572147eb5Chandler Carruthbool Type::isTrivialType() const { 937018a088b3b30e500efa9173f7cd4b1b1f6a065a8Chandler Carruth if (isDependentType()) 938b7e9589bce9852b4db9575f55ac9137572147eb5Chandler Carruth return false; 939b7e9589bce9852b4db9575f55ac9137572147eb5Chandler Carruth 940b7e9589bce9852b4db9575f55ac9137572147eb5Chandler Carruth // C++0x [basic.types]p9: 941b7e9589bce9852b4db9575f55ac9137572147eb5Chandler Carruth // Scalar types, trivial class types, arrays of such types, and 942b7e9589bce9852b4db9575f55ac9137572147eb5Chandler Carruth // cv-qualified versions of these types are collectively called trivial 943b7e9589bce9852b4db9575f55ac9137572147eb5Chandler Carruth // types. 944b7e9589bce9852b4db9575f55ac9137572147eb5Chandler Carruth const Type *BaseTy = getBaseElementTypeUnsafe(); 945b7e9589bce9852b4db9575f55ac9137572147eb5Chandler Carruth assert(BaseTy && "NULL element type"); 946018a088b3b30e500efa9173f7cd4b1b1f6a065a8Chandler Carruth 947018a088b3b30e500efa9173f7cd4b1b1f6a065a8Chandler Carruth // Return false for incomplete types after skipping any incomplete array 948018a088b3b30e500efa9173f7cd4b1b1f6a065a8Chandler Carruth // types which are expressly allowed by the standard and thus our API. 949018a088b3b30e500efa9173f7cd4b1b1f6a065a8Chandler Carruth if (BaseTy->isIncompleteType()) 950018a088b3b30e500efa9173f7cd4b1b1f6a065a8Chandler Carruth return false; 951018a088b3b30e500efa9173f7cd4b1b1f6a065a8Chandler Carruth 95225df423cfc6689cf21d51a66af84ea1e70d489dfChandler Carruth // As an extension, Clang treats vector types as Scalar types. 95325df423cfc6689cf21d51a66af84ea1e70d489dfChandler Carruth if (BaseTy->isScalarType() || BaseTy->isVectorType()) return true; 954b7e9589bce9852b4db9575f55ac9137572147eb5Chandler Carruth if (const RecordType *RT = BaseTy->getAs<RecordType>()) { 9555751838965eefa1c08e4fc545498a3ee45cd9611Chandler Carruth if (const CXXRecordDecl *ClassDecl = 9565751838965eefa1c08e4fc545498a3ee45cd9611Chandler Carruth dyn_cast<CXXRecordDecl>(RT->getDecl())) { 9575751838965eefa1c08e4fc545498a3ee45cd9611Chandler Carruth // C++0x [class]p5: 9585751838965eefa1c08e4fc545498a3ee45cd9611Chandler Carruth // A trivial class is a class that has a trivial default constructor 9595751838965eefa1c08e4fc545498a3ee45cd9611Chandler Carruth if (!ClassDecl->hasTrivialConstructor()) return false; 9605751838965eefa1c08e4fc545498a3ee45cd9611Chandler Carruth // and is trivially copyable. 9615751838965eefa1c08e4fc545498a3ee45cd9611Chandler Carruth if (!ClassDecl->isTriviallyCopyable()) return false; 9625751838965eefa1c08e4fc545498a3ee45cd9611Chandler Carruth } 963b7e9589bce9852b4db9575f55ac9137572147eb5Chandler Carruth 964b7e9589bce9852b4db9575f55ac9137572147eb5Chandler Carruth return true; 965b7e9589bce9852b4db9575f55ac9137572147eb5Chandler Carruth } 966b7e9589bce9852b4db9575f55ac9137572147eb5Chandler Carruth 967b7e9589bce9852b4db9575f55ac9137572147eb5Chandler Carruth // No other types can match. 968b7e9589bce9852b4db9575f55ac9137572147eb5Chandler Carruth return false; 969b7e9589bce9852b4db9575f55ac9137572147eb5Chandler Carruth} 970b7e9589bce9852b4db9575f55ac9137572147eb5Chandler Carruth 971636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruthbool Type::isStandardLayoutType() const { 972018a088b3b30e500efa9173f7cd4b1b1f6a065a8Chandler Carruth if (isDependentType()) 973636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth return false; 974636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth 975636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth // C++0x [basic.types]p9: 976636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth // Scalar types, standard-layout class types, arrays of such types, and 977636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth // cv-qualified versions of these types are collectively called 978636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth // standard-layout types. 979636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth const Type *BaseTy = getBaseElementTypeUnsafe(); 980636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth assert(BaseTy && "NULL element type"); 981018a088b3b30e500efa9173f7cd4b1b1f6a065a8Chandler Carruth 982018a088b3b30e500efa9173f7cd4b1b1f6a065a8Chandler Carruth // Return false for incomplete types after skipping any incomplete array 983018a088b3b30e500efa9173f7cd4b1b1f6a065a8Chandler Carruth // types which are expressly allowed by the standard and thus our API. 984018a088b3b30e500efa9173f7cd4b1b1f6a065a8Chandler Carruth if (BaseTy->isIncompleteType()) 985018a088b3b30e500efa9173f7cd4b1b1f6a065a8Chandler Carruth return false; 986018a088b3b30e500efa9173f7cd4b1b1f6a065a8Chandler Carruth 98725df423cfc6689cf21d51a66af84ea1e70d489dfChandler Carruth // As an extension, Clang treats vector types as Scalar types. 98825df423cfc6689cf21d51a66af84ea1e70d489dfChandler Carruth if (BaseTy->isScalarType() || BaseTy->isVectorType()) return true; 989636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth if (const RecordType *RT = BaseTy->getAs<RecordType>()) { 990636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth if (const CXXRecordDecl *ClassDecl = 991636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth dyn_cast<CXXRecordDecl>(RT->getDecl())) 992ec997dc66627957bcdcd3db7906a68c1e14a279cChandler Carruth if (!ClassDecl->isStandardLayout()) 993636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth return false; 994636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth 995636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth // Default to 'true' for non-C++ class types. 996636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth // FIXME: This is a bit dubious, but plain C structs should trivially meet 997636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth // all the requirements of standard layout classes. 998636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth return true; 999636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth } 1000636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth 1001636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth // No other types can match. 1002636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth return false; 1003636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth} 1004636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth 1005636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth// This is effectively the intersection of isTrivialType and 1006636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth// isStandardLayoutType. We implement it dircetly to avoid redundant 1007636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth// conversions from a type to a CXXRecordDecl. 100843fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruthbool Type::isCXX11PODType() const { 1009018a088b3b30e500efa9173f7cd4b1b1f6a065a8Chandler Carruth if (isDependentType()) 101043fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth return false; 101143fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth 101243fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth // C++11 [basic.types]p9: 101343fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth // Scalar types, POD classes, arrays of such types, and cv-qualified 101443fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth // versions of these types are collectively called trivial types. 101543fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth const Type *BaseTy = getBaseElementTypeUnsafe(); 101643fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth assert(BaseTy && "NULL element type"); 1017018a088b3b30e500efa9173f7cd4b1b1f6a065a8Chandler Carruth 1018018a088b3b30e500efa9173f7cd4b1b1f6a065a8Chandler Carruth // Return false for incomplete types after skipping any incomplete array 1019018a088b3b30e500efa9173f7cd4b1b1f6a065a8Chandler Carruth // types which are expressly allowed by the standard and thus our API. 1020018a088b3b30e500efa9173f7cd4b1b1f6a065a8Chandler Carruth if (BaseTy->isIncompleteType()) 1021018a088b3b30e500efa9173f7cd4b1b1f6a065a8Chandler Carruth return false; 1022018a088b3b30e500efa9173f7cd4b1b1f6a065a8Chandler Carruth 102325df423cfc6689cf21d51a66af84ea1e70d489dfChandler Carruth // As an extension, Clang treats vector types as Scalar types. 102425df423cfc6689cf21d51a66af84ea1e70d489dfChandler Carruth if (BaseTy->isScalarType() || BaseTy->isVectorType()) return true; 102543fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth if (const RecordType *RT = BaseTy->getAs<RecordType>()) { 102643fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth if (const CXXRecordDecl *ClassDecl = 102743fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth dyn_cast<CXXRecordDecl>(RT->getDecl())) { 102843fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth // C++11 [class]p10: 102943fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth // A POD struct is a non-union class that is both a trivial class [...] 103043fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth // C++11 [class]p5: 103143fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth // A trivial class is a class that has a trivial default constructor 103243fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth if (!ClassDecl->hasTrivialConstructor()) return false; 103343fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth // and is trivially copyable. 103443fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth if (!ClassDecl->isTriviallyCopyable()) return false; 103543fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth 103643fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth // C++11 [class]p10: 103743fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth // A POD struct is a non-union class that is both a trivial class and 103843fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth // a standard-layout class [...] 1039ec997dc66627957bcdcd3db7906a68c1e14a279cChandler Carruth if (!ClassDecl->isStandardLayout()) return false; 104043fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth 104143fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth // C++11 [class]p10: 104243fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth // A POD struct is a non-union class that is both a trivial class and 104343fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth // a standard-layout class, and has no non-static data members of type 104443fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth // non-POD struct, non-POD union (or array of such types). [...] 104543fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth // 104643fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth // We don't directly query the recursive aspect as the requiremets for 104743fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth // both standard-layout classes and trivial classes apply recursively 104843fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth // already. 104943fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth } 105043fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth 105143fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth return true; 105243fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth } 105343fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth 105443fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth // No other types can match. 105543fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth return false; 105643fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth} 105743fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth 10585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isPromotableIntegerType() const { 1059183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const BuiltinType *BT = getAs<BuiltinType>()) 10602a18dfe292cf3c406a769c3672080970ac586345Chris Lattner switch (BT->getKind()) { 10612a18dfe292cf3c406a769c3672080970ac586345Chris Lattner case BuiltinType::Bool: 10622a18dfe292cf3c406a769c3672080970ac586345Chris Lattner case BuiltinType::Char_S: 10632a18dfe292cf3c406a769c3672080970ac586345Chris Lattner case BuiltinType::Char_U: 10642a18dfe292cf3c406a769c3672080970ac586345Chris Lattner case BuiltinType::SChar: 10652a18dfe292cf3c406a769c3672080970ac586345Chris Lattner case BuiltinType::UChar: 10662a18dfe292cf3c406a769c3672080970ac586345Chris Lattner case BuiltinType::Short: 10672a18dfe292cf3c406a769c3672080970ac586345Chris Lattner case BuiltinType::UShort: 10682a18dfe292cf3c406a769c3672080970ac586345Chris Lattner return true; 10691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump default: 10702a18dfe292cf3c406a769c3672080970ac586345Chris Lattner return false; 10712a18dfe292cf3c406a769c3672080970ac586345Chris Lattner } 1072aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor 1073aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor // Enumerated types are promotable to their compatible integer types 1074aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor // (C99 6.3.1.1) a.k.a. its underlying type (C++ [conv.prom]p2). 1075aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor if (const EnumType *ET = getAs<EnumType>()){ 10761274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor if (this->isDependentType() || ET->getDecl()->getPromotionType().isNull() 10771274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor || ET->getDecl()->isScoped()) 1078aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor return false; 1079aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor 1080aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor const BuiltinType *BT 1081aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor = ET->getDecl()->getPromotionType()->getAs<BuiltinType>(); 1082aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor return BT->getKind() == BuiltinType::Int 1083aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor || BT->getKind() == BuiltinType::UInt; 1084aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor } 1085aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor 10862a18dfe292cf3c406a769c3672080970ac586345Chris Lattner return false; 10875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 10885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10896e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redlbool Type::isNullPtrType() const { 1090183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const BuiltinType *BT = getAs<BuiltinType>()) 10916e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl return BT->getKind() == BuiltinType::NullPtr; 10926e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl return false; 10936e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl} 10946e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl 109522b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedmanbool Type::isSpecifierType() const { 109622b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman // Note that this intentionally does not use the canonical type. 109722b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman switch (getTypeClass()) { 109822b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman case Builtin: 109922b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman case Record: 110022b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman case Enum: 110122b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman case Typedef: 1102c8f2c61f4f667c2bc3e4e74b274fa397a4232393Eli Friedman case Complex: 1103c8f2c61f4f667c2bc3e4e74b274fa397a4232393Eli Friedman case TypeOfExpr: 1104c8f2c61f4f667c2bc3e4e74b274fa397a4232393Eli Friedman case TypeOf: 1105c8f2c61f4f667c2bc3e4e74b274fa397a4232393Eli Friedman case TemplateTypeParm: 110649a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall case SubstTemplateTypeParm: 1107c8f2c61f4f667c2bc3e4e74b274fa397a4232393Eli Friedman case TemplateSpecialization: 1108465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case Elaborated: 11094714c12a1ab759156b78be8f109ea4c12213af57Douglas Gregor case DependentName: 111033500955d731c73717af52088b7fc0e7a85681e7John McCall case DependentTemplateSpecialization: 1111c8f2c61f4f667c2bc3e4e74b274fa397a4232393Eli Friedman case ObjCInterface: 1112c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall case ObjCObject: 1113c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall case ObjCObjectPointer: // FIXME: object pointers aren't really specifiers 111422b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman return true; 111522b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman default: 111622b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman return false; 111722b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman } 111822b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman} 111922b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman 1120465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraElaboratedTypeKeyword 1121465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraTypeWithKeyword::getKeywordForTypeSpec(unsigned TypeSpec) { 1122465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara switch (TypeSpec) { 1123465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara default: return ETK_None; 1124465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TST_typename: return ETK_Typename; 1125465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TST_class: return ETK_Class; 1126465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TST_struct: return ETK_Struct; 1127465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TST_union: return ETK_Union; 1128465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TST_enum: return ETK_Enum; 1129465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara } 1130465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara} 1131465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 1132465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraTagTypeKind 1133465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraTypeWithKeyword::getTagTypeKindForTypeSpec(unsigned TypeSpec) { 1134465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara switch(TypeSpec) { 1135465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TST_class: return TTK_Class; 1136465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TST_struct: return TTK_Struct; 1137465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TST_union: return TTK_Union; 1138465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TST_enum: return TTK_Enum; 1139465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara } 11407907fad723a0f4764a2396df620d9c58725b3053Douglas Gregor 11417907fad723a0f4764a2396df620d9c58725b3053Douglas Gregor llvm_unreachable("Type specifier is not a tag type kind."); 11427907fad723a0f4764a2396df620d9c58725b3053Douglas Gregor return TTK_Union; 1143465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara} 1144465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 1145465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraElaboratedTypeKeyword 1146465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraTypeWithKeyword::getKeywordForTagTypeKind(TagTypeKind Kind) { 1147465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara switch (Kind) { 1148465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TTK_Class: return ETK_Class; 1149465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TTK_Struct: return ETK_Struct; 1150465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TTK_Union: return ETK_Union; 1151465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TTK_Enum: return ETK_Enum; 1152465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara } 1153465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara llvm_unreachable("Unknown tag type kind."); 1154465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara} 1155465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 1156465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraTagTypeKind 1157465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraTypeWithKeyword::getTagTypeKindForKeyword(ElaboratedTypeKeyword Keyword) { 1158465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara switch (Keyword) { 1159465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Class: return TTK_Class; 1160465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Struct: return TTK_Struct; 1161465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Union: return TTK_Union; 1162465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Enum: return TTK_Enum; 1163465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_None: // Fall through. 1164465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Typename: 1165465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara llvm_unreachable("Elaborated type keyword is not a tag type kind."); 1166465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara } 1167465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara llvm_unreachable("Unknown elaborated type keyword."); 1168465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara} 1169465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 1170465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnarabool 1171465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraTypeWithKeyword::KeywordIsTagTypeKind(ElaboratedTypeKeyword Keyword) { 1172465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara switch (Keyword) { 1173465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_None: 1174465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Typename: 1175465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara return false; 1176465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Class: 1177465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Struct: 1178465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Union: 1179465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Enum: 11804033642464e8ba0982f88f34cffad808d247b393Douglas Gregor return true; 11814033642464e8ba0982f88f34cffad808d247b393Douglas Gregor } 1182465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara llvm_unreachable("Unknown elaborated type keyword."); 1183465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara} 1184465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 1185465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnaraconst char* 1186465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraTypeWithKeyword::getKeywordName(ElaboratedTypeKeyword Keyword) { 1187465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara switch (Keyword) { 1188465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_None: return ""; 1189465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Typename: return "typename"; 1190465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Class: return "class"; 1191465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Struct: return "struct"; 1192465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Union: return "union"; 1193465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Enum: return "enum"; 1194465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara } 11957907fad723a0f4764a2396df620d9c58725b3053Douglas Gregor 11967907fad723a0f4764a2396df620d9c58725b3053Douglas Gregor llvm_unreachable("Unknown elaborated type keyword."); 11977907fad723a0f4764a2396df620d9c58725b3053Douglas Gregor return ""; 1198465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara} 1199465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 120033500955d731c73717af52088b7fc0e7a85681e7John McCallDependentTemplateSpecializationType::DependentTemplateSpecializationType( 1201ef99001908e799c388f1363b1e607dad5f5b57d3John McCall ElaboratedTypeKeyword Keyword, 120233500955d731c73717af52088b7fc0e7a85681e7John McCall NestedNameSpecifier *NNS, const IdentifierInfo *Name, 120333500955d731c73717af52088b7fc0e7a85681e7John McCall unsigned NumArgs, const TemplateArgument *Args, 120433500955d731c73717af52088b7fc0e7a85681e7John McCall QualType Canon) 120535495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor : TypeWithKeyword(Keyword, DependentTemplateSpecialization, Canon, true, 1206d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /*VariablyModified=*/false, 1207aa2187de137e5b809dcbbe14f3b61ae907a3d8aaDouglas Gregor NNS && NNS->containsUnexpandedParameterPack()), 1208ef99001908e799c388f1363b1e607dad5f5b57d3John McCall NNS(NNS), Name(Name), NumArgs(NumArgs) { 1209aa2187de137e5b809dcbbe14f3b61ae907a3d8aaDouglas Gregor assert((!NNS || NNS->isDependent()) && 121033500955d731c73717af52088b7fc0e7a85681e7John McCall "DependentTemplateSpecializatonType requires dependent qualifier"); 1211d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor for (unsigned I = 0; I != NumArgs; ++I) { 1212d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor if (Args[I].containsUnexpandedParameterPack()) 1213d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor setContainsUnexpandedParameterPack(); 1214d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 121533500955d731c73717af52088b7fc0e7a85681e7John McCall new (&getArgBuffer()[I]) TemplateArgument(Args[I]); 1216d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor } 121733500955d731c73717af52088b7fc0e7a85681e7John McCall} 121833500955d731c73717af52088b7fc0e7a85681e7John McCall 121933500955d731c73717af52088b7fc0e7a85681e7John McCallvoid 122033500955d731c73717af52088b7fc0e7a85681e7John McCallDependentTemplateSpecializationType::Profile(llvm::FoldingSetNodeID &ID, 12214ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad const ASTContext &Context, 122233500955d731c73717af52088b7fc0e7a85681e7John McCall ElaboratedTypeKeyword Keyword, 122333500955d731c73717af52088b7fc0e7a85681e7John McCall NestedNameSpecifier *Qualifier, 122433500955d731c73717af52088b7fc0e7a85681e7John McCall const IdentifierInfo *Name, 122533500955d731c73717af52088b7fc0e7a85681e7John McCall unsigned NumArgs, 122633500955d731c73717af52088b7fc0e7a85681e7John McCall const TemplateArgument *Args) { 122733500955d731c73717af52088b7fc0e7a85681e7John McCall ID.AddInteger(Keyword); 122833500955d731c73717af52088b7fc0e7a85681e7John McCall ID.AddPointer(Qualifier); 122933500955d731c73717af52088b7fc0e7a85681e7John McCall ID.AddPointer(Name); 123033500955d731c73717af52088b7fc0e7a85681e7John McCall for (unsigned Idx = 0; Idx < NumArgs; ++Idx) 123133500955d731c73717af52088b7fc0e7a85681e7John McCall Args[Idx].Profile(ID, Context); 123233500955d731c73717af52088b7fc0e7a85681e7John McCall} 123333500955d731c73717af52088b7fc0e7a85681e7John McCall 1234465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnarabool Type::isElaboratedTypeSpecifier() const { 1235465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara ElaboratedTypeKeyword Keyword; 1236465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara if (const ElaboratedType *Elab = dyn_cast<ElaboratedType>(this)) 1237465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara Keyword = Elab->getKeyword(); 1238465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara else if (const DependentNameType *DepName = dyn_cast<DependentNameType>(this)) 1239465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara Keyword = DepName->getKeyword(); 124033500955d731c73717af52088b7fc0e7a85681e7John McCall else if (const DependentTemplateSpecializationType *DepTST = 124133500955d731c73717af52088b7fc0e7a85681e7John McCall dyn_cast<DependentTemplateSpecializationType>(this)) 124233500955d731c73717af52088b7fc0e7a85681e7John McCall Keyword = DepTST->getKeyword(); 1243465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara else 1244465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara return false; 1245465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 1246465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara return TypeWithKeyword::KeywordIsTagTypeKind(Keyword); 12474033642464e8ba0982f88f34cffad808d247b393Douglas Gregor} 12484033642464e8ba0982f88f34cffad808d247b393Douglas Gregor 1249cd01f17358dc8ef19338c0e2321138dd0a6160d9Argyrios Kyrtzidisconst char *Type::getTypeClassName() const { 1250b870b88df784c2940efce448ebfaf54dece14666John McCall switch (TypeBits.TC) { 1251cd01f17358dc8ef19338c0e2321138dd0a6160d9Argyrios Kyrtzidis#define ABSTRACT_TYPE(Derived, Base) 1252cd01f17358dc8ef19338c0e2321138dd0a6160d9Argyrios Kyrtzidis#define TYPE(Derived, Base) case Derived: return #Derived; 1253cd01f17358dc8ef19338c0e2321138dd0a6160d9Argyrios Kyrtzidis#include "clang/AST/TypeNodes.def" 1254cd01f17358dc8ef19338c0e2321138dd0a6160d9Argyrios Kyrtzidis } 12557907fad723a0f4764a2396df620d9c58725b3053Douglas Gregor 12567907fad723a0f4764a2396df620d9c58725b3053Douglas Gregor llvm_unreachable("Invalid type class."); 12577907fad723a0f4764a2396df620d9c58725b3053Douglas Gregor return 0; 1258cd01f17358dc8ef19338c0e2321138dd0a6160d9Argyrios Kyrtzidis} 1259cd01f17358dc8ef19338c0e2321138dd0a6160d9Argyrios Kyrtzidis 1260e4f2142d00fa5fdb580c4e2413da91882d955381Chris Lattnerconst char *BuiltinType::getName(const LangOptions &LO) const { 12615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer switch (getKind()) { 12625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Void: return "void"; 1263e4f2142d00fa5fdb580c4e2413da91882d955381Chris Lattner case Bool: return LO.Bool ? "bool" : "_Bool"; 12645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Char_S: return "char"; 12655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Char_U: return "char"; 12665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case SChar: return "signed char"; 12675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Short: return "short"; 12685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Int: return "int"; 12695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Long: return "long"; 12705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case LongLong: return "long long"; 12712df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner case Int128: return "__int128_t"; 12725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case UChar: return "unsigned char"; 12735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case UShort: return "unsigned short"; 12745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case UInt: return "unsigned int"; 12755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case ULong: return "unsigned long"; 12765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case ULongLong: return "unsigned long long"; 12772df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner case UInt128: return "__uint128_t"; 12785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Float: return "float"; 12795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Double: return "double"; 12805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case LongDouble: return "long double"; 12813f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner case WChar_S: 12823f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner case WChar_U: return "wchar_t"; 1283f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith case Char16: return "char16_t"; 1284f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith case Char32: return "char32_t"; 12856e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl case NullPtr: return "nullptr_t"; 12868e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor case Overload: return "<overloaded function type>"; 1287864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall case BoundMember: return "<bound member function type>"; 1288898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor case Dependent: return "<dependent type>"; 12891de4d4e8cb2e9c88809fea8092bc6e835a5473d2John McCall case UnknownAny: return "<unknown type>"; 1290de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff case ObjCId: return "id"; 1291de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff case ObjCClass: return "Class"; 1292bef0efd11bc4430a3ee437a3213cec5c18af855aChris Lattner case ObjCSel: return "SEL"; 12935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 12947907fad723a0f4764a2396df620d9c58725b3053Douglas Gregor 1295aab440b2cb0e583aeaf21f08c8247456f3142a23Nick Lewycky llvm_unreachable("Invalid builtin type."); 1296aab440b2cb0e583aeaf21f08c8247456f3142a23Nick Lewycky return 0; 12975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 12985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 12996398235d7890a81b785ea5af3b6e66d86bf184ccDouglas GregorQualType QualType::getNonLValueExprType(ASTContext &Context) const { 13005291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor if (const ReferenceType *RefType = getTypePtr()->getAs<ReferenceType>()) 13015291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor return RefType->getPointeeType(); 13025291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor 13035291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor // C++0x [basic.lval]: 13045291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor // Class prvalues can have cv-qualified types; non-class prvalues always 13055291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor // have cv-unqualified types. 13065291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor // 13075291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor // See also C99 6.3.2.1p2. 13085291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor if (!Context.getLangOptions().CPlusPlus || 13096dc1ef87044e6b177d4df0d2b593a94616180b3dChandler Carruth (!getTypePtr()->isDependentType() && !getTypePtr()->isRecordType())) 13105291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor return getUnqualifiedType(); 13115291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor 13125291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor return *this; 13135291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor} 13145291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor 131504a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCallllvm::StringRef FunctionType::getNameForCallConv(CallingConv CC) { 131604a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall switch (CC) { 13177907fad723a0f4764a2396df620d9c58725b3053Douglas Gregor case CC_Default: 13187907fad723a0f4764a2396df620d9c58725b3053Douglas Gregor llvm_unreachable("no name for default cc"); 13197907fad723a0f4764a2396df620d9c58725b3053Douglas Gregor return ""; 132004a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall 132104a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall case CC_C: return "cdecl"; 132204a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall case CC_X86StdCall: return "stdcall"; 132304a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall case CC_X86FastCall: return "fastcall"; 1324f813a2c03fcb05381b3252010435f557eb6b3cdeDouglas Gregor case CC_X86ThisCall: return "thiscall"; 132552fc314e1b5e1baee6305067cf831763d02bd243Dawn Perchik case CC_X86Pascal: return "pascal"; 1326414d8967e1d760ea1e19a4aca96b13777a8cf8c5Anton Korobeynikov case CC_AAPCS: return "aapcs"; 1327414d8967e1d760ea1e19a4aca96b13777a8cf8c5Anton Korobeynikov case CC_AAPCS_VFP: return "aapcs-vfp"; 132804a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall } 13297907fad723a0f4764a2396df620d9c58725b3053Douglas Gregor 13307907fad723a0f4764a2396df620d9c58725b3053Douglas Gregor llvm_unreachable("Invalid calling convention."); 13317907fad723a0f4764a2396df620d9c58725b3053Douglas Gregor return ""; 133204a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall} 133304a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall 1334e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCallFunctionProtoType::FunctionProtoType(QualType result, const QualType *args, 1335e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall unsigned numArgs, QualType canonical, 13368026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redl const ExtProtoInfo &epi) 1337c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor : FunctionType(FunctionProto, result, epi.Variadic, epi.TypeQuals, 1338c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor epi.RefQualifier, canonical, 1339e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall result->isDependentType(), 1340e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall result->isVariablyModifiedType(), 1341e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall result->containsUnexpandedParameterPack(), 1342e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall epi.ExtInfo), 1343e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall NumArgs(numArgs), NumExceptions(epi.NumExceptions), 134460618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl ExceptionSpecType(epi.ExceptionSpecType) 134535495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor{ 134635495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor // Fill in the trailing argument array. 1347e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall QualType *argSlot = reinterpret_cast<QualType*>(this+1); 134835495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor for (unsigned i = 0; i != numArgs; ++i) { 1349e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall if (args[i]->isDependentType()) 135035495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor setDependent(); 1351d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 1352e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall if (args[i]->containsUnexpandedParameterPack()) 1353d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor setContainsUnexpandedParameterPack(); 1354d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 1355e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall argSlot[i] = args[i]; 135635495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor } 1357e186269a8a41dbff1ebea2c251048892979d1078Douglas Gregor 135860618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl if (getExceptionSpecType() == EST_Dynamic) { 135960618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl // Fill in the exception array. 136060618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl QualType *exnSlot = argSlot + numArgs; 136160618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl for (unsigned i = 0, e = epi.NumExceptions; i != e; ++i) { 136260618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl if (epi.Exceptions[i]->isDependentType()) 136360618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl setDependent(); 1364e186269a8a41dbff1ebea2c251048892979d1078Douglas Gregor 136560618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl if (epi.Exceptions[i]->containsUnexpandedParameterPack()) 136660618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl setContainsUnexpandedParameterPack(); 136760618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl 136860618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl exnSlot[i] = epi.Exceptions[i]; 136960618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl } 137060618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl } else if (getExceptionSpecType() == EST_ComputedNoexcept) { 137160618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl // Store the noexcept expression and context. 137260618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl Expr **noexSlot = reinterpret_cast<Expr**>(argSlot + numArgs); 137360618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl *noexSlot = epi.NoexceptExpr; 1374e186269a8a41dbff1ebea2c251048892979d1078Douglas Gregor } 137535495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor} 137635495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor 137760618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian RedlFunctionProtoType::NoexceptResult 13788026f6d82f7fa544bc0453714fe94bca62a1196eSebastian RedlFunctionProtoType::getNoexceptSpec(ASTContext &ctx) const { 137960618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl ExceptionSpecificationType est = getExceptionSpecType(); 138060618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl if (est == EST_BasicNoexcept) 138160618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl return NR_Nothrow; 138260618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl 138360618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl if (est != EST_ComputedNoexcept) 138460618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl return NR_NoNoexcept; 138560618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl 138660618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl Expr *noexceptExpr = getNoexceptExpr(); 138760618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl if (!noexceptExpr) 138860618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl return NR_BadNoexcept; 138960618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl if (noexceptExpr->isValueDependent()) 139060618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl return NR_Dependent; 139160618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl 139260618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl llvm::APSInt value; 139360618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl bool isICE = noexceptExpr->isIntegerConstantExpr(value, ctx, 0, 139460618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl /*evaluated*/false); 139560618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl (void)isICE; 139660618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl assert(isICE && "AST should not contain bad noexcept expressions."); 139760618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl 139860618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl return value.getBoolValue() ? NR_Nothrow : NR_Throw; 139960618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl} 140060618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl 1401f5c65ffbd7374b6c8d9f1e361041578640cab320Douglas Gregorbool FunctionProtoType::isTemplateVariadic() const { 14027d5c0c1273bdc1cb3dff1cb5a62d07b1439e82c7Douglas Gregor for (unsigned ArgIdx = getNumArgs(); ArgIdx; --ArgIdx) 14037d5c0c1273bdc1cb3dff1cb5a62d07b1439e82c7Douglas Gregor if (isa<PackExpansionType>(getArgType(ArgIdx - 1))) 14047d5c0c1273bdc1cb3dff1cb5a62d07b1439e82c7Douglas Gregor return true; 14057d5c0c1273bdc1cb3dff1cb5a62d07b1439e82c7Douglas Gregor 14067d5c0c1273bdc1cb3dff1cb5a62d07b1439e82c7Douglas Gregor return false; 1407f5c65ffbd7374b6c8d9f1e361041578640cab320Douglas Gregor} 140835495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor 140972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregorvoid FunctionProtoType::Profile(llvm::FoldingSetNodeID &ID, QualType Result, 1410e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall const QualType *ArgTys, unsigned NumArgs, 141160618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl const ExtProtoInfo &epi, 14128026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redl const ASTContext &Context) { 14135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddPointer(Result.getAsOpaquePtr()); 14145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer for (unsigned i = 0; i != NumArgs; ++i) 14155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddPointer(ArgTys[i].getAsOpaquePtr()); 1416e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall ID.AddBoolean(epi.Variadic); 1417e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall ID.AddInteger(epi.TypeQuals); 1418c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor ID.AddInteger(epi.RefQualifier); 141960618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl ID.AddInteger(epi.ExceptionSpecType); 142060618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl if (epi.ExceptionSpecType == EST_Dynamic) { 1421e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall for (unsigned i = 0; i != epi.NumExceptions; ++i) 1422e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall ID.AddPointer(epi.Exceptions[i].getAsOpaquePtr()); 142360618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl } else if (epi.ExceptionSpecType == EST_ComputedNoexcept && epi.NoexceptExpr){ 14248026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redl epi.NoexceptExpr->Profile(ID, Context, true); 1425465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl } 1426e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall epi.ExtInfo.Profile(ID); 14275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 14285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 14298026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redlvoid FunctionProtoType::Profile(llvm::FoldingSetNodeID &ID, 14308026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redl const ASTContext &Ctx) { 143160618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl Profile(ID, getResultType(), arg_type_begin(), NumArgs, getExtProtoInfo(), 14328026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redl Ctx); 14335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 14345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1435bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCallQualType TypedefType::desugar() const { 1436bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall return getDecl()->getUnderlyingType(); 1437bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall} 1438bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 143972564e73277e29f6db3305d1f27ba408abb7ed88Douglas GregorTypeOfExprType::TypeOfExprType(Expr *E, QualType can) 144035495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor : Type(TypeOfExpr, can, E->isTypeDependent(), 1441d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor E->getType()->isVariablyModifiedType(), 1442d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor E->containsUnexpandedParameterPack()), 1443d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor TOExpr(E) { 1444898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor} 1445898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 1446bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCallQualType TypeOfExprType::desugar() const { 1447bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall return getUnderlyingExpr()->getType(); 1448bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall} 1449bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 14501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpvoid DependentTypeOfExprType::Profile(llvm::FoldingSetNodeID &ID, 14514ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad const ASTContext &Context, Expr *E) { 1452b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor E->Profile(ID, Context, true); 1453b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor} 1454b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor 1455563a03b1338d31c2462def43253a722bc885d384Anders CarlssonDecltypeType::DecltypeType(Expr *E, QualType underlyingType, QualType can) 145635495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor : Type(Decltype, can, E->isTypeDependent(), 1457d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor E->getType()->isVariablyModifiedType(), 1458d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor E->containsUnexpandedParameterPack()), 1459d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor E(E), 1460563a03b1338d31c2462def43253a722bc885d384Anders Carlsson UnderlyingType(underlyingType) { 1461395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson} 1462395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson 14634ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadDependentDecltypeType::DependentDecltypeType(const ASTContext &Context, Expr *E) 14649d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor : DecltypeType(E, Context.DependentTy), Context(Context) { } 14659d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor 14661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpvoid DependentDecltypeType::Profile(llvm::FoldingSetNodeID &ID, 14674ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad const ASTContext &Context, Expr *E) { 14689d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor E->Profile(ID, Context, true); 14699d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor} 14709d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor 147119c8576b7328f4dc2d07682f5da552875c1912efJohn McCallTagType::TagType(TypeClass TC, const TagDecl *D, QualType can) 1472d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor : Type(TC, can, D->isDependentType(), /*VariablyModified=*/false, 1473d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /*ContainsUnexpandedParameterPack=*/false), 1474ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl decl(const_cast<TagDecl*>(D)) {} 1475ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl 1476ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redlstatic TagDecl *getInterestingTagDecl(TagDecl *decl) { 1477ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl for (TagDecl::redecl_iterator I = decl->redecls_begin(), 1478ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl E = decl->redecls_end(); 1479ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl I != E; ++I) { 1480ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl if (I->isDefinition() || I->isBeingDefined()) 1481ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl return *I; 1482ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl } 1483ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl // If there's no definition (not even in progress), return what we have. 1484ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl return decl; 1485ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl} 1486ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl 1487ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian RedlTagDecl *TagType::getDecl() const { 1488ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl return getInterestingTagDecl(decl); 1489ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl} 1490ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl 1491ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redlbool TagType::isBeingDefined() const { 1492ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl return getDecl()->isBeingDefined(); 1493ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl} 1494ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl 1495ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian RedlCXXRecordDecl *InjectedClassNameType::getDecl() const { 1496ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl return cast<CXXRecordDecl>(getInterestingTagDecl(Decl)); 1497ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl} 14987da97d0f31e1ec16998d3de2cfd2e88fe3736673Douglas Gregor 14992daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattnerbool RecordType::classof(const TagType *TT) { 15002daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner return isa<RecordDecl>(TT->getDecl()); 15015edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner} 15025edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner 15032daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattnerbool EnumType::classof(const TagType *TT) { 15042daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner return isa<EnumDecl>(TT->getDecl()); 15055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 15065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1507b7efff4bae117604f442bb6859c844f90b15f3ffChandler CarruthIdentifierInfo *TemplateTypeParmType::getIdentifier() const { 15084fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth return isCanonicalUnqualified() ? 0 : getDecl()->getIdentifier(); 15094fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth} 15104fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth 1511c3069d618f4661d923cb1b5c4525b082fce73b04Douglas GregorSubstTemplateTypeParmPackType:: 1512c3069d618f4661d923cb1b5c4525b082fce73b04Douglas GregorSubstTemplateTypeParmPackType(const TemplateTypeParmType *Param, 1513c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor QualType Canon, 1514c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor const TemplateArgument &ArgPack) 1515c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor : Type(SubstTemplateTypeParmPack, Canon, true, false, true), Replaced(Param), 1516c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor Arguments(ArgPack.pack_begin()), NumArguments(ArgPack.pack_size()) 1517c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor{ 1518c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor} 1519c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor 1520c3069d618f4661d923cb1b5c4525b082fce73b04Douglas GregorTemplateArgument SubstTemplateTypeParmPackType::getArgumentPack() const { 1521c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor return TemplateArgument(Arguments, NumArguments); 1522c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor} 1523c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor 1524c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregorvoid SubstTemplateTypeParmPackType::Profile(llvm::FoldingSetNodeID &ID) { 1525c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor Profile(ID, getReplacedParameter(), getArgumentPack()); 1526c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor} 1527c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor 1528c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregorvoid SubstTemplateTypeParmPackType::Profile(llvm::FoldingSetNodeID &ID, 1529c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor const TemplateTypeParmType *Replaced, 1530c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor const TemplateArgument &ArgPack) { 1531c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor ID.AddPointer(Replaced); 1532c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor ID.AddInteger(ArgPack.pack_size()); 1533c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor for (TemplateArgument::pack_iterator P = ArgPack.pack_begin(), 1534c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor PEnd = ArgPack.pack_end(); 1535c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor P != PEnd; ++P) 1536c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor ID.AddPointer(P->getAsType().getAsOpaquePtr()); 1537c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor} 1538c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor 1539833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallbool TemplateSpecializationType:: 1540d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCallanyDependentTemplateArguments(const TemplateArgumentListInfo &Args) { 1541d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall return anyDependentTemplateArguments(Args.getArgumentArray(), Args.size()); 1542d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall} 1543d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall 1544d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCallbool TemplateSpecializationType:: 1545833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallanyDependentTemplateArguments(const TemplateArgumentLoc *Args, unsigned N) { 1546833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall for (unsigned i = 0; i != N; ++i) 1547bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (Args[i].getArgument().isDependent()) 1548833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return true; 1549833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return false; 1550833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall} 1551833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 1552833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallbool TemplateSpecializationType:: 1553833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallanyDependentTemplateArguments(const TemplateArgument *Args, unsigned N) { 1554833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall for (unsigned i = 0; i != N; ++i) 1555bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (Args[i].isDependent()) 1556833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return true; 1557833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return false; 1558833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall} 1559833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 15607532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas GregorTemplateSpecializationType:: 1561ef99001908e799c388f1363b1e607dad5f5b57d3John McCallTemplateSpecializationType(TemplateName T, 15623e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith const TemplateArgument *Args, unsigned NumArgs, 15633e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith QualType Canon, QualType AliasedType) 15641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : Type(TemplateSpecialization, 156540808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor Canon.isNull()? QualType(this, 0) : Canon, 15663e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith Canon.isNull()? T.isDependent() : Canon->isDependentType(), 15673e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith false, T.containsUnexpandedParameterPack()), 15683e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith Template(T), NumArgs(NumArgs) { 1569a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor assert(!T.getAsDependentTemplateName() && 1570a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor "Use DependentTemplateSpecializationType for dependent template-name"); 15711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump assert((!Canon.isNull() || 15727532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor T.isDependent() || anyDependentTemplateArguments(Args, NumArgs)) && 157340808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor "No canonical type for non-dependent class template specialization"); 157455f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 15751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TemplateArgument *TemplateArgs 157640808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor = reinterpret_cast<TemplateArgument *>(this + 1); 157735495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor for (unsigned Arg = 0; Arg < NumArgs; ++Arg) { 157835495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor // Update dependent and variably-modified bits. 15793e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith // If the canonical type exists and is non-dependent, the template 15803e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith // specialization type can be non-dependent even if one of the type 15813e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith // arguments is. Given: 15823e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith // template<typename T> using U = int; 15833e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith // U<T> is always non-dependent, irrespective of the type T. 15843e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith if (Canon.isNull() && Args[Arg].isDependent()) 158535495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor setDependent(); 158635495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor if (Args[Arg].getKind() == TemplateArgument::Type && 158735495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor Args[Arg].getAsType()->isVariablyModifiedType()) 158835495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor setVariablyModified(); 1589d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor if (Args[Arg].containsUnexpandedParameterPack()) 1590d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor setContainsUnexpandedParameterPack(); 1591d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 159240808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor new (&TemplateArgs[Arg]) TemplateArgument(Args[Arg]); 159335495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor } 15943e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith 15953e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith // Store the aliased type if this is a type alias template specialization. 15963e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith bool IsTypeAlias = !AliasedType.isNull(); 15973e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith assert(IsTypeAlias == isTypeAlias() && 15983e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith "allocated wrong size for type alias"); 15993e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith if (IsTypeAlias) { 16003e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith TemplateArgument *Begin = reinterpret_cast<TemplateArgument *>(this + 1); 16013e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith *reinterpret_cast<QualType*>(Begin + getNumArgs()) = AliasedType; 16023e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith } 160355f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor} 160455f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 16051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpvoid 16061eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTemplateSpecializationType::Profile(llvm::FoldingSetNodeID &ID, 16071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TemplateName T, 16081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const TemplateArgument *Args, 1609828e226ab7ed08b3eb766549e9d3306432137460Douglas Gregor unsigned NumArgs, 16104ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad const ASTContext &Context) { 16117532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor T.Profile(ID); 161240808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor for (unsigned Idx = 0; Idx < NumArgs; ++Idx) 1613828e226ab7ed08b3eb766549e9d3306432137460Douglas Gregor Args[Idx].Profile(ID, Context); 161455f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor} 161597e0179f1ae545e07d9f5e7c1d2ef5c5bab06676Anders Carlsson 16163e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smithbool TemplateSpecializationType::isTypeAlias() const { 16173e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith TemplateDecl *D = Template.getAsTemplateDecl(); 16183e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith return D && isa<TypeAliasTemplateDecl>(D); 16193e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith} 16203e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith 16214ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualType 16224ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualifierCollector::apply(const ASTContext &Context, QualType QT) const { 16230953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (!hasNonFastQualifiers()) 16240953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return QT.withFastQualifiers(getFastQualifiers()); 16251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 162649f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall return Context.getQualifiedType(QT, *this); 16275e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor} 16285e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor 16294ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualType 16304ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualifierCollector::apply(const ASTContext &Context, const Type *T) const { 16310953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (!hasNonFastQualifiers()) 16320953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return QualType(T, getFastQualifiers()); 16330953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 163449f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall return Context.getQualifiedType(T, *this); 16355e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor} 16365e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor 1637c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallvoid ObjCObjectTypeImpl::Profile(llvm::FoldingSetNodeID &ID, 1638c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall QualType BaseType, 1639c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCProtocolDecl * const *Protocols, 1640c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall unsigned NumProtocols) { 1641c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ID.AddPointer(BaseType.getAsOpaquePtr()); 1642c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff for (unsigned i = 0; i != NumProtocols; i++) 1643c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ID.AddPointer(Protocols[i]); 1644c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff} 1645c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff 1646c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallvoid ObjCObjectTypeImpl::Profile(llvm::FoldingSetNodeID &ID) { 1647c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall Profile(ID, getBaseType(), qual_begin(), getNumProtocols()); 1648c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff} 16490b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 1650b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCallnamespace { 16511fb0caaa7bef765b85972274e3b434af2572c141John McCall 1652b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall/// \brief The cached properties of a type. 1653b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCallclass CachedProperties { 1654b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall char linkage; 1655b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall char visibility; 1656b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall bool local; 1657b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall 1658b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCallpublic: 1659b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall CachedProperties(Linkage linkage, Visibility visibility, bool local) 1660b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall : linkage(linkage), visibility(visibility), local(local) {} 1661b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall 1662b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall Linkage getLinkage() const { return (Linkage) linkage; } 1663b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall Visibility getVisibility() const { return (Visibility) visibility; } 1664b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall bool hasLocalOrUnnamedType() const { return local; } 1665b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall 1666b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall friend CachedProperties merge(CachedProperties L, CachedProperties R) { 1667b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return CachedProperties(minLinkage(L.getLinkage(), R.getLinkage()), 1668b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall minVisibility(L.getVisibility(), R.getVisibility()), 1669b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall L.hasLocalOrUnnamedType() | R.hasLocalOrUnnamedType()); 1670b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall } 1671b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall}; 16721fb0caaa7bef765b85972274e3b434af2572c141John McCall} 16731fb0caaa7bef765b85972274e3b434af2572c141John McCall 1674b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCallstatic CachedProperties computeCachedProperties(const Type *T); 16750b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 1676b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCallnamespace clang { 1677b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall/// The type-property cache. This is templated so as to be 1678b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall/// instantiated at an internal type to prevent unnecessary symbol 1679b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall/// leakage. 1680b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCalltemplate <class Private> class TypePropertyCache { 1681b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCallpublic: 1682b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall static CachedProperties get(QualType T) { 1683b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return get(T.getTypePtr()); 1684b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall } 16851fb0caaa7bef765b85972274e3b434af2572c141John McCall 1686b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall static CachedProperties get(const Type *T) { 1687b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall ensure(T); 1688b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return CachedProperties(T->TypeBits.getLinkage(), 1689b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall T->TypeBits.getVisibility(), 1690b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall T->TypeBits.hasLocalOrUnnamedType()); 1691b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall } 1692db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor 1693b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall static void ensure(const Type *T) { 1694b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall // If the cache is valid, we're okay. 1695b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall if (T->TypeBits.isCacheValid()) return; 1696b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall 1697b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall // If this type is non-canonical, ask its canonical type for the 1698b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall // relevant information. 16993b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (!T->isCanonicalUnqualified()) { 17003b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall const Type *CT = T->getCanonicalTypeInternal().getTypePtr(); 1701b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall ensure(CT); 1702b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall T->TypeBits.CacheValidAndVisibility = 1703b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall CT->TypeBits.CacheValidAndVisibility; 1704b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall T->TypeBits.CachedLinkage = CT->TypeBits.CachedLinkage; 1705b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall T->TypeBits.CachedLocalOrUnnamed = CT->TypeBits.CachedLocalOrUnnamed; 1706b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return; 1707b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall } 17081fb0caaa7bef765b85972274e3b434af2572c141John McCall 1709b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall // Compute the cached properties and then set the cache. 1710b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall CachedProperties Result = computeCachedProperties(T); 1711b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall T->TypeBits.CacheValidAndVisibility = Result.getVisibility() + 1U; 1712b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall assert(T->TypeBits.isCacheValid() && 1713b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall T->TypeBits.getVisibility() == Result.getVisibility()); 1714b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall T->TypeBits.CachedLinkage = Result.getLinkage(); 1715b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall T->TypeBits.CachedLocalOrUnnamed = Result.hasLocalOrUnnamedType(); 1716b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall } 1717b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall}; 17181fb0caaa7bef765b85972274e3b434af2572c141John McCall} 17191fb0caaa7bef765b85972274e3b434af2572c141John McCall 1720b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall// Instantiate the friend template at a private class. In a 1721b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall// reasonable implementation, these symbols will be internal. 1722b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall// It is terrible that this is the best way to accomplish this. 1723b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCallnamespace { class Private {}; } 1724b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCalltypedef TypePropertyCache<Private> Cache; 17251fb0caaa7bef765b85972274e3b434af2572c141John McCall 1726b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCallstatic CachedProperties computeCachedProperties(const Type *T) { 1727b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall switch (T->getTypeClass()) { 1728b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall#define TYPE(Class,Base) 1729b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall#define NON_CANONICAL_TYPE(Class,Base) case Type::Class: 1730b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall#include "clang/AST/TypeNodes.def" 1731b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall llvm_unreachable("didn't expect a non-canonical type here"); 173260e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor 1733b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall#define TYPE(Class,Base) 1734b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall#define DEPENDENT_TYPE(Class,Base) case Type::Class: 1735b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall#define NON_CANONICAL_UNLESS_DEPENDENT_TYPE(Class,Base) case Type::Class: 1736b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall#include "clang/AST/TypeNodes.def" 1737b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall // Treat dependent types as external. 1738b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall assert(T->isDependentType()); 17391fb0caaa7bef765b85972274e3b434af2572c141John McCall return CachedProperties(ExternalLinkage, DefaultVisibility, false); 17401fb0caaa7bef765b85972274e3b434af2572c141John McCall 1741b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::Builtin: 1742b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall // C++ [basic.link]p8: 1743b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall // A type is said to have linkage if and only if: 1744b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall // - it is a fundamental type (3.9.1); or 1745b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return CachedProperties(ExternalLinkage, DefaultVisibility, false); 17460b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 1747b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::Record: 1748b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::Enum: { 1749b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall const TagDecl *Tag = cast<TagType>(T)->getDecl(); 1750b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall 1751b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall // C++ [basic.link]p8: 1752b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall // - it is a class or enumeration type that is named (or has a name 1753b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall // for linkage purposes (7.1.3)) and the name has linkage; or 1754b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall // - it is a specialization of a class template (14); or 1755b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall NamedDecl::LinkageInfo LV = Tag->getLinkageAndVisibility(); 1756b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall bool IsLocalOrUnnamed = 1757b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall Tag->getDeclContext()->isFunctionOrMethod() || 1758162e1c1b487352434552147967c3dd296ebee2f7Richard Smith (!Tag->getIdentifier() && !Tag->getTypedefNameForAnonDecl()); 1759b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return CachedProperties(LV.linkage(), LV.visibility(), IsLocalOrUnnamed); 1760b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall } 17610b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 1762b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall // C++ [basic.link]p8: 1763b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall // - it is a compound type (3.9.2) other than a class or enumeration, 1764b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall // compounded exclusively from types that have linkage; or 1765b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::Complex: 1766b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return Cache::get(cast<ComplexType>(T)->getElementType()); 1767b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::Pointer: 1768b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return Cache::get(cast<PointerType>(T)->getPointeeType()); 1769b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::BlockPointer: 1770b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return Cache::get(cast<BlockPointerType>(T)->getPointeeType()); 1771b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::LValueReference: 1772b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::RValueReference: 1773b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return Cache::get(cast<ReferenceType>(T)->getPointeeType()); 1774b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::MemberPointer: { 1775b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall const MemberPointerType *MPT = cast<MemberPointerType>(T); 1776b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return merge(Cache::get(MPT->getClass()), 1777b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall Cache::get(MPT->getPointeeType())); 1778b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall } 1779b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::ConstantArray: 1780b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::IncompleteArray: 1781b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::VariableArray: 1782b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return Cache::get(cast<ArrayType>(T)->getElementType()); 1783b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::Vector: 1784b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::ExtVector: 1785b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return Cache::get(cast<VectorType>(T)->getElementType()); 1786b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::FunctionNoProto: 1787b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return Cache::get(cast<FunctionType>(T)->getResultType()); 1788b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::FunctionProto: { 1789b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall const FunctionProtoType *FPT = cast<FunctionProtoType>(T); 1790b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall CachedProperties result = Cache::get(FPT->getResultType()); 1791b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall for (FunctionProtoType::arg_type_iterator ai = FPT->arg_type_begin(), 1792b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall ae = FPT->arg_type_end(); ai != ae; ++ai) 1793b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall result = merge(result, Cache::get(*ai)); 1794b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return result; 1795b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall } 1796b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::ObjCInterface: { 1797b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall NamedDecl::LinkageInfo LV = 1798b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall cast<ObjCInterfaceType>(T)->getDecl()->getLinkageAndVisibility(); 1799b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return CachedProperties(LV.linkage(), LV.visibility(), false); 1800b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall } 1801b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::ObjCObject: 1802b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return Cache::get(cast<ObjCObjectType>(T)->getBaseType()); 1803b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::ObjCObjectPointer: 1804b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return Cache::get(cast<ObjCObjectPointerType>(T)->getPointeeType()); 1805b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall } 18060b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 1807b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall llvm_unreachable("unhandled type class"); 18080b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 1809b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall // C++ [basic.link]p8: 1810b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall // Names not covered by these rules have no linkage. 1811b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return CachedProperties(NoLinkage, DefaultVisibility, false); 18120b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor} 18130b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 1814b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall/// \brief Determine the linkage of this type. 1815b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCallLinkage Type::getLinkage() const { 1816b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall Cache::ensure(this); 1817b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return TypeBits.getLinkage(); 18180b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor} 18190b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 1820b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall/// \brief Determine the linkage of this type. 1821b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCallVisibility Type::getVisibility() const { 1822b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall Cache::ensure(this); 1823b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return TypeBits.getVisibility(); 18241fb0caaa7bef765b85972274e3b434af2572c141John McCall} 18251fb0caaa7bef765b85972274e3b434af2572c141John McCall 1826b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCallbool Type::hasUnnamedOrLocalType() const { 1827b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall Cache::ensure(this); 1828b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return TypeBits.hasLocalOrUnnamedType(); 18290b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor} 18300b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 1831b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCallstd::pair<Linkage,Visibility> Type::getLinkageAndVisibility() const { 1832b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall Cache::ensure(this); 1833b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return std::make_pair(TypeBits.getLinkage(), TypeBits.getVisibility()); 18340b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor} 18350b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 1836b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCallvoid Type::ClearLinkageCache() { 1837b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall TypeBits.CacheValidAndVisibility = 0; 1838b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall if (QualType(this, 0) != CanonicalType) 1839b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall CanonicalType->TypeBits.CacheValidAndVisibility = 0; 18400b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor} 18413b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 18423b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallbool Type::hasSizedVLAType() const { 18433b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (!isVariablyModifiedType()) return false; 18443b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 18453b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (const PointerType *ptr = getAs<PointerType>()) 18463b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return ptr->getPointeeType()->hasSizedVLAType(); 18473b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (const ReferenceType *ref = getAs<ReferenceType>()) 18483b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return ref->getPointeeType()->hasSizedVLAType(); 18493b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (const ArrayType *arr = getAsArrayTypeUnsafe()) { 18503b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (isa<VariableArrayType>(arr) && 18513b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall cast<VariableArrayType>(arr)->getSizeExpr()) 18523b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return true; 18533b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 18543b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return arr->getElementType()->hasSizedVLAType(); 18553b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall } 18563b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 18573b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return false; 18583b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall} 18590d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall 18600d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCallQualType::DestructionKind QualType::isDestructedTypeImpl(QualType type) { 18610d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall /// Currently, the only destruction kind we recognize is C++ objects 18620d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall /// with non-trivial destructors. 18630d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall const CXXRecordDecl *record = 18640d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall type->getBaseElementTypeUnsafe()->getAsCXXRecordDecl(); 18650d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall if (record && !record->hasTrivialDestructor()) 18660d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall return DK_cxx_destructor; 18670d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall 18680d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall return DK_none; 18690d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall} 1870