Type.cpp revision 1de4d4e8cb2e9c88809fea8092bc6e835a5473d2
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 30bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCallbool QualType::isConstant(QualType T, ASTContext &Ctx) { 31bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall if (T.isConstQualified()) 32b381aac9bae6d608c72267dd0ed08ec6369e94e4Nuno Lopes return true; 33b381aac9bae6d608c72267dd0ed08ec6369e94e4Nuno Lopes 34bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall if (const ArrayType *AT = Ctx.getAsArrayType(T)) 35bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall return AT->getElementType().isConstant(Ctx); 36b381aac9bae6d608c72267dd0ed08ec6369e94e4Nuno Lopes 37b381aac9bae6d608c72267dd0ed08ec6369e94e4Nuno Lopes return false; 38b381aac9bae6d608c72267dd0ed08ec6369e94e4Nuno Lopes} 39b381aac9bae6d608c72267dd0ed08ec6369e94e4Nuno Lopes 402767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregorunsigned ConstantArrayType::getNumAddressingBits(ASTContext &Context, 412767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor QualType ElementType, 422767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor const llvm::APInt &NumElements) { 432767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor llvm::APSInt SizeExtended(NumElements, true); 442767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor unsigned SizeTypeBits = Context.getTypeSize(Context.getSizeType()); 459f71a8f4c7a182a5236da9e747d57cc1d1bd24c2Jay Foad SizeExtended = SizeExtended.extend(std::max(SizeTypeBits, 469f71a8f4c7a182a5236da9e747d57cc1d1bd24c2Jay Foad SizeExtended.getBitWidth()) * 2); 472767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor 482767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor uint64_t ElementSize 492767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor = Context.getTypeSizeInChars(ElementType).getQuantity(); 502767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor llvm::APSInt TotalSize(llvm::APInt(SizeExtended.getBitWidth(), ElementSize)); 512767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor TotalSize *= SizeExtended; 522767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor 532767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor return TotalSize.getActiveBits(); 542767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor} 552767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor 562767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregorunsigned ConstantArrayType::getMaxSizeBits(ASTContext &Context) { 572767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor unsigned Bits = Context.getTypeSize(Context.getSizeType()); 582767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor 592767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor // GCC appears to only allow 63 bits worth of address space when compiling 602767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor // for 64-bit, so we do the same. 612767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor if (Bits == 64) 622767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor --Bits; 632767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor 642767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor return Bits; 652767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor} 662767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor 674ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadDependentSizedArrayType::DependentSizedArrayType(const ASTContext &Context, 68d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor QualType et, QualType can, 69d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor Expr *e, ArraySizeModifier sm, 70d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor unsigned tq, 71d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor SourceRange brackets) 72d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor : ArrayType(DependentSizedArray, et, can, sm, tq, 73d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor (et->containsUnexpandedParameterPack() || 74d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor (e && e->containsUnexpandedParameterPack()))), 75d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor Context(Context), SizeExpr((Stmt*) e), Brackets(brackets) 76d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor{ 77d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor} 78d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpvoid DependentSizedArrayType::Profile(llvm::FoldingSetNodeID &ID, 804ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad const ASTContext &Context, 8104d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor QualType ET, 8204d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor ArraySizeModifier SizeMod, 8304d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor unsigned TypeQuals, 8404d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor Expr *E) { 8504d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor ID.AddPointer(ET.getAsOpaquePtr()); 8604d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor ID.AddInteger(SizeMod); 8704d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor ID.AddInteger(TypeQuals); 8804d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor E->Profile(ID, Context, true); 8904d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor} 9004d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor 914ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadDependentSizedExtVectorType::DependentSizedExtVectorType(const 924ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad ASTContext &Context, 93d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor QualType ElementType, 94d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor QualType can, 95d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor Expr *SizeExpr, 96d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor SourceLocation loc) 97d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor : Type(DependentSizedExtVector, can, /*Dependent=*/true, 98d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor ElementType->isVariablyModifiedType(), 99d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor (ElementType->containsUnexpandedParameterPack() || 100d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor (SizeExpr && SizeExpr->containsUnexpandedParameterPack()))), 101d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor Context(Context), SizeExpr(SizeExpr), ElementType(ElementType), 102d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor loc(loc) 103d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor{ 104d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor} 105d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 1061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpvoid 1071eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpDependentSizedExtVectorType::Profile(llvm::FoldingSetNodeID &ID, 1084ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad const ASTContext &Context, 1092ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor QualType ElementType, Expr *SizeExpr) { 1102ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor ID.AddPointer(ElementType.getAsOpaquePtr()); 1112ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor SizeExpr->Profile(ID, Context, true); 1122ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor} 1132ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor 114d0937224f383c7cc72c947119380f9713a070c73Douglas GregorVectorType::VectorType(QualType vecType, unsigned nElements, QualType canonType, 115d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor VectorKind vecKind) 116d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor : Type(Vector, canonType, vecType->isDependentType(), 117d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor vecType->isVariablyModifiedType(), 118d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor vecType->containsUnexpandedParameterPack()), 119d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor ElementType(vecType) 120d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor{ 121d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor VectorTypeBits.VecKind = vecKind; 122d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor VectorTypeBits.NumElements = nElements; 123d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor} 124d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 125d0937224f383c7cc72c947119380f9713a070c73Douglas GregorVectorType::VectorType(TypeClass tc, QualType vecType, unsigned nElements, 126d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor QualType canonType, VectorKind vecKind) 127d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor : Type(tc, canonType, vecType->isDependentType(), 128d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor vecType->isVariablyModifiedType(), 129d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor vecType->containsUnexpandedParameterPack()), 130d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor ElementType(vecType) 131d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor{ 132d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor VectorTypeBits.VecKind = vecKind; 133d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor VectorTypeBits.NumElements = nElements; 134d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor} 135d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 136c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner/// getArrayElementTypeNoTypeQual - If this is an array type, return the 137c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner/// element type of the array, potentially with type qualifiers missing. 138c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner/// This method should never be used when type qualifiers are meaningful. 139c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattnerconst Type *Type::getArrayElementTypeNoTypeQual() const { 140c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // If this is directly an array type, return it. 141c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner if (const ArrayType *ATy = dyn_cast<ArrayType>(this)) 142c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return ATy->getElementType().getTypePtr(); 1431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 144c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // If the canonical form of this type isn't the right kind, reject it. 1450953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (!isa<ArrayType>(CanonicalType)) 146c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return 0; 1471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 148c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // If this is a typedef for an array type, strip the typedef off without 149c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // losing all typedef information. 150bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall return cast<ArrayType>(getUnqualifiedDesugaredType()) 151bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall ->getElementType().getTypePtr(); 1522fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner} 1532fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner 1542fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner/// getDesugaredType - Return the specified type with any "sugar" removed from 1552fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner/// the type. This takes off typedefs, typeof's etc. If the outer level of 1562fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner/// the type is already concrete, it returns it unmodified. This is similar 1572fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner/// to getting the canonical type, but it doesn't remove *all* typedefs. For 1582fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner/// example, it returns "T*" as "T*", (not as "int*"), because the pointer is 1592fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner/// concrete. 1604ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualType QualType::getDesugaredType(QualType T, const ASTContext &Context) { 16149f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall SplitQualType split = getSplitDesugaredType(T); 16249f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall return Context.getQualifiedType(split.first, split.second); 16349f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall} 16449f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall 16549f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCallSplitQualType QualType::getSplitDesugaredType(QualType T) { 1660953e767ff7817f97b3ab20896b229891eeff45bJohn McCall QualifierCollector Qs; 167c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner 168bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType Cur = T; 169bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall while (true) { 170bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall const Type *CurTy = Qs.strip(Cur); 171bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall switch (CurTy->getTypeClass()) { 172bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall#define ABSTRACT_TYPE(Class, Parent) 173bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall#define TYPE(Class, Parent) \ 174bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall case Type::Class: { \ 175bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall const Class##Type *Ty = cast<Class##Type>(CurTy); \ 176bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall if (!Ty->isSugared()) \ 17749f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall return SplitQualType(Ty, Qs); \ 178bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall Cur = Ty->desugar(); \ 179bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall break; \ 180bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall } 181bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall#include "clang/AST/TypeNodes.def" 182bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall } 183969c689d893a248eca4f049f5b89f747e66e4bffDouglas Gregor } 184bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall} 1855cdf82164dd7c2b2320d6735c63ace4331e0716dDouglas Gregor 18662c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCallSplitQualType QualType::getSplitUnqualifiedTypeImpl(QualType type) { 18762c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall SplitQualType split = type.split(); 18862c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall 18962c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall // All the qualifiers we've seen so far. 19062c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall Qualifiers quals = split.second; 19162c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall 19262c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall // The last type node we saw with any nodes inside it. 19362c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall const Type *lastTypeWithQuals = split.first; 19462c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall 19562c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall while (true) { 19662c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall QualType next; 19762c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall 19862c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall // Do a single-step desugar, aborting the loop if the type isn't 19962c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall // sugared. 20062c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall switch (split.first->getTypeClass()) { 20162c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall#define ABSTRACT_TYPE(Class, Parent) 20262c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall#define TYPE(Class, Parent) \ 20362c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall case Type::Class: { \ 20462c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall const Class##Type *ty = cast<Class##Type>(split.first); \ 20562c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall if (!ty->isSugared()) goto done; \ 20662c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall next = ty->desugar(); \ 20762c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall break; \ 20862c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall } 20962c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall#include "clang/AST/TypeNodes.def" 21062c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall } 21162c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall 21262c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall // Otherwise, split the underlying type. If that yields qualifiers, 21362c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall // update the information. 21462c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall split = next.split(); 21562c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall if (!split.second.empty()) { 21662c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall lastTypeWithQuals = split.first; 21762c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall quals.addConsistentQualifiers(split.second); 21862c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall } 21962c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall } 22062c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall 22162c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall done: 22262c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall return SplitQualType(lastTypeWithQuals, quals); 22362c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall} 22462c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall 225075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo BagnaraQualType QualType::IgnoreParens(QualType T) { 22662c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall // FIXME: this seems inherently un-qualifiers-safe. 227075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara while (const ParenType *PT = T->getAs<ParenType>()) 228075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara T = PT->getInnerType(); 229075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara return T; 230075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara} 231075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 232bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall/// getUnqualifiedDesugaredType - Pull any qualifiers and syntactic 233bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall/// sugar off the given type. This should produce an object of the 234bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall/// same dynamic type as the canonical type. 235bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCallconst Type *Type::getUnqualifiedDesugaredType() const { 236bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall const Type *Cur = this; 237bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 238bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall while (true) { 239bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall switch (Cur->getTypeClass()) { 240bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall#define ABSTRACT_TYPE(Class, Parent) 241bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall#define TYPE(Class, Parent) \ 242bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall case Class: { \ 243bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall const Class##Type *Ty = cast<Class##Type>(Cur); \ 244bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall if (!Ty->isSugared()) return Cur; \ 245bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall Cur = Ty->desugar().getTypePtr(); \ 246bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall break; \ 247bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall } 248bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall#include "clang/AST/TypeNodes.def" 249bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall } 250bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall } 251c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner} 252c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner 2535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// isVoidType - Helper method to determine if this is the 'void' type. 2545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isVoidType() const { 2555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 2565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return BT->getKind() == BuiltinType::Void; 2575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return false; 2585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 2595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isDerivedType() const { 2615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer switch (CanonicalType->getTypeClass()) { 2625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Pointer: 263fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff case VariableArray: 264fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff case ConstantArray: 265c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman case IncompleteArray: 2665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case FunctionProto: 2675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case FunctionNoProto: 2687c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl case LValueReference: 2697c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl case RValueReference: 27072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor case Record: 2715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return true; 2725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer default: 2735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return false; 2745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 2765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 27799dc91422144483c20d1c7381bc9ac634b646b04Chris Lattnerbool Type::isClassType() const { 2786217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const RecordType *RT = getAs<RecordType>()) 279f728a4a05df2455e1c6e62173ab720a92cd4a074Chris Lattner return RT->getDecl()->isClass(); 28099dc91422144483c20d1c7381bc9ac634b646b04Chris Lattner return false; 28199dc91422144483c20d1c7381bc9ac634b646b04Chris Lattner} 282c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattnerbool Type::isStructureType() const { 2836217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const RecordType *RT = getAs<RecordType>()) 284f728a4a05df2455e1c6e62173ab720a92cd4a074Chris Lattner return RT->getDecl()->isStruct(); 285c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner return false; 286c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner} 287fb87b89fc9eb103e19fb8e4b925c23f0bd091b99Douglas Gregorbool Type::isStructureOrClassType() const { 288fb87b89fc9eb103e19fb8e4b925c23f0bd091b99Douglas Gregor if (const RecordType *RT = getAs<RecordType>()) 289fb87b89fc9eb103e19fb8e4b925c23f0bd091b99Douglas Gregor return RT->getDecl()->isStruct() || RT->getDecl()->isClass(); 290fb87b89fc9eb103e19fb8e4b925c23f0bd091b99Douglas Gregor return false; 291fb87b89fc9eb103e19fb8e4b925c23f0bd091b99Douglas Gregor} 2927154a77e7c1f23418342d3b72836ab504aa7821eSteve Naroffbool Type::isVoidPointerType() const { 2936217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const PointerType *PT = getAs<PointerType>()) 2947154a77e7c1f23418342d3b72836ab504aa7821eSteve Naroff return PT->getPointeeType()->isVoidType(); 2957154a77e7c1f23418342d3b72836ab504aa7821eSteve Naroff return false; 2967154a77e7c1f23418342d3b72836ab504aa7821eSteve Naroff} 2977154a77e7c1f23418342d3b72836ab504aa7821eSteve Naroff 298c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattnerbool Type::isUnionType() const { 2996217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const RecordType *RT = getAs<RecordType>()) 300f728a4a05df2455e1c6e62173ab720a92cd4a074Chris Lattner return RT->getDecl()->isUnion(); 301c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner return false; 302c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner} 303c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner 304c6fb90a7246c2d5d3233e70107bf9d8c7c9e535bChris Lattnerbool Type::isComplexType() const { 30502f62a9fedbc370fba081303399410a3afdde29fSteve Naroff if (const ComplexType *CT = dyn_cast<ComplexType>(CanonicalType)) 30602f62a9fedbc370fba081303399410a3afdde29fSteve Naroff return CT->getElementType()->isFloatingType(); 30702f62a9fedbc370fba081303399410a3afdde29fSteve Naroff return false; 308c6fb90a7246c2d5d3233e70107bf9d8c7c9e535bChris Lattner} 309c6fb90a7246c2d5d3233e70107bf9d8c7c9e535bChris Lattner 3104cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroffbool Type::isComplexIntegerType() const { 3114cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroff // Check for GCC complex integer extension. 3120953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return getAsComplexIntegerType(); 3134cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroff} 3144cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroff 3154cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroffconst ComplexType *Type::getAsComplexIntegerType() const { 3160953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (const ComplexType *Complex = getAs<ComplexType>()) 3170953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (Complex->getElementType()->isIntegerType()) 3180953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return Complex; 3190953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return 0; 3204cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroff} 3214cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroff 32214108da7f7fc059772711e4ffee1322a27b152a7Steve NaroffQualType Type::getPointeeType() const { 3236217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const PointerType *PT = getAs<PointerType>()) 32414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return PT->getPointeeType(); 325183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) 32614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return OPT->getPointeeType(); 3276217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const BlockPointerType *BPT = getAs<BlockPointerType>()) 32814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return BPT->getPointeeType(); 3299c21289a866b677d21ed3d5ecfdfd5ced5a55410Mike Stump if (const ReferenceType *RT = getAs<ReferenceType>()) 3309c21289a866b677d21ed3d5ecfdfd5ced5a55410Mike Stump return RT->getPointeeType(); 33114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return QualType(); 33214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff} 333b77792eabf5882cf9af8cc810599b20432fda6c2Chris Lattner 334c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattnerconst RecordType *Type::getAsStructureType() const { 3357064f5c95bbdb17680d0ea658d4090898c2592d3Steve Naroff // If this is directly a structure type, return it. 336c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner if (const RecordType *RT = dyn_cast<RecordType>(this)) { 33739ba4aeca296b1c9f04bde7d9d3cbbf129f1abd3Argyrios Kyrtzidis if (RT->getDecl()->isStruct()) 338c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner return RT; 3397064f5c95bbdb17680d0ea658d4090898c2592d3Steve Naroff } 340dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner 341dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner // If the canonical form of this type isn't the right kind, reject it. 342c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner if (const RecordType *RT = dyn_cast<RecordType>(CanonicalType)) { 34339ba4aeca296b1c9f04bde7d9d3cbbf129f1abd3Argyrios Kyrtzidis if (!RT->getDecl()->isStruct()) 344dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner return 0; 3451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 346dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner // If this is a typedef for a structure type, strip the typedef off without 347dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner // losing all typedef information. 348bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall return cast<RecordType>(getUnqualifiedDesugaredType()); 3495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 3507064f5c95bbdb17680d0ea658d4090898c2592d3Steve Naroff return 0; 3515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 3525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpconst RecordType *Type::getAsUnionType() const { 3547064f5c95bbdb17680d0ea658d4090898c2592d3Steve Naroff // If this is directly a union type, return it. 355c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner if (const RecordType *RT = dyn_cast<RecordType>(this)) { 35639ba4aeca296b1c9f04bde7d9d3cbbf129f1abd3Argyrios Kyrtzidis if (RT->getDecl()->isUnion()) 357c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner return RT; 3587064f5c95bbdb17680d0ea658d4090898c2592d3Steve Naroff } 3591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 360dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner // If the canonical form of this type isn't the right kind, reject it. 361c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner if (const RecordType *RT = dyn_cast<RecordType>(CanonicalType)) { 36239ba4aeca296b1c9f04bde7d9d3cbbf129f1abd3Argyrios Kyrtzidis if (!RT->getDecl()->isUnion()) 363dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner return 0; 364dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner 365dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner // If this is a typedef for a union type, strip the typedef off without 366dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner // losing all typedef information. 367bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall return cast<RecordType>(getUnqualifiedDesugaredType()); 3685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 3691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3707064f5c95bbdb17680d0ea658d4090898c2592d3Steve Naroff return 0; 3715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 3725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 373c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallObjCObjectType::ObjCObjectType(QualType Canonical, QualType Base, 374c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCProtocolDecl * const *Protocols, 375c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall unsigned NumProtocols) 376d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor : Type(ObjCObject, Canonical, false, false, false), 377d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor BaseType(Base) 378d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor{ 379b870b88df784c2940efce448ebfaf54dece14666John McCall ObjCObjectTypeBits.NumProtocols = NumProtocols; 38071c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall assert(getNumProtocols() == NumProtocols && 381c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall "bitfield overflow in protocol count"); 382fd6a0887a099256c35a5b23e9afd517ffe95fa0aDouglas Gregor if (NumProtocols) 383c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall memcpy(getProtocolStorage(), Protocols, 384c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall NumProtocols * sizeof(ObjCProtocolDecl*)); 38571842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek} 38671842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek 387c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallconst ObjCObjectType *Type::getAsObjCQualifiedInterfaceType() const { 388c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall // There is no sugar for ObjCObjectType's, just return the canonical 389c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff // type pointer if it is the right class. There is no typedef information to 390c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff // return and these cannot be Address-space qualified. 391c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall if (const ObjCObjectType *T = getAs<ObjCObjectType>()) 392c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall if (T->getNumProtocols() && T->getInterface()) 393c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return T; 394c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff return 0; 395c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff} 396c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff 397c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroffbool Type::isObjCQualifiedInterfaceType() const { 398e61ad0b7063fcd97204b1cce5558685144267eb6Steve Naroff return getAsObjCQualifiedInterfaceType() != 0; 399c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff} 400c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff 401d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroffconst ObjCObjectPointerType *Type::getAsObjCQualifiedIdType() const { 402eca7be6b7ebd93682eeaab2c71d59f2995dacdccChris Lattner // There is no sugar for ObjCQualifiedIdType's, just return the canonical 403eca7be6b7ebd93682eeaab2c71d59f2995dacdccChris Lattner // type pointer if it is the right class. 404183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) { 405d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff if (OPT->isObjCQualifiedIdType()) 406d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff return OPT; 407d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff } 408d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff return 0; 409368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner} 410368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner 411759abb4d9ec14ae32104a9677b60f0542b60d1d8Fariborz Jahanianconst ObjCObjectPointerType *Type::getAsObjCQualifiedClassType() const { 412759abb4d9ec14ae32104a9677b60f0542b60d1d8Fariborz Jahanian // There is no sugar for ObjCQualifiedClassType's, just return the canonical 413759abb4d9ec14ae32104a9677b60f0542b60d1d8Fariborz Jahanian // type pointer if it is the right class. 414759abb4d9ec14ae32104a9677b60f0542b60d1d8Fariborz Jahanian if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) { 415759abb4d9ec14ae32104a9677b60f0542b60d1d8Fariborz Jahanian if (OPT->isObjCQualifiedClassType()) 416759abb4d9ec14ae32104a9677b60f0542b60d1d8Fariborz Jahanian return OPT; 417759abb4d9ec14ae32104a9677b60f0542b60d1d8Fariborz Jahanian } 418759abb4d9ec14ae32104a9677b60f0542b60d1d8Fariborz Jahanian return 0; 419759abb4d9ec14ae32104a9677b60f0542b60d1d8Fariborz Jahanian} 420759abb4d9ec14ae32104a9677b60f0542b60d1d8Fariborz Jahanian 42114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroffconst ObjCObjectPointerType *Type::getAsObjCInterfacePointerType() const { 422183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) { 42314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff if (OPT->getInterfaceType()) 42414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return OPT; 42514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff } 42614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return 0; 42714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff} 42814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff 429a91d6a6619a91d0ca7102d8ab5678d855f04d850Fariborz Jahanianconst CXXRecordDecl *Type::getCXXRecordDeclForPointerType() const { 4306217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const PointerType *PT = getAs<PointerType>()) 4316217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const RecordType *RT = PT->getPointeeType()->getAs<RecordType>()) 432a91d6a6619a91d0ca7102d8ab5678d855f04d850Fariborz Jahanian return dyn_cast<CXXRecordDecl>(RT->getDecl()); 433a91d6a6619a91d0ca7102d8ab5678d855f04d850Fariborz Jahanian return 0; 434a91d6a6619a91d0ca7102d8ab5678d855f04d850Fariborz Jahanian} 435a91d6a6619a91d0ca7102d8ab5678d855f04d850Fariborz Jahanian 436c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas GregorCXXRecordDecl *Type::getAsCXXRecordDecl() const { 437c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor if (const RecordType *RT = getAs<RecordType>()) 438c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor return dyn_cast<CXXRecordDecl>(RT->getDecl()); 439c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor else if (const InjectedClassNameType *Injected 440c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor = getAs<InjectedClassNameType>()) 441c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor return Injected->getDecl(); 442c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor 443c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor return 0; 444c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor} 445c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor 44634b41d939a1328f484511c6002ba2456db879a29Richard Smithnamespace { 44734b41d939a1328f484511c6002ba2456db879a29Richard Smith class GetContainedAutoVisitor : 44834b41d939a1328f484511c6002ba2456db879a29Richard Smith public TypeVisitor<GetContainedAutoVisitor, AutoType*> { 44934b41d939a1328f484511c6002ba2456db879a29Richard Smith public: 45034b41d939a1328f484511c6002ba2456db879a29Richard Smith using TypeVisitor<GetContainedAutoVisitor, AutoType*>::Visit; 45134b41d939a1328f484511c6002ba2456db879a29Richard Smith AutoType *Visit(QualType T) { 45234b41d939a1328f484511c6002ba2456db879a29Richard Smith if (T.isNull()) 45334b41d939a1328f484511c6002ba2456db879a29Richard Smith return 0; 45434b41d939a1328f484511c6002ba2456db879a29Richard Smith return Visit(T.getTypePtr()); 45534b41d939a1328f484511c6002ba2456db879a29Richard Smith } 45634b41d939a1328f484511c6002ba2456db879a29Richard Smith 45734b41d939a1328f484511c6002ba2456db879a29Richard Smith // The 'auto' type itself. 45834b41d939a1328f484511c6002ba2456db879a29Richard Smith AutoType *VisitAutoType(const AutoType *AT) { 45934b41d939a1328f484511c6002ba2456db879a29Richard Smith return const_cast<AutoType*>(AT); 46034b41d939a1328f484511c6002ba2456db879a29Richard Smith } 46134b41d939a1328f484511c6002ba2456db879a29Richard Smith 46234b41d939a1328f484511c6002ba2456db879a29Richard Smith // Only these types can contain the desired 'auto' type. 46334b41d939a1328f484511c6002ba2456db879a29Richard Smith AutoType *VisitPointerType(const PointerType *T) { 46434b41d939a1328f484511c6002ba2456db879a29Richard Smith return Visit(T->getPointeeType()); 46534b41d939a1328f484511c6002ba2456db879a29Richard Smith } 46634b41d939a1328f484511c6002ba2456db879a29Richard Smith AutoType *VisitBlockPointerType(const BlockPointerType *T) { 46734b41d939a1328f484511c6002ba2456db879a29Richard Smith return Visit(T->getPointeeType()); 46834b41d939a1328f484511c6002ba2456db879a29Richard Smith } 46934b41d939a1328f484511c6002ba2456db879a29Richard Smith AutoType *VisitReferenceType(const ReferenceType *T) { 47034b41d939a1328f484511c6002ba2456db879a29Richard Smith return Visit(T->getPointeeTypeAsWritten()); 47134b41d939a1328f484511c6002ba2456db879a29Richard Smith } 47234b41d939a1328f484511c6002ba2456db879a29Richard Smith AutoType *VisitMemberPointerType(const MemberPointerType *T) { 47334b41d939a1328f484511c6002ba2456db879a29Richard Smith return Visit(T->getPointeeType()); 47434b41d939a1328f484511c6002ba2456db879a29Richard Smith } 47534b41d939a1328f484511c6002ba2456db879a29Richard Smith AutoType *VisitArrayType(const ArrayType *T) { 47634b41d939a1328f484511c6002ba2456db879a29Richard Smith return Visit(T->getElementType()); 47734b41d939a1328f484511c6002ba2456db879a29Richard Smith } 47834b41d939a1328f484511c6002ba2456db879a29Richard Smith AutoType *VisitDependentSizedExtVectorType( 47934b41d939a1328f484511c6002ba2456db879a29Richard Smith const DependentSizedExtVectorType *T) { 48034b41d939a1328f484511c6002ba2456db879a29Richard Smith return Visit(T->getElementType()); 48134b41d939a1328f484511c6002ba2456db879a29Richard Smith } 48234b41d939a1328f484511c6002ba2456db879a29Richard Smith AutoType *VisitVectorType(const VectorType *T) { 48334b41d939a1328f484511c6002ba2456db879a29Richard Smith return Visit(T->getElementType()); 48434b41d939a1328f484511c6002ba2456db879a29Richard Smith } 48534b41d939a1328f484511c6002ba2456db879a29Richard Smith AutoType *VisitFunctionType(const FunctionType *T) { 48634b41d939a1328f484511c6002ba2456db879a29Richard Smith return Visit(T->getResultType()); 48734b41d939a1328f484511c6002ba2456db879a29Richard Smith } 48834b41d939a1328f484511c6002ba2456db879a29Richard Smith AutoType *VisitParenType(const ParenType *T) { 48934b41d939a1328f484511c6002ba2456db879a29Richard Smith return Visit(T->getInnerType()); 49034b41d939a1328f484511c6002ba2456db879a29Richard Smith } 49134b41d939a1328f484511c6002ba2456db879a29Richard Smith AutoType *VisitAttributedType(const AttributedType *T) { 49234b41d939a1328f484511c6002ba2456db879a29Richard Smith return Visit(T->getModifiedType()); 49334b41d939a1328f484511c6002ba2456db879a29Richard Smith } 49434b41d939a1328f484511c6002ba2456db879a29Richard Smith }; 49534b41d939a1328f484511c6002ba2456db879a29Richard Smith} 49634b41d939a1328f484511c6002ba2456db879a29Richard Smith 49734b41d939a1328f484511c6002ba2456db879a29Richard SmithAutoType *Type::getContainedAutoType() const { 49834b41d939a1328f484511c6002ba2456db879a29Richard Smith return GetContainedAutoVisitor().Visit(this); 49934b41d939a1328f484511c6002ba2456db879a29Richard Smith} 50034b41d939a1328f484511c6002ba2456db879a29Richard Smith 5015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isIntegerType() const { 5025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 5035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return BT->getKind() >= BuiltinType::Bool && 5042df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner BT->getKind() <= BuiltinType::Int128; 5051274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) 506834a72ac74cf4ff07ba6215545dba3db578f8a07Chris Lattner // Incomplete enum types are not treated as integer types. 5078e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor // FIXME: In C++, enum types are never integer types. 5081274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor return ET->getDecl()->isComplete(); 509f60946222721d9ba3c059563935c17b84703187aDouglas Gregor return false; 510f60946222721d9ba3c059563935c17b84703187aDouglas Gregor} 511f60946222721d9ba3c059563935c17b84703187aDouglas Gregor 512f60946222721d9ba3c059563935c17b84703187aDouglas Gregorbool Type::hasIntegerRepresentation() const { 513c63b96ad706e054a1390dd2ab53af9f05d33bbb1Steve Naroff if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType)) 514c63b96ad706e054a1390dd2ab53af9f05d33bbb1Steve Naroff return VT->getElementType()->isIntegerType(); 515f60946222721d9ba3c059563935c17b84703187aDouglas Gregor else 516f60946222721d9ba3c059563935c17b84703187aDouglas Gregor return isIntegerType(); 5175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 5185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5199d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// \brief Determine whether this type is an integral type. 5209d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// 5219d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// This routine determines whether the given type is an integral type per 5229d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// C++ [basic.fundamental]p7. Although the C standard does not define the 5239d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// term "integral type", it has a similar term "integer type", and in C++ 5249d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// the two terms are equivalent. However, C's "integer type" includes 5259d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// enumeration types, while C++'s "integer type" does not. The \c ASTContext 5269d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// parameter is used to determine whether we should be following the C or 5279d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// C++ rules when determining whether this type is an integral/integer type. 5289d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// 5299d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// For cases where C permits "an integer type" and C++ permits "an integral 5309d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// type", use this routine. 5319d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// 5329d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// For cases where C permits "an integer type" and C++ permits "an integral 5339d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// or enumeration type", use \c isIntegralOrEnumerationType() instead. 5349d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// 5359d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// \param Ctx The context in which this type occurs. 5369d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// 5379d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// \returns true if the type is considered an integral type, false otherwise. 5389d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregorbool Type::isIntegralType(ASTContext &Ctx) const { 53933e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 54033e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian return BT->getKind() >= BuiltinType::Bool && 541f5f7d864f5067d1ea4bff7fcf41b53a43b7b48baAnders Carlsson BT->getKind() <= BuiltinType::Int128; 5429d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor 5439d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor if (!Ctx.getLangOptions().CPlusPlus) 5441274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) 5451274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor return ET->getDecl()->isComplete(); // Complete enum types are integral in C. 5469d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor 54733e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian return false; 54833e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian} 54933e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian 5502ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregorbool Type::isIntegralOrEnumerationType() const { 5512ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 5522ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor return BT->getKind() >= BuiltinType::Bool && 5532ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor BT->getKind() <= BuiltinType::Int128; 55434fd628d22f54baddf30cf80c401b2f862a31b23Eli Friedman 55534fd628d22f54baddf30cf80c401b2f862a31b23Eli Friedman // Check for a complete enum type; incomplete enum types are not properly an 55634fd628d22f54baddf30cf80c401b2f862a31b23Eli Friedman // enumeration type in the sense required here. 5571274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) 5581274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor return ET->getDecl()->isComplete(); 55934fd628d22f54baddf30cf80c401b2f862a31b23Eli Friedman 5602ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor return false; 5612ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor} 5622ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor 5631274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregorbool Type::isIntegralOrUnscopedEnumerationType() const { 5641274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 5651274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor return BT->getKind() >= BuiltinType::Bool && 5661274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor BT->getKind() <= BuiltinType::Int128; 5671274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor 5681274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor // Check for a complete enum type; incomplete enum types are not properly an 5691274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor // enumeration type in the sense required here. 5701274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor // C++0x: However, if the underlying type of the enum is fixed, it is 5711274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor // considered complete. 5721274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) 5731274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor return ET->getDecl()->isComplete() && !ET->getDecl()->isScoped(); 5741274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor 5751274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor return false; 5761274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor} 5771274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor 5781274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor 57913b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroffbool Type::isBooleanType() const { 58013b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 58113b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff return BT->getKind() == BuiltinType::Bool; 58213b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff return false; 58313b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff} 58413b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff 58513b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroffbool Type::isCharType() const { 58613b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 58713b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff return BT->getKind() == BuiltinType::Char_U || 58813b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff BT->getKind() == BuiltinType::UChar || 589c67ad5f299bb2c09e4567def8ff0d34bd15a42fdAnders Carlsson BT->getKind() == BuiltinType::Char_S || 590c67ad5f299bb2c09e4567def8ff0d34bd15a42fdAnders Carlsson BT->getKind() == BuiltinType::SChar; 59113b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff return false; 59213b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff} 59313b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff 59477a52233f7c0f162672652051bfe78b65ad4f789Douglas Gregorbool Type::isWideCharType() const { 59577a52233f7c0f162672652051bfe78b65ad4f789Douglas Gregor if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 5963f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner return BT->getKind() == BuiltinType::WChar_S || 5973f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner BT->getKind() == BuiltinType::WChar_U; 59877a52233f7c0f162672652051bfe78b65ad4f789Douglas Gregor return false; 59977a52233f7c0f162672652051bfe78b65ad4f789Douglas Gregor} 60077a52233f7c0f162672652051bfe78b65ad4f789Douglas Gregor 60120093b4bf698f292c664676987541d5103b65b15Douglas Gregor/// \brief Determine whether this type is any of the built-in character 60220093b4bf698f292c664676987541d5103b65b15Douglas Gregor/// types. 60320093b4bf698f292c664676987541d5103b65b15Douglas Gregorbool Type::isAnyCharacterType() const { 6043f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType); 6053f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner if (BT == 0) return false; 6063f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner switch (BT->getKind()) { 6073f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner default: return false; 6083f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner case BuiltinType::Char_U: 6093f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner case BuiltinType::UChar: 6103f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner case BuiltinType::WChar_U: 6113f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner case BuiltinType::Char16: 6123f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner case BuiltinType::Char32: 6133f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner case BuiltinType::Char_S: 6143f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner case BuiltinType::SChar: 6153f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner case BuiltinType::WChar_S: 6163f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner return true; 6173f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner } 61820093b4bf698f292c664676987541d5103b65b15Douglas Gregor} 61920093b4bf698f292c664676987541d5103b65b15Douglas Gregor 620d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner/// isSignedIntegerType - Return true if this is an integer type that is 621d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner/// signed, according to C99 6.2.5p4 [char, signed char, short, int, long..], 622f60946222721d9ba3c059563935c17b84703187aDouglas Gregor/// an enum decl which has a signed representation 6235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isSignedIntegerType() const { 6245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) { 6255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return BT->getKind() >= BuiltinType::Char_S && 626f5f7d864f5067d1ea4bff7fcf41b53a43b7b48baAnders Carlsson BT->getKind() <= BuiltinType::Int128; 6275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 6281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 629bbd340717422bf011d56cd0164d2576601368111Fariborz Jahanian if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) { 630bbd340717422bf011d56cd0164d2576601368111Fariborz Jahanian // Incomplete enum types are not treated as integer types. 631bbd340717422bf011d56cd0164d2576601368111Fariborz Jahanian // FIXME: In C++, enum types are never integer types. 632bbd340717422bf011d56cd0164d2576601368111Fariborz Jahanian if (ET->getDecl()->isComplete()) 633bbd340717422bf011d56cd0164d2576601368111Fariborz Jahanian return ET->getDecl()->getIntegerType()->isSignedIntegerType(); 634bbd340717422bf011d56cd0164d2576601368111Fariborz Jahanian } 6351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 636f60946222721d9ba3c059563935c17b84703187aDouglas Gregor return false; 637f60946222721d9ba3c059563935c17b84703187aDouglas Gregor} 638f60946222721d9ba3c059563935c17b84703187aDouglas Gregor 639f60946222721d9ba3c059563935c17b84703187aDouglas Gregorbool Type::hasSignedIntegerRepresentation() const { 640c63b96ad706e054a1390dd2ab53af9f05d33bbb1Steve Naroff if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType)) 641c63b96ad706e054a1390dd2ab53af9f05d33bbb1Steve Naroff return VT->getElementType()->isSignedIntegerType(); 642f60946222721d9ba3c059563935c17b84703187aDouglas Gregor else 643f60946222721d9ba3c059563935c17b84703187aDouglas Gregor return isSignedIntegerType(); 6445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 6455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 646d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner/// isUnsignedIntegerType - Return true if this is an integer type that is 647d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner/// unsigned, according to C99 6.2.5p6 [which returns true for _Bool], an enum 648f60946222721d9ba3c059563935c17b84703187aDouglas Gregor/// decl which has an unsigned representation 6495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isUnsignedIntegerType() const { 6505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) { 6515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return BT->getKind() >= BuiltinType::Bool && 6521c03ca30ae962199ef702324b48550f6af7fdc32Anders Carlsson BT->getKind() <= BuiltinType::UInt128; 6535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 654d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner 655bbd340717422bf011d56cd0164d2576601368111Fariborz Jahanian if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) { 656bbd340717422bf011d56cd0164d2576601368111Fariborz Jahanian // Incomplete enum types are not treated as integer types. 657bbd340717422bf011d56cd0164d2576601368111Fariborz Jahanian // FIXME: In C++, enum types are never integer types. 658bbd340717422bf011d56cd0164d2576601368111Fariborz Jahanian if (ET->getDecl()->isComplete()) 659bbd340717422bf011d56cd0164d2576601368111Fariborz Jahanian return ET->getDecl()->getIntegerType()->isUnsignedIntegerType(); 660bbd340717422bf011d56cd0164d2576601368111Fariborz Jahanian } 661d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner 662f60946222721d9ba3c059563935c17b84703187aDouglas Gregor return false; 663f60946222721d9ba3c059563935c17b84703187aDouglas Gregor} 664f60946222721d9ba3c059563935c17b84703187aDouglas Gregor 665f60946222721d9ba3c059563935c17b84703187aDouglas Gregorbool Type::hasUnsignedIntegerRepresentation() const { 666c63b96ad706e054a1390dd2ab53af9f05d33bbb1Steve Naroff if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType)) 667c63b96ad706e054a1390dd2ab53af9f05d33bbb1Steve Naroff return VT->getElementType()->isUnsignedIntegerType(); 668f60946222721d9ba3c059563935c17b84703187aDouglas Gregor else 669f60946222721d9ba3c059563935c17b84703187aDouglas Gregor return isUnsignedIntegerType(); 6705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 6715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isFloatingType() const { 6735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 6745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return BT->getKind() >= BuiltinType::Float && 6755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer BT->getKind() <= BuiltinType::LongDouble; 6765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (const ComplexType *CT = dyn_cast<ComplexType>(CanonicalType)) 677729a2131228cb7fcbc00bd8af36bc6f14d12317dChris Lattner return CT->getElementType()->isFloatingType(); 6788eee119bf4f1693dde17b8552c1f9f81bf2b681eDouglas Gregor return false; 6798eee119bf4f1693dde17b8552c1f9f81bf2b681eDouglas Gregor} 6808eee119bf4f1693dde17b8552c1f9f81bf2b681eDouglas Gregor 6818eee119bf4f1693dde17b8552c1f9f81bf2b681eDouglas Gregorbool Type::hasFloatingRepresentation() const { 682c63b96ad706e054a1390dd2ab53af9f05d33bbb1Steve Naroff if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType)) 683c63b96ad706e054a1390dd2ab53af9f05d33bbb1Steve Naroff return VT->getElementType()->isFloatingType(); 6848eee119bf4f1693dde17b8552c1f9f81bf2b681eDouglas Gregor else 6858eee119bf4f1693dde17b8552c1f9f81bf2b681eDouglas Gregor return isFloatingType(); 6865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 6875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isRealFloatingType() const { 6895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 690680523a91dd3351389667c8de17121ba7ae82673John McCall return BT->isFloatingPoint(); 6915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return false; 6925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 6935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isRealType() const { 6955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 6965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return BT->getKind() >= BuiltinType::Bool && 6975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer BT->getKind() <= BuiltinType::LongDouble; 6981274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) 6991274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor return ET->getDecl()->isComplete() && !ET->getDecl()->isScoped(); 7005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return false; 7015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 7025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isArithmeticType() const { 7045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 705a7fbf7282eadebaf1293d9f970b01fb57f4b0ae4Douglas Gregor return BT->getKind() >= BuiltinType::Bool && 706a7fbf7282eadebaf1293d9f970b01fb57f4b0ae4Douglas Gregor BT->getKind() <= BuiltinType::LongDouble; 70737c1b78a20a09b0456aa5caa15e159027010ca22Chris Lattner if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) 70837c1b78a20a09b0456aa5caa15e159027010ca22Chris Lattner // GCC allows forward declaration of enum types (forbid by C99 6.7.2.3p2). 70937c1b78a20a09b0456aa5caa15e159027010ca22Chris Lattner // If a body isn't seen by the time we get here, return false. 7101274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor // 7111274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor // C++0x: Enumerations are not arithmetic types. For now, just return 7121274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor // false for scoped enumerations since that will disable any 7131274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor // unwanted implicit conversions. 7141274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor return !ET->getDecl()->isScoped() && ET->getDecl()->isComplete(); 71500619623af0b9d3271e31402ec1a95e84c2c4526Douglas Gregor return isa<ComplexType>(CanonicalType); 7165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 7175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isScalarType() const { 7195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 720daa8e4e888758d55a7a759dd4a91b83921cef222John McCall return BT->getKind() > BuiltinType::Void && 721daa8e4e888758d55a7a759dd4a91b83921cef222John McCall BT->getKind() <= BuiltinType::NullPtr; 7221274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) 723834a72ac74cf4ff07ba6215545dba3db578f8a07Chris Lattner // Enums are scalar types, but only if they are defined. Incomplete enums 724834a72ac74cf4ff07ba6215545dba3db578f8a07Chris Lattner // are not treated as scalar types. 7251274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor return ET->getDecl()->isComplete(); 7265618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff return isa<PointerType>(CanonicalType) || 7275618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff isa<BlockPointerType>(CanonicalType) || 728f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl isa<MemberPointerType>(CanonicalType) || 7295618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff isa<ComplexType>(CanonicalType) || 730d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff isa<ObjCObjectPointerType>(CanonicalType); 7315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 7325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 733daa8e4e888758d55a7a759dd4a91b83921cef222John McCallType::ScalarTypeKind Type::getScalarTypeKind() const { 734daa8e4e888758d55a7a759dd4a91b83921cef222John McCall assert(isScalarType()); 735daa8e4e888758d55a7a759dd4a91b83921cef222John McCall 736daa8e4e888758d55a7a759dd4a91b83921cef222John McCall const Type *T = CanonicalType.getTypePtr(); 737daa8e4e888758d55a7a759dd4a91b83921cef222John McCall if (const BuiltinType *BT = dyn_cast<BuiltinType>(T)) { 738daa8e4e888758d55a7a759dd4a91b83921cef222John McCall if (BT->getKind() == BuiltinType::Bool) return STK_Bool; 739daa8e4e888758d55a7a759dd4a91b83921cef222John McCall if (BT->getKind() == BuiltinType::NullPtr) return STK_Pointer; 740daa8e4e888758d55a7a759dd4a91b83921cef222John McCall if (BT->isInteger()) return STK_Integral; 741daa8e4e888758d55a7a759dd4a91b83921cef222John McCall if (BT->isFloatingPoint()) return STK_Floating; 742daa8e4e888758d55a7a759dd4a91b83921cef222John McCall llvm_unreachable("unknown scalar builtin type"); 743daa8e4e888758d55a7a759dd4a91b83921cef222John McCall } else if (isa<PointerType>(T) || 744daa8e4e888758d55a7a759dd4a91b83921cef222John McCall isa<BlockPointerType>(T) || 745daa8e4e888758d55a7a759dd4a91b83921cef222John McCall isa<ObjCObjectPointerType>(T)) { 746daa8e4e888758d55a7a759dd4a91b83921cef222John McCall return STK_Pointer; 747daa8e4e888758d55a7a759dd4a91b83921cef222John McCall } else if (isa<MemberPointerType>(T)) { 748daa8e4e888758d55a7a759dd4a91b83921cef222John McCall return STK_MemberPointer; 749daa8e4e888758d55a7a759dd4a91b83921cef222John McCall } else if (isa<EnumType>(T)) { 750daa8e4e888758d55a7a759dd4a91b83921cef222John McCall assert(cast<EnumType>(T)->getDecl()->isComplete()); 751daa8e4e888758d55a7a759dd4a91b83921cef222John McCall return STK_Integral; 752daa8e4e888758d55a7a759dd4a91b83921cef222John McCall } else if (const ComplexType *CT = dyn_cast<ComplexType>(T)) { 753daa8e4e888758d55a7a759dd4a91b83921cef222John McCall if (CT->getElementType()->isRealFloatingType()) 754daa8e4e888758d55a7a759dd4a91b83921cef222John McCall return STK_FloatingComplex; 755daa8e4e888758d55a7a759dd4a91b83921cef222John McCall return STK_IntegralComplex; 756daa8e4e888758d55a7a759dd4a91b83921cef222John McCall } 757daa8e4e888758d55a7a759dd4a91b83921cef222John McCall 758daa8e4e888758d55a7a759dd4a91b83921cef222John McCall llvm_unreachable("unknown scalar type"); 759daa8e4e888758d55a7a759dd4a91b83921cef222John McCall return STK_Pointer; 760daa8e4e888758d55a7a759dd4a91b83921cef222John McCall} 761daa8e4e888758d55a7a759dd4a91b83921cef222John McCall 762d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor/// \brief Determines whether the type is a C++ aggregate type or C 763d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor/// aggregate or union type. 764d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor/// 765d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor/// An aggregate type is an array or a class type (struct, union, or 766d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor/// class) that has no user-declared constructors, no private or 767d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor/// protected non-static data members, no base classes, and no virtual 768d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor/// functions (C++ [dcl.init.aggr]p1). The notion of an aggregate type 769d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor/// subsumes the notion of C aggregates (C99 6.2.5p21) because it also 770d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor/// includes union types. 7715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isAggregateType() const { 772c1efaecf0373f1a55c5ef4c234357cf726fc0600Douglas Gregor if (const RecordType *Record = dyn_cast<RecordType>(CanonicalType)) { 773c1efaecf0373f1a55c5ef4c234357cf726fc0600Douglas Gregor if (CXXRecordDecl *ClassDecl = dyn_cast<CXXRecordDecl>(Record->getDecl())) 774c1efaecf0373f1a55c5ef4c234357cf726fc0600Douglas Gregor return ClassDecl->isAggregate(); 775c1efaecf0373f1a55c5ef4c234357cf726fc0600Douglas Gregor 776d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor return true; 777c1efaecf0373f1a55c5ef4c234357cf726fc0600Douglas Gregor } 778c1efaecf0373f1a55c5ef4c234357cf726fc0600Douglas Gregor 779c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman return isa<ArrayType>(CanonicalType); 7805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 7815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7829bfa73c5ab7bf4b0e749d04f29da6884e8d5bd9fChris Lattner/// isConstantSizeType - Return true if this is not a variable sized type, 7839bfa73c5ab7bf4b0e749d04f29da6884e8d5bd9fChris Lattner/// according to the rules of C99 6.7.5p3. It is not legal to call this on 784898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// incomplete types or dependent types. 7853c2b3170041f69a92904e3bab9b6d654eaf260acEli Friedmanbool Type::isConstantSizeType() const { 786d52a4578144ab2887912e52eabec58a857a44adbChris Lattner assert(!isIncompleteType() && "This doesn't make sense for incomplete types"); 787898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor assert(!isDependentType() && "This doesn't make sense for dependent types"); 7889bfa73c5ab7bf4b0e749d04f29da6884e8d5bd9fChris Lattner // The VAT must have a size, as it is known to be complete. 7899bfa73c5ab7bf4b0e749d04f29da6884e8d5bd9fChris Lattner return !isa<VariableArrayType>(CanonicalType); 7905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 7915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// isIncompleteType - Return true if this is an incomplete type (C99 6.2.5p1) 7935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// - a type that can describe objects, but which lacks information needed to 7945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// determine its size. 7951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpbool Type::isIncompleteType() const { 7961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump switch (CanonicalType->getTypeClass()) { 7975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer default: return false; 7985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Builtin: 7995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Void is the only incomplete builtin type. Per C99 6.2.5p19, it can never 8005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // be completed. 8015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return isVoidType(); 80272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor case Enum: 8031274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor // An enumeration with fixed underlying type is complete (C++0x 7.2p3). 8041274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor if (cast<EnumType>(CanonicalType)->getDecl()->isFixed()) 8051274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor return false; 8061274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor // Fall through. 8071274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor case Record: 8085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // A tagged type (struct/union/enum/class) is incomplete if the decl is a 8095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // forward declaration, but not a full definition (C99 6.2.5p22). 8105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return !cast<TagType>(CanonicalType)->getDecl()->isDefinition(); 811923d56d436f750bc1f29db50e641078725558a1bSebastian Redl case ConstantArray: 812923d56d436f750bc1f29db50e641078725558a1bSebastian Redl // An array is incomplete if its element type is incomplete 813923d56d436f750bc1f29db50e641078725558a1bSebastian Redl // (C++ [dcl.array]p1). 814923d56d436f750bc1f29db50e641078725558a1bSebastian Redl // We don't handle variable arrays (they're not allowed in C++) or 815923d56d436f750bc1f29db50e641078725558a1bSebastian Redl // dependent-sized arrays (dependent types are never treated as incomplete). 816923d56d436f750bc1f29db50e641078725558a1bSebastian Redl return cast<ArrayType>(CanonicalType)->getElementType()->isIncompleteType(); 817c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman case IncompleteArray: 8185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // An array of unknown size is an incomplete type (C99 6.2.5p22). 819c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman return true; 820c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall case ObjCObject: 821d0221526bcc81f49eff5c992978176e83ada3bc7Douglas Gregor return cast<ObjCObjectType>(CanonicalType)->getBaseType() 822d0221526bcc81f49eff5c992978176e83ada3bc7Douglas Gregor ->isIncompleteType(); 8231efaa9594a81709a17658fd80ae7e783e1026407Chris Lattner case ObjCInterface: 8241efaa9594a81709a17658fd80ae7e783e1026407Chris Lattner // ObjC interfaces are incomplete if they are @class, not @interface. 825d0221526bcc81f49eff5c992978176e83ada3bc7Douglas Gregor return cast<ObjCInterfaceType>(CanonicalType)->getDecl()->isForwardDecl(); 8265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 8275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 8285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 82964b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl/// isPODType - Return true if this is a plain-old-data type (C++ 3.9p10) 83064b45f7e0d3167f040841ac2920aead7f080730dSebastian Redlbool Type::isPODType() const { 83164b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl // The compiler shouldn't query this for incomplete types, but the user might. 832607a1788d9529c8e8494ac528764aa2c678a1a97Sebastian Redl // We return false for that case. Except for incomplete arrays of PODs, which 833607a1788d9529c8e8494ac528764aa2c678a1a97Sebastian Redl // are PODs according to the standard. 834607a1788d9529c8e8494ac528764aa2c678a1a97Sebastian Redl if (isIncompleteArrayType() && 835607a1788d9529c8e8494ac528764aa2c678a1a97Sebastian Redl cast<ArrayType>(CanonicalType)->getElementType()->isPODType()) 836607a1788d9529c8e8494ac528764aa2c678a1a97Sebastian Redl return true; 83764b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl if (isIncompleteType()) 83864b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl return false; 83964b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 84064b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl switch (CanonicalType->getTypeClass()) { 84164b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl // Everything not explicitly mentioned is not POD. 84264b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl default: return false; 84364b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl case VariableArray: 84464b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl case ConstantArray: 845607a1788d9529c8e8494ac528764aa2c678a1a97Sebastian Redl // IncompleteArray is handled above. 84664b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl return cast<ArrayType>(CanonicalType)->getElementType()->isPODType(); 84764b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 84864b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl case Builtin: 84964b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl case Complex: 85064b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl case Pointer: 851f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl case MemberPointer: 85264b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl case Vector: 85364b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl case ExtVector: 854d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff case ObjCObjectPointer: 8552263f822c31d0855ca8c48bfd9624322bf776f0bFariborz Jahanian case BlockPointer: 85664b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl return true; 85764b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 85872564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor case Enum: 85972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor return true; 86072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor 86172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor case Record: 8621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (CXXRecordDecl *ClassDecl 863c1efaecf0373f1a55c5ef4c234357cf726fc0600Douglas Gregor = dyn_cast<CXXRecordDecl>(cast<RecordType>(CanonicalType)->getDecl())) 864c1efaecf0373f1a55c5ef4c234357cf726fc0600Douglas Gregor return ClassDecl->isPOD(); 865c1efaecf0373f1a55c5ef4c234357cf726fc0600Douglas Gregor 86664b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl // C struct/union is POD. 86764b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl return true; 86864b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl } 86964b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl} 87064b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 871ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redlbool Type::isLiteralType() const { 872ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl if (isIncompleteType()) 873ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl return false; 874ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl 875ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl // C++0x [basic.types]p10: 876ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl // A type is a literal type if it is: 877ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl switch (CanonicalType->getTypeClass()) { 878ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl // We're whitelisting 879ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl default: return false; 880ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl 881ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl // -- a scalar type 882ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl case Builtin: 883ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl case Complex: 884ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl case Pointer: 885ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl case MemberPointer: 886ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl case Vector: 887ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl case ExtVector: 888ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl case ObjCObjectPointer: 889ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl case Enum: 890ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl return true; 891ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl 892ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl // -- a class type with ... 893ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl case Record: 894ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl // FIXME: Do the tests 895ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl return false; 896ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl 897ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl // -- an array of literal type 898ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl // Extension: variable arrays cannot be literal types, since they're 899ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl // runtime-sized. 900ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl case ConstantArray: 901ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl return cast<ArrayType>(CanonicalType)->getElementType()->isLiteralType(); 902ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl } 903ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl} 904ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl 9055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isPromotableIntegerType() const { 906183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const BuiltinType *BT = getAs<BuiltinType>()) 9072a18dfe292cf3c406a769c3672080970ac586345Chris Lattner switch (BT->getKind()) { 9082a18dfe292cf3c406a769c3672080970ac586345Chris Lattner case BuiltinType::Bool: 9092a18dfe292cf3c406a769c3672080970ac586345Chris Lattner case BuiltinType::Char_S: 9102a18dfe292cf3c406a769c3672080970ac586345Chris Lattner case BuiltinType::Char_U: 9112a18dfe292cf3c406a769c3672080970ac586345Chris Lattner case BuiltinType::SChar: 9122a18dfe292cf3c406a769c3672080970ac586345Chris Lattner case BuiltinType::UChar: 9132a18dfe292cf3c406a769c3672080970ac586345Chris Lattner case BuiltinType::Short: 9142a18dfe292cf3c406a769c3672080970ac586345Chris Lattner case BuiltinType::UShort: 9152a18dfe292cf3c406a769c3672080970ac586345Chris Lattner return true; 9161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump default: 9172a18dfe292cf3c406a769c3672080970ac586345Chris Lattner return false; 9182a18dfe292cf3c406a769c3672080970ac586345Chris Lattner } 919aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor 920aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor // Enumerated types are promotable to their compatible integer types 921aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor // (C99 6.3.1.1) a.k.a. its underlying type (C++ [conv.prom]p2). 922aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor if (const EnumType *ET = getAs<EnumType>()){ 9231274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor if (this->isDependentType() || ET->getDecl()->getPromotionType().isNull() 9241274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor || ET->getDecl()->isScoped()) 925aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor return false; 926aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor 927aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor const BuiltinType *BT 928aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor = ET->getDecl()->getPromotionType()->getAs<BuiltinType>(); 929aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor return BT->getKind() == BuiltinType::Int 930aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor || BT->getKind() == BuiltinType::UInt; 931aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor } 932aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor 9332a18dfe292cf3c406a769c3672080970ac586345Chris Lattner return false; 9345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 9355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 9366e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redlbool Type::isNullPtrType() const { 937183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const BuiltinType *BT = getAs<BuiltinType>()) 9386e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl return BT->getKind() == BuiltinType::NullPtr; 9396e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl return false; 9406e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl} 9416e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl 94222b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedmanbool Type::isSpecifierType() const { 94322b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman // Note that this intentionally does not use the canonical type. 94422b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman switch (getTypeClass()) { 94522b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman case Builtin: 94622b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman case Record: 94722b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman case Enum: 94822b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman case Typedef: 949c8f2c61f4f667c2bc3e4e74b274fa397a4232393Eli Friedman case Complex: 950c8f2c61f4f667c2bc3e4e74b274fa397a4232393Eli Friedman case TypeOfExpr: 951c8f2c61f4f667c2bc3e4e74b274fa397a4232393Eli Friedman case TypeOf: 952c8f2c61f4f667c2bc3e4e74b274fa397a4232393Eli Friedman case TemplateTypeParm: 95349a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall case SubstTemplateTypeParm: 954c8f2c61f4f667c2bc3e4e74b274fa397a4232393Eli Friedman case TemplateSpecialization: 955465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case Elaborated: 9564714c12a1ab759156b78be8f109ea4c12213af57Douglas Gregor case DependentName: 95733500955d731c73717af52088b7fc0e7a85681e7John McCall case DependentTemplateSpecialization: 958c8f2c61f4f667c2bc3e4e74b274fa397a4232393Eli Friedman case ObjCInterface: 959c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall case ObjCObject: 960c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall case ObjCObjectPointer: // FIXME: object pointers aren't really specifiers 96122b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman return true; 96222b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman default: 96322b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman return false; 96422b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman } 96522b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman} 96622b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman 967465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraElaboratedTypeKeyword 968465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraTypeWithKeyword::getKeywordForTypeSpec(unsigned TypeSpec) { 969465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara switch (TypeSpec) { 970465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara default: return ETK_None; 971465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TST_typename: return ETK_Typename; 972465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TST_class: return ETK_Class; 973465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TST_struct: return ETK_Struct; 974465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TST_union: return ETK_Union; 975465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TST_enum: return ETK_Enum; 976465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara } 977465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara} 978465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 979465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraTagTypeKind 980465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraTypeWithKeyword::getTagTypeKindForTypeSpec(unsigned TypeSpec) { 981465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara switch(TypeSpec) { 982465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TST_class: return TTK_Class; 983465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TST_struct: return TTK_Struct; 984465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TST_union: return TTK_Union; 985465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TST_enum: return TTK_Enum; 986465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara } 9877907fad723a0f4764a2396df620d9c58725b3053Douglas Gregor 9887907fad723a0f4764a2396df620d9c58725b3053Douglas Gregor llvm_unreachable("Type specifier is not a tag type kind."); 9897907fad723a0f4764a2396df620d9c58725b3053Douglas Gregor return TTK_Union; 990465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara} 991465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 992465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraElaboratedTypeKeyword 993465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraTypeWithKeyword::getKeywordForTagTypeKind(TagTypeKind Kind) { 994465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara switch (Kind) { 995465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TTK_Class: return ETK_Class; 996465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TTK_Struct: return ETK_Struct; 997465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TTK_Union: return ETK_Union; 998465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TTK_Enum: return ETK_Enum; 999465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara } 1000465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara llvm_unreachable("Unknown tag type kind."); 1001465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara} 1002465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 1003465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraTagTypeKind 1004465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraTypeWithKeyword::getTagTypeKindForKeyword(ElaboratedTypeKeyword Keyword) { 1005465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara switch (Keyword) { 1006465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Class: return TTK_Class; 1007465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Struct: return TTK_Struct; 1008465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Union: return TTK_Union; 1009465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Enum: return TTK_Enum; 1010465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_None: // Fall through. 1011465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Typename: 1012465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara llvm_unreachable("Elaborated type keyword is not a tag type kind."); 1013465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara } 1014465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara llvm_unreachable("Unknown elaborated type keyword."); 1015465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara} 1016465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 1017465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnarabool 1018465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraTypeWithKeyword::KeywordIsTagTypeKind(ElaboratedTypeKeyword Keyword) { 1019465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara switch (Keyword) { 1020465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_None: 1021465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Typename: 1022465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara return false; 1023465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Class: 1024465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Struct: 1025465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Union: 1026465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Enum: 10274033642464e8ba0982f88f34cffad808d247b393Douglas Gregor return true; 10284033642464e8ba0982f88f34cffad808d247b393Douglas Gregor } 1029465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara llvm_unreachable("Unknown elaborated type keyword."); 1030465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara} 1031465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 1032465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnaraconst char* 1033465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraTypeWithKeyword::getKeywordName(ElaboratedTypeKeyword Keyword) { 1034465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara switch (Keyword) { 1035465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_None: return ""; 1036465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Typename: return "typename"; 1037465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Class: return "class"; 1038465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Struct: return "struct"; 1039465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Union: return "union"; 1040465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Enum: return "enum"; 1041465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara } 10427907fad723a0f4764a2396df620d9c58725b3053Douglas Gregor 10437907fad723a0f4764a2396df620d9c58725b3053Douglas Gregor llvm_unreachable("Unknown elaborated type keyword."); 10447907fad723a0f4764a2396df620d9c58725b3053Douglas Gregor return ""; 1045465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara} 1046465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 104733500955d731c73717af52088b7fc0e7a85681e7John McCallDependentTemplateSpecializationType::DependentTemplateSpecializationType( 1048ef99001908e799c388f1363b1e607dad5f5b57d3John McCall ElaboratedTypeKeyword Keyword, 104933500955d731c73717af52088b7fc0e7a85681e7John McCall NestedNameSpecifier *NNS, const IdentifierInfo *Name, 105033500955d731c73717af52088b7fc0e7a85681e7John McCall unsigned NumArgs, const TemplateArgument *Args, 105133500955d731c73717af52088b7fc0e7a85681e7John McCall QualType Canon) 105235495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor : TypeWithKeyword(Keyword, DependentTemplateSpecialization, Canon, true, 1053d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /*VariablyModified=*/false, 1054aa2187de137e5b809dcbbe14f3b61ae907a3d8aaDouglas Gregor NNS && NNS->containsUnexpandedParameterPack()), 1055ef99001908e799c388f1363b1e607dad5f5b57d3John McCall NNS(NNS), Name(Name), NumArgs(NumArgs) { 1056aa2187de137e5b809dcbbe14f3b61ae907a3d8aaDouglas Gregor assert((!NNS || NNS->isDependent()) && 105733500955d731c73717af52088b7fc0e7a85681e7John McCall "DependentTemplateSpecializatonType requires dependent qualifier"); 1058d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor for (unsigned I = 0; I != NumArgs; ++I) { 1059d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor if (Args[I].containsUnexpandedParameterPack()) 1060d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor setContainsUnexpandedParameterPack(); 1061d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 106233500955d731c73717af52088b7fc0e7a85681e7John McCall new (&getArgBuffer()[I]) TemplateArgument(Args[I]); 1063d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor } 106433500955d731c73717af52088b7fc0e7a85681e7John McCall} 106533500955d731c73717af52088b7fc0e7a85681e7John McCall 106633500955d731c73717af52088b7fc0e7a85681e7John McCallvoid 106733500955d731c73717af52088b7fc0e7a85681e7John McCallDependentTemplateSpecializationType::Profile(llvm::FoldingSetNodeID &ID, 10684ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad const ASTContext &Context, 106933500955d731c73717af52088b7fc0e7a85681e7John McCall ElaboratedTypeKeyword Keyword, 107033500955d731c73717af52088b7fc0e7a85681e7John McCall NestedNameSpecifier *Qualifier, 107133500955d731c73717af52088b7fc0e7a85681e7John McCall const IdentifierInfo *Name, 107233500955d731c73717af52088b7fc0e7a85681e7John McCall unsigned NumArgs, 107333500955d731c73717af52088b7fc0e7a85681e7John McCall const TemplateArgument *Args) { 107433500955d731c73717af52088b7fc0e7a85681e7John McCall ID.AddInteger(Keyword); 107533500955d731c73717af52088b7fc0e7a85681e7John McCall ID.AddPointer(Qualifier); 107633500955d731c73717af52088b7fc0e7a85681e7John McCall ID.AddPointer(Name); 107733500955d731c73717af52088b7fc0e7a85681e7John McCall for (unsigned Idx = 0; Idx < NumArgs; ++Idx) 107833500955d731c73717af52088b7fc0e7a85681e7John McCall Args[Idx].Profile(ID, Context); 107933500955d731c73717af52088b7fc0e7a85681e7John McCall} 108033500955d731c73717af52088b7fc0e7a85681e7John McCall 1081465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnarabool Type::isElaboratedTypeSpecifier() const { 1082465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara ElaboratedTypeKeyword Keyword; 1083465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara if (const ElaboratedType *Elab = dyn_cast<ElaboratedType>(this)) 1084465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara Keyword = Elab->getKeyword(); 1085465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara else if (const DependentNameType *DepName = dyn_cast<DependentNameType>(this)) 1086465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara Keyword = DepName->getKeyword(); 108733500955d731c73717af52088b7fc0e7a85681e7John McCall else if (const DependentTemplateSpecializationType *DepTST = 108833500955d731c73717af52088b7fc0e7a85681e7John McCall dyn_cast<DependentTemplateSpecializationType>(this)) 108933500955d731c73717af52088b7fc0e7a85681e7John McCall Keyword = DepTST->getKeyword(); 1090465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara else 1091465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara return false; 1092465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 1093465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara return TypeWithKeyword::KeywordIsTagTypeKind(Keyword); 10944033642464e8ba0982f88f34cffad808d247b393Douglas Gregor} 10954033642464e8ba0982f88f34cffad808d247b393Douglas Gregor 1096cd01f17358dc8ef19338c0e2321138dd0a6160d9Argyrios Kyrtzidisconst char *Type::getTypeClassName() const { 1097b870b88df784c2940efce448ebfaf54dece14666John McCall switch (TypeBits.TC) { 1098cd01f17358dc8ef19338c0e2321138dd0a6160d9Argyrios Kyrtzidis#define ABSTRACT_TYPE(Derived, Base) 1099cd01f17358dc8ef19338c0e2321138dd0a6160d9Argyrios Kyrtzidis#define TYPE(Derived, Base) case Derived: return #Derived; 1100cd01f17358dc8ef19338c0e2321138dd0a6160d9Argyrios Kyrtzidis#include "clang/AST/TypeNodes.def" 1101cd01f17358dc8ef19338c0e2321138dd0a6160d9Argyrios Kyrtzidis } 11027907fad723a0f4764a2396df620d9c58725b3053Douglas Gregor 11037907fad723a0f4764a2396df620d9c58725b3053Douglas Gregor llvm_unreachable("Invalid type class."); 11047907fad723a0f4764a2396df620d9c58725b3053Douglas Gregor return 0; 1105cd01f17358dc8ef19338c0e2321138dd0a6160d9Argyrios Kyrtzidis} 1106cd01f17358dc8ef19338c0e2321138dd0a6160d9Argyrios Kyrtzidis 1107e4f2142d00fa5fdb580c4e2413da91882d955381Chris Lattnerconst char *BuiltinType::getName(const LangOptions &LO) const { 11085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer switch (getKind()) { 11095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Void: return "void"; 1110e4f2142d00fa5fdb580c4e2413da91882d955381Chris Lattner case Bool: return LO.Bool ? "bool" : "_Bool"; 11115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Char_S: return "char"; 11125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Char_U: return "char"; 11135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case SChar: return "signed char"; 11145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Short: return "short"; 11155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Int: return "int"; 11165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Long: return "long"; 11175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case LongLong: return "long long"; 11182df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner case Int128: return "__int128_t"; 11195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case UChar: return "unsigned char"; 11205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case UShort: return "unsigned short"; 11215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case UInt: return "unsigned int"; 11225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case ULong: return "unsigned long"; 11235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case ULongLong: return "unsigned long long"; 11242df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner case UInt128: return "__uint128_t"; 11255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Float: return "float"; 11265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Double: return "double"; 11275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case LongDouble: return "long double"; 11283f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner case WChar_S: 11293f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner case WChar_U: return "wchar_t"; 1130f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith case Char16: return "char16_t"; 1131f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith case Char32: return "char32_t"; 11326e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl case NullPtr: return "nullptr_t"; 11338e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor case Overload: return "<overloaded function type>"; 1134898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor case Dependent: return "<dependent type>"; 11351de4d4e8cb2e9c88809fea8092bc6e835a5473d2John McCall case UnknownAny: return "<unknown type>"; 1136de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff case ObjCId: return "id"; 1137de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff case ObjCClass: return "Class"; 1138bef0efd11bc4430a3ee437a3213cec5c18af855aChris Lattner case ObjCSel: return "SEL"; 11395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 11407907fad723a0f4764a2396df620d9c58725b3053Douglas Gregor 1141aab440b2cb0e583aeaf21f08c8247456f3142a23Nick Lewycky llvm_unreachable("Invalid builtin type."); 1142aab440b2cb0e583aeaf21f08c8247456f3142a23Nick Lewycky return 0; 11435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 11445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11456398235d7890a81b785ea5af3b6e66d86bf184ccDouglas GregorQualType QualType::getNonLValueExprType(ASTContext &Context) const { 11465291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor if (const ReferenceType *RefType = getTypePtr()->getAs<ReferenceType>()) 11475291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor return RefType->getPointeeType(); 11485291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor 11495291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor // C++0x [basic.lval]: 11505291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor // Class prvalues can have cv-qualified types; non-class prvalues always 11515291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor // have cv-unqualified types. 11525291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor // 11535291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor // See also C99 6.3.2.1p2. 11545291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor if (!Context.getLangOptions().CPlusPlus || 11556dc1ef87044e6b177d4df0d2b593a94616180b3dChandler Carruth (!getTypePtr()->isDependentType() && !getTypePtr()->isRecordType())) 11565291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor return getUnqualifiedType(); 11575291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor 11585291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor return *this; 11595291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor} 11605291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor 116104a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCallllvm::StringRef FunctionType::getNameForCallConv(CallingConv CC) { 116204a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall switch (CC) { 11637907fad723a0f4764a2396df620d9c58725b3053Douglas Gregor case CC_Default: 11647907fad723a0f4764a2396df620d9c58725b3053Douglas Gregor llvm_unreachable("no name for default cc"); 11657907fad723a0f4764a2396df620d9c58725b3053Douglas Gregor return ""; 116604a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall 116704a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall case CC_C: return "cdecl"; 116804a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall case CC_X86StdCall: return "stdcall"; 116904a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall case CC_X86FastCall: return "fastcall"; 1170f813a2c03fcb05381b3252010435f557eb6b3cdeDouglas Gregor case CC_X86ThisCall: return "thiscall"; 117152fc314e1b5e1baee6305067cf831763d02bd243Dawn Perchik case CC_X86Pascal: return "pascal"; 117204a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall } 11737907fad723a0f4764a2396df620d9c58725b3053Douglas Gregor 11747907fad723a0f4764a2396df620d9c58725b3053Douglas Gregor llvm_unreachable("Invalid calling convention."); 11757907fad723a0f4764a2396df620d9c58725b3053Douglas Gregor return ""; 117604a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall} 117704a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall 1178e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCallFunctionProtoType::FunctionProtoType(QualType result, const QualType *args, 1179e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall unsigned numArgs, QualType canonical, 11808026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redl const ExtProtoInfo &epi) 1181c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor : FunctionType(FunctionProto, result, epi.Variadic, epi.TypeQuals, 1182c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor epi.RefQualifier, canonical, 1183e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall result->isDependentType(), 1184e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall result->isVariablyModifiedType(), 1185e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall result->containsUnexpandedParameterPack(), 1186e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall epi.ExtInfo), 1187e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall NumArgs(numArgs), NumExceptions(epi.NumExceptions), 118860618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl ExceptionSpecType(epi.ExceptionSpecType) 118935495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor{ 119035495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor // Fill in the trailing argument array. 1191e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall QualType *argSlot = reinterpret_cast<QualType*>(this+1); 119235495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor for (unsigned i = 0; i != numArgs; ++i) { 1193e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall if (args[i]->isDependentType()) 119435495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor setDependent(); 1195d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 1196e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall if (args[i]->containsUnexpandedParameterPack()) 1197d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor setContainsUnexpandedParameterPack(); 1198d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 1199e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall argSlot[i] = args[i]; 120035495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor } 1201e186269a8a41dbff1ebea2c251048892979d1078Douglas Gregor 120260618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl if (getExceptionSpecType() == EST_Dynamic) { 120360618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl // Fill in the exception array. 120460618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl QualType *exnSlot = argSlot + numArgs; 120560618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl for (unsigned i = 0, e = epi.NumExceptions; i != e; ++i) { 120660618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl if (epi.Exceptions[i]->isDependentType()) 120760618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl setDependent(); 1208e186269a8a41dbff1ebea2c251048892979d1078Douglas Gregor 120960618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl if (epi.Exceptions[i]->containsUnexpandedParameterPack()) 121060618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl setContainsUnexpandedParameterPack(); 121160618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl 121260618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl exnSlot[i] = epi.Exceptions[i]; 121360618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl } 121460618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl } else if (getExceptionSpecType() == EST_ComputedNoexcept) { 121560618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl // Store the noexcept expression and context. 121660618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl Expr **noexSlot = reinterpret_cast<Expr**>(argSlot + numArgs); 121760618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl *noexSlot = epi.NoexceptExpr; 1218e186269a8a41dbff1ebea2c251048892979d1078Douglas Gregor } 121935495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor} 122035495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor 122160618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian RedlFunctionProtoType::NoexceptResult 12228026f6d82f7fa544bc0453714fe94bca62a1196eSebastian RedlFunctionProtoType::getNoexceptSpec(ASTContext &ctx) const { 122360618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl ExceptionSpecificationType est = getExceptionSpecType(); 122460618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl if (est == EST_BasicNoexcept) 122560618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl return NR_Nothrow; 122660618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl 122760618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl if (est != EST_ComputedNoexcept) 122860618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl return NR_NoNoexcept; 122960618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl 123060618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl Expr *noexceptExpr = getNoexceptExpr(); 123160618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl if (!noexceptExpr) 123260618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl return NR_BadNoexcept; 123360618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl if (noexceptExpr->isValueDependent()) 123460618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl return NR_Dependent; 123560618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl 123660618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl llvm::APSInt value; 123760618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl bool isICE = noexceptExpr->isIntegerConstantExpr(value, ctx, 0, 123860618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl /*evaluated*/false); 123960618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl (void)isICE; 124060618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl assert(isICE && "AST should not contain bad noexcept expressions."); 124160618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl 124260618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl return value.getBoolValue() ? NR_Nothrow : NR_Throw; 124360618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl} 124460618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl 1245f5c65ffbd7374b6c8d9f1e361041578640cab320Douglas Gregorbool FunctionProtoType::isTemplateVariadic() const { 12467d5c0c1273bdc1cb3dff1cb5a62d07b1439e82c7Douglas Gregor for (unsigned ArgIdx = getNumArgs(); ArgIdx; --ArgIdx) 12477d5c0c1273bdc1cb3dff1cb5a62d07b1439e82c7Douglas Gregor if (isa<PackExpansionType>(getArgType(ArgIdx - 1))) 12487d5c0c1273bdc1cb3dff1cb5a62d07b1439e82c7Douglas Gregor return true; 12497d5c0c1273bdc1cb3dff1cb5a62d07b1439e82c7Douglas Gregor 12507d5c0c1273bdc1cb3dff1cb5a62d07b1439e82c7Douglas Gregor return false; 1251f5c65ffbd7374b6c8d9f1e361041578640cab320Douglas Gregor} 125235495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor 125372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregorvoid FunctionProtoType::Profile(llvm::FoldingSetNodeID &ID, QualType Result, 1254e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall const QualType *ArgTys, unsigned NumArgs, 125560618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl const ExtProtoInfo &epi, 12568026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redl const ASTContext &Context) { 12575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddPointer(Result.getAsOpaquePtr()); 12585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer for (unsigned i = 0; i != NumArgs; ++i) 12595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddPointer(ArgTys[i].getAsOpaquePtr()); 1260e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall ID.AddBoolean(epi.Variadic); 1261e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall ID.AddInteger(epi.TypeQuals); 1262c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor ID.AddInteger(epi.RefQualifier); 126360618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl ID.AddInteger(epi.ExceptionSpecType); 126460618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl if (epi.ExceptionSpecType == EST_Dynamic) { 1265e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall for (unsigned i = 0; i != epi.NumExceptions; ++i) 1266e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall ID.AddPointer(epi.Exceptions[i].getAsOpaquePtr()); 126760618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl } else if (epi.ExceptionSpecType == EST_ComputedNoexcept && epi.NoexceptExpr){ 12688026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redl epi.NoexceptExpr->Profile(ID, Context, true); 1269465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl } 1270e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall epi.ExtInfo.Profile(ID); 12715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 12725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 12738026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redlvoid FunctionProtoType::Profile(llvm::FoldingSetNodeID &ID, 12748026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redl const ASTContext &Ctx) { 127560618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl Profile(ID, getResultType(), arg_type_begin(), NumArgs, getExtProtoInfo(), 12768026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redl Ctx); 12775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 12785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1279bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCallQualType TypedefType::desugar() const { 1280bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall return getDecl()->getUnderlyingType(); 1281bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall} 1282bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 128372564e73277e29f6db3305d1f27ba408abb7ed88Douglas GregorTypeOfExprType::TypeOfExprType(Expr *E, QualType can) 128435495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor : Type(TypeOfExpr, can, E->isTypeDependent(), 1285d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor E->getType()->isVariablyModifiedType(), 1286d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor E->containsUnexpandedParameterPack()), 1287d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor TOExpr(E) { 1288898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor} 1289898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 1290bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCallQualType TypeOfExprType::desugar() const { 1291bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall return getUnderlyingExpr()->getType(); 1292bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall} 1293bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 12941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpvoid DependentTypeOfExprType::Profile(llvm::FoldingSetNodeID &ID, 12954ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad const ASTContext &Context, Expr *E) { 1296b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor E->Profile(ID, Context, true); 1297b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor} 1298b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor 1299563a03b1338d31c2462def43253a722bc885d384Anders CarlssonDecltypeType::DecltypeType(Expr *E, QualType underlyingType, QualType can) 130035495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor : Type(Decltype, can, E->isTypeDependent(), 1301d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor E->getType()->isVariablyModifiedType(), 1302d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor E->containsUnexpandedParameterPack()), 1303d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor E(E), 1304563a03b1338d31c2462def43253a722bc885d384Anders Carlsson UnderlyingType(underlyingType) { 1305395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson} 1306395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson 13074ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadDependentDecltypeType::DependentDecltypeType(const ASTContext &Context, Expr *E) 13089d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor : DecltypeType(E, Context.DependentTy), Context(Context) { } 13099d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor 13101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpvoid DependentDecltypeType::Profile(llvm::FoldingSetNodeID &ID, 13114ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad const ASTContext &Context, Expr *E) { 13129d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor E->Profile(ID, Context, true); 13139d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor} 13149d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor 131519c8576b7328f4dc2d07682f5da552875c1912efJohn McCallTagType::TagType(TypeClass TC, const TagDecl *D, QualType can) 1316d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor : Type(TC, can, D->isDependentType(), /*VariablyModified=*/false, 1317d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /*ContainsUnexpandedParameterPack=*/false), 1318ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl decl(const_cast<TagDecl*>(D)) {} 1319ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl 1320ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redlstatic TagDecl *getInterestingTagDecl(TagDecl *decl) { 1321ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl for (TagDecl::redecl_iterator I = decl->redecls_begin(), 1322ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl E = decl->redecls_end(); 1323ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl I != E; ++I) { 1324ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl if (I->isDefinition() || I->isBeingDefined()) 1325ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl return *I; 1326ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl } 1327ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl // If there's no definition (not even in progress), return what we have. 1328ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl return decl; 1329ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl} 1330ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl 1331ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian RedlTagDecl *TagType::getDecl() const { 1332ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl return getInterestingTagDecl(decl); 1333ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl} 1334ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl 1335ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redlbool TagType::isBeingDefined() const { 1336ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl return getDecl()->isBeingDefined(); 1337ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl} 1338ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl 1339ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian RedlCXXRecordDecl *InjectedClassNameType::getDecl() const { 1340ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl return cast<CXXRecordDecl>(getInterestingTagDecl(Decl)); 1341ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl} 13427da97d0f31e1ec16998d3de2cfd2e88fe3736673Douglas Gregor 13432daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattnerbool RecordType::classof(const TagType *TT) { 13442daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner return isa<RecordDecl>(TT->getDecl()); 13455edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner} 13465edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner 13472daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattnerbool EnumType::classof(const TagType *TT) { 13482daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner return isa<EnumDecl>(TT->getDecl()); 13495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 13505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1351c3069d618f4661d923cb1b5c4525b082fce73b04Douglas GregorSubstTemplateTypeParmPackType:: 1352c3069d618f4661d923cb1b5c4525b082fce73b04Douglas GregorSubstTemplateTypeParmPackType(const TemplateTypeParmType *Param, 1353c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor QualType Canon, 1354c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor const TemplateArgument &ArgPack) 1355c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor : Type(SubstTemplateTypeParmPack, Canon, true, false, true), Replaced(Param), 1356c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor Arguments(ArgPack.pack_begin()), NumArguments(ArgPack.pack_size()) 1357c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor{ 1358c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor} 1359c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor 1360c3069d618f4661d923cb1b5c4525b082fce73b04Douglas GregorTemplateArgument SubstTemplateTypeParmPackType::getArgumentPack() const { 1361c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor return TemplateArgument(Arguments, NumArguments); 1362c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor} 1363c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor 1364c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregorvoid SubstTemplateTypeParmPackType::Profile(llvm::FoldingSetNodeID &ID) { 1365c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor Profile(ID, getReplacedParameter(), getArgumentPack()); 1366c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor} 1367c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor 1368c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregorvoid SubstTemplateTypeParmPackType::Profile(llvm::FoldingSetNodeID &ID, 1369c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor const TemplateTypeParmType *Replaced, 1370c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor const TemplateArgument &ArgPack) { 1371c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor ID.AddPointer(Replaced); 1372c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor ID.AddInteger(ArgPack.pack_size()); 1373c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor for (TemplateArgument::pack_iterator P = ArgPack.pack_begin(), 1374c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor PEnd = ArgPack.pack_end(); 1375c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor P != PEnd; ++P) 1376c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor ID.AddPointer(P->getAsType().getAsOpaquePtr()); 1377c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor} 1378c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor 1379833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallbool TemplateSpecializationType:: 1380d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCallanyDependentTemplateArguments(const TemplateArgumentListInfo &Args) { 1381d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall return anyDependentTemplateArguments(Args.getArgumentArray(), Args.size()); 1382d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall} 1383d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall 1384d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCallbool TemplateSpecializationType:: 1385833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallanyDependentTemplateArguments(const TemplateArgumentLoc *Args, unsigned N) { 1386833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall for (unsigned i = 0; i != N; ++i) 1387bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (Args[i].getArgument().isDependent()) 1388833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return true; 1389833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return false; 1390833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall} 1391833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 1392833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallbool TemplateSpecializationType:: 1393833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallanyDependentTemplateArguments(const TemplateArgument *Args, unsigned N) { 1394833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall for (unsigned i = 0; i != N; ++i) 1395bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (Args[i].isDependent()) 1396833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return true; 1397833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return false; 1398833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall} 1399833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 14007532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas GregorTemplateSpecializationType:: 1401ef99001908e799c388f1363b1e607dad5f5b57d3John McCallTemplateSpecializationType(TemplateName T, 1402828e226ab7ed08b3eb766549e9d3306432137460Douglas Gregor const TemplateArgument *Args, 14037532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor unsigned NumArgs, QualType Canon) 14041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : Type(TemplateSpecialization, 140540808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor Canon.isNull()? QualType(this, 0) : Canon, 1406a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor T.isDependent(), false, T.containsUnexpandedParameterPack()), 140735495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor Template(T), NumArgs(NumArgs) 140835495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor{ 1409a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor assert(!T.getAsDependentTemplateName() && 1410a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor "Use DependentTemplateSpecializationType for dependent template-name"); 14111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump assert((!Canon.isNull() || 14127532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor T.isDependent() || anyDependentTemplateArguments(Args, NumArgs)) && 141340808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor "No canonical type for non-dependent class template specialization"); 141455f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 14151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TemplateArgument *TemplateArgs 141640808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor = reinterpret_cast<TemplateArgument *>(this + 1); 141735495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor for (unsigned Arg = 0; Arg < NumArgs; ++Arg) { 141835495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor // Update dependent and variably-modified bits. 1419bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (Args[Arg].isDependent()) 142035495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor setDependent(); 142135495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor if (Args[Arg].getKind() == TemplateArgument::Type && 142235495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor Args[Arg].getAsType()->isVariablyModifiedType()) 142335495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor setVariablyModified(); 1424d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor if (Args[Arg].containsUnexpandedParameterPack()) 1425d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor setContainsUnexpandedParameterPack(); 1426d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 142740808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor new (&TemplateArgs[Arg]) TemplateArgument(Args[Arg]); 142835495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor } 142955f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor} 143055f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 14311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpvoid 14321eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTemplateSpecializationType::Profile(llvm::FoldingSetNodeID &ID, 14331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TemplateName T, 14341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const TemplateArgument *Args, 1435828e226ab7ed08b3eb766549e9d3306432137460Douglas Gregor unsigned NumArgs, 14364ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad const ASTContext &Context) { 14377532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor T.Profile(ID); 143840808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor for (unsigned Idx = 0; Idx < NumArgs; ++Idx) 1439828e226ab7ed08b3eb766549e9d3306432137460Douglas Gregor Args[Idx].Profile(ID, Context); 144055f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor} 144197e0179f1ae545e07d9f5e7c1d2ef5c5bab06676Anders Carlsson 14424ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualType 14434ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualifierCollector::apply(const ASTContext &Context, QualType QT) const { 14440953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (!hasNonFastQualifiers()) 14450953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return QT.withFastQualifiers(getFastQualifiers()); 14461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 144749f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall return Context.getQualifiedType(QT, *this); 14485e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor} 14495e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor 14504ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualType 14514ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualifierCollector::apply(const ASTContext &Context, const Type *T) const { 14520953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (!hasNonFastQualifiers()) 14530953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return QualType(T, getFastQualifiers()); 14540953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 145549f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall return Context.getQualifiedType(T, *this); 14565e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor} 14575e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor 1458c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallvoid ObjCObjectTypeImpl::Profile(llvm::FoldingSetNodeID &ID, 1459c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall QualType BaseType, 1460c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCProtocolDecl * const *Protocols, 1461c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall unsigned NumProtocols) { 1462c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ID.AddPointer(BaseType.getAsOpaquePtr()); 1463c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff for (unsigned i = 0; i != NumProtocols; i++) 1464c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ID.AddPointer(Protocols[i]); 1465c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff} 1466c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff 1467c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallvoid ObjCObjectTypeImpl::Profile(llvm::FoldingSetNodeID &ID) { 1468c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall Profile(ID, getBaseType(), qual_begin(), getNumProtocols()); 1469c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff} 14700b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 1471b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCallnamespace { 14721fb0caaa7bef765b85972274e3b434af2572c141John McCall 1473b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall/// \brief The cached properties of a type. 1474b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCallclass CachedProperties { 1475b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall char linkage; 1476b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall char visibility; 1477b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall bool local; 1478b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall 1479b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCallpublic: 1480b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall CachedProperties(Linkage linkage, Visibility visibility, bool local) 1481b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall : linkage(linkage), visibility(visibility), local(local) {} 1482b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall 1483b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall Linkage getLinkage() const { return (Linkage) linkage; } 1484b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall Visibility getVisibility() const { return (Visibility) visibility; } 1485b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall bool hasLocalOrUnnamedType() const { return local; } 1486b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall 1487b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall friend CachedProperties merge(CachedProperties L, CachedProperties R) { 1488b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return CachedProperties(minLinkage(L.getLinkage(), R.getLinkage()), 1489b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall minVisibility(L.getVisibility(), R.getVisibility()), 1490b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall L.hasLocalOrUnnamedType() | R.hasLocalOrUnnamedType()); 1491b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall } 1492b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall}; 14931fb0caaa7bef765b85972274e3b434af2572c141John McCall} 14941fb0caaa7bef765b85972274e3b434af2572c141John McCall 1495b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCallstatic CachedProperties computeCachedProperties(const Type *T); 14960b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 1497b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCallnamespace clang { 1498b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall/// The type-property cache. This is templated so as to be 1499b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall/// instantiated at an internal type to prevent unnecessary symbol 1500b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall/// leakage. 1501b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCalltemplate <class Private> class TypePropertyCache { 1502b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCallpublic: 1503b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall static CachedProperties get(QualType T) { 1504b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return get(T.getTypePtr()); 1505b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall } 15061fb0caaa7bef765b85972274e3b434af2572c141John McCall 1507b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall static CachedProperties get(const Type *T) { 1508b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall ensure(T); 1509b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return CachedProperties(T->TypeBits.getLinkage(), 1510b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall T->TypeBits.getVisibility(), 1511b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall T->TypeBits.hasLocalOrUnnamedType()); 1512b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall } 1513db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor 1514b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall static void ensure(const Type *T) { 1515b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall // If the cache is valid, we're okay. 1516b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall if (T->TypeBits.isCacheValid()) return; 1517b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall 1518b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall // If this type is non-canonical, ask its canonical type for the 1519b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall // relevant information. 15203b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (!T->isCanonicalUnqualified()) { 15213b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall const Type *CT = T->getCanonicalTypeInternal().getTypePtr(); 1522b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall ensure(CT); 1523b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall T->TypeBits.CacheValidAndVisibility = 1524b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall CT->TypeBits.CacheValidAndVisibility; 1525b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall T->TypeBits.CachedLinkage = CT->TypeBits.CachedLinkage; 1526b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall T->TypeBits.CachedLocalOrUnnamed = CT->TypeBits.CachedLocalOrUnnamed; 1527b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return; 1528b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall } 15291fb0caaa7bef765b85972274e3b434af2572c141John McCall 1530b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall // Compute the cached properties and then set the cache. 1531b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall CachedProperties Result = computeCachedProperties(T); 1532b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall T->TypeBits.CacheValidAndVisibility = Result.getVisibility() + 1U; 1533b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall assert(T->TypeBits.isCacheValid() && 1534b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall T->TypeBits.getVisibility() == Result.getVisibility()); 1535b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall T->TypeBits.CachedLinkage = Result.getLinkage(); 1536b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall T->TypeBits.CachedLocalOrUnnamed = Result.hasLocalOrUnnamedType(); 1537b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall } 1538b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall}; 15391fb0caaa7bef765b85972274e3b434af2572c141John McCall} 15401fb0caaa7bef765b85972274e3b434af2572c141John McCall 1541b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall// Instantiate the friend template at a private class. In a 1542b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall// reasonable implementation, these symbols will be internal. 1543b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall// It is terrible that this is the best way to accomplish this. 1544b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCallnamespace { class Private {}; } 1545b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCalltypedef TypePropertyCache<Private> Cache; 15461fb0caaa7bef765b85972274e3b434af2572c141John McCall 1547b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCallstatic CachedProperties computeCachedProperties(const Type *T) { 1548b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall switch (T->getTypeClass()) { 1549b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall#define TYPE(Class,Base) 1550b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall#define NON_CANONICAL_TYPE(Class,Base) case Type::Class: 1551b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall#include "clang/AST/TypeNodes.def" 1552b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall llvm_unreachable("didn't expect a non-canonical type here"); 155360e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor 1554b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall#define TYPE(Class,Base) 1555b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall#define DEPENDENT_TYPE(Class,Base) case Type::Class: 1556b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall#define NON_CANONICAL_UNLESS_DEPENDENT_TYPE(Class,Base) case Type::Class: 1557b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall#include "clang/AST/TypeNodes.def" 1558b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall // Treat dependent types as external. 1559b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall assert(T->isDependentType()); 15601fb0caaa7bef765b85972274e3b434af2572c141John McCall return CachedProperties(ExternalLinkage, DefaultVisibility, false); 15611fb0caaa7bef765b85972274e3b434af2572c141John McCall 1562b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::Builtin: 1563b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall // C++ [basic.link]p8: 1564b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall // A type is said to have linkage if and only if: 1565b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall // - it is a fundamental type (3.9.1); or 1566b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return CachedProperties(ExternalLinkage, DefaultVisibility, false); 15670b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 1568b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::Record: 1569b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::Enum: { 1570b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall const TagDecl *Tag = cast<TagType>(T)->getDecl(); 1571b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall 1572b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall // C++ [basic.link]p8: 1573b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall // - it is a class or enumeration type that is named (or has a name 1574b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall // for linkage purposes (7.1.3)) and the name has linkage; or 1575b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall // - it is a specialization of a class template (14); or 1576b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall NamedDecl::LinkageInfo LV = Tag->getLinkageAndVisibility(); 1577b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall bool IsLocalOrUnnamed = 1578b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall Tag->getDeclContext()->isFunctionOrMethod() || 1579b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall (!Tag->getIdentifier() && !Tag->getTypedefForAnonDecl()); 1580b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return CachedProperties(LV.linkage(), LV.visibility(), IsLocalOrUnnamed); 1581b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall } 15820b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 1583b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall // C++ [basic.link]p8: 1584b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall // - it is a compound type (3.9.2) other than a class or enumeration, 1585b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall // compounded exclusively from types that have linkage; or 1586b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::Complex: 1587b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return Cache::get(cast<ComplexType>(T)->getElementType()); 1588b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::Pointer: 1589b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return Cache::get(cast<PointerType>(T)->getPointeeType()); 1590b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::BlockPointer: 1591b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return Cache::get(cast<BlockPointerType>(T)->getPointeeType()); 1592b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::LValueReference: 1593b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::RValueReference: 1594b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return Cache::get(cast<ReferenceType>(T)->getPointeeType()); 1595b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::MemberPointer: { 1596b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall const MemberPointerType *MPT = cast<MemberPointerType>(T); 1597b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return merge(Cache::get(MPT->getClass()), 1598b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall Cache::get(MPT->getPointeeType())); 1599b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall } 1600b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::ConstantArray: 1601b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::IncompleteArray: 1602b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::VariableArray: 1603b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return Cache::get(cast<ArrayType>(T)->getElementType()); 1604b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::Vector: 1605b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::ExtVector: 1606b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return Cache::get(cast<VectorType>(T)->getElementType()); 1607b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::FunctionNoProto: 1608b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return Cache::get(cast<FunctionType>(T)->getResultType()); 1609b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::FunctionProto: { 1610b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall const FunctionProtoType *FPT = cast<FunctionProtoType>(T); 1611b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall CachedProperties result = Cache::get(FPT->getResultType()); 1612b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall for (FunctionProtoType::arg_type_iterator ai = FPT->arg_type_begin(), 1613b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall ae = FPT->arg_type_end(); ai != ae; ++ai) 1614b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall result = merge(result, Cache::get(*ai)); 1615b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return result; 1616b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall } 1617b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::ObjCInterface: { 1618b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall NamedDecl::LinkageInfo LV = 1619b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall cast<ObjCInterfaceType>(T)->getDecl()->getLinkageAndVisibility(); 1620b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return CachedProperties(LV.linkage(), LV.visibility(), false); 1621b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall } 1622b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::ObjCObject: 1623b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return Cache::get(cast<ObjCObjectType>(T)->getBaseType()); 1624b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::ObjCObjectPointer: 1625b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return Cache::get(cast<ObjCObjectPointerType>(T)->getPointeeType()); 1626b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall } 16270b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 1628b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall llvm_unreachable("unhandled type class"); 16290b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 1630b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall // C++ [basic.link]p8: 1631b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall // Names not covered by these rules have no linkage. 1632b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return CachedProperties(NoLinkage, DefaultVisibility, false); 16330b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor} 16340b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 1635b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall/// \brief Determine the linkage of this type. 1636b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCallLinkage Type::getLinkage() const { 1637b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall Cache::ensure(this); 1638b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return TypeBits.getLinkage(); 16390b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor} 16400b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 1641b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall/// \brief Determine the linkage of this type. 1642b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCallVisibility Type::getVisibility() const { 1643b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall Cache::ensure(this); 1644b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return TypeBits.getVisibility(); 16451fb0caaa7bef765b85972274e3b434af2572c141John McCall} 16461fb0caaa7bef765b85972274e3b434af2572c141John McCall 1647b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCallbool Type::hasUnnamedOrLocalType() const { 1648b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall Cache::ensure(this); 1649b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return TypeBits.hasLocalOrUnnamedType(); 16500b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor} 16510b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 1652b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCallstd::pair<Linkage,Visibility> Type::getLinkageAndVisibility() const { 1653b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall Cache::ensure(this); 1654b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return std::make_pair(TypeBits.getLinkage(), TypeBits.getVisibility()); 16550b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor} 16560b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 1657b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCallvoid Type::ClearLinkageCache() { 1658b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall TypeBits.CacheValidAndVisibility = 0; 1659b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall if (QualType(this, 0) != CanonicalType) 1660b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall CanonicalType->TypeBits.CacheValidAndVisibility = 0; 16610b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor} 16623b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 16633b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallbool Type::hasSizedVLAType() const { 16643b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (!isVariablyModifiedType()) return false; 16653b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 16663b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (const PointerType *ptr = getAs<PointerType>()) 16673b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return ptr->getPointeeType()->hasSizedVLAType(); 16683b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (const ReferenceType *ref = getAs<ReferenceType>()) 16693b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return ref->getPointeeType()->hasSizedVLAType(); 16703b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (const ArrayType *arr = getAsArrayTypeUnsafe()) { 16713b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (isa<VariableArrayType>(arr) && 16723b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall cast<VariableArrayType>(arr)->getSizeExpr()) 16733b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return true; 16743b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 16753b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return arr->getElementType()->hasSizedVLAType(); 16763b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall } 16773b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 16783b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return false; 16793b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall} 16800d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall 16810d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCallQualType::DestructionKind QualType::isDestructedTypeImpl(QualType type) { 16820d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall /// Currently, the only destruction kind we recognize is C++ objects 16830d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall /// with non-trivial destructors. 16840d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall const CXXRecordDecl *record = 16850d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall type->getBaseElementTypeUnsafe()->getAsCXXRecordDecl(); 16860d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall if (record && !record->hasTrivialDestructor()) 16870d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall return DK_cxx_destructor; 16880d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall 16890d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall return DK_none; 16900d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall} 1691