Type.cpp revision ccf43505dbc47da041c06125f90b3bd3ac7eac97
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" 155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "clang/AST/Type.h" 1649aa7ff1245abd03e6e998e01302df31e4c6f8f6Argyrios Kyrtzidis#include "clang/AST/DeclCXX.h" 17980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff#include "clang/AST/DeclObjC.h" 18aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor#include "clang/AST/DeclTemplate.h" 195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "clang/AST/Expr.h" 20d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor#include "clang/AST/PrettyPrinter.h" 215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "llvm/ADT/StringExtras.h" 22bad351822117eaf280081494e3dbe4a06c0dbfcfDouglas Gregor#include "llvm/Support/raw_ostream.h" 235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing namespace clang; 245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 25bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCallbool QualType::isConstant(QualType T, ASTContext &Ctx) { 26bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall if (T.isConstQualified()) 27b381aac9bae6d608c72267dd0ed08ec6369e94e4Nuno Lopes return true; 28b381aac9bae6d608c72267dd0ed08ec6369e94e4Nuno Lopes 29bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall if (const ArrayType *AT = Ctx.getAsArrayType(T)) 30bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall return AT->getElementType().isConstant(Ctx); 31b381aac9bae6d608c72267dd0ed08ec6369e94e4Nuno Lopes 32b381aac9bae6d608c72267dd0ed08ec6369e94e4Nuno Lopes return false; 33b381aac9bae6d608c72267dd0ed08ec6369e94e4Nuno Lopes} 34b381aac9bae6d608c72267dd0ed08ec6369e94e4Nuno Lopes 35566c2ba743065ec090f5154d5c30cf593aa12a6eTed Kremenekvoid Type::Destroy(ASTContext& C) { 36566c2ba743065ec090f5154d5c30cf593aa12a6eTed Kremenek this->~Type(); 373e9704981d7691fdd44913bf1786e8d760d8a627Steve Naroff C.Deallocate(this); 384b05b1dee6cc65ae61d93dab7edff72710f24589Ted Kremenek} 394b05b1dee6cc65ae61d93dab7edff72710f24589Ted Kremenek 404b05b1dee6cc65ae61d93dab7edff72710f24589Ted Kremenekvoid VariableArrayType::Destroy(ASTContext& C) { 41f91f5c8a66ffd812f61819836529f8ad437f7e2bEli Friedman if (SizeExpr) 42f91f5c8a66ffd812f61819836529f8ad437f7e2bEli Friedman SizeExpr->Destroy(C); 43566c2ba743065ec090f5154d5c30cf593aa12a6eTed Kremenek this->~VariableArrayType(); 443e9704981d7691fdd44913bf1786e8d760d8a627Steve Naroff C.Deallocate(this); 454b05b1dee6cc65ae61d93dab7edff72710f24589Ted Kremenek} 465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 47898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorvoid DependentSizedArrayType::Destroy(ASTContext& C) { 48e7f38406a38f453e83000a1e52a5ec0aada66e51Argyrios Kyrtzidis // FIXME: Resource contention like in ConstantArrayWithExprType ? 49e7f38406a38f453e83000a1e52a5ec0aada66e51Argyrios Kyrtzidis // May crash, depending on platform or a particular build. 50e7f38406a38f453e83000a1e52a5ec0aada66e51Argyrios Kyrtzidis // SizeExpr->Destroy(C); 51566c2ba743065ec090f5154d5c30cf593aa12a6eTed Kremenek this->~DependentSizedArrayType(); 523e9704981d7691fdd44913bf1786e8d760d8a627Steve Naroff C.Deallocate(this); 53898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor} 54c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner 551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpvoid DependentSizedArrayType::Profile(llvm::FoldingSetNodeID &ID, 5604d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor ASTContext &Context, 5704d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor QualType ET, 5804d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor ArraySizeModifier SizeMod, 5904d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor unsigned TypeQuals, 6004d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor Expr *E) { 6104d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor ID.AddPointer(ET.getAsOpaquePtr()); 6204d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor ID.AddInteger(SizeMod); 6304d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor ID.AddInteger(TypeQuals); 6404d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor E->Profile(ID, Context, true); 6504d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor} 6604d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor 671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpvoid 681eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpDependentSizedExtVectorType::Profile(llvm::FoldingSetNodeID &ID, 692ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor ASTContext &Context, 702ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor QualType ElementType, Expr *SizeExpr) { 712ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor ID.AddPointer(ElementType.getAsOpaquePtr()); 722ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor SizeExpr->Profile(ID, Context, true); 732ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor} 742ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor 759cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregorvoid DependentSizedExtVectorType::Destroy(ASTContext& C) { 76bd1099efde211cbb63fce3feee4ebcc6bac58781Douglas Gregor // FIXME: Deallocate size expression, once we're cloning properly. 77bd1099efde211cbb63fce3feee4ebcc6bac58781Douglas Gregor// if (SizeExpr) 78bd1099efde211cbb63fce3feee4ebcc6bac58781Douglas Gregor// SizeExpr->Destroy(C); 799cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor this->~DependentSizedExtVectorType(); 809cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor C.Deallocate(this); 819cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor} 829cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor 83c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner/// getArrayElementTypeNoTypeQual - If this is an array type, return the 84c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner/// element type of the array, potentially with type qualifiers missing. 85c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner/// This method should never be used when type qualifiers are meaningful. 86c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattnerconst Type *Type::getArrayElementTypeNoTypeQual() const { 87c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // If this is directly an array type, return it. 88c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner if (const ArrayType *ATy = dyn_cast<ArrayType>(this)) 89c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return ATy->getElementType().getTypePtr(); 901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 91c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // If the canonical form of this type isn't the right kind, reject it. 920953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (!isa<ArrayType>(CanonicalType)) 93c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return 0; 941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 95c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // If this is a typedef for an array type, strip the typedef off without 96c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // losing all typedef information. 97bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall return cast<ArrayType>(getUnqualifiedDesugaredType()) 98bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall ->getElementType().getTypePtr(); 992fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner} 1002fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner 101fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor/// \brief Retrieve the unqualified variant of the given type, removing as 102fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor/// little sugar as possible. 103fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor/// 104fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor/// This routine looks through various kinds of sugar to find the 105fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor/// least-desuraged type that is unqualified. For example, given: 106fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor/// 107fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor/// \code 108fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor/// typedef int Integer; 109fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor/// typedef const Integer CInteger; 110fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor/// typedef CInteger DifferenceType; 111fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor/// \endcode 112fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor/// 113fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor/// Executing \c getUnqualifiedTypeSlow() on the type \c DifferenceType will 114fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor/// desugar until we hit the type \c Integer, which has no qualifiers on it. 115fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas GregorQualType QualType::getUnqualifiedTypeSlow() const { 116fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor QualType Cur = *this; 117fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor while (true) { 118fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor if (!Cur.hasQualifiers()) 119fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor return Cur; 120fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor 121fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor const Type *CurTy = Cur.getTypePtr(); 122fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor switch (CurTy->getTypeClass()) { 123fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor#define ABSTRACT_TYPE(Class, Parent) 124fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor#define TYPE(Class, Parent) \ 125fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor case Type::Class: { \ 126fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor const Class##Type *Ty = cast<Class##Type>(CurTy); \ 127fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor if (!Ty->isSugared()) \ 128fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor return Cur.getLocalUnqualifiedType(); \ 129fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor Cur = Ty->desugar(); \ 130fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor break; \ 131fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor } 132fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor#include "clang/AST/TypeNodes.def" 133fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor } 134fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor } 135fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor 136fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor return Cur.getUnqualifiedType(); 137fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor} 138fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor 1392fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner/// getDesugaredType - Return the specified type with any "sugar" removed from 1402fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner/// the type. This takes off typedefs, typeof's etc. If the outer level of 1412fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner/// the type is already concrete, it returns it unmodified. This is similar 1422fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner/// to getting the canonical type, but it doesn't remove *all* typedefs. For 1432fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner/// example, it returns "T*" as "T*", (not as "int*"), because the pointer is 1442fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner/// concrete. 145bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCallQualType QualType::getDesugaredType(QualType T) { 1460953e767ff7817f97b3ab20896b229891eeff45bJohn McCall QualifierCollector Qs; 147c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner 148bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType Cur = T; 149bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall while (true) { 150bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall const Type *CurTy = Qs.strip(Cur); 151bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall switch (CurTy->getTypeClass()) { 152bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall#define ABSTRACT_TYPE(Class, Parent) 153bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall#define TYPE(Class, Parent) \ 154bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall case Type::Class: { \ 155bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall const Class##Type *Ty = cast<Class##Type>(CurTy); \ 156bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall if (!Ty->isSugared()) \ 157bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall return Qs.apply(Cur); \ 158bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall Cur = Ty->desugar(); \ 159bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall break; \ 160bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall } 161bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall#include "clang/AST/TypeNodes.def" 162bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall } 163969c689d893a248eca4f049f5b89f747e66e4bffDouglas Gregor } 164bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall} 1655cdf82164dd7c2b2320d6735c63ace4331e0716dDouglas Gregor 166bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall/// getUnqualifiedDesugaredType - Pull any qualifiers and syntactic 167bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall/// sugar off the given type. This should produce an object of the 168bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall/// same dynamic type as the canonical type. 169bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCallconst Type *Type::getUnqualifiedDesugaredType() const { 170bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall const Type *Cur = this; 171bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 172bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall while (true) { 173bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall switch (Cur->getTypeClass()) { 174bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall#define ABSTRACT_TYPE(Class, Parent) 175bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall#define TYPE(Class, Parent) \ 176bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall case Class: { \ 177bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall const Class##Type *Ty = cast<Class##Type>(Cur); \ 178bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall if (!Ty->isSugared()) return Cur; \ 179bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall Cur = Ty->desugar().getTypePtr(); \ 180bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall break; \ 181bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall } 182bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall#include "clang/AST/TypeNodes.def" 183bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall } 184bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall } 185c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner} 186c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner 1875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// isVoidType - Helper method to determine if this is the 'void' type. 1885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isVoidType() const { 1895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 1905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return BT->getKind() == BuiltinType::Void; 1915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return false; 1925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 1935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isObjectType() const { 195bad0e656c3732e3539a9cd6525de721d7e47408bDouglas Gregor if (isa<FunctionType>(CanonicalType) || isa<ReferenceType>(CanonicalType) || 196bad0e656c3732e3539a9cd6525de721d7e47408bDouglas Gregor isa<IncompleteArrayType>(CanonicalType) || isVoidType()) 1975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return false; 198bad0e656c3732e3539a9cd6525de721d7e47408bDouglas Gregor return true; 1995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 2005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isDerivedType() const { 2025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer switch (CanonicalType->getTypeClass()) { 2035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Pointer: 204fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff case VariableArray: 205fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff case ConstantArray: 206c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman case IncompleteArray: 2075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case FunctionProto: 2085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case FunctionNoProto: 2097c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl case LValueReference: 2107c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl case RValueReference: 21172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor case Record: 2125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return true; 2135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer default: 2145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return false; 2155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 2175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 21899dc91422144483c20d1c7381bc9ac634b646b04Chris Lattnerbool Type::isClassType() const { 2196217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const RecordType *RT = getAs<RecordType>()) 220f728a4a05df2455e1c6e62173ab720a92cd4a074Chris Lattner return RT->getDecl()->isClass(); 22199dc91422144483c20d1c7381bc9ac634b646b04Chris Lattner return false; 22299dc91422144483c20d1c7381bc9ac634b646b04Chris Lattner} 223c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattnerbool Type::isStructureType() const { 2246217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const RecordType *RT = getAs<RecordType>()) 225f728a4a05df2455e1c6e62173ab720a92cd4a074Chris Lattner return RT->getDecl()->isStruct(); 226c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner return false; 227c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner} 2287154a77e7c1f23418342d3b72836ab504aa7821eSteve Naroffbool Type::isVoidPointerType() const { 2296217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const PointerType *PT = getAs<PointerType>()) 2307154a77e7c1f23418342d3b72836ab504aa7821eSteve Naroff return PT->getPointeeType()->isVoidType(); 2317154a77e7c1f23418342d3b72836ab504aa7821eSteve Naroff return false; 2327154a77e7c1f23418342d3b72836ab504aa7821eSteve Naroff} 2337154a77e7c1f23418342d3b72836ab504aa7821eSteve Naroff 234c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattnerbool Type::isUnionType() const { 2356217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const RecordType *RT = getAs<RecordType>()) 236f728a4a05df2455e1c6e62173ab720a92cd4a074Chris Lattner return RT->getDecl()->isUnion(); 237c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner return false; 238c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner} 239c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner 240c6fb90a7246c2d5d3233e70107bf9d8c7c9e535bChris Lattnerbool Type::isComplexType() const { 24102f62a9fedbc370fba081303399410a3afdde29fSteve Naroff if (const ComplexType *CT = dyn_cast<ComplexType>(CanonicalType)) 24202f62a9fedbc370fba081303399410a3afdde29fSteve Naroff return CT->getElementType()->isFloatingType(); 24302f62a9fedbc370fba081303399410a3afdde29fSteve Naroff return false; 244c6fb90a7246c2d5d3233e70107bf9d8c7c9e535bChris Lattner} 245c6fb90a7246c2d5d3233e70107bf9d8c7c9e535bChris Lattner 2464cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroffbool Type::isComplexIntegerType() const { 2474cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroff // Check for GCC complex integer extension. 2480953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return getAsComplexIntegerType(); 2494cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroff} 2504cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroff 2514cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroffconst ComplexType *Type::getAsComplexIntegerType() const { 2520953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (const ComplexType *Complex = getAs<ComplexType>()) 2530953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (Complex->getElementType()->isIntegerType()) 2540953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return Complex; 2550953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return 0; 2564cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroff} 2574cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroff 25814108da7f7fc059772711e4ffee1322a27b152a7Steve NaroffQualType Type::getPointeeType() const { 2596217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const PointerType *PT = getAs<PointerType>()) 26014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return PT->getPointeeType(); 261183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) 26214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return OPT->getPointeeType(); 2636217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const BlockPointerType *BPT = getAs<BlockPointerType>()) 26414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return BPT->getPointeeType(); 2659c21289a866b677d21ed3d5ecfdfd5ced5a55410Mike Stump if (const ReferenceType *RT = getAs<ReferenceType>()) 2669c21289a866b677d21ed3d5ecfdfd5ced5a55410Mike Stump return RT->getPointeeType(); 26714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return QualType(); 26814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff} 269b77792eabf5882cf9af8cc810599b20432fda6c2Chris Lattner 270d3f2f79fedfef7cae818c55a1f3d7a8f5992e5a0Eli Friedman/// isVariablyModifiedType (C99 6.7.5p3) - Return true for variable length 271d3f2f79fedfef7cae818c55a1f3d7a8f5992e5a0Eli Friedman/// array types and types that contain variable array types in their 272d3f2f79fedfef7cae818c55a1f3d7a8f5992e5a0Eli Friedman/// declarator 273d7444aac1af1c2c1d5e5b7467ecf6006ee2d8abeSteve Naroffbool Type::isVariablyModifiedType() const { 274c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // A VLA is a variably modified type. 275c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner if (isVariableArrayType()) 276d3f2f79fedfef7cae818c55a1f3d7a8f5992e5a0Eli Friedman return true; 277d3f2f79fedfef7cae818c55a1f3d7a8f5992e5a0Eli Friedman 278d3f2f79fedfef7cae818c55a1f3d7a8f5992e5a0Eli Friedman // An array can contain a variably modified type 279c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner if (const Type *T = getArrayElementTypeNoTypeQual()) 280c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return T->isVariablyModifiedType(); 281d3f2f79fedfef7cae818c55a1f3d7a8f5992e5a0Eli Friedman 282f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl // A pointer can point to a variably modified type. 283f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl // Also, C++ references and member pointers can point to a variably modified 284f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl // type, where VLAs appear as an extension to C++, and should be treated 285f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl // correctly. 2866217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const PointerType *PT = getAs<PointerType>()) 287d3f2f79fedfef7cae818c55a1f3d7a8f5992e5a0Eli Friedman return PT->getPointeeType()->isVariablyModifiedType(); 2886217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const ReferenceType *RT = getAs<ReferenceType>()) 28968694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar return RT->getPointeeType()->isVariablyModifiedType(); 2906217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const MemberPointerType *PT = getAs<MemberPointerType>()) 2918edef7c31d27fc9d5d163660702a8a7730a0d19fSebastian Redl return PT->getPointeeType()->isVariablyModifiedType(); 292d3f2f79fedfef7cae818c55a1f3d7a8f5992e5a0Eli Friedman 293d3f2f79fedfef7cae818c55a1f3d7a8f5992e5a0Eli Friedman // A function can return a variably modified type 294d3f2f79fedfef7cae818c55a1f3d7a8f5992e5a0Eli Friedman // This one isn't completely obvious, but it follows from the 295d3f2f79fedfef7cae818c55a1f3d7a8f5992e5a0Eli Friedman // definition in C99 6.7.5p3. Because of this rule, it's 296d3f2f79fedfef7cae818c55a1f3d7a8f5992e5a0Eli Friedman // illegal to declare a function returning a variably modified type. 297183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const FunctionType *FT = getAs<FunctionType>()) 298d3f2f79fedfef7cae818c55a1f3d7a8f5992e5a0Eli Friedman return FT->getResultType()->isVariablyModifiedType(); 299d3f2f79fedfef7cae818c55a1f3d7a8f5992e5a0Eli Friedman 300d7444aac1af1c2c1d5e5b7467ecf6006ee2d8abeSteve Naroff return false; 301d7444aac1af1c2c1d5e5b7467ecf6006ee2d8abeSteve Naroff} 302d7444aac1af1c2c1d5e5b7467ecf6006ee2d8abeSteve Naroff 303c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattnerconst RecordType *Type::getAsStructureType() const { 3047064f5c95bbdb17680d0ea658d4090898c2592d3Steve Naroff // If this is directly a structure type, return it. 305c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner if (const RecordType *RT = dyn_cast<RecordType>(this)) { 30639ba4aeca296b1c9f04bde7d9d3cbbf129f1abd3Argyrios Kyrtzidis if (RT->getDecl()->isStruct()) 307c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner return RT; 3087064f5c95bbdb17680d0ea658d4090898c2592d3Steve Naroff } 309dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner 310dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner // If the canonical form of this type isn't the right kind, reject it. 311c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner if (const RecordType *RT = dyn_cast<RecordType>(CanonicalType)) { 31239ba4aeca296b1c9f04bde7d9d3cbbf129f1abd3Argyrios Kyrtzidis if (!RT->getDecl()->isStruct()) 313dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner return 0; 3141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 315dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner // If this is a typedef for a structure type, strip the typedef off without 316dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner // losing all typedef information. 317bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall return cast<RecordType>(getUnqualifiedDesugaredType()); 3185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 3197064f5c95bbdb17680d0ea658d4090898c2592d3Steve Naroff return 0; 3205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 3215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpconst RecordType *Type::getAsUnionType() const { 3237064f5c95bbdb17680d0ea658d4090898c2592d3Steve Naroff // If this is directly a union type, return it. 324c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner if (const RecordType *RT = dyn_cast<RecordType>(this)) { 32539ba4aeca296b1c9f04bde7d9d3cbbf129f1abd3Argyrios Kyrtzidis if (RT->getDecl()->isUnion()) 326c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner return RT; 3277064f5c95bbdb17680d0ea658d4090898c2592d3Steve Naroff } 3281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 329dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner // If the canonical form of this type isn't the right kind, reject it. 330c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner if (const RecordType *RT = dyn_cast<RecordType>(CanonicalType)) { 33139ba4aeca296b1c9f04bde7d9d3cbbf129f1abd3Argyrios Kyrtzidis if (!RT->getDecl()->isUnion()) 332dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner return 0; 333dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner 334dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner // If this is a typedef for a union type, strip the typedef off without 335dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner // losing all typedef information. 336bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall return cast<RecordType>(getUnqualifiedDesugaredType()); 3375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 3381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3397064f5c95bbdb17680d0ea658d4090898c2592d3Steve Naroff return 0; 3405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 3415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 342c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroffconst ObjCInterfaceType *Type::getAsObjCQualifiedInterfaceType() const { 343c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff // There is no sugar for ObjCInterfaceType's, just return the canonical 344c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff // type pointer if it is the right class. There is no typedef information to 345c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff // return and these cannot be Address-space qualified. 346183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const ObjCInterfaceType *OIT = getAs<ObjCInterfaceType>()) 347c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff if (OIT->getNumProtocols()) 348c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff return OIT; 349c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff return 0; 350c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff} 351c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff 352c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroffbool Type::isObjCQualifiedInterfaceType() const { 353e61ad0b7063fcd97204b1cce5558685144267eb6Steve Naroff return getAsObjCQualifiedInterfaceType() != 0; 354c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff} 355c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff 356d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroffconst ObjCObjectPointerType *Type::getAsObjCQualifiedIdType() const { 357eca7be6b7ebd93682eeaab2c71d59f2995dacdccChris Lattner // There is no sugar for ObjCQualifiedIdType's, just return the canonical 358eca7be6b7ebd93682eeaab2c71d59f2995dacdccChris Lattner // type pointer if it is the right class. 359183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) { 360d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff if (OPT->isObjCQualifiedIdType()) 361d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff return OPT; 362d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff } 363d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff return 0; 364368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner} 365368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner 36614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroffconst ObjCObjectPointerType *Type::getAsObjCInterfacePointerType() const { 367183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) { 36814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff if (OPT->getInterfaceType()) 36914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return OPT; 37014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff } 37114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return 0; 37214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff} 37314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff 374a91d6a6619a91d0ca7102d8ab5678d855f04d850Fariborz Jahanianconst CXXRecordDecl *Type::getCXXRecordDeclForPointerType() const { 3756217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const PointerType *PT = getAs<PointerType>()) 3766217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const RecordType *RT = PT->getPointeeType()->getAs<RecordType>()) 377a91d6a6619a91d0ca7102d8ab5678d855f04d850Fariborz Jahanian return dyn_cast<CXXRecordDecl>(RT->getDecl()); 378a91d6a6619a91d0ca7102d8ab5678d855f04d850Fariborz Jahanian return 0; 379a91d6a6619a91d0ca7102d8ab5678d855f04d850Fariborz Jahanian} 380a91d6a6619a91d0ca7102d8ab5678d855f04d850Fariborz Jahanian 3815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isIntegerType() const { 3825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 3835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return BT->getKind() >= BuiltinType::Bool && 3842df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner BT->getKind() <= BuiltinType::Int128; 3855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (const TagType *TT = dyn_cast<TagType>(CanonicalType)) 386834a72ac74cf4ff07ba6215545dba3db578f8a07Chris Lattner // Incomplete enum types are not treated as integer types. 3878e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor // FIXME: In C++, enum types are never integer types. 388834a72ac74cf4ff07ba6215545dba3db578f8a07Chris Lattner if (TT->getDecl()->isEnum() && TT->getDecl()->isDefinition()) 3895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return true; 390f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman if (isa<FixedWidthIntType>(CanonicalType)) 391f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman return true; 392c63b96ad706e054a1390dd2ab53af9f05d33bbb1Steve Naroff if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType)) 393c63b96ad706e054a1390dd2ab53af9f05d33bbb1Steve Naroff return VT->getElementType()->isIntegerType(); 3945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return false; 3955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 3965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 39733e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanianbool Type::isIntegralType() const { 39833e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 39933e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian return BT->getKind() >= BuiltinType::Bool && 40033e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian BT->getKind() <= BuiltinType::LongLong; 40133e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian if (const TagType *TT = dyn_cast<TagType>(CanonicalType)) 402834a72ac74cf4ff07ba6215545dba3db578f8a07Chris Lattner if (TT->getDecl()->isEnum() && TT->getDecl()->isDefinition()) 403834a72ac74cf4ff07ba6215545dba3db578f8a07Chris Lattner return true; // Complete enum types are integral. 4048e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor // FIXME: In C++, enum types are never integral. 405f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman if (isa<FixedWidthIntType>(CanonicalType)) 406f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman return true; 40733e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian return false; 40833e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian} 40933e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian 41013b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroffbool Type::isEnumeralType() const { 41113b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff if (const TagType *TT = dyn_cast<TagType>(CanonicalType)) 41239ba4aeca296b1c9f04bde7d9d3cbbf129f1abd3Argyrios Kyrtzidis return TT->getDecl()->isEnum(); 41313b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff return false; 41413b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff} 41513b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff 41613b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroffbool Type::isBooleanType() const { 41713b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 41813b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff return BT->getKind() == BuiltinType::Bool; 41913b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff return false; 42013b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff} 42113b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff 42213b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroffbool Type::isCharType() const { 42313b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 42413b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff return BT->getKind() == BuiltinType::Char_U || 42513b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff BT->getKind() == BuiltinType::UChar || 426c67ad5f299bb2c09e4567def8ff0d34bd15a42fdAnders Carlsson BT->getKind() == BuiltinType::Char_S || 427c67ad5f299bb2c09e4567def8ff0d34bd15a42fdAnders Carlsson BT->getKind() == BuiltinType::SChar; 42813b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff return false; 42913b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff} 43013b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff 43177a52233f7c0f162672652051bfe78b65ad4f789Douglas Gregorbool Type::isWideCharType() const { 43277a52233f7c0f162672652051bfe78b65ad4f789Douglas Gregor if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 43377a52233f7c0f162672652051bfe78b65ad4f789Douglas Gregor return BT->getKind() == BuiltinType::WChar; 43477a52233f7c0f162672652051bfe78b65ad4f789Douglas Gregor return false; 43577a52233f7c0f162672652051bfe78b65ad4f789Douglas Gregor} 43677a52233f7c0f162672652051bfe78b65ad4f789Douglas Gregor 437d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner/// isSignedIntegerType - Return true if this is an integer type that is 438d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner/// signed, according to C99 6.2.5p4 [char, signed char, short, int, long..], 439d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner/// an enum decl which has a signed representation, or a vector of signed 440d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner/// integer element type. 4415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isSignedIntegerType() const { 4425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) { 4435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return BT->getKind() >= BuiltinType::Char_S && 4445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer BT->getKind() <= BuiltinType::LongLong; 4455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 4461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 44737c1b78a20a09b0456aa5caa15e159027010ca22Chris Lattner if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) 44837c1b78a20a09b0456aa5caa15e159027010ca22Chris Lattner return ET->getDecl()->getIntegerType()->isSignedIntegerType(); 4491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 450f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman if (const FixedWidthIntType *FWIT = 451f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman dyn_cast<FixedWidthIntType>(CanonicalType)) 452f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman return FWIT->isSigned(); 4531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 454c63b96ad706e054a1390dd2ab53af9f05d33bbb1Steve Naroff if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType)) 455c63b96ad706e054a1390dd2ab53af9f05d33bbb1Steve Naroff return VT->getElementType()->isSignedIntegerType(); 4565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return false; 4575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 4585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 459d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner/// isUnsignedIntegerType - Return true if this is an integer type that is 460d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner/// unsigned, according to C99 6.2.5p6 [which returns true for _Bool], an enum 461d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner/// decl which has an unsigned representation, or a vector of unsigned integer 462d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner/// element type. 4635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isUnsignedIntegerType() const { 4645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) { 4655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return BT->getKind() >= BuiltinType::Bool && 4661c03ca30ae962199ef702324b48550f6af7fdc32Anders Carlsson BT->getKind() <= BuiltinType::UInt128; 4675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 468d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner 46937c1b78a20a09b0456aa5caa15e159027010ca22Chris Lattner if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) 47037c1b78a20a09b0456aa5caa15e159027010ca22Chris Lattner return ET->getDecl()->getIntegerType()->isUnsignedIntegerType(); 471d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner 472f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman if (const FixedWidthIntType *FWIT = 473f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman dyn_cast<FixedWidthIntType>(CanonicalType)) 474f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman return !FWIT->isSigned(); 475f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman 476c63b96ad706e054a1390dd2ab53af9f05d33bbb1Steve Naroff if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType)) 477c63b96ad706e054a1390dd2ab53af9f05d33bbb1Steve Naroff return VT->getElementType()->isUnsignedIntegerType(); 4785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return false; 4795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 4805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isFloatingType() const { 4825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 4835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return BT->getKind() >= BuiltinType::Float && 4845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer BT->getKind() <= BuiltinType::LongDouble; 4855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (const ComplexType *CT = dyn_cast<ComplexType>(CanonicalType)) 486729a2131228cb7fcbc00bd8af36bc6f14d12317dChris Lattner return CT->getElementType()->isFloatingType(); 487c63b96ad706e054a1390dd2ab53af9f05d33bbb1Steve Naroff if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType)) 488c63b96ad706e054a1390dd2ab53af9f05d33bbb1Steve Naroff return VT->getElementType()->isFloatingType(); 4895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return false; 4905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 4915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isRealFloatingType() const { 4935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 494680523a91dd3351389667c8de17121ba7ae82673John McCall return BT->isFloatingPoint(); 495c63b96ad706e054a1390dd2ab53af9f05d33bbb1Steve Naroff if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType)) 496c63b96ad706e054a1390dd2ab53af9f05d33bbb1Steve Naroff return VT->getElementType()->isRealFloatingType(); 4975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return false; 4985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 4995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isRealType() const { 5015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 5025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return BT->getKind() >= BuiltinType::Bool && 5035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer BT->getKind() <= BuiltinType::LongDouble; 5045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (const TagType *TT = dyn_cast<TagType>(CanonicalType)) 505834a72ac74cf4ff07ba6215545dba3db578f8a07Chris Lattner return TT->getDecl()->isEnum() && TT->getDecl()->isDefinition(); 506f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman if (isa<FixedWidthIntType>(CanonicalType)) 507f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman return true; 508c63b96ad706e054a1390dd2ab53af9f05d33bbb1Steve Naroff if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType)) 509c63b96ad706e054a1390dd2ab53af9f05d33bbb1Steve Naroff return VT->getElementType()->isRealType(); 5105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return false; 5115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 5125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isArithmeticType() const { 5145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 515a7fbf7282eadebaf1293d9f970b01fb57f4b0ae4Douglas Gregor return BT->getKind() >= BuiltinType::Bool && 516a7fbf7282eadebaf1293d9f970b01fb57f4b0ae4Douglas Gregor BT->getKind() <= BuiltinType::LongDouble; 51737c1b78a20a09b0456aa5caa15e159027010ca22Chris Lattner if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) 51837c1b78a20a09b0456aa5caa15e159027010ca22Chris Lattner // GCC allows forward declaration of enum types (forbid by C99 6.7.2.3p2). 51937c1b78a20a09b0456aa5caa15e159027010ca22Chris Lattner // If a body isn't seen by the time we get here, return false. 52037c1b78a20a09b0456aa5caa15e159027010ca22Chris Lattner return ET->getDecl()->isDefinition(); 521f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman if (isa<FixedWidthIntType>(CanonicalType)) 522f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman return true; 5235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return isa<ComplexType>(CanonicalType) || isa<VectorType>(CanonicalType); 5245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 5255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isScalarType() const { 5275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 5285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return BT->getKind() != BuiltinType::Void; 5295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (const TagType *TT = dyn_cast<TagType>(CanonicalType)) { 530834a72ac74cf4ff07ba6215545dba3db578f8a07Chris Lattner // Enums are scalar types, but only if they are defined. Incomplete enums 531834a72ac74cf4ff07ba6215545dba3db578f8a07Chris Lattner // are not treated as scalar types. 532834a72ac74cf4ff07ba6215545dba3db578f8a07Chris Lattner if (TT->getDecl()->isEnum() && TT->getDecl()->isDefinition()) 5335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return true; 5345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return false; 5355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 536f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman if (isa<FixedWidthIntType>(CanonicalType)) 537f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman return true; 5385618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff return isa<PointerType>(CanonicalType) || 5395618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff isa<BlockPointerType>(CanonicalType) || 540f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl isa<MemberPointerType>(CanonicalType) || 5415618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff isa<ComplexType>(CanonicalType) || 542d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff isa<ObjCObjectPointerType>(CanonicalType); 5435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 5445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 545d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor/// \brief Determines whether the type is a C++ aggregate type or C 546d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor/// aggregate or union type. 547d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor/// 548d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor/// An aggregate type is an array or a class type (struct, union, or 549d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor/// class) that has no user-declared constructors, no private or 550d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor/// protected non-static data members, no base classes, and no virtual 551d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor/// functions (C++ [dcl.init.aggr]p1). The notion of an aggregate type 552d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor/// subsumes the notion of C aggregates (C99 6.2.5p21) because it also 553d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor/// includes union types. 5545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isAggregateType() const { 555c1efaecf0373f1a55c5ef4c234357cf726fc0600Douglas Gregor if (const RecordType *Record = dyn_cast<RecordType>(CanonicalType)) { 556c1efaecf0373f1a55c5ef4c234357cf726fc0600Douglas Gregor if (CXXRecordDecl *ClassDecl = dyn_cast<CXXRecordDecl>(Record->getDecl())) 557c1efaecf0373f1a55c5ef4c234357cf726fc0600Douglas Gregor return ClassDecl->isAggregate(); 558c1efaecf0373f1a55c5ef4c234357cf726fc0600Douglas Gregor 559d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor return true; 560c1efaecf0373f1a55c5ef4c234357cf726fc0600Douglas Gregor } 561c1efaecf0373f1a55c5ef4c234357cf726fc0600Douglas Gregor 562c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman return isa<ArrayType>(CanonicalType); 5635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 5645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5659bfa73c5ab7bf4b0e749d04f29da6884e8d5bd9fChris Lattner/// isConstantSizeType - Return true if this is not a variable sized type, 5669bfa73c5ab7bf4b0e749d04f29da6884e8d5bd9fChris Lattner/// according to the rules of C99 6.7.5p3. It is not legal to call this on 567898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// incomplete types or dependent types. 5683c2b3170041f69a92904e3bab9b6d654eaf260acEli Friedmanbool Type::isConstantSizeType() const { 569d52a4578144ab2887912e52eabec58a857a44adbChris Lattner assert(!isIncompleteType() && "This doesn't make sense for incomplete types"); 570898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor assert(!isDependentType() && "This doesn't make sense for dependent types"); 5719bfa73c5ab7bf4b0e749d04f29da6884e8d5bd9fChris Lattner // The VAT must have a size, as it is known to be complete. 5729bfa73c5ab7bf4b0e749d04f29da6884e8d5bd9fChris Lattner return !isa<VariableArrayType>(CanonicalType); 5735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 5745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// isIncompleteType - Return true if this is an incomplete type (C99 6.2.5p1) 5765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// - a type that can describe objects, but which lacks information needed to 5775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// determine its size. 5781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpbool Type::isIncompleteType() const { 5791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump switch (CanonicalType->getTypeClass()) { 5805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer default: return false; 5815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Builtin: 5825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Void is the only incomplete builtin type. Per C99 6.2.5p19, it can never 5835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // be completed. 5845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return isVoidType(); 58572564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor case Record: 58672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor case Enum: 5875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // A tagged type (struct/union/enum/class) is incomplete if the decl is a 5885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // forward declaration, but not a full definition (C99 6.2.5p22). 5895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return !cast<TagType>(CanonicalType)->getDecl()->isDefinition(); 590923d56d436f750bc1f29db50e641078725558a1bSebastian Redl case ConstantArray: 591923d56d436f750bc1f29db50e641078725558a1bSebastian Redl // An array is incomplete if its element type is incomplete 592923d56d436f750bc1f29db50e641078725558a1bSebastian Redl // (C++ [dcl.array]p1). 593923d56d436f750bc1f29db50e641078725558a1bSebastian Redl // We don't handle variable arrays (they're not allowed in C++) or 594923d56d436f750bc1f29db50e641078725558a1bSebastian Redl // dependent-sized arrays (dependent types are never treated as incomplete). 595923d56d436f750bc1f29db50e641078725558a1bSebastian Redl return cast<ArrayType>(CanonicalType)->getElementType()->isIncompleteType(); 596c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman case IncompleteArray: 5975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // An array of unknown size is an incomplete type (C99 6.2.5p22). 598c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman return true; 5991efaa9594a81709a17658fd80ae7e783e1026407Chris Lattner case ObjCInterface: 6001efaa9594a81709a17658fd80ae7e783e1026407Chris Lattner // ObjC interfaces are incomplete if they are @class, not @interface. 6011efaa9594a81709a17658fd80ae7e783e1026407Chris Lattner return cast<ObjCInterfaceType>(this)->getDecl()->isForwardDecl(); 6025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 6035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 6045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 60564b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl/// isPODType - Return true if this is a plain-old-data type (C++ 3.9p10) 60664b45f7e0d3167f040841ac2920aead7f080730dSebastian Redlbool Type::isPODType() const { 60764b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl // The compiler shouldn't query this for incomplete types, but the user might. 60864b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl // We return false for that case. 60964b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl if (isIncompleteType()) 61064b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl return false; 61164b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 61264b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl switch (CanonicalType->getTypeClass()) { 61364b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl // Everything not explicitly mentioned is not POD. 61464b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl default: return false; 61564b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl case VariableArray: 61664b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl case ConstantArray: 61764b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl // IncompleteArray is caught by isIncompleteType() above. 61864b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl return cast<ArrayType>(CanonicalType)->getElementType()->isPODType(); 61964b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 62064b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl case Builtin: 62164b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl case Complex: 62264b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl case Pointer: 623f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl case MemberPointer: 62464b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl case Vector: 62564b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl case ExtVector: 626d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff case ObjCObjectPointer: 62764b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl return true; 62864b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 62972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor case Enum: 63072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor return true; 63172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor 63272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor case Record: 6331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (CXXRecordDecl *ClassDecl 634c1efaecf0373f1a55c5ef4c234357cf726fc0600Douglas Gregor = dyn_cast<CXXRecordDecl>(cast<RecordType>(CanonicalType)->getDecl())) 635c1efaecf0373f1a55c5ef4c234357cf726fc0600Douglas Gregor return ClassDecl->isPOD(); 636c1efaecf0373f1a55c5ef4c234357cf726fc0600Douglas Gregor 63764b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl // C struct/union is POD. 63864b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl return true; 63964b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl } 64064b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl} 64164b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 642ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redlbool Type::isLiteralType() const { 643ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl if (isIncompleteType()) 644ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl return false; 645ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl 646ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl // C++0x [basic.types]p10: 647ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl // A type is a literal type if it is: 648ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl switch (CanonicalType->getTypeClass()) { 649ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl // We're whitelisting 650ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl default: return false; 651ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl 652ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl // -- a scalar type 653ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl case Builtin: 654ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl case Complex: 655ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl case Pointer: 656ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl case MemberPointer: 657ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl case Vector: 658ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl case ExtVector: 659ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl case ObjCObjectPointer: 660ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl case Enum: 661ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl return true; 662ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl 663ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl // -- a class type with ... 664ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl case Record: 665ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl // FIXME: Do the tests 666ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl return false; 667ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl 668ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl // -- an array of literal type 669ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl // Extension: variable arrays cannot be literal types, since they're 670ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl // runtime-sized. 671ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl case ConstantArray: 672ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl return cast<ArrayType>(CanonicalType)->getElementType()->isLiteralType(); 673ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl } 674ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl} 675ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl 6765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isPromotableIntegerType() const { 677183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const BuiltinType *BT = getAs<BuiltinType>()) 6782a18dfe292cf3c406a769c3672080970ac586345Chris Lattner switch (BT->getKind()) { 6792a18dfe292cf3c406a769c3672080970ac586345Chris Lattner case BuiltinType::Bool: 6802a18dfe292cf3c406a769c3672080970ac586345Chris Lattner case BuiltinType::Char_S: 6812a18dfe292cf3c406a769c3672080970ac586345Chris Lattner case BuiltinType::Char_U: 6822a18dfe292cf3c406a769c3672080970ac586345Chris Lattner case BuiltinType::SChar: 6832a18dfe292cf3c406a769c3672080970ac586345Chris Lattner case BuiltinType::UChar: 6842a18dfe292cf3c406a769c3672080970ac586345Chris Lattner case BuiltinType::Short: 6852a18dfe292cf3c406a769c3672080970ac586345Chris Lattner case BuiltinType::UShort: 6862a18dfe292cf3c406a769c3672080970ac586345Chris Lattner return true; 6871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump default: 6882a18dfe292cf3c406a769c3672080970ac586345Chris Lattner return false; 6892a18dfe292cf3c406a769c3672080970ac586345Chris Lattner } 6902a18dfe292cf3c406a769c3672080970ac586345Chris Lattner return false; 6915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 6925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6936e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redlbool Type::isNullPtrType() const { 694183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const BuiltinType *BT = getAs<BuiltinType>()) 6956e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl return BT->getKind() == BuiltinType::NullPtr; 6966e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl return false; 6976e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl} 6986e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl 69922b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedmanbool Type::isSpecifierType() const { 70022b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman // Note that this intentionally does not use the canonical type. 70122b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman switch (getTypeClass()) { 70222b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman case Builtin: 70322b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman case Record: 70422b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman case Enum: 70522b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman case Typedef: 706c8f2c61f4f667c2bc3e4e74b274fa397a4232393Eli Friedman case Complex: 707c8f2c61f4f667c2bc3e4e74b274fa397a4232393Eli Friedman case TypeOfExpr: 708c8f2c61f4f667c2bc3e4e74b274fa397a4232393Eli Friedman case TypeOf: 709c8f2c61f4f667c2bc3e4e74b274fa397a4232393Eli Friedman case TemplateTypeParm: 71049a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall case SubstTemplateTypeParm: 711c8f2c61f4f667c2bc3e4e74b274fa397a4232393Eli Friedman case TemplateSpecialization: 712c8f2c61f4f667c2bc3e4e74b274fa397a4232393Eli Friedman case QualifiedName: 713c8f2c61f4f667c2bc3e4e74b274fa397a4232393Eli Friedman case Typename: 714c8f2c61f4f667c2bc3e4e74b274fa397a4232393Eli Friedman case ObjCInterface: 715d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff case ObjCObjectPointer: 71622b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman return true; 71722b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman default: 71822b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman return false; 71922b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman } 72022b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman} 72122b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman 722cd01f17358dc8ef19338c0e2321138dd0a6160d9Argyrios Kyrtzidisconst char *Type::getTypeClassName() const { 723cd01f17358dc8ef19338c0e2321138dd0a6160d9Argyrios Kyrtzidis switch (TC) { 724cd01f17358dc8ef19338c0e2321138dd0a6160d9Argyrios Kyrtzidis default: assert(0 && "Type class not in TypeNodes.def!"); 725cd01f17358dc8ef19338c0e2321138dd0a6160d9Argyrios Kyrtzidis#define ABSTRACT_TYPE(Derived, Base) 726cd01f17358dc8ef19338c0e2321138dd0a6160d9Argyrios Kyrtzidis#define TYPE(Derived, Base) case Derived: return #Derived; 727cd01f17358dc8ef19338c0e2321138dd0a6160d9Argyrios Kyrtzidis#include "clang/AST/TypeNodes.def" 728cd01f17358dc8ef19338c0e2321138dd0a6160d9Argyrios Kyrtzidis } 729cd01f17358dc8ef19338c0e2321138dd0a6160d9Argyrios Kyrtzidis} 730cd01f17358dc8ef19338c0e2321138dd0a6160d9Argyrios Kyrtzidis 731e4f2142d00fa5fdb580c4e2413da91882d955381Chris Lattnerconst char *BuiltinType::getName(const LangOptions &LO) const { 7325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer switch (getKind()) { 7335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer default: assert(0 && "Unknown builtin type!"); 7345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Void: return "void"; 735e4f2142d00fa5fdb580c4e2413da91882d955381Chris Lattner case Bool: return LO.Bool ? "bool" : "_Bool"; 7365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Char_S: return "char"; 7375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Char_U: return "char"; 7385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case SChar: return "signed char"; 7395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Short: return "short"; 7405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Int: return "int"; 7415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Long: return "long"; 7425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case LongLong: return "long long"; 7432df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner case Int128: return "__int128_t"; 7445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case UChar: return "unsigned char"; 7455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case UShort: return "unsigned short"; 7465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case UInt: return "unsigned int"; 7475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case ULong: return "unsigned long"; 7485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case ULongLong: return "unsigned long long"; 7492df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner case UInt128: return "__uint128_t"; 7505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Float: return "float"; 7515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Double: return "double"; 7525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case LongDouble: return "long double"; 75346713efe13c89f4ec9cd9546c7b598fe7186089bArgyrios Kyrtzidis case WChar: return "wchar_t"; 754f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith case Char16: return "char16_t"; 755f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith case Char32: return "char32_t"; 7566e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl case NullPtr: return "nullptr_t"; 7578e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor case Overload: return "<overloaded function type>"; 758898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor case Dependent: return "<dependent type>"; 7596a75cd9c1d54625fca7b5477ab9545bcdbd85ea4Anders Carlsson case UndeducedAuto: return "auto"; 760de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff case ObjCId: return "id"; 761de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff case ObjCClass: return "Class"; 76204765ac135e0c4e6b78651c2a287d80a32b2b8b9Fariborz Jahanian case ObjCSel: return "SEL"; 7635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 7645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 7655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 76672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregorvoid FunctionProtoType::Profile(llvm::FoldingSetNodeID &ID, QualType Result, 767942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner arg_type_iterator ArgTys, 768971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis unsigned NumArgs, bool isVariadic, 769465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl unsigned TypeQuals, bool hasExceptionSpec, 770465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl bool anyExceptionSpec, unsigned NumExceptions, 7712455636163fdd18581d7fdae816433f886d88213Mike Stump exception_iterator Exs, bool NoReturn) { 7725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddPointer(Result.getAsOpaquePtr()); 7735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer for (unsigned i = 0; i != NumArgs; ++i) 7745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddPointer(ArgTys[i].getAsOpaquePtr()); 7755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddInteger(isVariadic); 776971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis ID.AddInteger(TypeQuals); 777465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl ID.AddInteger(hasExceptionSpec); 778465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl if (hasExceptionSpec) { 779465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl ID.AddInteger(anyExceptionSpec); 7801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump for (unsigned i = 0; i != NumExceptions; ++i) 781465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl ID.AddPointer(Exs[i].getAsOpaquePtr()); 782465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl } 7832455636163fdd18581d7fdae816433f886d88213Mike Stump ID.AddInteger(NoReturn); 7845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 7855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 78672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregorvoid FunctionProtoType::Profile(llvm::FoldingSetNodeID &ID) { 787971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis Profile(ID, getResultType(), arg_type_begin(), NumArgs, isVariadic(), 788465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl getTypeQuals(), hasExceptionSpec(), hasAnyExceptionSpec(), 7892455636163fdd18581d7fdae816433f886d88213Mike Stump getNumExceptions(), exception_begin(), getNoReturnAttr()); 7905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 7915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 792d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroffvoid ObjCObjectPointerType::Profile(llvm::FoldingSetNodeID &ID, 79314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff QualType OIT, ObjCProtocolDecl **protocols, 794d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff unsigned NumProtocols) { 79514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff ID.AddPointer(OIT.getAsOpaquePtr()); 7964b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian for (unsigned i = 0; i != NumProtocols; i++) 7974b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian ID.AddPointer(protocols[i]); 7984b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian} 7994b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian 800d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroffvoid ObjCObjectPointerType::Profile(llvm::FoldingSetNodeID &ID) { 80114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff if (getNumProtocols()) 80214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff Profile(ID, getPointeeType(), &Protocols[0], getNumProtocols()); 80314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff else 80414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff Profile(ID, getPointeeType(), 0, 0); 8054b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian} 8064b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian 807a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner/// LookThroughTypedefs - Return the ultimate type this typedef corresponds to 808a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner/// potentially looking through *all* consequtive typedefs. This returns the 809a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner/// sum of the type qualifiers, so if you have: 810a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner/// typedef const int A; 811a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner/// typedef volatile A B; 812a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner/// looking through the typedefs for B will give you "const volatile A". 813a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner/// 814a2c7767ce7d8feb10253f4b650826a20f3324c6fChris LattnerQualType TypedefType::LookThroughTypedefs() const { 815a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner // Usually, there is only a single level of typedefs, be fast in that case. 816a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner QualType FirstType = getDecl()->getUnderlyingType(); 817a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner if (!isa<TypedefType>(FirstType)) 818a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner return FirstType; 8191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 820a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner // Otherwise, do the fully general loop. 8210953e767ff7817f97b3ab20896b229891eeff45bJohn McCall QualifierCollector Qs; 8221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8230953e767ff7817f97b3ab20896b229891eeff45bJohn McCall QualType CurType; 8240953e767ff7817f97b3ab20896b229891eeff45bJohn McCall const TypedefType *TDT = this; 8250953e767ff7817f97b3ab20896b229891eeff45bJohn McCall do { 8260953e767ff7817f97b3ab20896b229891eeff45bJohn McCall CurType = TDT->getDecl()->getUnderlyingType(); 8270953e767ff7817f97b3ab20896b229891eeff45bJohn McCall TDT = dyn_cast<TypedefType>(Qs.strip(CurType)); 8280953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } while (TDT); 8291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8300953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return Qs.apply(CurType); 831a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner} 8325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 833bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCallQualType TypedefType::desugar() const { 834bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall return getDecl()->getUnderlyingType(); 835bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall} 836bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 83772564e73277e29f6db3305d1f27ba408abb7ed88Douglas GregorTypeOfExprType::TypeOfExprType(Expr *E, QualType can) 83872564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor : Type(TypeOfExpr, can, E->isTypeDependent()), TOExpr(E) { 839898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor} 840898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 841bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCallQualType TypeOfExprType::desugar() const { 842bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall return getUnderlyingExpr()->getType(); 843bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall} 844bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 8451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpvoid DependentTypeOfExprType::Profile(llvm::FoldingSetNodeID &ID, 846b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor ASTContext &Context, Expr *E) { 847b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor E->Profile(ID, Context, true); 848b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor} 849b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor 850563a03b1338d31c2462def43253a722bc885d384Anders CarlssonDecltypeType::DecltypeType(Expr *E, QualType underlyingType, QualType can) 8511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : Type(Decltype, can, E->isTypeDependent()), E(E), 852563a03b1338d31c2462def43253a722bc885d384Anders Carlsson UnderlyingType(underlyingType) { 853395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson} 854395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson 8559d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas GregorDependentDecltypeType::DependentDecltypeType(ASTContext &Context, Expr *E) 8569d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor : DecltypeType(E, Context.DependentTy), Context(Context) { } 8579d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor 8581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpvoid DependentDecltypeType::Profile(llvm::FoldingSetNodeID &ID, 8599d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor ASTContext &Context, Expr *E) { 8609d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor E->Profile(ID, Context, true); 8619d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor} 8629d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor 8631eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTagType::TagType(TypeClass TC, TagDecl *D, QualType can) 8647da97d0f31e1ec16998d3de2cfd2e88fe3736673Douglas Gregor : Type(TC, can, D->isDependentType()), decl(D, 0) {} 8657da97d0f31e1ec16998d3de2cfd2e88fe3736673Douglas Gregor 8662daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattnerbool RecordType::classof(const TagType *TT) { 8672daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner return isa<RecordDecl>(TT->getDecl()); 8685edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner} 8695edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner 8702daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattnerbool EnumType::classof(const TagType *TT) { 8712daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner return isa<EnumDecl>(TT->getDecl()); 8725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 8735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 874833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallstatic bool isDependent(const TemplateArgument &Arg) { 875833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall switch (Arg.getKind()) { 876833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall case TemplateArgument::Null: 877833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall assert(false && "Should not have a NULL template argument"); 878833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return false; 879833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 880833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall case TemplateArgument::Type: 881833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return Arg.getAsType()->isDependentType(); 882833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 883788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor case TemplateArgument::Template: 884788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor return Arg.getAsTemplate().isDependent(); 885788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor 886833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall case TemplateArgument::Declaration: 887833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall case TemplateArgument::Integral: 888833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall // Never dependent 889833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return false; 890833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 891833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall case TemplateArgument::Expression: 892833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return (Arg.getAsExpr()->isTypeDependent() || 893833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall Arg.getAsExpr()->isValueDependent()); 894833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 895833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall case TemplateArgument::Pack: 896833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall assert(0 && "FIXME: Implement!"); 897833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return false; 89855f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor } 89940808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor 90040808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor return false; 90155f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor} 90255f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 903833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallbool TemplateSpecializationType:: 904d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCallanyDependentTemplateArguments(const TemplateArgumentListInfo &Args) { 905d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall return anyDependentTemplateArguments(Args.getArgumentArray(), Args.size()); 906d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall} 907d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall 908d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCallbool TemplateSpecializationType:: 909833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallanyDependentTemplateArguments(const TemplateArgumentLoc *Args, unsigned N) { 910833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall for (unsigned i = 0; i != N; ++i) 911833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall if (isDependent(Args[i].getArgument())) 912833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return true; 913833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return false; 914833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall} 915833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 916833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallbool TemplateSpecializationType:: 917833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallanyDependentTemplateArguments(const TemplateArgument *Args, unsigned N) { 918833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall for (unsigned i = 0; i != N; ++i) 919833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall if (isDependent(Args[i])) 920833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return true; 921833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return false; 922833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall} 923833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 9247532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas GregorTemplateSpecializationType:: 9251eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTemplateSpecializationType(ASTContext &Context, TemplateName T, 926828e226ab7ed08b3eb766549e9d3306432137460Douglas Gregor const TemplateArgument *Args, 9277532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor unsigned NumArgs, QualType Canon) 9281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : Type(TemplateSpecialization, 92940808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor Canon.isNull()? QualType(this, 0) : Canon, 9307532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor T.isDependent() || anyDependentTemplateArguments(Args, NumArgs)), 931828e226ab7ed08b3eb766549e9d3306432137460Douglas Gregor Context(Context), 9321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Template(T), NumArgs(NumArgs) { 9331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump assert((!Canon.isNull() || 9347532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor T.isDependent() || anyDependentTemplateArguments(Args, NumArgs)) && 93540808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor "No canonical type for non-dependent class template specialization"); 93655f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 9371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TemplateArgument *TemplateArgs 93840808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor = reinterpret_cast<TemplateArgument *>(this + 1); 93955f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor for (unsigned Arg = 0; Arg < NumArgs; ++Arg) 94040808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor new (&TemplateArgs[Arg]) TemplateArgument(Args[Arg]); 94155f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor} 94255f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 9437532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregorvoid TemplateSpecializationType::Destroy(ASTContext& C) { 944ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor for (unsigned Arg = 0; Arg < NumArgs; ++Arg) { 945ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor // FIXME: Not all expressions get cloned, so we can't yet perform 946ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor // this destruction. 947ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor // if (Expr *E = getArg(Arg).getAsExpr()) 948ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor // E->Destroy(C); 949ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor } 95040808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor} 95140808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor 9527532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas GregorTemplateSpecializationType::iterator 9537532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas GregorTemplateSpecializationType::end() const { 95440808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor return begin() + getNumArgs(); 9555908e9f25bc9a334c99c095e0b1e6a515445be2dDouglas Gregor} 9565908e9f25bc9a334c99c095e0b1e6a515445be2dDouglas Gregor 95740808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregorconst TemplateArgument & 9587532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas GregorTemplateSpecializationType::getArg(unsigned Idx) const { 95940808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor assert(Idx < getNumArgs() && "Template argument out of range"); 96040808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor return getArgs()[Idx]; 96155f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor} 96255f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 9631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpvoid 9641eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTemplateSpecializationType::Profile(llvm::FoldingSetNodeID &ID, 9651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TemplateName T, 9661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const TemplateArgument *Args, 967828e226ab7ed08b3eb766549e9d3306432137460Douglas Gregor unsigned NumArgs, 968828e226ab7ed08b3eb766549e9d3306432137460Douglas Gregor ASTContext &Context) { 9697532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor T.Profile(ID); 97040808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor for (unsigned Idx = 0; Idx < NumArgs; ++Idx) 971828e226ab7ed08b3eb766549e9d3306432137460Douglas Gregor Args[Idx].Profile(ID, Context); 97255f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor} 97397e0179f1ae545e07d9f5e7c1d2ef5c5bab06676Anders Carlsson 9740953e767ff7817f97b3ab20896b229891eeff45bJohn McCallQualType QualifierCollector::apply(QualType QT) const { 9750953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (!hasNonFastQualifiers()) 9760953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return QT.withFastQualifiers(getFastQualifiers()); 9771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9780953e767ff7817f97b3ab20896b229891eeff45bJohn McCall assert(Context && "extended qualifiers but no context!"); 9790953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return Context->getQualifiedType(QT, *this); 9805e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor} 9815e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor 9820953e767ff7817f97b3ab20896b229891eeff45bJohn McCallQualType QualifierCollector::apply(const Type *T) const { 9830953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (!hasNonFastQualifiers()) 9840953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return QualType(T, getFastQualifiers()); 9850953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 9860953e767ff7817f97b3ab20896b229891eeff45bJohn McCall assert(Context && "extended qualifiers but no context!"); 9870953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return Context->getQualifiedType(T, *this); 9885e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor} 9895e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor 990c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroffvoid ObjCInterfaceType::Profile(llvm::FoldingSetNodeID &ID, 991c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff const ObjCInterfaceDecl *Decl, 9921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ObjCProtocolDecl **protocols, 993c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff unsigned NumProtocols) { 994c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff ID.AddPointer(Decl); 995c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff for (unsigned i = 0; i != NumProtocols; i++) 996c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff ID.AddPointer(protocols[i]); 997c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff} 998c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff 999c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroffvoid ObjCInterfaceType::Profile(llvm::FoldingSetNodeID &ID) { 1000c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff if (getNumProtocols()) 1001c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff Profile(ID, getDecl(), &Protocols[0], getNumProtocols()); 1002c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff else 1003c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff Profile(ID, getDecl(), 0, 0); 1004c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff} 1005