Type.cpp revision c3069d618f4661d923cb1b5c4525b082fce73b04
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" 245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "llvm/ADT/StringExtras.h" 25bad351822117eaf280081494e3dbe4a06c0dbfcfDouglas Gregor#include "llvm/Support/raw_ostream.h" 262767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor#include <algorithm> 275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing namespace clang; 285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 29bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCallbool QualType::isConstant(QualType T, ASTContext &Ctx) { 30bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall if (T.isConstQualified()) 31b381aac9bae6d608c72267dd0ed08ec6369e94e4Nuno Lopes return true; 32b381aac9bae6d608c72267dd0ed08ec6369e94e4Nuno Lopes 33bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall if (const ArrayType *AT = Ctx.getAsArrayType(T)) 34bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall return AT->getElementType().isConstant(Ctx); 35b381aac9bae6d608c72267dd0ed08ec6369e94e4Nuno Lopes 36b381aac9bae6d608c72267dd0ed08ec6369e94e4Nuno Lopes return false; 37b381aac9bae6d608c72267dd0ed08ec6369e94e4Nuno Lopes} 38b381aac9bae6d608c72267dd0ed08ec6369e94e4Nuno Lopes 392767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregorunsigned ConstantArrayType::getNumAddressingBits(ASTContext &Context, 402767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor QualType ElementType, 412767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor const llvm::APInt &NumElements) { 422767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor llvm::APSInt SizeExtended(NumElements, true); 432767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor unsigned SizeTypeBits = Context.getTypeSize(Context.getSizeType()); 449f71a8f4c7a182a5236da9e747d57cc1d1bd24c2Jay Foad SizeExtended = SizeExtended.extend(std::max(SizeTypeBits, 459f71a8f4c7a182a5236da9e747d57cc1d1bd24c2Jay Foad SizeExtended.getBitWidth()) * 2); 462767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor 472767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor uint64_t ElementSize 482767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor = Context.getTypeSizeInChars(ElementType).getQuantity(); 492767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor llvm::APSInt TotalSize(llvm::APInt(SizeExtended.getBitWidth(), ElementSize)); 502767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor TotalSize *= SizeExtended; 512767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor 522767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor return TotalSize.getActiveBits(); 532767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor} 542767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor 552767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregorunsigned ConstantArrayType::getMaxSizeBits(ASTContext &Context) { 562767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor unsigned Bits = Context.getTypeSize(Context.getSizeType()); 572767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor 582767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor // GCC appears to only allow 63 bits worth of address space when compiling 592767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor // for 64-bit, so we do the same. 602767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor if (Bits == 64) 612767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor --Bits; 622767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor 632767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor return Bits; 642767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor} 652767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor 664ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadDependentSizedArrayType::DependentSizedArrayType(const ASTContext &Context, 67d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor QualType et, QualType can, 68d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor Expr *e, ArraySizeModifier sm, 69d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor unsigned tq, 70d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor SourceRange brackets) 71d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor : ArrayType(DependentSizedArray, et, can, sm, tq, 72d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor (et->containsUnexpandedParameterPack() || 73d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor (e && e->containsUnexpandedParameterPack()))), 74d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor Context(Context), SizeExpr((Stmt*) e), Brackets(brackets) 75d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor{ 76d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor} 77d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpvoid DependentSizedArrayType::Profile(llvm::FoldingSetNodeID &ID, 794ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad const ASTContext &Context, 8004d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor QualType ET, 8104d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor ArraySizeModifier SizeMod, 8204d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor unsigned TypeQuals, 8304d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor Expr *E) { 8404d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor ID.AddPointer(ET.getAsOpaquePtr()); 8504d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor ID.AddInteger(SizeMod); 8604d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor ID.AddInteger(TypeQuals); 8704d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor E->Profile(ID, Context, true); 8804d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor} 8904d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor 904ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadDependentSizedExtVectorType::DependentSizedExtVectorType(const 914ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad ASTContext &Context, 92d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor QualType ElementType, 93d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor QualType can, 94d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor Expr *SizeExpr, 95d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor SourceLocation loc) 96d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor : Type(DependentSizedExtVector, can, /*Dependent=*/true, 97d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor ElementType->isVariablyModifiedType(), 98d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor (ElementType->containsUnexpandedParameterPack() || 99d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor (SizeExpr && SizeExpr->containsUnexpandedParameterPack()))), 100d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor Context(Context), SizeExpr(SizeExpr), ElementType(ElementType), 101d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor loc(loc) 102d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor{ 103d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor} 104d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 1051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpvoid 1061eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpDependentSizedExtVectorType::Profile(llvm::FoldingSetNodeID &ID, 1074ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad const ASTContext &Context, 1082ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor QualType ElementType, Expr *SizeExpr) { 1092ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor ID.AddPointer(ElementType.getAsOpaquePtr()); 1102ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor SizeExpr->Profile(ID, Context, true); 1112ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor} 1122ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor 113d0937224f383c7cc72c947119380f9713a070c73Douglas GregorVectorType::VectorType(QualType vecType, unsigned nElements, QualType canonType, 114d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor VectorKind vecKind) 115d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor : Type(Vector, canonType, vecType->isDependentType(), 116d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor vecType->isVariablyModifiedType(), 117d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor vecType->containsUnexpandedParameterPack()), 118d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor ElementType(vecType) 119d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor{ 120d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor VectorTypeBits.VecKind = vecKind; 121d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor VectorTypeBits.NumElements = nElements; 122d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor} 123d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 124d0937224f383c7cc72c947119380f9713a070c73Douglas GregorVectorType::VectorType(TypeClass tc, QualType vecType, unsigned nElements, 125d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor QualType canonType, VectorKind vecKind) 126d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor : Type(tc, canonType, vecType->isDependentType(), 127d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor vecType->isVariablyModifiedType(), 128d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor vecType->containsUnexpandedParameterPack()), 129d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor ElementType(vecType) 130d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor{ 131d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor VectorTypeBits.VecKind = vecKind; 132d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor VectorTypeBits.NumElements = nElements; 133d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor} 134d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 135c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner/// getArrayElementTypeNoTypeQual - If this is an array type, return the 136c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner/// element type of the array, potentially with type qualifiers missing. 137c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner/// This method should never be used when type qualifiers are meaningful. 138c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattnerconst Type *Type::getArrayElementTypeNoTypeQual() const { 139c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // If this is directly an array type, return it. 140c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner if (const ArrayType *ATy = dyn_cast<ArrayType>(this)) 141c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return ATy->getElementType().getTypePtr(); 1421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 143c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // If the canonical form of this type isn't the right kind, reject it. 1440953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (!isa<ArrayType>(CanonicalType)) 145c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return 0; 1461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 147c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // If this is a typedef for an array type, strip the typedef off without 148c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // losing all typedef information. 149bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall return cast<ArrayType>(getUnqualifiedDesugaredType()) 150bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall ->getElementType().getTypePtr(); 1512fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner} 1522fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner 153fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor/// \brief Retrieve the unqualified variant of the given type, removing as 154fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor/// little sugar as possible. 155fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor/// 156fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor/// This routine looks through various kinds of sugar to find the 157fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor/// least-desuraged type that is unqualified. For example, given: 158fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor/// 159fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor/// \code 160fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor/// typedef int Integer; 161fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor/// typedef const Integer CInteger; 162fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor/// typedef CInteger DifferenceType; 163fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor/// \endcode 164fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor/// 165fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor/// Executing \c getUnqualifiedTypeSlow() on the type \c DifferenceType will 166fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor/// desugar until we hit the type \c Integer, which has no qualifiers on it. 167fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas GregorQualType QualType::getUnqualifiedTypeSlow() const { 168fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor QualType Cur = *this; 169fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor while (true) { 170fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor if (!Cur.hasQualifiers()) 171fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor return Cur; 172fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor 173fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor const Type *CurTy = Cur.getTypePtr(); 174fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor switch (CurTy->getTypeClass()) { 175fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor#define ABSTRACT_TYPE(Class, Parent) 176fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor#define TYPE(Class, Parent) \ 177fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor case Type::Class: { \ 178fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor const Class##Type *Ty = cast<Class##Type>(CurTy); \ 179fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor if (!Ty->isSugared()) \ 180fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor return Cur.getLocalUnqualifiedType(); \ 181fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor Cur = Ty->desugar(); \ 182fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor break; \ 183fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor } 184fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor#include "clang/AST/TypeNodes.def" 185fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor } 186fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor } 187fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor 188fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor return Cur.getUnqualifiedType(); 189fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor} 190fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor 1912fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner/// getDesugaredType - Return the specified type with any "sugar" removed from 1922fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner/// the type. This takes off typedefs, typeof's etc. If the outer level of 1932fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner/// the type is already concrete, it returns it unmodified. This is similar 1942fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner/// to getting the canonical type, but it doesn't remove *all* typedefs. For 1952fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner/// example, it returns "T*" as "T*", (not as "int*"), because the pointer is 1962fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner/// concrete. 1974ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualType QualType::getDesugaredType(QualType T, const ASTContext &Context) { 19849f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall SplitQualType split = getSplitDesugaredType(T); 19949f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall return Context.getQualifiedType(split.first, split.second); 20049f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall} 20149f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall 20249f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCallSplitQualType QualType::getSplitDesugaredType(QualType T) { 2030953e767ff7817f97b3ab20896b229891eeff45bJohn McCall QualifierCollector Qs; 204c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner 205bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType Cur = T; 206bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall while (true) { 207bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall const Type *CurTy = Qs.strip(Cur); 208bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall switch (CurTy->getTypeClass()) { 209bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall#define ABSTRACT_TYPE(Class, Parent) 210bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall#define TYPE(Class, Parent) \ 211bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall case Type::Class: { \ 212bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall const Class##Type *Ty = cast<Class##Type>(CurTy); \ 213bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall if (!Ty->isSugared()) \ 21449f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall return SplitQualType(Ty, Qs); \ 215bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall Cur = Ty->desugar(); \ 216bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall break; \ 217bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall } 218bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall#include "clang/AST/TypeNodes.def" 219bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall } 220969c689d893a248eca4f049f5b89f747e66e4bffDouglas Gregor } 221bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall} 2225cdf82164dd7c2b2320d6735c63ace4331e0716dDouglas Gregor 223075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo BagnaraQualType QualType::IgnoreParens(QualType T) { 224075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara while (const ParenType *PT = T->getAs<ParenType>()) 225075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara T = PT->getInnerType(); 226075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara return T; 227075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara} 228075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 229bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall/// getUnqualifiedDesugaredType - Pull any qualifiers and syntactic 230bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall/// sugar off the given type. This should produce an object of the 231bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall/// same dynamic type as the canonical type. 232bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCallconst Type *Type::getUnqualifiedDesugaredType() const { 233bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall const Type *Cur = this; 234bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 235bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall while (true) { 236bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall switch (Cur->getTypeClass()) { 237bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall#define ABSTRACT_TYPE(Class, Parent) 238bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall#define TYPE(Class, Parent) \ 239bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall case Class: { \ 240bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall const Class##Type *Ty = cast<Class##Type>(Cur); \ 241bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall if (!Ty->isSugared()) return Cur; \ 242bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall Cur = Ty->desugar().getTypePtr(); \ 243bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall break; \ 244bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall } 245bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall#include "clang/AST/TypeNodes.def" 246bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall } 247bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall } 248c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner} 249c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner 2505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// isVoidType - Helper method to determine if this is the 'void' type. 2515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isVoidType() const { 2525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 2535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return BT->getKind() == BuiltinType::Void; 2545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return false; 2555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 2565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isDerivedType() const { 2585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer switch (CanonicalType->getTypeClass()) { 2595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Pointer: 260fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff case VariableArray: 261fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff case ConstantArray: 262c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman case IncompleteArray: 2635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case FunctionProto: 2645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case FunctionNoProto: 2657c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl case LValueReference: 2667c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl case RValueReference: 26772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor case Record: 2685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return true; 2695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer default: 2705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return false; 2715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 2735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 27499dc91422144483c20d1c7381bc9ac634b646b04Chris Lattnerbool Type::isClassType() const { 2756217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const RecordType *RT = getAs<RecordType>()) 276f728a4a05df2455e1c6e62173ab720a92cd4a074Chris Lattner return RT->getDecl()->isClass(); 27799dc91422144483c20d1c7381bc9ac634b646b04Chris Lattner return false; 27899dc91422144483c20d1c7381bc9ac634b646b04Chris Lattner} 279c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattnerbool Type::isStructureType() const { 2806217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const RecordType *RT = getAs<RecordType>()) 281f728a4a05df2455e1c6e62173ab720a92cd4a074Chris Lattner return RT->getDecl()->isStruct(); 282c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner return false; 283c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner} 284fb87b89fc9eb103e19fb8e4b925c23f0bd091b99Douglas Gregorbool Type::isStructureOrClassType() const { 285fb87b89fc9eb103e19fb8e4b925c23f0bd091b99Douglas Gregor if (const RecordType *RT = getAs<RecordType>()) 286fb87b89fc9eb103e19fb8e4b925c23f0bd091b99Douglas Gregor return RT->getDecl()->isStruct() || RT->getDecl()->isClass(); 287fb87b89fc9eb103e19fb8e4b925c23f0bd091b99Douglas Gregor return false; 288fb87b89fc9eb103e19fb8e4b925c23f0bd091b99Douglas Gregor} 2897154a77e7c1f23418342d3b72836ab504aa7821eSteve Naroffbool Type::isVoidPointerType() const { 2906217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const PointerType *PT = getAs<PointerType>()) 2917154a77e7c1f23418342d3b72836ab504aa7821eSteve Naroff return PT->getPointeeType()->isVoidType(); 2927154a77e7c1f23418342d3b72836ab504aa7821eSteve Naroff return false; 2937154a77e7c1f23418342d3b72836ab504aa7821eSteve Naroff} 2947154a77e7c1f23418342d3b72836ab504aa7821eSteve Naroff 295c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattnerbool Type::isUnionType() const { 2966217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const RecordType *RT = getAs<RecordType>()) 297f728a4a05df2455e1c6e62173ab720a92cd4a074Chris Lattner return RT->getDecl()->isUnion(); 298c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner return false; 299c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner} 300c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner 301c6fb90a7246c2d5d3233e70107bf9d8c7c9e535bChris Lattnerbool Type::isComplexType() const { 30202f62a9fedbc370fba081303399410a3afdde29fSteve Naroff if (const ComplexType *CT = dyn_cast<ComplexType>(CanonicalType)) 30302f62a9fedbc370fba081303399410a3afdde29fSteve Naroff return CT->getElementType()->isFloatingType(); 30402f62a9fedbc370fba081303399410a3afdde29fSteve Naroff return false; 305c6fb90a7246c2d5d3233e70107bf9d8c7c9e535bChris Lattner} 306c6fb90a7246c2d5d3233e70107bf9d8c7c9e535bChris Lattner 3074cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroffbool Type::isComplexIntegerType() const { 3084cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroff // Check for GCC complex integer extension. 3090953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return getAsComplexIntegerType(); 3104cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroff} 3114cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroff 3124cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroffconst ComplexType *Type::getAsComplexIntegerType() const { 3130953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (const ComplexType *Complex = getAs<ComplexType>()) 3140953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (Complex->getElementType()->isIntegerType()) 3150953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return Complex; 3160953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return 0; 3174cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroff} 3184cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroff 31914108da7f7fc059772711e4ffee1322a27b152a7Steve NaroffQualType Type::getPointeeType() const { 3206217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const PointerType *PT = getAs<PointerType>()) 32114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return PT->getPointeeType(); 322183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) 32314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return OPT->getPointeeType(); 3246217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const BlockPointerType *BPT = getAs<BlockPointerType>()) 32514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return BPT->getPointeeType(); 3269c21289a866b677d21ed3d5ecfdfd5ced5a55410Mike Stump if (const ReferenceType *RT = getAs<ReferenceType>()) 3279c21289a866b677d21ed3d5ecfdfd5ced5a55410Mike Stump return RT->getPointeeType(); 32814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return QualType(); 32914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff} 330b77792eabf5882cf9af8cc810599b20432fda6c2Chris Lattner 331c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattnerconst RecordType *Type::getAsStructureType() const { 3327064f5c95bbdb17680d0ea658d4090898c2592d3Steve Naroff // If this is directly a structure type, return it. 333c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner if (const RecordType *RT = dyn_cast<RecordType>(this)) { 33439ba4aeca296b1c9f04bde7d9d3cbbf129f1abd3Argyrios Kyrtzidis if (RT->getDecl()->isStruct()) 335c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner return RT; 3367064f5c95bbdb17680d0ea658d4090898c2592d3Steve Naroff } 337dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner 338dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner // If the canonical form of this type isn't the right kind, reject it. 339c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner if (const RecordType *RT = dyn_cast<RecordType>(CanonicalType)) { 34039ba4aeca296b1c9f04bde7d9d3cbbf129f1abd3Argyrios Kyrtzidis if (!RT->getDecl()->isStruct()) 341dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner return 0; 3421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 343dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner // If this is a typedef for a structure type, strip the typedef off without 344dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner // losing all typedef information. 345bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall return cast<RecordType>(getUnqualifiedDesugaredType()); 3465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 3477064f5c95bbdb17680d0ea658d4090898c2592d3Steve Naroff return 0; 3485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 3495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpconst RecordType *Type::getAsUnionType() const { 3517064f5c95bbdb17680d0ea658d4090898c2592d3Steve Naroff // If this is directly a union type, return it. 352c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner if (const RecordType *RT = dyn_cast<RecordType>(this)) { 35339ba4aeca296b1c9f04bde7d9d3cbbf129f1abd3Argyrios Kyrtzidis if (RT->getDecl()->isUnion()) 354c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner return RT; 3557064f5c95bbdb17680d0ea658d4090898c2592d3Steve Naroff } 3561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 357dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner // If the canonical form of this type isn't the right kind, reject it. 358c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner if (const RecordType *RT = dyn_cast<RecordType>(CanonicalType)) { 35939ba4aeca296b1c9f04bde7d9d3cbbf129f1abd3Argyrios Kyrtzidis if (!RT->getDecl()->isUnion()) 360dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner return 0; 361dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner 362dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner // If this is a typedef for a union type, strip the typedef off without 363dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner // losing all typedef information. 364bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall return cast<RecordType>(getUnqualifiedDesugaredType()); 3655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 3661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3677064f5c95bbdb17680d0ea658d4090898c2592d3Steve Naroff return 0; 3685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 3695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 370c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallObjCObjectType::ObjCObjectType(QualType Canonical, QualType Base, 371c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCProtocolDecl * const *Protocols, 372c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall unsigned NumProtocols) 373d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor : Type(ObjCObject, Canonical, false, false, false), 374d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor BaseType(Base) 375d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor{ 376b870b88df784c2940efce448ebfaf54dece14666John McCall ObjCObjectTypeBits.NumProtocols = NumProtocols; 37771c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall assert(getNumProtocols() == NumProtocols && 378c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall "bitfield overflow in protocol count"); 379fd6a0887a099256c35a5b23e9afd517ffe95fa0aDouglas Gregor if (NumProtocols) 380c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall memcpy(getProtocolStorage(), Protocols, 381c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall NumProtocols * sizeof(ObjCProtocolDecl*)); 38271842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek} 38371842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek 384c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallconst ObjCObjectType *Type::getAsObjCQualifiedInterfaceType() const { 385c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall // There is no sugar for ObjCObjectType's, just return the canonical 386c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff // type pointer if it is the right class. There is no typedef information to 387c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff // return and these cannot be Address-space qualified. 388c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall if (const ObjCObjectType *T = getAs<ObjCObjectType>()) 389c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall if (T->getNumProtocols() && T->getInterface()) 390c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return T; 391c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff return 0; 392c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff} 393c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff 394c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroffbool Type::isObjCQualifiedInterfaceType() const { 395e61ad0b7063fcd97204b1cce5558685144267eb6Steve Naroff return getAsObjCQualifiedInterfaceType() != 0; 396c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff} 397c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff 398d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroffconst ObjCObjectPointerType *Type::getAsObjCQualifiedIdType() const { 399eca7be6b7ebd93682eeaab2c71d59f2995dacdccChris Lattner // There is no sugar for ObjCQualifiedIdType's, just return the canonical 400eca7be6b7ebd93682eeaab2c71d59f2995dacdccChris Lattner // type pointer if it is the right class. 401183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) { 402d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff if (OPT->isObjCQualifiedIdType()) 403d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff return OPT; 404d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff } 405d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff return 0; 406368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner} 407368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner 40814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroffconst ObjCObjectPointerType *Type::getAsObjCInterfacePointerType() const { 409183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) { 41014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff if (OPT->getInterfaceType()) 41114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return OPT; 41214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff } 41314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return 0; 41414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff} 41514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff 416a91d6a6619a91d0ca7102d8ab5678d855f04d850Fariborz Jahanianconst CXXRecordDecl *Type::getCXXRecordDeclForPointerType() const { 4176217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const PointerType *PT = getAs<PointerType>()) 4186217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const RecordType *RT = PT->getPointeeType()->getAs<RecordType>()) 419a91d6a6619a91d0ca7102d8ab5678d855f04d850Fariborz Jahanian return dyn_cast<CXXRecordDecl>(RT->getDecl()); 420a91d6a6619a91d0ca7102d8ab5678d855f04d850Fariborz Jahanian return 0; 421a91d6a6619a91d0ca7102d8ab5678d855f04d850Fariborz Jahanian} 422a91d6a6619a91d0ca7102d8ab5678d855f04d850Fariborz Jahanian 423c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas GregorCXXRecordDecl *Type::getAsCXXRecordDecl() const { 424c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor if (const RecordType *RT = getAs<RecordType>()) 425c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor return dyn_cast<CXXRecordDecl>(RT->getDecl()); 426c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor else if (const InjectedClassNameType *Injected 427c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor = getAs<InjectedClassNameType>()) 428c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor return Injected->getDecl(); 429c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor 430c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor return 0; 431c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor} 432c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor 4335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isIntegerType() const { 4345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 4355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return BT->getKind() >= BuiltinType::Bool && 4362df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner BT->getKind() <= BuiltinType::Int128; 4371274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) 438834a72ac74cf4ff07ba6215545dba3db578f8a07Chris Lattner // Incomplete enum types are not treated as integer types. 4398e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor // FIXME: In C++, enum types are never integer types. 4401274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor return ET->getDecl()->isComplete(); 441f60946222721d9ba3c059563935c17b84703187aDouglas Gregor return false; 442f60946222721d9ba3c059563935c17b84703187aDouglas Gregor} 443f60946222721d9ba3c059563935c17b84703187aDouglas Gregor 444f60946222721d9ba3c059563935c17b84703187aDouglas Gregorbool Type::hasIntegerRepresentation() const { 445c63b96ad706e054a1390dd2ab53af9f05d33bbb1Steve Naroff if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType)) 446c63b96ad706e054a1390dd2ab53af9f05d33bbb1Steve Naroff return VT->getElementType()->isIntegerType(); 447f60946222721d9ba3c059563935c17b84703187aDouglas Gregor else 448f60946222721d9ba3c059563935c17b84703187aDouglas Gregor return isIntegerType(); 4495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 4505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4519d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// \brief Determine whether this type is an integral type. 4529d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// 4539d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// This routine determines whether the given type is an integral type per 4549d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// C++ [basic.fundamental]p7. Although the C standard does not define the 4559d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// term "integral type", it has a similar term "integer type", and in C++ 4569d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// the two terms are equivalent. However, C's "integer type" includes 4579d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// enumeration types, while C++'s "integer type" does not. The \c ASTContext 4589d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// parameter is used to determine whether we should be following the C or 4599d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// C++ rules when determining whether this type is an integral/integer type. 4609d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// 4619d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// For cases where C permits "an integer type" and C++ permits "an integral 4629d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// type", use this routine. 4639d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// 4649d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// For cases where C permits "an integer type" and C++ permits "an integral 4659d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// or enumeration type", use \c isIntegralOrEnumerationType() instead. 4669d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// 4679d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// \param Ctx The context in which this type occurs. 4689d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// 4699d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// \returns true if the type is considered an integral type, false otherwise. 4709d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregorbool Type::isIntegralType(ASTContext &Ctx) const { 47133e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 47233e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian return BT->getKind() >= BuiltinType::Bool && 473f5f7d864f5067d1ea4bff7fcf41b53a43b7b48baAnders Carlsson BT->getKind() <= BuiltinType::Int128; 4749d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor 4759d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor if (!Ctx.getLangOptions().CPlusPlus) 4761274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) 4771274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor return ET->getDecl()->isComplete(); // Complete enum types are integral in C. 4789d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor 47933e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian return false; 48033e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian} 48133e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian 4822ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregorbool Type::isIntegralOrEnumerationType() const { 4832ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 4842ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor return BT->getKind() >= BuiltinType::Bool && 4852ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor BT->getKind() <= BuiltinType::Int128; 48634fd628d22f54baddf30cf80c401b2f862a31b23Eli Friedman 48734fd628d22f54baddf30cf80c401b2f862a31b23Eli Friedman // Check for a complete enum type; incomplete enum types are not properly an 48834fd628d22f54baddf30cf80c401b2f862a31b23Eli Friedman // enumeration type in the sense required here. 4891274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) 4901274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor return ET->getDecl()->isComplete(); 49134fd628d22f54baddf30cf80c401b2f862a31b23Eli Friedman 4922ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor return false; 4932ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor} 4942ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor 4951274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregorbool Type::isIntegralOrUnscopedEnumerationType() const { 4961274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 4971274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor return BT->getKind() >= BuiltinType::Bool && 4981274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor BT->getKind() <= BuiltinType::Int128; 4991274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor 5001274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor // Check for a complete enum type; incomplete enum types are not properly an 5011274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor // enumeration type in the sense required here. 5021274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor // C++0x: However, if the underlying type of the enum is fixed, it is 5031274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor // considered complete. 5041274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) 5051274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor return ET->getDecl()->isComplete() && !ET->getDecl()->isScoped(); 5061274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor 5071274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor return false; 5081274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor} 5091274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor 5101274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor 51113b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroffbool Type::isBooleanType() const { 51213b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 51313b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff return BT->getKind() == BuiltinType::Bool; 51413b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff return false; 51513b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff} 51613b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff 51713b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroffbool Type::isCharType() const { 51813b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 51913b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff return BT->getKind() == BuiltinType::Char_U || 52013b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff BT->getKind() == BuiltinType::UChar || 521c67ad5f299bb2c09e4567def8ff0d34bd15a42fdAnders Carlsson BT->getKind() == BuiltinType::Char_S || 522c67ad5f299bb2c09e4567def8ff0d34bd15a42fdAnders Carlsson BT->getKind() == BuiltinType::SChar; 52313b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff return false; 52413b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff} 52513b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff 52677a52233f7c0f162672652051bfe78b65ad4f789Douglas Gregorbool Type::isWideCharType() const { 52777a52233f7c0f162672652051bfe78b65ad4f789Douglas Gregor if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 5283f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner return BT->getKind() == BuiltinType::WChar_S || 5293f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner BT->getKind() == BuiltinType::WChar_U; 53077a52233f7c0f162672652051bfe78b65ad4f789Douglas Gregor return false; 53177a52233f7c0f162672652051bfe78b65ad4f789Douglas Gregor} 53277a52233f7c0f162672652051bfe78b65ad4f789Douglas Gregor 53320093b4bf698f292c664676987541d5103b65b15Douglas Gregor/// \brief Determine whether this type is any of the built-in character 53420093b4bf698f292c664676987541d5103b65b15Douglas Gregor/// types. 53520093b4bf698f292c664676987541d5103b65b15Douglas Gregorbool Type::isAnyCharacterType() const { 5363f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType); 5373f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner if (BT == 0) return false; 5383f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner switch (BT->getKind()) { 5393f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner default: return false; 5403f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner case BuiltinType::Char_U: 5413f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner case BuiltinType::UChar: 5423f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner case BuiltinType::WChar_U: 5433f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner case BuiltinType::Char16: 5443f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner case BuiltinType::Char32: 5453f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner case BuiltinType::Char_S: 5463f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner case BuiltinType::SChar: 5473f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner case BuiltinType::WChar_S: 5483f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner return true; 5493f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner } 55020093b4bf698f292c664676987541d5103b65b15Douglas Gregor} 55120093b4bf698f292c664676987541d5103b65b15Douglas Gregor 552d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner/// isSignedIntegerType - Return true if this is an integer type that is 553d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner/// signed, according to C99 6.2.5p4 [char, signed char, short, int, long..], 554f60946222721d9ba3c059563935c17b84703187aDouglas Gregor/// an enum decl which has a signed representation 5555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isSignedIntegerType() const { 5565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) { 5575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return BT->getKind() >= BuiltinType::Char_S && 558f5f7d864f5067d1ea4bff7fcf41b53a43b7b48baAnders Carlsson BT->getKind() <= BuiltinType::Int128; 5595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 5601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 561bbd340717422bf011d56cd0164d2576601368111Fariborz Jahanian if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) { 562bbd340717422bf011d56cd0164d2576601368111Fariborz Jahanian // Incomplete enum types are not treated as integer types. 563bbd340717422bf011d56cd0164d2576601368111Fariborz Jahanian // FIXME: In C++, enum types are never integer types. 564bbd340717422bf011d56cd0164d2576601368111Fariborz Jahanian if (ET->getDecl()->isComplete()) 565bbd340717422bf011d56cd0164d2576601368111Fariborz Jahanian return ET->getDecl()->getIntegerType()->isSignedIntegerType(); 566bbd340717422bf011d56cd0164d2576601368111Fariborz Jahanian } 5671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 568f60946222721d9ba3c059563935c17b84703187aDouglas Gregor return false; 569f60946222721d9ba3c059563935c17b84703187aDouglas Gregor} 570f60946222721d9ba3c059563935c17b84703187aDouglas Gregor 571f60946222721d9ba3c059563935c17b84703187aDouglas Gregorbool Type::hasSignedIntegerRepresentation() const { 572c63b96ad706e054a1390dd2ab53af9f05d33bbb1Steve Naroff if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType)) 573c63b96ad706e054a1390dd2ab53af9f05d33bbb1Steve Naroff return VT->getElementType()->isSignedIntegerType(); 574f60946222721d9ba3c059563935c17b84703187aDouglas Gregor else 575f60946222721d9ba3c059563935c17b84703187aDouglas Gregor return isSignedIntegerType(); 5765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 5775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 578d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner/// isUnsignedIntegerType - Return true if this is an integer type that is 579d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner/// unsigned, according to C99 6.2.5p6 [which returns true for _Bool], an enum 580f60946222721d9ba3c059563935c17b84703187aDouglas Gregor/// decl which has an unsigned representation 5815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isUnsignedIntegerType() const { 5825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) { 5835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return BT->getKind() >= BuiltinType::Bool && 5841c03ca30ae962199ef702324b48550f6af7fdc32Anders Carlsson BT->getKind() <= BuiltinType::UInt128; 5855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 586d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner 587bbd340717422bf011d56cd0164d2576601368111Fariborz Jahanian if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) { 588bbd340717422bf011d56cd0164d2576601368111Fariborz Jahanian // Incomplete enum types are not treated as integer types. 589bbd340717422bf011d56cd0164d2576601368111Fariborz Jahanian // FIXME: In C++, enum types are never integer types. 590bbd340717422bf011d56cd0164d2576601368111Fariborz Jahanian if (ET->getDecl()->isComplete()) 591bbd340717422bf011d56cd0164d2576601368111Fariborz Jahanian return ET->getDecl()->getIntegerType()->isUnsignedIntegerType(); 592bbd340717422bf011d56cd0164d2576601368111Fariborz Jahanian } 593d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner 594f60946222721d9ba3c059563935c17b84703187aDouglas Gregor return false; 595f60946222721d9ba3c059563935c17b84703187aDouglas Gregor} 596f60946222721d9ba3c059563935c17b84703187aDouglas Gregor 597f60946222721d9ba3c059563935c17b84703187aDouglas Gregorbool Type::hasUnsignedIntegerRepresentation() const { 598c63b96ad706e054a1390dd2ab53af9f05d33bbb1Steve Naroff if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType)) 599c63b96ad706e054a1390dd2ab53af9f05d33bbb1Steve Naroff return VT->getElementType()->isUnsignedIntegerType(); 600f60946222721d9ba3c059563935c17b84703187aDouglas Gregor else 601f60946222721d9ba3c059563935c17b84703187aDouglas Gregor return isUnsignedIntegerType(); 6025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 6035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isFloatingType() const { 6055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 6065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return BT->getKind() >= BuiltinType::Float && 6075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer BT->getKind() <= BuiltinType::LongDouble; 6085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (const ComplexType *CT = dyn_cast<ComplexType>(CanonicalType)) 609729a2131228cb7fcbc00bd8af36bc6f14d12317dChris Lattner return CT->getElementType()->isFloatingType(); 6108eee119bf4f1693dde17b8552c1f9f81bf2b681eDouglas Gregor return false; 6118eee119bf4f1693dde17b8552c1f9f81bf2b681eDouglas Gregor} 6128eee119bf4f1693dde17b8552c1f9f81bf2b681eDouglas Gregor 6138eee119bf4f1693dde17b8552c1f9f81bf2b681eDouglas Gregorbool Type::hasFloatingRepresentation() const { 614c63b96ad706e054a1390dd2ab53af9f05d33bbb1Steve Naroff if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType)) 615c63b96ad706e054a1390dd2ab53af9f05d33bbb1Steve Naroff return VT->getElementType()->isFloatingType(); 6168eee119bf4f1693dde17b8552c1f9f81bf2b681eDouglas Gregor else 6178eee119bf4f1693dde17b8552c1f9f81bf2b681eDouglas Gregor return isFloatingType(); 6185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 6195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isRealFloatingType() const { 6215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 622680523a91dd3351389667c8de17121ba7ae82673John McCall return BT->isFloatingPoint(); 6235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return false; 6245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 6255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isRealType() const { 6275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 6285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return BT->getKind() >= BuiltinType::Bool && 6295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer BT->getKind() <= BuiltinType::LongDouble; 6301274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) 6311274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor return ET->getDecl()->isComplete() && !ET->getDecl()->isScoped(); 6325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return false; 6335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 6345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isArithmeticType() const { 6365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 637a7fbf7282eadebaf1293d9f970b01fb57f4b0ae4Douglas Gregor return BT->getKind() >= BuiltinType::Bool && 638a7fbf7282eadebaf1293d9f970b01fb57f4b0ae4Douglas Gregor BT->getKind() <= BuiltinType::LongDouble; 63937c1b78a20a09b0456aa5caa15e159027010ca22Chris Lattner if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) 64037c1b78a20a09b0456aa5caa15e159027010ca22Chris Lattner // GCC allows forward declaration of enum types (forbid by C99 6.7.2.3p2). 64137c1b78a20a09b0456aa5caa15e159027010ca22Chris Lattner // If a body isn't seen by the time we get here, return false. 6421274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor // 6431274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor // C++0x: Enumerations are not arithmetic types. For now, just return 6441274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor // false for scoped enumerations since that will disable any 6451274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor // unwanted implicit conversions. 6461274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor return !ET->getDecl()->isScoped() && ET->getDecl()->isComplete(); 64700619623af0b9d3271e31402ec1a95e84c2c4526Douglas Gregor return isa<ComplexType>(CanonicalType); 6485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 6495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isScalarType() const { 6515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 652daa8e4e888758d55a7a759dd4a91b83921cef222John McCall return BT->getKind() > BuiltinType::Void && 653daa8e4e888758d55a7a759dd4a91b83921cef222John McCall BT->getKind() <= BuiltinType::NullPtr; 6541274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) 655834a72ac74cf4ff07ba6215545dba3db578f8a07Chris Lattner // Enums are scalar types, but only if they are defined. Incomplete enums 656834a72ac74cf4ff07ba6215545dba3db578f8a07Chris Lattner // are not treated as scalar types. 6571274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor return ET->getDecl()->isComplete(); 6585618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff return isa<PointerType>(CanonicalType) || 6595618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff isa<BlockPointerType>(CanonicalType) || 660f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl isa<MemberPointerType>(CanonicalType) || 6615618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff isa<ComplexType>(CanonicalType) || 662d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff isa<ObjCObjectPointerType>(CanonicalType); 6635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 6645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 665daa8e4e888758d55a7a759dd4a91b83921cef222John McCallType::ScalarTypeKind Type::getScalarTypeKind() const { 666daa8e4e888758d55a7a759dd4a91b83921cef222John McCall assert(isScalarType()); 667daa8e4e888758d55a7a759dd4a91b83921cef222John McCall 668daa8e4e888758d55a7a759dd4a91b83921cef222John McCall const Type *T = CanonicalType.getTypePtr(); 669daa8e4e888758d55a7a759dd4a91b83921cef222John McCall if (const BuiltinType *BT = dyn_cast<BuiltinType>(T)) { 670daa8e4e888758d55a7a759dd4a91b83921cef222John McCall if (BT->getKind() == BuiltinType::Bool) return STK_Bool; 671daa8e4e888758d55a7a759dd4a91b83921cef222John McCall if (BT->getKind() == BuiltinType::NullPtr) return STK_Pointer; 672daa8e4e888758d55a7a759dd4a91b83921cef222John McCall if (BT->isInteger()) return STK_Integral; 673daa8e4e888758d55a7a759dd4a91b83921cef222John McCall if (BT->isFloatingPoint()) return STK_Floating; 674daa8e4e888758d55a7a759dd4a91b83921cef222John McCall llvm_unreachable("unknown scalar builtin type"); 675daa8e4e888758d55a7a759dd4a91b83921cef222John McCall } else if (isa<PointerType>(T) || 676daa8e4e888758d55a7a759dd4a91b83921cef222John McCall isa<BlockPointerType>(T) || 677daa8e4e888758d55a7a759dd4a91b83921cef222John McCall isa<ObjCObjectPointerType>(T)) { 678daa8e4e888758d55a7a759dd4a91b83921cef222John McCall return STK_Pointer; 679daa8e4e888758d55a7a759dd4a91b83921cef222John McCall } else if (isa<MemberPointerType>(T)) { 680daa8e4e888758d55a7a759dd4a91b83921cef222John McCall return STK_MemberPointer; 681daa8e4e888758d55a7a759dd4a91b83921cef222John McCall } else if (isa<EnumType>(T)) { 682daa8e4e888758d55a7a759dd4a91b83921cef222John McCall assert(cast<EnumType>(T)->getDecl()->isComplete()); 683daa8e4e888758d55a7a759dd4a91b83921cef222John McCall return STK_Integral; 684daa8e4e888758d55a7a759dd4a91b83921cef222John McCall } else if (const ComplexType *CT = dyn_cast<ComplexType>(T)) { 685daa8e4e888758d55a7a759dd4a91b83921cef222John McCall if (CT->getElementType()->isRealFloatingType()) 686daa8e4e888758d55a7a759dd4a91b83921cef222John McCall return STK_FloatingComplex; 687daa8e4e888758d55a7a759dd4a91b83921cef222John McCall return STK_IntegralComplex; 688daa8e4e888758d55a7a759dd4a91b83921cef222John McCall } 689daa8e4e888758d55a7a759dd4a91b83921cef222John McCall 690daa8e4e888758d55a7a759dd4a91b83921cef222John McCall llvm_unreachable("unknown scalar type"); 691daa8e4e888758d55a7a759dd4a91b83921cef222John McCall return STK_Pointer; 692daa8e4e888758d55a7a759dd4a91b83921cef222John McCall} 693daa8e4e888758d55a7a759dd4a91b83921cef222John McCall 694d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor/// \brief Determines whether the type is a C++ aggregate type or C 695d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor/// aggregate or union type. 696d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor/// 697d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor/// An aggregate type is an array or a class type (struct, union, or 698d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor/// class) that has no user-declared constructors, no private or 699d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor/// protected non-static data members, no base classes, and no virtual 700d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor/// functions (C++ [dcl.init.aggr]p1). The notion of an aggregate type 701d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor/// subsumes the notion of C aggregates (C99 6.2.5p21) because it also 702d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor/// includes union types. 7035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isAggregateType() const { 704c1efaecf0373f1a55c5ef4c234357cf726fc0600Douglas Gregor if (const RecordType *Record = dyn_cast<RecordType>(CanonicalType)) { 705c1efaecf0373f1a55c5ef4c234357cf726fc0600Douglas Gregor if (CXXRecordDecl *ClassDecl = dyn_cast<CXXRecordDecl>(Record->getDecl())) 706c1efaecf0373f1a55c5ef4c234357cf726fc0600Douglas Gregor return ClassDecl->isAggregate(); 707c1efaecf0373f1a55c5ef4c234357cf726fc0600Douglas Gregor 708d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor return true; 709c1efaecf0373f1a55c5ef4c234357cf726fc0600Douglas Gregor } 710c1efaecf0373f1a55c5ef4c234357cf726fc0600Douglas Gregor 711c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman return isa<ArrayType>(CanonicalType); 7125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 7135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7149bfa73c5ab7bf4b0e749d04f29da6884e8d5bd9fChris Lattner/// isConstantSizeType - Return true if this is not a variable sized type, 7159bfa73c5ab7bf4b0e749d04f29da6884e8d5bd9fChris Lattner/// according to the rules of C99 6.7.5p3. It is not legal to call this on 716898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// incomplete types or dependent types. 7173c2b3170041f69a92904e3bab9b6d654eaf260acEli Friedmanbool Type::isConstantSizeType() const { 718d52a4578144ab2887912e52eabec58a857a44adbChris Lattner assert(!isIncompleteType() && "This doesn't make sense for incomplete types"); 719898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor assert(!isDependentType() && "This doesn't make sense for dependent types"); 7209bfa73c5ab7bf4b0e749d04f29da6884e8d5bd9fChris Lattner // The VAT must have a size, as it is known to be complete. 7219bfa73c5ab7bf4b0e749d04f29da6884e8d5bd9fChris Lattner return !isa<VariableArrayType>(CanonicalType); 7225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 7235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// isIncompleteType - Return true if this is an incomplete type (C99 6.2.5p1) 7255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// - a type that can describe objects, but which lacks information needed to 7265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// determine its size. 7271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpbool Type::isIncompleteType() const { 7281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump switch (CanonicalType->getTypeClass()) { 7295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer default: return false; 7305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Builtin: 7315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Void is the only incomplete builtin type. Per C99 6.2.5p19, it can never 7325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // be completed. 7335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return isVoidType(); 73472564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor case Enum: 7351274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor // An enumeration with fixed underlying type is complete (C++0x 7.2p3). 7361274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor if (cast<EnumType>(CanonicalType)->getDecl()->isFixed()) 7371274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor return false; 7381274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor // Fall through. 7391274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor case Record: 7405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // A tagged type (struct/union/enum/class) is incomplete if the decl is a 7415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // forward declaration, but not a full definition (C99 6.2.5p22). 7425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return !cast<TagType>(CanonicalType)->getDecl()->isDefinition(); 743923d56d436f750bc1f29db50e641078725558a1bSebastian Redl case ConstantArray: 744923d56d436f750bc1f29db50e641078725558a1bSebastian Redl // An array is incomplete if its element type is incomplete 745923d56d436f750bc1f29db50e641078725558a1bSebastian Redl // (C++ [dcl.array]p1). 746923d56d436f750bc1f29db50e641078725558a1bSebastian Redl // We don't handle variable arrays (they're not allowed in C++) or 747923d56d436f750bc1f29db50e641078725558a1bSebastian Redl // dependent-sized arrays (dependent types are never treated as incomplete). 748923d56d436f750bc1f29db50e641078725558a1bSebastian Redl return cast<ArrayType>(CanonicalType)->getElementType()->isIncompleteType(); 749c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman case IncompleteArray: 7505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // An array of unknown size is an incomplete type (C99 6.2.5p22). 751c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman return true; 752c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall case ObjCObject: 753d0221526bcc81f49eff5c992978176e83ada3bc7Douglas Gregor return cast<ObjCObjectType>(CanonicalType)->getBaseType() 754d0221526bcc81f49eff5c992978176e83ada3bc7Douglas Gregor ->isIncompleteType(); 7551efaa9594a81709a17658fd80ae7e783e1026407Chris Lattner case ObjCInterface: 7561efaa9594a81709a17658fd80ae7e783e1026407Chris Lattner // ObjC interfaces are incomplete if they are @class, not @interface. 757d0221526bcc81f49eff5c992978176e83ada3bc7Douglas Gregor return cast<ObjCInterfaceType>(CanonicalType)->getDecl()->isForwardDecl(); 7585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 7595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 7605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 76164b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl/// isPODType - Return true if this is a plain-old-data type (C++ 3.9p10) 76264b45f7e0d3167f040841ac2920aead7f080730dSebastian Redlbool Type::isPODType() const { 76364b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl // The compiler shouldn't query this for incomplete types, but the user might. 764607a1788d9529c8e8494ac528764aa2c678a1a97Sebastian Redl // We return false for that case. Except for incomplete arrays of PODs, which 765607a1788d9529c8e8494ac528764aa2c678a1a97Sebastian Redl // are PODs according to the standard. 766607a1788d9529c8e8494ac528764aa2c678a1a97Sebastian Redl if (isIncompleteArrayType() && 767607a1788d9529c8e8494ac528764aa2c678a1a97Sebastian Redl cast<ArrayType>(CanonicalType)->getElementType()->isPODType()) 768607a1788d9529c8e8494ac528764aa2c678a1a97Sebastian Redl return true; 76964b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl if (isIncompleteType()) 77064b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl return false; 77164b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 77264b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl switch (CanonicalType->getTypeClass()) { 77364b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl // Everything not explicitly mentioned is not POD. 77464b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl default: return false; 77564b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl case VariableArray: 77664b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl case ConstantArray: 777607a1788d9529c8e8494ac528764aa2c678a1a97Sebastian Redl // IncompleteArray is handled above. 77864b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl return cast<ArrayType>(CanonicalType)->getElementType()->isPODType(); 77964b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 78064b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl case Builtin: 78164b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl case Complex: 78264b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl case Pointer: 783f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl case MemberPointer: 78464b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl case Vector: 78564b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl case ExtVector: 786d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff case ObjCObjectPointer: 7872263f822c31d0855ca8c48bfd9624322bf776f0bFariborz Jahanian case BlockPointer: 78864b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl return true; 78964b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 79072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor case Enum: 79172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor return true; 79272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor 79372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor case Record: 7941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (CXXRecordDecl *ClassDecl 795c1efaecf0373f1a55c5ef4c234357cf726fc0600Douglas Gregor = dyn_cast<CXXRecordDecl>(cast<RecordType>(CanonicalType)->getDecl())) 796c1efaecf0373f1a55c5ef4c234357cf726fc0600Douglas Gregor return ClassDecl->isPOD(); 797c1efaecf0373f1a55c5ef4c234357cf726fc0600Douglas Gregor 79864b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl // C struct/union is POD. 79964b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl return true; 80064b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl } 80164b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl} 80264b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 803ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redlbool Type::isLiteralType() const { 804ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl if (isIncompleteType()) 805ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl return false; 806ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl 807ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl // C++0x [basic.types]p10: 808ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl // A type is a literal type if it is: 809ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl switch (CanonicalType->getTypeClass()) { 810ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl // We're whitelisting 811ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl default: return false; 812ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl 813ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl // -- a scalar type 814ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl case Builtin: 815ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl case Complex: 816ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl case Pointer: 817ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl case MemberPointer: 818ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl case Vector: 819ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl case ExtVector: 820ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl case ObjCObjectPointer: 821ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl case Enum: 822ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl return true; 823ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl 824ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl // -- a class type with ... 825ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl case Record: 826ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl // FIXME: Do the tests 827ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl return false; 828ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl 829ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl // -- an array of literal type 830ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl // Extension: variable arrays cannot be literal types, since they're 831ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl // runtime-sized. 832ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl case ConstantArray: 833ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl return cast<ArrayType>(CanonicalType)->getElementType()->isLiteralType(); 834ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl } 835ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl} 836ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl 8375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isPromotableIntegerType() const { 838183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const BuiltinType *BT = getAs<BuiltinType>()) 8392a18dfe292cf3c406a769c3672080970ac586345Chris Lattner switch (BT->getKind()) { 8402a18dfe292cf3c406a769c3672080970ac586345Chris Lattner case BuiltinType::Bool: 8412a18dfe292cf3c406a769c3672080970ac586345Chris Lattner case BuiltinType::Char_S: 8422a18dfe292cf3c406a769c3672080970ac586345Chris Lattner case BuiltinType::Char_U: 8432a18dfe292cf3c406a769c3672080970ac586345Chris Lattner case BuiltinType::SChar: 8442a18dfe292cf3c406a769c3672080970ac586345Chris Lattner case BuiltinType::UChar: 8452a18dfe292cf3c406a769c3672080970ac586345Chris Lattner case BuiltinType::Short: 8462a18dfe292cf3c406a769c3672080970ac586345Chris Lattner case BuiltinType::UShort: 8472a18dfe292cf3c406a769c3672080970ac586345Chris Lattner return true; 8481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump default: 8492a18dfe292cf3c406a769c3672080970ac586345Chris Lattner return false; 8502a18dfe292cf3c406a769c3672080970ac586345Chris Lattner } 851aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor 852aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor // Enumerated types are promotable to their compatible integer types 853aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor // (C99 6.3.1.1) a.k.a. its underlying type (C++ [conv.prom]p2). 854aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor if (const EnumType *ET = getAs<EnumType>()){ 8551274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor if (this->isDependentType() || ET->getDecl()->getPromotionType().isNull() 8561274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor || ET->getDecl()->isScoped()) 857aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor return false; 858aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor 859aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor const BuiltinType *BT 860aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor = ET->getDecl()->getPromotionType()->getAs<BuiltinType>(); 861aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor return BT->getKind() == BuiltinType::Int 862aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor || BT->getKind() == BuiltinType::UInt; 863aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor } 864aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor 8652a18dfe292cf3c406a769c3672080970ac586345Chris Lattner return false; 8665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 8675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8686e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redlbool Type::isNullPtrType() const { 869183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const BuiltinType *BT = getAs<BuiltinType>()) 8706e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl return BT->getKind() == BuiltinType::NullPtr; 8716e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl return false; 8726e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl} 8736e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl 87422b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedmanbool Type::isSpecifierType() const { 87522b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman // Note that this intentionally does not use the canonical type. 87622b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman switch (getTypeClass()) { 87722b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman case Builtin: 87822b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman case Record: 87922b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman case Enum: 88022b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman case Typedef: 881c8f2c61f4f667c2bc3e4e74b274fa397a4232393Eli Friedman case Complex: 882c8f2c61f4f667c2bc3e4e74b274fa397a4232393Eli Friedman case TypeOfExpr: 883c8f2c61f4f667c2bc3e4e74b274fa397a4232393Eli Friedman case TypeOf: 884c8f2c61f4f667c2bc3e4e74b274fa397a4232393Eli Friedman case TemplateTypeParm: 88549a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall case SubstTemplateTypeParm: 886c8f2c61f4f667c2bc3e4e74b274fa397a4232393Eli Friedman case TemplateSpecialization: 887465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case Elaborated: 8884714c12a1ab759156b78be8f109ea4c12213af57Douglas Gregor case DependentName: 88933500955d731c73717af52088b7fc0e7a85681e7John McCall case DependentTemplateSpecialization: 890c8f2c61f4f667c2bc3e4e74b274fa397a4232393Eli Friedman case ObjCInterface: 891c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall case ObjCObject: 892c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall case ObjCObjectPointer: // FIXME: object pointers aren't really specifiers 89322b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman return true; 89422b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman default: 89522b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman return false; 89622b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman } 89722b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman} 89822b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman 899465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraElaboratedTypeKeyword 900465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraTypeWithKeyword::getKeywordForTypeSpec(unsigned TypeSpec) { 901465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara switch (TypeSpec) { 902465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara default: return ETK_None; 903465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TST_typename: return ETK_Typename; 904465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TST_class: return ETK_Class; 905465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TST_struct: return ETK_Struct; 906465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TST_union: return ETK_Union; 907465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TST_enum: return ETK_Enum; 908465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara } 909465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara} 910465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 911465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraTagTypeKind 912465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraTypeWithKeyword::getTagTypeKindForTypeSpec(unsigned TypeSpec) { 913465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara switch(TypeSpec) { 914465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TST_class: return TTK_Class; 915465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TST_struct: return TTK_Struct; 916465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TST_union: return TTK_Union; 917465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TST_enum: return TTK_Enum; 918465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara } 9197907fad723a0f4764a2396df620d9c58725b3053Douglas Gregor 9207907fad723a0f4764a2396df620d9c58725b3053Douglas Gregor llvm_unreachable("Type specifier is not a tag type kind."); 9217907fad723a0f4764a2396df620d9c58725b3053Douglas Gregor return TTK_Union; 922465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara} 923465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 924465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraElaboratedTypeKeyword 925465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraTypeWithKeyword::getKeywordForTagTypeKind(TagTypeKind Kind) { 926465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara switch (Kind) { 927465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TTK_Class: return ETK_Class; 928465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TTK_Struct: return ETK_Struct; 929465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TTK_Union: return ETK_Union; 930465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TTK_Enum: return ETK_Enum; 931465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara } 932465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara llvm_unreachable("Unknown tag type kind."); 933465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara} 934465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 935465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraTagTypeKind 936465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraTypeWithKeyword::getTagTypeKindForKeyword(ElaboratedTypeKeyword Keyword) { 937465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara switch (Keyword) { 938465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Class: return TTK_Class; 939465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Struct: return TTK_Struct; 940465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Union: return TTK_Union; 941465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Enum: return TTK_Enum; 942465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_None: // Fall through. 943465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Typename: 944465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara llvm_unreachable("Elaborated type keyword is not a tag type kind."); 945465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara } 946465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara llvm_unreachable("Unknown elaborated type keyword."); 947465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara} 948465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 949465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnarabool 950465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraTypeWithKeyword::KeywordIsTagTypeKind(ElaboratedTypeKeyword Keyword) { 951465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara switch (Keyword) { 952465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_None: 953465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Typename: 954465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara return false; 955465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Class: 956465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Struct: 957465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Union: 958465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Enum: 9594033642464e8ba0982f88f34cffad808d247b393Douglas Gregor return true; 9604033642464e8ba0982f88f34cffad808d247b393Douglas Gregor } 961465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara llvm_unreachable("Unknown elaborated type keyword."); 962465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara} 963465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 964465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnaraconst char* 965465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraTypeWithKeyword::getKeywordName(ElaboratedTypeKeyword Keyword) { 966465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara switch (Keyword) { 967465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_None: return ""; 968465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Typename: return "typename"; 969465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Class: return "class"; 970465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Struct: return "struct"; 971465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Union: return "union"; 972465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Enum: return "enum"; 973465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara } 9747907fad723a0f4764a2396df620d9c58725b3053Douglas Gregor 9757907fad723a0f4764a2396df620d9c58725b3053Douglas Gregor llvm_unreachable("Unknown elaborated type keyword."); 9767907fad723a0f4764a2396df620d9c58725b3053Douglas Gregor return ""; 977465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara} 978465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 97933500955d731c73717af52088b7fc0e7a85681e7John McCallDependentTemplateSpecializationType::DependentTemplateSpecializationType( 980ef99001908e799c388f1363b1e607dad5f5b57d3John McCall ElaboratedTypeKeyword Keyword, 98133500955d731c73717af52088b7fc0e7a85681e7John McCall NestedNameSpecifier *NNS, const IdentifierInfo *Name, 98233500955d731c73717af52088b7fc0e7a85681e7John McCall unsigned NumArgs, const TemplateArgument *Args, 98333500955d731c73717af52088b7fc0e7a85681e7John McCall QualType Canon) 98435495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor : TypeWithKeyword(Keyword, DependentTemplateSpecialization, Canon, true, 985d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /*VariablyModified=*/false, 986d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor NNS->containsUnexpandedParameterPack()), 987ef99001908e799c388f1363b1e607dad5f5b57d3John McCall NNS(NNS), Name(Name), NumArgs(NumArgs) { 98833500955d731c73717af52088b7fc0e7a85681e7John McCall assert(NNS && NNS->isDependent() && 98933500955d731c73717af52088b7fc0e7a85681e7John McCall "DependentTemplateSpecializatonType requires dependent qualifier"); 990d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor for (unsigned I = 0; I != NumArgs; ++I) { 991d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor if (Args[I].containsUnexpandedParameterPack()) 992d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor setContainsUnexpandedParameterPack(); 993d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 99433500955d731c73717af52088b7fc0e7a85681e7John McCall new (&getArgBuffer()[I]) TemplateArgument(Args[I]); 995d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor } 99633500955d731c73717af52088b7fc0e7a85681e7John McCall} 99733500955d731c73717af52088b7fc0e7a85681e7John McCall 99833500955d731c73717af52088b7fc0e7a85681e7John McCallvoid 99933500955d731c73717af52088b7fc0e7a85681e7John McCallDependentTemplateSpecializationType::Profile(llvm::FoldingSetNodeID &ID, 10004ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad const ASTContext &Context, 100133500955d731c73717af52088b7fc0e7a85681e7John McCall ElaboratedTypeKeyword Keyword, 100233500955d731c73717af52088b7fc0e7a85681e7John McCall NestedNameSpecifier *Qualifier, 100333500955d731c73717af52088b7fc0e7a85681e7John McCall const IdentifierInfo *Name, 100433500955d731c73717af52088b7fc0e7a85681e7John McCall unsigned NumArgs, 100533500955d731c73717af52088b7fc0e7a85681e7John McCall const TemplateArgument *Args) { 100633500955d731c73717af52088b7fc0e7a85681e7John McCall ID.AddInteger(Keyword); 100733500955d731c73717af52088b7fc0e7a85681e7John McCall ID.AddPointer(Qualifier); 100833500955d731c73717af52088b7fc0e7a85681e7John McCall ID.AddPointer(Name); 100933500955d731c73717af52088b7fc0e7a85681e7John McCall for (unsigned Idx = 0; Idx < NumArgs; ++Idx) 101033500955d731c73717af52088b7fc0e7a85681e7John McCall Args[Idx].Profile(ID, Context); 101133500955d731c73717af52088b7fc0e7a85681e7John McCall} 101233500955d731c73717af52088b7fc0e7a85681e7John McCall 1013465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnarabool Type::isElaboratedTypeSpecifier() const { 1014465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara ElaboratedTypeKeyword Keyword; 1015465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara if (const ElaboratedType *Elab = dyn_cast<ElaboratedType>(this)) 1016465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara Keyword = Elab->getKeyword(); 1017465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara else if (const DependentNameType *DepName = dyn_cast<DependentNameType>(this)) 1018465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara Keyword = DepName->getKeyword(); 101933500955d731c73717af52088b7fc0e7a85681e7John McCall else if (const DependentTemplateSpecializationType *DepTST = 102033500955d731c73717af52088b7fc0e7a85681e7John McCall dyn_cast<DependentTemplateSpecializationType>(this)) 102133500955d731c73717af52088b7fc0e7a85681e7John McCall Keyword = DepTST->getKeyword(); 1022465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara else 1023465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara return false; 1024465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 1025465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara return TypeWithKeyword::KeywordIsTagTypeKind(Keyword); 10264033642464e8ba0982f88f34cffad808d247b393Douglas Gregor} 10274033642464e8ba0982f88f34cffad808d247b393Douglas Gregor 1028cd01f17358dc8ef19338c0e2321138dd0a6160d9Argyrios Kyrtzidisconst char *Type::getTypeClassName() const { 1029b870b88df784c2940efce448ebfaf54dece14666John McCall switch (TypeBits.TC) { 1030cd01f17358dc8ef19338c0e2321138dd0a6160d9Argyrios Kyrtzidis#define ABSTRACT_TYPE(Derived, Base) 1031cd01f17358dc8ef19338c0e2321138dd0a6160d9Argyrios Kyrtzidis#define TYPE(Derived, Base) case Derived: return #Derived; 1032cd01f17358dc8ef19338c0e2321138dd0a6160d9Argyrios Kyrtzidis#include "clang/AST/TypeNodes.def" 1033cd01f17358dc8ef19338c0e2321138dd0a6160d9Argyrios Kyrtzidis } 10347907fad723a0f4764a2396df620d9c58725b3053Douglas Gregor 10357907fad723a0f4764a2396df620d9c58725b3053Douglas Gregor llvm_unreachable("Invalid type class."); 10367907fad723a0f4764a2396df620d9c58725b3053Douglas Gregor return 0; 1037cd01f17358dc8ef19338c0e2321138dd0a6160d9Argyrios Kyrtzidis} 1038cd01f17358dc8ef19338c0e2321138dd0a6160d9Argyrios Kyrtzidis 1039e4f2142d00fa5fdb580c4e2413da91882d955381Chris Lattnerconst char *BuiltinType::getName(const LangOptions &LO) const { 10405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer switch (getKind()) { 10415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Void: return "void"; 1042e4f2142d00fa5fdb580c4e2413da91882d955381Chris Lattner case Bool: return LO.Bool ? "bool" : "_Bool"; 10435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Char_S: return "char"; 10445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Char_U: return "char"; 10455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case SChar: return "signed char"; 10465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Short: return "short"; 10475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Int: return "int"; 10485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Long: return "long"; 10495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case LongLong: return "long long"; 10502df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner case Int128: return "__int128_t"; 10515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case UChar: return "unsigned char"; 10525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case UShort: return "unsigned short"; 10535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case UInt: return "unsigned int"; 10545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case ULong: return "unsigned long"; 10555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case ULongLong: return "unsigned long long"; 10562df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner case UInt128: return "__uint128_t"; 10575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Float: return "float"; 10585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Double: return "double"; 10595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case LongDouble: return "long double"; 10603f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner case WChar_S: 10613f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner case WChar_U: return "wchar_t"; 1062f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith case Char16: return "char16_t"; 1063f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith case Char32: return "char32_t"; 10646e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl case NullPtr: return "nullptr_t"; 10658e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor case Overload: return "<overloaded function type>"; 1066898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor case Dependent: return "<dependent type>"; 10676a75cd9c1d54625fca7b5477ab9545bcdbd85ea4Anders Carlsson case UndeducedAuto: return "auto"; 1068de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff case ObjCId: return "id"; 1069de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff case ObjCClass: return "Class"; 1070bef0efd11bc4430a3ee437a3213cec5c18af855aChris Lattner case ObjCSel: return "SEL"; 10715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 10727907fad723a0f4764a2396df620d9c58725b3053Douglas Gregor 1073aab440b2cb0e583aeaf21f08c8247456f3142a23Nick Lewycky llvm_unreachable("Invalid builtin type."); 1074aab440b2cb0e583aeaf21f08c8247456f3142a23Nick Lewycky return 0; 10755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 10765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10776398235d7890a81b785ea5af3b6e66d86bf184ccDouglas GregorQualType QualType::getNonLValueExprType(ASTContext &Context) const { 10785291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor if (const ReferenceType *RefType = getTypePtr()->getAs<ReferenceType>()) 10795291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor return RefType->getPointeeType(); 10805291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor 10815291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor // C++0x [basic.lval]: 10825291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor // Class prvalues can have cv-qualified types; non-class prvalues always 10835291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor // have cv-unqualified types. 10845291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor // 10855291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor // See also C99 6.3.2.1p2. 10865291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor if (!Context.getLangOptions().CPlusPlus || 10876dc1ef87044e6b177d4df0d2b593a94616180b3dChandler Carruth (!getTypePtr()->isDependentType() && !getTypePtr()->isRecordType())) 10885291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor return getUnqualifiedType(); 10895291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor 10905291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor return *this; 10915291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor} 10925291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor 109304a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCallllvm::StringRef FunctionType::getNameForCallConv(CallingConv CC) { 109404a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall switch (CC) { 10957907fad723a0f4764a2396df620d9c58725b3053Douglas Gregor case CC_Default: 10967907fad723a0f4764a2396df620d9c58725b3053Douglas Gregor llvm_unreachable("no name for default cc"); 10977907fad723a0f4764a2396df620d9c58725b3053Douglas Gregor return ""; 109804a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall 109904a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall case CC_C: return "cdecl"; 110004a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall case CC_X86StdCall: return "stdcall"; 110104a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall case CC_X86FastCall: return "fastcall"; 1102f813a2c03fcb05381b3252010435f557eb6b3cdeDouglas Gregor case CC_X86ThisCall: return "thiscall"; 110352fc314e1b5e1baee6305067cf831763d02bd243Dawn Perchik case CC_X86Pascal: return "pascal"; 110404a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall } 11057907fad723a0f4764a2396df620d9c58725b3053Douglas Gregor 11067907fad723a0f4764a2396df620d9c58725b3053Douglas Gregor llvm_unreachable("Invalid calling convention."); 11077907fad723a0f4764a2396df620d9c58725b3053Douglas Gregor return ""; 110804a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall} 110904a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall 1110e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCallFunctionProtoType::FunctionProtoType(QualType result, const QualType *args, 1111e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall unsigned numArgs, QualType canonical, 1112e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall const ExtProtoInfo &epi) 1113e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall : FunctionType(FunctionProto, result, epi.Variadic, epi.TypeQuals, canonical, 1114e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall result->isDependentType(), 1115e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall result->isVariablyModifiedType(), 1116e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall result->containsUnexpandedParameterPack(), 1117e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall epi.ExtInfo), 1118e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall NumArgs(numArgs), NumExceptions(epi.NumExceptions), 1119e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall HasExceptionSpec(epi.HasExceptionSpec), 1120e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall HasAnyExceptionSpec(epi.HasAnyExceptionSpec) 112135495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor{ 112235495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor // Fill in the trailing argument array. 1123e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall QualType *argSlot = reinterpret_cast<QualType*>(this+1); 112435495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor for (unsigned i = 0; i != numArgs; ++i) { 1125e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall if (args[i]->isDependentType()) 112635495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor setDependent(); 1127d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 1128e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall if (args[i]->containsUnexpandedParameterPack()) 1129d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor setContainsUnexpandedParameterPack(); 1130d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 1131e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall argSlot[i] = args[i]; 113235495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor } 113335495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor 113435495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor // Fill in the exception array. 1135e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall QualType *exnSlot = argSlot + numArgs; 1136e186269a8a41dbff1ebea2c251048892979d1078Douglas Gregor for (unsigned i = 0, e = epi.NumExceptions; i != e; ++i) { 1137e186269a8a41dbff1ebea2c251048892979d1078Douglas Gregor if (epi.Exceptions[i]->isDependentType()) 1138e186269a8a41dbff1ebea2c251048892979d1078Douglas Gregor setDependent(); 1139e186269a8a41dbff1ebea2c251048892979d1078Douglas Gregor 1140e186269a8a41dbff1ebea2c251048892979d1078Douglas Gregor if (epi.Exceptions[i]->containsUnexpandedParameterPack()) 1141e186269a8a41dbff1ebea2c251048892979d1078Douglas Gregor setContainsUnexpandedParameterPack(); 1142e186269a8a41dbff1ebea2c251048892979d1078Douglas Gregor 1143e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall exnSlot[i] = epi.Exceptions[i]; 1144e186269a8a41dbff1ebea2c251048892979d1078Douglas Gregor } 114535495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor} 114635495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor 1147f5c65ffbd7374b6c8d9f1e361041578640cab320Douglas Gregorbool FunctionProtoType::isTemplateVariadic() const { 11487d5c0c1273bdc1cb3dff1cb5a62d07b1439e82c7Douglas Gregor for (unsigned ArgIdx = getNumArgs(); ArgIdx; --ArgIdx) 11497d5c0c1273bdc1cb3dff1cb5a62d07b1439e82c7Douglas Gregor if (isa<PackExpansionType>(getArgType(ArgIdx - 1))) 11507d5c0c1273bdc1cb3dff1cb5a62d07b1439e82c7Douglas Gregor return true; 11517d5c0c1273bdc1cb3dff1cb5a62d07b1439e82c7Douglas Gregor 11527d5c0c1273bdc1cb3dff1cb5a62d07b1439e82c7Douglas Gregor return false; 1153f5c65ffbd7374b6c8d9f1e361041578640cab320Douglas Gregor} 115435495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor 115572564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregorvoid FunctionProtoType::Profile(llvm::FoldingSetNodeID &ID, QualType Result, 1156e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall const QualType *ArgTys, unsigned NumArgs, 1157e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall const ExtProtoInfo &epi) { 11585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddPointer(Result.getAsOpaquePtr()); 11595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer for (unsigned i = 0; i != NumArgs; ++i) 11605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddPointer(ArgTys[i].getAsOpaquePtr()); 1161e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall ID.AddBoolean(epi.Variadic); 1162e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall ID.AddInteger(epi.TypeQuals); 1163e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall if (epi.HasExceptionSpec) { 1164e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall ID.AddBoolean(epi.HasAnyExceptionSpec); 1165e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall for (unsigned i = 0; i != epi.NumExceptions; ++i) 1166e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall ID.AddPointer(epi.Exceptions[i].getAsOpaquePtr()); 1167465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl } 1168e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall epi.ExtInfo.Profile(ID); 11695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 11705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 117172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregorvoid FunctionProtoType::Profile(llvm::FoldingSetNodeID &ID) { 1172e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall Profile(ID, getResultType(), arg_type_begin(), NumArgs, getExtProtoInfo()); 11735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 11745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1175bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCallQualType TypedefType::desugar() const { 1176bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall return getDecl()->getUnderlyingType(); 1177bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall} 1178bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 117972564e73277e29f6db3305d1f27ba408abb7ed88Douglas GregorTypeOfExprType::TypeOfExprType(Expr *E, QualType can) 118035495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor : Type(TypeOfExpr, can, E->isTypeDependent(), 1181d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor E->getType()->isVariablyModifiedType(), 1182d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor E->containsUnexpandedParameterPack()), 1183d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor TOExpr(E) { 1184898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor} 1185898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 1186bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCallQualType TypeOfExprType::desugar() const { 1187bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall return getUnderlyingExpr()->getType(); 1188bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall} 1189bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 11901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpvoid DependentTypeOfExprType::Profile(llvm::FoldingSetNodeID &ID, 11914ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad const ASTContext &Context, Expr *E) { 1192b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor E->Profile(ID, Context, true); 1193b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor} 1194b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor 1195563a03b1338d31c2462def43253a722bc885d384Anders CarlssonDecltypeType::DecltypeType(Expr *E, QualType underlyingType, QualType can) 119635495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor : Type(Decltype, can, E->isTypeDependent(), 1197d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor E->getType()->isVariablyModifiedType(), 1198d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor E->containsUnexpandedParameterPack()), 1199d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor E(E), 1200563a03b1338d31c2462def43253a722bc885d384Anders Carlsson UnderlyingType(underlyingType) { 1201395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson} 1202395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson 12034ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadDependentDecltypeType::DependentDecltypeType(const ASTContext &Context, Expr *E) 12049d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor : DecltypeType(E, Context.DependentTy), Context(Context) { } 12059d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor 12061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpvoid DependentDecltypeType::Profile(llvm::FoldingSetNodeID &ID, 12074ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad const ASTContext &Context, Expr *E) { 12089d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor E->Profile(ID, Context, true); 12099d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor} 12109d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor 121119c8576b7328f4dc2d07682f5da552875c1912efJohn McCallTagType::TagType(TypeClass TC, const TagDecl *D, QualType can) 1212d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor : Type(TC, can, D->isDependentType(), /*VariablyModified=*/false, 1213d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /*ContainsUnexpandedParameterPack=*/false), 1214ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl decl(const_cast<TagDecl*>(D)) {} 1215ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl 1216ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redlstatic TagDecl *getInterestingTagDecl(TagDecl *decl) { 1217ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl for (TagDecl::redecl_iterator I = decl->redecls_begin(), 1218ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl E = decl->redecls_end(); 1219ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl I != E; ++I) { 1220ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl if (I->isDefinition() || I->isBeingDefined()) 1221ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl return *I; 1222ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl } 1223ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl // If there's no definition (not even in progress), return what we have. 1224ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl return decl; 1225ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl} 1226ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl 1227ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian RedlTagDecl *TagType::getDecl() const { 1228ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl return getInterestingTagDecl(decl); 1229ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl} 1230ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl 1231ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redlbool TagType::isBeingDefined() const { 1232ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl return getDecl()->isBeingDefined(); 1233ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl} 1234ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl 1235ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian RedlCXXRecordDecl *InjectedClassNameType::getDecl() const { 1236ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl return cast<CXXRecordDecl>(getInterestingTagDecl(Decl)); 1237ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl} 12387da97d0f31e1ec16998d3de2cfd2e88fe3736673Douglas Gregor 12392daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattnerbool RecordType::classof(const TagType *TT) { 12402daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner return isa<RecordDecl>(TT->getDecl()); 12415edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner} 12425edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner 12432daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattnerbool EnumType::classof(const TagType *TT) { 12442daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner return isa<EnumDecl>(TT->getDecl()); 12455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 12465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1247c3069d618f4661d923cb1b5c4525b082fce73b04Douglas GregorSubstTemplateTypeParmPackType:: 1248c3069d618f4661d923cb1b5c4525b082fce73b04Douglas GregorSubstTemplateTypeParmPackType(const TemplateTypeParmType *Param, 1249c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor QualType Canon, 1250c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor const TemplateArgument &ArgPack) 1251c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor : Type(SubstTemplateTypeParmPack, Canon, true, false, true), Replaced(Param), 1252c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor Arguments(ArgPack.pack_begin()), NumArguments(ArgPack.pack_size()) 1253c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor{ 1254c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor} 1255c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor 1256c3069d618f4661d923cb1b5c4525b082fce73b04Douglas GregorTemplateArgument SubstTemplateTypeParmPackType::getArgumentPack() const { 1257c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor return TemplateArgument(Arguments, NumArguments); 1258c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor} 1259c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor 1260c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregorvoid SubstTemplateTypeParmPackType::Profile(llvm::FoldingSetNodeID &ID) { 1261c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor Profile(ID, getReplacedParameter(), getArgumentPack()); 1262c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor} 1263c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor 1264c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregorvoid SubstTemplateTypeParmPackType::Profile(llvm::FoldingSetNodeID &ID, 1265c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor const TemplateTypeParmType *Replaced, 1266c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor const TemplateArgument &ArgPack) { 1267c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor ID.AddPointer(Replaced); 1268c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor ID.AddInteger(ArgPack.pack_size()); 1269c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor for (TemplateArgument::pack_iterator P = ArgPack.pack_begin(), 1270c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor PEnd = ArgPack.pack_end(); 1271c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor P != PEnd; ++P) 1272c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor ID.AddPointer(P->getAsType().getAsOpaquePtr()); 1273c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor} 1274c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor 1275833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallbool TemplateSpecializationType:: 1276d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCallanyDependentTemplateArguments(const TemplateArgumentListInfo &Args) { 1277d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall return anyDependentTemplateArguments(Args.getArgumentArray(), Args.size()); 1278d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall} 1279d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall 1280d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCallbool TemplateSpecializationType:: 1281833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallanyDependentTemplateArguments(const TemplateArgumentLoc *Args, unsigned N) { 1282833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall for (unsigned i = 0; i != N; ++i) 1283bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (Args[i].getArgument().isDependent()) 1284833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return true; 1285833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return false; 1286833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall} 1287833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 1288833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallbool TemplateSpecializationType:: 1289833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallanyDependentTemplateArguments(const TemplateArgument *Args, unsigned N) { 1290833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall for (unsigned i = 0; i != N; ++i) 1291bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (Args[i].isDependent()) 1292833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return true; 1293833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return false; 1294833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall} 1295833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 12967532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas GregorTemplateSpecializationType:: 1297ef99001908e799c388f1363b1e607dad5f5b57d3John McCallTemplateSpecializationType(TemplateName T, 1298828e226ab7ed08b3eb766549e9d3306432137460Douglas Gregor const TemplateArgument *Args, 12997532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor unsigned NumArgs, QualType Canon) 13001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : Type(TemplateSpecialization, 130140808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor Canon.isNull()? QualType(this, 0) : Canon, 1302d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor T.isDependent(), false, 1303d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor T.containsUnexpandedParameterPack()), 130435495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor Template(T), NumArgs(NumArgs) 130535495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor{ 13061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump assert((!Canon.isNull() || 13077532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor T.isDependent() || anyDependentTemplateArguments(Args, NumArgs)) && 130840808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor "No canonical type for non-dependent class template specialization"); 130955f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 13101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TemplateArgument *TemplateArgs 131140808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor = reinterpret_cast<TemplateArgument *>(this + 1); 131235495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor for (unsigned Arg = 0; Arg < NumArgs; ++Arg) { 131335495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor // Update dependent and variably-modified bits. 1314bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor if (Args[Arg].isDependent()) 131535495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor setDependent(); 131635495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor if (Args[Arg].getKind() == TemplateArgument::Type && 131735495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor Args[Arg].getAsType()->isVariablyModifiedType()) 131835495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor setVariablyModified(); 1319d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor if (Args[Arg].containsUnexpandedParameterPack()) 1320d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor setContainsUnexpandedParameterPack(); 1321d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 132240808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor new (&TemplateArgs[Arg]) TemplateArgument(Args[Arg]); 132335495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor } 132455f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor} 132555f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 13261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpvoid 13271eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTemplateSpecializationType::Profile(llvm::FoldingSetNodeID &ID, 13281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TemplateName T, 13291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const TemplateArgument *Args, 1330828e226ab7ed08b3eb766549e9d3306432137460Douglas Gregor unsigned NumArgs, 13314ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad const ASTContext &Context) { 13327532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor T.Profile(ID); 133340808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor for (unsigned Idx = 0; Idx < NumArgs; ++Idx) 1334828e226ab7ed08b3eb766549e9d3306432137460Douglas Gregor Args[Idx].Profile(ID, Context); 133555f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor} 133697e0179f1ae545e07d9f5e7c1d2ef5c5bab06676Anders Carlsson 13374ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualType 13384ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualifierCollector::apply(const ASTContext &Context, QualType QT) const { 13390953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (!hasNonFastQualifiers()) 13400953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return QT.withFastQualifiers(getFastQualifiers()); 13411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 134249f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall return Context.getQualifiedType(QT, *this); 13435e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor} 13445e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor 13454ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualType 13464ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualifierCollector::apply(const ASTContext &Context, const Type *T) const { 13470953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (!hasNonFastQualifiers()) 13480953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return QualType(T, getFastQualifiers()); 13490953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 135049f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall return Context.getQualifiedType(T, *this); 13515e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor} 13525e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor 1353c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallvoid ObjCObjectTypeImpl::Profile(llvm::FoldingSetNodeID &ID, 1354c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall QualType BaseType, 1355c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCProtocolDecl * const *Protocols, 1356c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall unsigned NumProtocols) { 1357c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ID.AddPointer(BaseType.getAsOpaquePtr()); 1358c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff for (unsigned i = 0; i != NumProtocols; i++) 1359c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ID.AddPointer(Protocols[i]); 1360c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff} 1361c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff 1362c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallvoid ObjCObjectTypeImpl::Profile(llvm::FoldingSetNodeID &ID) { 1363c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall Profile(ID, getBaseType(), qual_begin(), getNumProtocols()); 1364c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff} 13650b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 1366b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCallnamespace { 13671fb0caaa7bef765b85972274e3b434af2572c141John McCall 1368b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall/// \brief The cached properties of a type. 1369b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCallclass CachedProperties { 1370b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall char linkage; 1371b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall char visibility; 1372b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall bool local; 1373b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall 1374b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCallpublic: 1375b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall CachedProperties(Linkage linkage, Visibility visibility, bool local) 1376b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall : linkage(linkage), visibility(visibility), local(local) {} 1377b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall 1378b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall Linkage getLinkage() const { return (Linkage) linkage; } 1379b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall Visibility getVisibility() const { return (Visibility) visibility; } 1380b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall bool hasLocalOrUnnamedType() const { return local; } 1381b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall 1382b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall friend CachedProperties merge(CachedProperties L, CachedProperties R) { 1383b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return CachedProperties(minLinkage(L.getLinkage(), R.getLinkage()), 1384b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall minVisibility(L.getVisibility(), R.getVisibility()), 1385b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall L.hasLocalOrUnnamedType() | R.hasLocalOrUnnamedType()); 1386b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall } 1387b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall}; 13881fb0caaa7bef765b85972274e3b434af2572c141John McCall} 13891fb0caaa7bef765b85972274e3b434af2572c141John McCall 1390b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCallstatic CachedProperties computeCachedProperties(const Type *T); 13910b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 1392b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCallnamespace clang { 1393b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall/// The type-property cache. This is templated so as to be 1394b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall/// instantiated at an internal type to prevent unnecessary symbol 1395b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall/// leakage. 1396b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCalltemplate <class Private> class TypePropertyCache { 1397b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCallpublic: 1398b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall static CachedProperties get(QualType T) { 1399b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return get(T.getTypePtr()); 1400b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall } 14011fb0caaa7bef765b85972274e3b434af2572c141John McCall 1402b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall static CachedProperties get(const Type *T) { 1403b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall ensure(T); 1404b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return CachedProperties(T->TypeBits.getLinkage(), 1405b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall T->TypeBits.getVisibility(), 1406b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall T->TypeBits.hasLocalOrUnnamedType()); 1407b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall } 1408db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor 1409b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall static void ensure(const Type *T) { 1410b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall // If the cache is valid, we're okay. 1411b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall if (T->TypeBits.isCacheValid()) return; 1412b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall 1413b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall // If this type is non-canonical, ask its canonical type for the 1414b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall // relevant information. 1415b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall if (QualType(T, 0) != T->CanonicalType) { 1416b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall const Type *CT = T->CanonicalType.getTypePtr(); 1417b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall ensure(CT); 1418b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall T->TypeBits.CacheValidAndVisibility = 1419b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall CT->TypeBits.CacheValidAndVisibility; 1420b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall T->TypeBits.CachedLinkage = CT->TypeBits.CachedLinkage; 1421b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall T->TypeBits.CachedLocalOrUnnamed = CT->TypeBits.CachedLocalOrUnnamed; 1422b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return; 1423b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall } 14241fb0caaa7bef765b85972274e3b434af2572c141John McCall 1425b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall // Compute the cached properties and then set the cache. 1426b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall CachedProperties Result = computeCachedProperties(T); 1427b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall T->TypeBits.CacheValidAndVisibility = Result.getVisibility() + 1U; 1428b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall assert(T->TypeBits.isCacheValid() && 1429b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall T->TypeBits.getVisibility() == Result.getVisibility()); 1430b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall T->TypeBits.CachedLinkage = Result.getLinkage(); 1431b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall T->TypeBits.CachedLocalOrUnnamed = Result.hasLocalOrUnnamedType(); 1432b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall } 1433b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall}; 14341fb0caaa7bef765b85972274e3b434af2572c141John McCall} 14351fb0caaa7bef765b85972274e3b434af2572c141John McCall 1436b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall// Instantiate the friend template at a private class. In a 1437b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall// reasonable implementation, these symbols will be internal. 1438b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall// It is terrible that this is the best way to accomplish this. 1439b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCallnamespace { class Private {}; } 1440b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCalltypedef TypePropertyCache<Private> Cache; 14411fb0caaa7bef765b85972274e3b434af2572c141John McCall 1442b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCallstatic CachedProperties computeCachedProperties(const Type *T) { 1443b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall switch (T->getTypeClass()) { 1444b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall#define TYPE(Class,Base) 1445b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall#define NON_CANONICAL_TYPE(Class,Base) case Type::Class: 1446b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall#include "clang/AST/TypeNodes.def" 1447b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall llvm_unreachable("didn't expect a non-canonical type here"); 144860e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor 1449b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall#define TYPE(Class,Base) 1450b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall#define DEPENDENT_TYPE(Class,Base) case Type::Class: 1451b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall#define NON_CANONICAL_UNLESS_DEPENDENT_TYPE(Class,Base) case Type::Class: 1452b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall#include "clang/AST/TypeNodes.def" 1453b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall // Treat dependent types as external. 1454b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall assert(T->isDependentType()); 14551fb0caaa7bef765b85972274e3b434af2572c141John McCall return CachedProperties(ExternalLinkage, DefaultVisibility, false); 14561fb0caaa7bef765b85972274e3b434af2572c141John McCall 1457b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::Builtin: 1458b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall // C++ [basic.link]p8: 1459b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall // A type is said to have linkage if and only if: 1460b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall // - it is a fundamental type (3.9.1); or 1461b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return CachedProperties(ExternalLinkage, DefaultVisibility, false); 14620b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 1463b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::Record: 1464b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::Enum: { 1465b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall const TagDecl *Tag = cast<TagType>(T)->getDecl(); 1466b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall 1467b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall // C++ [basic.link]p8: 1468b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall // - it is a class or enumeration type that is named (or has a name 1469b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall // for linkage purposes (7.1.3)) and the name has linkage; or 1470b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall // - it is a specialization of a class template (14); or 1471b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall NamedDecl::LinkageInfo LV = Tag->getLinkageAndVisibility(); 1472b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall bool IsLocalOrUnnamed = 1473b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall Tag->getDeclContext()->isFunctionOrMethod() || 1474b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall (!Tag->getIdentifier() && !Tag->getTypedefForAnonDecl()); 1475b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return CachedProperties(LV.linkage(), LV.visibility(), IsLocalOrUnnamed); 1476b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall } 14770b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 1478b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall // C++ [basic.link]p8: 1479b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall // - it is a compound type (3.9.2) other than a class or enumeration, 1480b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall // compounded exclusively from types that have linkage; or 1481b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::Complex: 1482b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return Cache::get(cast<ComplexType>(T)->getElementType()); 1483b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::Pointer: 1484b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return Cache::get(cast<PointerType>(T)->getPointeeType()); 1485b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::BlockPointer: 1486b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return Cache::get(cast<BlockPointerType>(T)->getPointeeType()); 1487b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::LValueReference: 1488b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::RValueReference: 1489b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return Cache::get(cast<ReferenceType>(T)->getPointeeType()); 1490b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::MemberPointer: { 1491b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall const MemberPointerType *MPT = cast<MemberPointerType>(T); 1492b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return merge(Cache::get(MPT->getClass()), 1493b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall Cache::get(MPT->getPointeeType())); 1494b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall } 1495b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::ConstantArray: 1496b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::IncompleteArray: 1497b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::VariableArray: 1498b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return Cache::get(cast<ArrayType>(T)->getElementType()); 1499b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::Vector: 1500b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::ExtVector: 1501b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return Cache::get(cast<VectorType>(T)->getElementType()); 1502b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::FunctionNoProto: 1503b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return Cache::get(cast<FunctionType>(T)->getResultType()); 1504b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::FunctionProto: { 1505b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall const FunctionProtoType *FPT = cast<FunctionProtoType>(T); 1506b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall CachedProperties result = Cache::get(FPT->getResultType()); 1507b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall for (FunctionProtoType::arg_type_iterator ai = FPT->arg_type_begin(), 1508b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall ae = FPT->arg_type_end(); ai != ae; ++ai) 1509b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall result = merge(result, Cache::get(*ai)); 1510b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return result; 1511b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall } 1512b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::ObjCInterface: { 1513b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall NamedDecl::LinkageInfo LV = 1514b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall cast<ObjCInterfaceType>(T)->getDecl()->getLinkageAndVisibility(); 1515b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return CachedProperties(LV.linkage(), LV.visibility(), false); 1516b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall } 1517b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::ObjCObject: 1518b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return Cache::get(cast<ObjCObjectType>(T)->getBaseType()); 1519b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall case Type::ObjCObjectPointer: 1520b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return Cache::get(cast<ObjCObjectPointerType>(T)->getPointeeType()); 1521b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall } 15220b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 1523b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall llvm_unreachable("unhandled type class"); 15240b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 1525b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall // C++ [basic.link]p8: 1526b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall // Names not covered by these rules have no linkage. 1527b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return CachedProperties(NoLinkage, DefaultVisibility, false); 15280b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor} 15290b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 1530b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall/// \brief Determine the linkage of this type. 1531b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCallLinkage Type::getLinkage() const { 1532b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall Cache::ensure(this); 1533b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return TypeBits.getLinkage(); 15340b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor} 15350b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 1536b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall/// \brief Determine the linkage of this type. 1537b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCallVisibility Type::getVisibility() const { 1538b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall Cache::ensure(this); 1539b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return TypeBits.getVisibility(); 15401fb0caaa7bef765b85972274e3b434af2572c141John McCall} 15411fb0caaa7bef765b85972274e3b434af2572c141John McCall 1542b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCallbool Type::hasUnnamedOrLocalType() const { 1543b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall Cache::ensure(this); 1544b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return TypeBits.hasLocalOrUnnamedType(); 15450b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor} 15460b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 1547b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCallstd::pair<Linkage,Visibility> Type::getLinkageAndVisibility() const { 1548b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall Cache::ensure(this); 1549b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall return std::make_pair(TypeBits.getLinkage(), TypeBits.getVisibility()); 15500b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor} 15510b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 1552b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCallvoid Type::ClearLinkageCache() { 1553b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall TypeBits.CacheValidAndVisibility = 0; 1554b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall if (QualType(this, 0) != CanonicalType) 1555b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall CanonicalType->TypeBits.CacheValidAndVisibility = 0; 15560b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor} 1557