Type.cpp revision 71c3673d1e3756d8ef3cbc559fcad1d0b2f18a1f
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" 22465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara#include "clang/Basic/Specifiers.h" 235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "llvm/ADT/StringExtras.h" 24bad351822117eaf280081494e3dbe4a06c0dbfcfDouglas Gregor#include "llvm/Support/raw_ostream.h" 252767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor#include <algorithm> 265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing namespace clang; 275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 28bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCallbool QualType::isConstant(QualType T, ASTContext &Ctx) { 29bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall if (T.isConstQualified()) 30b381aac9bae6d608c72267dd0ed08ec6369e94e4Nuno Lopes return true; 31b381aac9bae6d608c72267dd0ed08ec6369e94e4Nuno Lopes 32bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall if (const ArrayType *AT = Ctx.getAsArrayType(T)) 33bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall return AT->getElementType().isConstant(Ctx); 34b381aac9bae6d608c72267dd0ed08ec6369e94e4Nuno Lopes 35b381aac9bae6d608c72267dd0ed08ec6369e94e4Nuno Lopes return false; 36b381aac9bae6d608c72267dd0ed08ec6369e94e4Nuno Lopes} 37b381aac9bae6d608c72267dd0ed08ec6369e94e4Nuno Lopes 38afb6416bf7f04a00c44092e802f335bb3636489cDouglas GregorType::~Type() { } 39afb6416bf7f04a00c44092e802f335bb3636489cDouglas Gregor 402767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregorunsigned ConstantArrayType::getNumAddressingBits(ASTContext &Context, 412767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor QualType ElementType, 422767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor const llvm::APInt &NumElements) { 432767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor llvm::APSInt SizeExtended(NumElements, true); 442767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor unsigned SizeTypeBits = Context.getTypeSize(Context.getSizeType()); 452767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor SizeExtended.extend(std::max(SizeTypeBits, 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 661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpvoid DependentSizedArrayType::Profile(llvm::FoldingSetNodeID &ID, 6704d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor ASTContext &Context, 6804d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor QualType ET, 6904d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor ArraySizeModifier SizeMod, 7004d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor unsigned TypeQuals, 7104d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor Expr *E) { 7204d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor ID.AddPointer(ET.getAsOpaquePtr()); 7304d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor ID.AddInteger(SizeMod); 7404d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor ID.AddInteger(TypeQuals); 7504d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor E->Profile(ID, Context, true); 7604d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor} 7704d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor 781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpvoid 791eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpDependentSizedExtVectorType::Profile(llvm::FoldingSetNodeID &ID, 802ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor ASTContext &Context, 812ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor QualType ElementType, Expr *SizeExpr) { 822ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor ID.AddPointer(ElementType.getAsOpaquePtr()); 832ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor SizeExpr->Profile(ID, Context, true); 842ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor} 852ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor 86c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner/// getArrayElementTypeNoTypeQual - If this is an array type, return the 87c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner/// element type of the array, potentially with type qualifiers missing. 88c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner/// This method should never be used when type qualifiers are meaningful. 89c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattnerconst Type *Type::getArrayElementTypeNoTypeQual() const { 90c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // If this is directly an array type, return it. 91c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner if (const ArrayType *ATy = dyn_cast<ArrayType>(this)) 92c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return ATy->getElementType().getTypePtr(); 931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 94c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // If the canonical form of this type isn't the right kind, reject it. 950953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (!isa<ArrayType>(CanonicalType)) 96c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return 0; 971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 98c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // If this is a typedef for an array type, strip the typedef off without 99c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // losing all typedef information. 100bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall return cast<ArrayType>(getUnqualifiedDesugaredType()) 101bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall ->getElementType().getTypePtr(); 1022fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner} 1032fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner 104fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor/// \brief Retrieve the unqualified variant of the given type, removing as 105fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor/// little sugar as possible. 106fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor/// 107fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor/// This routine looks through various kinds of sugar to find the 108fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor/// least-desuraged type that is unqualified. For example, given: 109fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor/// 110fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor/// \code 111fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor/// typedef int Integer; 112fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor/// typedef const Integer CInteger; 113fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor/// typedef CInteger DifferenceType; 114fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor/// \endcode 115fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor/// 116fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor/// Executing \c getUnqualifiedTypeSlow() on the type \c DifferenceType will 117fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor/// desugar until we hit the type \c Integer, which has no qualifiers on it. 118fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas GregorQualType QualType::getUnqualifiedTypeSlow() const { 119fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor QualType Cur = *this; 120fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor while (true) { 121fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor if (!Cur.hasQualifiers()) 122fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor return Cur; 123fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor 124fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor const Type *CurTy = Cur.getTypePtr(); 125fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor switch (CurTy->getTypeClass()) { 126fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor#define ABSTRACT_TYPE(Class, Parent) 127fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor#define TYPE(Class, Parent) \ 128fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor case Type::Class: { \ 129fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor const Class##Type *Ty = cast<Class##Type>(CurTy); \ 130fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor if (!Ty->isSugared()) \ 131fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor return Cur.getLocalUnqualifiedType(); \ 132fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor Cur = Ty->desugar(); \ 133fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor break; \ 134fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor } 135fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor#include "clang/AST/TypeNodes.def" 136fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor } 137fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor } 138fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor 139fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor return Cur.getUnqualifiedType(); 140fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor} 141fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor 1422fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner/// getDesugaredType - Return the specified type with any "sugar" removed from 1432fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner/// the type. This takes off typedefs, typeof's etc. If the outer level of 1442fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner/// the type is already concrete, it returns it unmodified. This is similar 1452fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner/// to getting the canonical type, but it doesn't remove *all* typedefs. For 1462fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner/// example, it returns "T*" as "T*", (not as "int*"), because the pointer is 1472fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner/// concrete. 148bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCallQualType QualType::getDesugaredType(QualType T) { 1490953e767ff7817f97b3ab20896b229891eeff45bJohn McCall QualifierCollector Qs; 150c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner 151bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall QualType Cur = T; 152bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall while (true) { 153bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall const Type *CurTy = Qs.strip(Cur); 154bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall switch (CurTy->getTypeClass()) { 155bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall#define ABSTRACT_TYPE(Class, Parent) 156bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall#define TYPE(Class, Parent) \ 157bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall case Type::Class: { \ 158bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall const Class##Type *Ty = cast<Class##Type>(CurTy); \ 159bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall if (!Ty->isSugared()) \ 160bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall return Qs.apply(Cur); \ 161bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall Cur = Ty->desugar(); \ 162bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall break; \ 163bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall } 164bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall#include "clang/AST/TypeNodes.def" 165bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall } 166969c689d893a248eca4f049f5b89f747e66e4bffDouglas Gregor } 167bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall} 1685cdf82164dd7c2b2320d6735c63ace4331e0716dDouglas Gregor 169bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall/// getUnqualifiedDesugaredType - Pull any qualifiers and syntactic 170bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall/// sugar off the given type. This should produce an object of the 171bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall/// same dynamic type as the canonical type. 172bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCallconst Type *Type::getUnqualifiedDesugaredType() const { 173bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall const Type *Cur = this; 174bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 175bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall while (true) { 176bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall switch (Cur->getTypeClass()) { 177bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall#define ABSTRACT_TYPE(Class, Parent) 178bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall#define TYPE(Class, Parent) \ 179bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall case Class: { \ 180bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall const Class##Type *Ty = cast<Class##Type>(Cur); \ 181bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall if (!Ty->isSugared()) return Cur; \ 182bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall Cur = Ty->desugar().getTypePtr(); \ 183bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall break; \ 184bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall } 185bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall#include "clang/AST/TypeNodes.def" 186bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall } 187bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall } 188c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner} 189c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner 1905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// isVoidType - Helper method to determine if this is the 'void' type. 1915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isVoidType() const { 1925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 1935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return BT->getKind() == BuiltinType::Void; 1945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return false; 1955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 1965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isDerivedType() const { 1985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer switch (CanonicalType->getTypeClass()) { 1995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Pointer: 200fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff case VariableArray: 201fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff case ConstantArray: 202c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman case IncompleteArray: 2035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case FunctionProto: 2045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case FunctionNoProto: 2057c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl case LValueReference: 2067c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl case RValueReference: 20772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor case Record: 2085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return true; 2095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer default: 2105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return false; 2115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 2135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 21499dc91422144483c20d1c7381bc9ac634b646b04Chris Lattnerbool Type::isClassType() const { 2156217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const RecordType *RT = getAs<RecordType>()) 216f728a4a05df2455e1c6e62173ab720a92cd4a074Chris Lattner return RT->getDecl()->isClass(); 21799dc91422144483c20d1c7381bc9ac634b646b04Chris Lattner return false; 21899dc91422144483c20d1c7381bc9ac634b646b04Chris Lattner} 219c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattnerbool Type::isStructureType() const { 2206217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const RecordType *RT = getAs<RecordType>()) 221f728a4a05df2455e1c6e62173ab720a92cd4a074Chris Lattner return RT->getDecl()->isStruct(); 222c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner return false; 223c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner} 224fb87b89fc9eb103e19fb8e4b925c23f0bd091b99Douglas Gregorbool Type::isStructureOrClassType() const { 225fb87b89fc9eb103e19fb8e4b925c23f0bd091b99Douglas Gregor if (const RecordType *RT = getAs<RecordType>()) 226fb87b89fc9eb103e19fb8e4b925c23f0bd091b99Douglas Gregor return RT->getDecl()->isStruct() || RT->getDecl()->isClass(); 227fb87b89fc9eb103e19fb8e4b925c23f0bd091b99Douglas Gregor return false; 228fb87b89fc9eb103e19fb8e4b925c23f0bd091b99Douglas Gregor} 2297154a77e7c1f23418342d3b72836ab504aa7821eSteve Naroffbool Type::isVoidPointerType() const { 2306217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const PointerType *PT = getAs<PointerType>()) 2317154a77e7c1f23418342d3b72836ab504aa7821eSteve Naroff return PT->getPointeeType()->isVoidType(); 2327154a77e7c1f23418342d3b72836ab504aa7821eSteve Naroff return false; 2337154a77e7c1f23418342d3b72836ab504aa7821eSteve Naroff} 2347154a77e7c1f23418342d3b72836ab504aa7821eSteve Naroff 235c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattnerbool Type::isUnionType() const { 2366217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const RecordType *RT = getAs<RecordType>()) 237f728a4a05df2455e1c6e62173ab720a92cd4a074Chris Lattner return RT->getDecl()->isUnion(); 238c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner return false; 239c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner} 240c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner 241c6fb90a7246c2d5d3233e70107bf9d8c7c9e535bChris Lattnerbool Type::isComplexType() const { 24202f62a9fedbc370fba081303399410a3afdde29fSteve Naroff if (const ComplexType *CT = dyn_cast<ComplexType>(CanonicalType)) 24302f62a9fedbc370fba081303399410a3afdde29fSteve Naroff return CT->getElementType()->isFloatingType(); 24402f62a9fedbc370fba081303399410a3afdde29fSteve Naroff return false; 245c6fb90a7246c2d5d3233e70107bf9d8c7c9e535bChris Lattner} 246c6fb90a7246c2d5d3233e70107bf9d8c7c9e535bChris Lattner 2474cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroffbool Type::isComplexIntegerType() const { 2484cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroff // Check for GCC complex integer extension. 2490953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return getAsComplexIntegerType(); 2504cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroff} 2514cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroff 2524cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroffconst ComplexType *Type::getAsComplexIntegerType() const { 2530953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (const ComplexType *Complex = getAs<ComplexType>()) 2540953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (Complex->getElementType()->isIntegerType()) 2550953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return Complex; 2560953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return 0; 2574cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroff} 2584cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroff 25914108da7f7fc059772711e4ffee1322a27b152a7Steve NaroffQualType Type::getPointeeType() const { 2606217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const PointerType *PT = getAs<PointerType>()) 26114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return PT->getPointeeType(); 262183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) 26314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return OPT->getPointeeType(); 2646217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const BlockPointerType *BPT = getAs<BlockPointerType>()) 26514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return BPT->getPointeeType(); 2669c21289a866b677d21ed3d5ecfdfd5ced5a55410Mike Stump if (const ReferenceType *RT = getAs<ReferenceType>()) 2679c21289a866b677d21ed3d5ecfdfd5ced5a55410Mike Stump return RT->getPointeeType(); 26814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return QualType(); 26914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff} 270b77792eabf5882cf9af8cc810599b20432fda6c2Chris Lattner 271c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattnerconst RecordType *Type::getAsStructureType() const { 2727064f5c95bbdb17680d0ea658d4090898c2592d3Steve Naroff // If this is directly a structure type, return it. 273c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner if (const RecordType *RT = dyn_cast<RecordType>(this)) { 27439ba4aeca296b1c9f04bde7d9d3cbbf129f1abd3Argyrios Kyrtzidis if (RT->getDecl()->isStruct()) 275c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner return RT; 2767064f5c95bbdb17680d0ea658d4090898c2592d3Steve Naroff } 277dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner 278dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner // If the canonical form of this type isn't the right kind, reject it. 279c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner if (const RecordType *RT = dyn_cast<RecordType>(CanonicalType)) { 28039ba4aeca296b1c9f04bde7d9d3cbbf129f1abd3Argyrios Kyrtzidis if (!RT->getDecl()->isStruct()) 281dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner return 0; 2821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 283dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner // If this is a typedef for a structure type, strip the typedef off without 284dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner // losing all typedef information. 285bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall return cast<RecordType>(getUnqualifiedDesugaredType()); 2865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2877064f5c95bbdb17680d0ea658d4090898c2592d3Steve Naroff return 0; 2885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 2895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpconst RecordType *Type::getAsUnionType() const { 2917064f5c95bbdb17680d0ea658d4090898c2592d3Steve Naroff // If this is directly a union type, return it. 292c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner if (const RecordType *RT = dyn_cast<RecordType>(this)) { 29339ba4aeca296b1c9f04bde7d9d3cbbf129f1abd3Argyrios Kyrtzidis if (RT->getDecl()->isUnion()) 294c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner return RT; 2957064f5c95bbdb17680d0ea658d4090898c2592d3Steve Naroff } 2961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 297dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner // If the canonical form of this type isn't the right kind, reject it. 298c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner if (const RecordType *RT = dyn_cast<RecordType>(CanonicalType)) { 29939ba4aeca296b1c9f04bde7d9d3cbbf129f1abd3Argyrios Kyrtzidis if (!RT->getDecl()->isUnion()) 300dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner return 0; 301dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner 302dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner // If this is a typedef for a union type, strip the typedef off without 303dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner // losing all typedef information. 304bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall return cast<RecordType>(getUnqualifiedDesugaredType()); 3055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 3061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3077064f5c95bbdb17680d0ea658d4090898c2592d3Steve Naroff return 0; 3085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 3095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 310c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallObjCObjectType::ObjCObjectType(QualType Canonical, QualType Base, 311c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCProtocolDecl * const *Protocols, 312c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall unsigned NumProtocols) 31335495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor : Type(ObjCObject, Canonical, false, false), 314c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall BaseType(Base) { 31571c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall SubclassBits = NumProtocols; 31671c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall assert(getNumProtocols() == NumProtocols && 317c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall "bitfield overflow in protocol count"); 318fd6a0887a099256c35a5b23e9afd517ffe95fa0aDouglas Gregor if (NumProtocols) 319c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall memcpy(getProtocolStorage(), Protocols, 320c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall NumProtocols * sizeof(ObjCProtocolDecl*)); 32171842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek} 32271842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek 323c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallconst ObjCObjectType *Type::getAsObjCQualifiedInterfaceType() const { 324c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall // There is no sugar for ObjCObjectType's, just return the canonical 325c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff // type pointer if it is the right class. There is no typedef information to 326c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff // return and these cannot be Address-space qualified. 327c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall if (const ObjCObjectType *T = getAs<ObjCObjectType>()) 328c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall if (T->getNumProtocols() && T->getInterface()) 329c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return T; 330c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff return 0; 331c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff} 332c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff 333c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroffbool Type::isObjCQualifiedInterfaceType() const { 334e61ad0b7063fcd97204b1cce5558685144267eb6Steve Naroff return getAsObjCQualifiedInterfaceType() != 0; 335c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff} 336c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff 337d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroffconst ObjCObjectPointerType *Type::getAsObjCQualifiedIdType() const { 338eca7be6b7ebd93682eeaab2c71d59f2995dacdccChris Lattner // There is no sugar for ObjCQualifiedIdType's, just return the canonical 339eca7be6b7ebd93682eeaab2c71d59f2995dacdccChris Lattner // type pointer if it is the right class. 340183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) { 341d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff if (OPT->isObjCQualifiedIdType()) 342d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff return OPT; 343d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff } 344d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff return 0; 345368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner} 346368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner 34714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroffconst ObjCObjectPointerType *Type::getAsObjCInterfacePointerType() const { 348183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) { 34914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff if (OPT->getInterfaceType()) 35014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return OPT; 35114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff } 35214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return 0; 35314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff} 35414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff 355a91d6a6619a91d0ca7102d8ab5678d855f04d850Fariborz Jahanianconst CXXRecordDecl *Type::getCXXRecordDeclForPointerType() const { 3566217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const PointerType *PT = getAs<PointerType>()) 3576217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const RecordType *RT = PT->getPointeeType()->getAs<RecordType>()) 358a91d6a6619a91d0ca7102d8ab5678d855f04d850Fariborz Jahanian return dyn_cast<CXXRecordDecl>(RT->getDecl()); 359a91d6a6619a91d0ca7102d8ab5678d855f04d850Fariborz Jahanian return 0; 360a91d6a6619a91d0ca7102d8ab5678d855f04d850Fariborz Jahanian} 361a91d6a6619a91d0ca7102d8ab5678d855f04d850Fariborz Jahanian 362c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas GregorCXXRecordDecl *Type::getAsCXXRecordDecl() const { 363c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor if (const RecordType *RT = getAs<RecordType>()) 364c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor return dyn_cast<CXXRecordDecl>(RT->getDecl()); 365c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor else if (const InjectedClassNameType *Injected 366c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor = getAs<InjectedClassNameType>()) 367c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor return Injected->getDecl(); 368c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor 369c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor return 0; 370c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor} 371c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor 3725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isIntegerType() const { 3735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 3745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return BT->getKind() >= BuiltinType::Bool && 3752df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner BT->getKind() <= BuiltinType::Int128; 3761274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) 377834a72ac74cf4ff07ba6215545dba3db578f8a07Chris Lattner // Incomplete enum types are not treated as integer types. 3788e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor // FIXME: In C++, enum types are never integer types. 3791274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor return ET->getDecl()->isComplete(); 380f60946222721d9ba3c059563935c17b84703187aDouglas Gregor return false; 381f60946222721d9ba3c059563935c17b84703187aDouglas Gregor} 382f60946222721d9ba3c059563935c17b84703187aDouglas Gregor 383f60946222721d9ba3c059563935c17b84703187aDouglas Gregorbool Type::hasIntegerRepresentation() const { 384c63b96ad706e054a1390dd2ab53af9f05d33bbb1Steve Naroff if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType)) 385c63b96ad706e054a1390dd2ab53af9f05d33bbb1Steve Naroff return VT->getElementType()->isIntegerType(); 386f60946222721d9ba3c059563935c17b84703187aDouglas Gregor else 387f60946222721d9ba3c059563935c17b84703187aDouglas Gregor return isIntegerType(); 3885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 3895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3909d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// \brief Determine whether this type is an integral type. 3919d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// 3929d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// This routine determines whether the given type is an integral type per 3939d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// C++ [basic.fundamental]p7. Although the C standard does not define the 3949d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// term "integral type", it has a similar term "integer type", and in C++ 3959d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// the two terms are equivalent. However, C's "integer type" includes 3969d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// enumeration types, while C++'s "integer type" does not. The \c ASTContext 3979d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// parameter is used to determine whether we should be following the C or 3989d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// C++ rules when determining whether this type is an integral/integer type. 3999d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// 4009d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// For cases where C permits "an integer type" and C++ permits "an integral 4019d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// type", use this routine. 4029d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// 4039d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// For cases where C permits "an integer type" and C++ permits "an integral 4049d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// or enumeration type", use \c isIntegralOrEnumerationType() instead. 4059d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// 4069d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// \param Ctx The context in which this type occurs. 4079d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// 4089d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// \returns true if the type is considered an integral type, false otherwise. 4099d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregorbool Type::isIntegralType(ASTContext &Ctx) const { 41033e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 41133e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian return BT->getKind() >= BuiltinType::Bool && 412f5f7d864f5067d1ea4bff7fcf41b53a43b7b48baAnders Carlsson BT->getKind() <= BuiltinType::Int128; 4139d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor 4149d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor if (!Ctx.getLangOptions().CPlusPlus) 4151274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) 4161274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor return ET->getDecl()->isComplete(); // Complete enum types are integral in C. 4179d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor 41833e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian return false; 41933e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian} 42033e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian 4212ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregorbool Type::isIntegralOrEnumerationType() const { 4222ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 4232ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor return BT->getKind() >= BuiltinType::Bool && 4242ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor BT->getKind() <= BuiltinType::Int128; 42534fd628d22f54baddf30cf80c401b2f862a31b23Eli Friedman 42634fd628d22f54baddf30cf80c401b2f862a31b23Eli Friedman // Check for a complete enum type; incomplete enum types are not properly an 42734fd628d22f54baddf30cf80c401b2f862a31b23Eli Friedman // enumeration type in the sense required here. 4281274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) 4291274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor return ET->getDecl()->isComplete(); 43034fd628d22f54baddf30cf80c401b2f862a31b23Eli Friedman 4312ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor return false; 4322ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor} 4332ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor 4341274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregorbool Type::isIntegralOrUnscopedEnumerationType() const { 4351274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 4361274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor return BT->getKind() >= BuiltinType::Bool && 4371274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor BT->getKind() <= BuiltinType::Int128; 4381274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor 4391274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor // Check for a complete enum type; incomplete enum types are not properly an 4401274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor // enumeration type in the sense required here. 4411274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor // C++0x: However, if the underlying type of the enum is fixed, it is 4421274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor // considered complete. 4431274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) 4441274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor return ET->getDecl()->isComplete() && !ET->getDecl()->isScoped(); 4451274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor 4461274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor return false; 4471274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor} 4481274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor 4491274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor 45013b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroffbool Type::isBooleanType() const { 45113b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 45213b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff return BT->getKind() == BuiltinType::Bool; 45313b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff return false; 45413b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff} 45513b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff 45613b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroffbool Type::isCharType() const { 45713b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 45813b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff return BT->getKind() == BuiltinType::Char_U || 45913b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff BT->getKind() == BuiltinType::UChar || 460c67ad5f299bb2c09e4567def8ff0d34bd15a42fdAnders Carlsson BT->getKind() == BuiltinType::Char_S || 461c67ad5f299bb2c09e4567def8ff0d34bd15a42fdAnders Carlsson BT->getKind() == BuiltinType::SChar; 46213b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff return false; 46313b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff} 46413b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff 46577a52233f7c0f162672652051bfe78b65ad4f789Douglas Gregorbool Type::isWideCharType() const { 46677a52233f7c0f162672652051bfe78b65ad4f789Douglas Gregor if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 46777a52233f7c0f162672652051bfe78b65ad4f789Douglas Gregor return BT->getKind() == BuiltinType::WChar; 46877a52233f7c0f162672652051bfe78b65ad4f789Douglas Gregor return false; 46977a52233f7c0f162672652051bfe78b65ad4f789Douglas Gregor} 47077a52233f7c0f162672652051bfe78b65ad4f789Douglas Gregor 47120093b4bf698f292c664676987541d5103b65b15Douglas Gregor/// \brief Determine whether this type is any of the built-in character 47220093b4bf698f292c664676987541d5103b65b15Douglas Gregor/// types. 47320093b4bf698f292c664676987541d5103b65b15Douglas Gregorbool Type::isAnyCharacterType() const { 47420093b4bf698f292c664676987541d5103b65b15Douglas Gregor if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 47520093b4bf698f292c664676987541d5103b65b15Douglas Gregor return (BT->getKind() >= BuiltinType::Char_U && 47620093b4bf698f292c664676987541d5103b65b15Douglas Gregor BT->getKind() <= BuiltinType::Char32) || 47720093b4bf698f292c664676987541d5103b65b15Douglas Gregor (BT->getKind() >= BuiltinType::Char_S && 47820093b4bf698f292c664676987541d5103b65b15Douglas Gregor BT->getKind() <= BuiltinType::WChar); 47920093b4bf698f292c664676987541d5103b65b15Douglas Gregor 48020093b4bf698f292c664676987541d5103b65b15Douglas Gregor return false; 48120093b4bf698f292c664676987541d5103b65b15Douglas Gregor} 48220093b4bf698f292c664676987541d5103b65b15Douglas Gregor 483d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner/// isSignedIntegerType - Return true if this is an integer type that is 484d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner/// signed, according to C99 6.2.5p4 [char, signed char, short, int, long..], 485f60946222721d9ba3c059563935c17b84703187aDouglas Gregor/// an enum decl which has a signed representation 4865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isSignedIntegerType() const { 4875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) { 4885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return BT->getKind() >= BuiltinType::Char_S && 489f5f7d864f5067d1ea4bff7fcf41b53a43b7b48baAnders Carlsson BT->getKind() <= BuiltinType::Int128; 4905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 4911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 49237c1b78a20a09b0456aa5caa15e159027010ca22Chris Lattner if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) 49337c1b78a20a09b0456aa5caa15e159027010ca22Chris Lattner return ET->getDecl()->getIntegerType()->isSignedIntegerType(); 4941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 495f60946222721d9ba3c059563935c17b84703187aDouglas Gregor return false; 496f60946222721d9ba3c059563935c17b84703187aDouglas Gregor} 497f60946222721d9ba3c059563935c17b84703187aDouglas Gregor 498f60946222721d9ba3c059563935c17b84703187aDouglas Gregorbool Type::hasSignedIntegerRepresentation() const { 499c63b96ad706e054a1390dd2ab53af9f05d33bbb1Steve Naroff if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType)) 500c63b96ad706e054a1390dd2ab53af9f05d33bbb1Steve Naroff return VT->getElementType()->isSignedIntegerType(); 501f60946222721d9ba3c059563935c17b84703187aDouglas Gregor else 502f60946222721d9ba3c059563935c17b84703187aDouglas Gregor return isSignedIntegerType(); 5035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 5045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 505d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner/// isUnsignedIntegerType - Return true if this is an integer type that is 506d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner/// unsigned, according to C99 6.2.5p6 [which returns true for _Bool], an enum 507f60946222721d9ba3c059563935c17b84703187aDouglas Gregor/// decl which has an unsigned representation 5085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isUnsignedIntegerType() const { 5095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) { 5105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return BT->getKind() >= BuiltinType::Bool && 5111c03ca30ae962199ef702324b48550f6af7fdc32Anders Carlsson BT->getKind() <= BuiltinType::UInt128; 5125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 513d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner 51437c1b78a20a09b0456aa5caa15e159027010ca22Chris Lattner if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) 51537c1b78a20a09b0456aa5caa15e159027010ca22Chris Lattner return ET->getDecl()->getIntegerType()->isUnsignedIntegerType(); 516d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner 517f60946222721d9ba3c059563935c17b84703187aDouglas Gregor return false; 518f60946222721d9ba3c059563935c17b84703187aDouglas Gregor} 519f60946222721d9ba3c059563935c17b84703187aDouglas Gregor 520f60946222721d9ba3c059563935c17b84703187aDouglas Gregorbool Type::hasUnsignedIntegerRepresentation() const { 521c63b96ad706e054a1390dd2ab53af9f05d33bbb1Steve Naroff if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType)) 522c63b96ad706e054a1390dd2ab53af9f05d33bbb1Steve Naroff return VT->getElementType()->isUnsignedIntegerType(); 523f60946222721d9ba3c059563935c17b84703187aDouglas Gregor else 524f60946222721d9ba3c059563935c17b84703187aDouglas Gregor return isUnsignedIntegerType(); 5255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 5265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isFloatingType() const { 5285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 5295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return BT->getKind() >= BuiltinType::Float && 5305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer BT->getKind() <= BuiltinType::LongDouble; 5315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (const ComplexType *CT = dyn_cast<ComplexType>(CanonicalType)) 532729a2131228cb7fcbc00bd8af36bc6f14d12317dChris Lattner return CT->getElementType()->isFloatingType(); 5338eee119bf4f1693dde17b8552c1f9f81bf2b681eDouglas Gregor return false; 5348eee119bf4f1693dde17b8552c1f9f81bf2b681eDouglas Gregor} 5358eee119bf4f1693dde17b8552c1f9f81bf2b681eDouglas Gregor 5368eee119bf4f1693dde17b8552c1f9f81bf2b681eDouglas Gregorbool Type::hasFloatingRepresentation() const { 537c63b96ad706e054a1390dd2ab53af9f05d33bbb1Steve Naroff if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType)) 538c63b96ad706e054a1390dd2ab53af9f05d33bbb1Steve Naroff return VT->getElementType()->isFloatingType(); 5398eee119bf4f1693dde17b8552c1f9f81bf2b681eDouglas Gregor else 5408eee119bf4f1693dde17b8552c1f9f81bf2b681eDouglas Gregor return isFloatingType(); 5415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 5425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isRealFloatingType() const { 5445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 545680523a91dd3351389667c8de17121ba7ae82673John McCall return BT->isFloatingPoint(); 5465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return false; 5475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 5485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isRealType() const { 5505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 5515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return BT->getKind() >= BuiltinType::Bool && 5525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer BT->getKind() <= BuiltinType::LongDouble; 5531274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) 5541274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor return ET->getDecl()->isComplete() && !ET->getDecl()->isScoped(); 5555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return false; 5565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 5575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isArithmeticType() const { 5595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 560a7fbf7282eadebaf1293d9f970b01fb57f4b0ae4Douglas Gregor return BT->getKind() >= BuiltinType::Bool && 561a7fbf7282eadebaf1293d9f970b01fb57f4b0ae4Douglas Gregor BT->getKind() <= BuiltinType::LongDouble; 56237c1b78a20a09b0456aa5caa15e159027010ca22Chris Lattner if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) 56337c1b78a20a09b0456aa5caa15e159027010ca22Chris Lattner // GCC allows forward declaration of enum types (forbid by C99 6.7.2.3p2). 56437c1b78a20a09b0456aa5caa15e159027010ca22Chris Lattner // If a body isn't seen by the time we get here, return false. 5651274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor // 5661274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor // C++0x: Enumerations are not arithmetic types. For now, just return 5671274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor // false for scoped enumerations since that will disable any 5681274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor // unwanted implicit conversions. 5691274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor return !ET->getDecl()->isScoped() && ET->getDecl()->isComplete(); 57000619623af0b9d3271e31402ec1a95e84c2c4526Douglas Gregor return isa<ComplexType>(CanonicalType); 5715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 5725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isScalarType() const { 5745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 5752cd11fefb62c580651e4269e1488381c2d6d07adJohn McCall return BT->getKind() != BuiltinType::Void && !BT->isPlaceholderType(); 5761274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) 577834a72ac74cf4ff07ba6215545dba3db578f8a07Chris Lattner // Enums are scalar types, but only if they are defined. Incomplete enums 578834a72ac74cf4ff07ba6215545dba3db578f8a07Chris Lattner // are not treated as scalar types. 5791274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor return ET->getDecl()->isComplete(); 5805618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff return isa<PointerType>(CanonicalType) || 5815618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff isa<BlockPointerType>(CanonicalType) || 582f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl isa<MemberPointerType>(CanonicalType) || 5835618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff isa<ComplexType>(CanonicalType) || 584d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff isa<ObjCObjectPointerType>(CanonicalType); 5855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 5865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 587d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor/// \brief Determines whether the type is a C++ aggregate type or C 588d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor/// aggregate or union type. 589d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor/// 590d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor/// An aggregate type is an array or a class type (struct, union, or 591d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor/// class) that has no user-declared constructors, no private or 592d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor/// protected non-static data members, no base classes, and no virtual 593d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor/// functions (C++ [dcl.init.aggr]p1). The notion of an aggregate type 594d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor/// subsumes the notion of C aggregates (C99 6.2.5p21) because it also 595d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor/// includes union types. 5965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isAggregateType() const { 597c1efaecf0373f1a55c5ef4c234357cf726fc0600Douglas Gregor if (const RecordType *Record = dyn_cast<RecordType>(CanonicalType)) { 598c1efaecf0373f1a55c5ef4c234357cf726fc0600Douglas Gregor if (CXXRecordDecl *ClassDecl = dyn_cast<CXXRecordDecl>(Record->getDecl())) 599c1efaecf0373f1a55c5ef4c234357cf726fc0600Douglas Gregor return ClassDecl->isAggregate(); 600c1efaecf0373f1a55c5ef4c234357cf726fc0600Douglas Gregor 601d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor return true; 602c1efaecf0373f1a55c5ef4c234357cf726fc0600Douglas Gregor } 603c1efaecf0373f1a55c5ef4c234357cf726fc0600Douglas Gregor 604c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman return isa<ArrayType>(CanonicalType); 6055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 6065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6079bfa73c5ab7bf4b0e749d04f29da6884e8d5bd9fChris Lattner/// isConstantSizeType - Return true if this is not a variable sized type, 6089bfa73c5ab7bf4b0e749d04f29da6884e8d5bd9fChris Lattner/// according to the rules of C99 6.7.5p3. It is not legal to call this on 609898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// incomplete types or dependent types. 6103c2b3170041f69a92904e3bab9b6d654eaf260acEli Friedmanbool Type::isConstantSizeType() const { 611d52a4578144ab2887912e52eabec58a857a44adbChris Lattner assert(!isIncompleteType() && "This doesn't make sense for incomplete types"); 612898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor assert(!isDependentType() && "This doesn't make sense for dependent types"); 6139bfa73c5ab7bf4b0e749d04f29da6884e8d5bd9fChris Lattner // The VAT must have a size, as it is known to be complete. 6149bfa73c5ab7bf4b0e749d04f29da6884e8d5bd9fChris Lattner return !isa<VariableArrayType>(CanonicalType); 6155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 6165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// isIncompleteType - Return true if this is an incomplete type (C99 6.2.5p1) 6185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// - a type that can describe objects, but which lacks information needed to 6195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// determine its size. 6201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpbool Type::isIncompleteType() const { 6211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump switch (CanonicalType->getTypeClass()) { 6225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer default: return false; 6235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Builtin: 6245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Void is the only incomplete builtin type. Per C99 6.2.5p19, it can never 6255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // be completed. 6265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return isVoidType(); 62772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor case Enum: 6281274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor // An enumeration with fixed underlying type is complete (C++0x 7.2p3). 6291274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor if (cast<EnumType>(CanonicalType)->getDecl()->isFixed()) 6301274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor return false; 6311274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor // Fall through. 6321274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor case Record: 6335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // A tagged type (struct/union/enum/class) is incomplete if the decl is a 6345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // forward declaration, but not a full definition (C99 6.2.5p22). 6355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return !cast<TagType>(CanonicalType)->getDecl()->isDefinition(); 636923d56d436f750bc1f29db50e641078725558a1bSebastian Redl case ConstantArray: 637923d56d436f750bc1f29db50e641078725558a1bSebastian Redl // An array is incomplete if its element type is incomplete 638923d56d436f750bc1f29db50e641078725558a1bSebastian Redl // (C++ [dcl.array]p1). 639923d56d436f750bc1f29db50e641078725558a1bSebastian Redl // We don't handle variable arrays (they're not allowed in C++) or 640923d56d436f750bc1f29db50e641078725558a1bSebastian Redl // dependent-sized arrays (dependent types are never treated as incomplete). 641923d56d436f750bc1f29db50e641078725558a1bSebastian Redl return cast<ArrayType>(CanonicalType)->getElementType()->isIncompleteType(); 642c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman case IncompleteArray: 6435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // An array of unknown size is an incomplete type (C99 6.2.5p22). 644c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman return true; 645c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall case ObjCObject: 646d0221526bcc81f49eff5c992978176e83ada3bc7Douglas Gregor return cast<ObjCObjectType>(CanonicalType)->getBaseType() 647d0221526bcc81f49eff5c992978176e83ada3bc7Douglas Gregor ->isIncompleteType(); 6481efaa9594a81709a17658fd80ae7e783e1026407Chris Lattner case ObjCInterface: 6491efaa9594a81709a17658fd80ae7e783e1026407Chris Lattner // ObjC interfaces are incomplete if they are @class, not @interface. 650d0221526bcc81f49eff5c992978176e83ada3bc7Douglas Gregor return cast<ObjCInterfaceType>(CanonicalType)->getDecl()->isForwardDecl(); 6515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 6525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 6535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 65464b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl/// isPODType - Return true if this is a plain-old-data type (C++ 3.9p10) 65564b45f7e0d3167f040841ac2920aead7f080730dSebastian Redlbool Type::isPODType() const { 65664b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl // The compiler shouldn't query this for incomplete types, but the user might. 657607a1788d9529c8e8494ac528764aa2c678a1a97Sebastian Redl // We return false for that case. Except for incomplete arrays of PODs, which 658607a1788d9529c8e8494ac528764aa2c678a1a97Sebastian Redl // are PODs according to the standard. 659607a1788d9529c8e8494ac528764aa2c678a1a97Sebastian Redl if (isIncompleteArrayType() && 660607a1788d9529c8e8494ac528764aa2c678a1a97Sebastian Redl cast<ArrayType>(CanonicalType)->getElementType()->isPODType()) 661607a1788d9529c8e8494ac528764aa2c678a1a97Sebastian Redl return true; 66264b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl if (isIncompleteType()) 66364b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl return false; 66464b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 66564b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl switch (CanonicalType->getTypeClass()) { 66664b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl // Everything not explicitly mentioned is not POD. 66764b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl default: return false; 66864b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl case VariableArray: 66964b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl case ConstantArray: 670607a1788d9529c8e8494ac528764aa2c678a1a97Sebastian Redl // IncompleteArray is handled above. 67164b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl return cast<ArrayType>(CanonicalType)->getElementType()->isPODType(); 67264b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 67364b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl case Builtin: 67464b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl case Complex: 67564b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl case Pointer: 676f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl case MemberPointer: 67764b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl case Vector: 67864b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl case ExtVector: 679d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff case ObjCObjectPointer: 6802263f822c31d0855ca8c48bfd9624322bf776f0bFariborz Jahanian case BlockPointer: 68164b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl return true; 68264b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 68372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor case Enum: 68472564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor return true; 68572564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor 68672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor case Record: 6871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (CXXRecordDecl *ClassDecl 688c1efaecf0373f1a55c5ef4c234357cf726fc0600Douglas Gregor = dyn_cast<CXXRecordDecl>(cast<RecordType>(CanonicalType)->getDecl())) 689c1efaecf0373f1a55c5ef4c234357cf726fc0600Douglas Gregor return ClassDecl->isPOD(); 690c1efaecf0373f1a55c5ef4c234357cf726fc0600Douglas Gregor 69164b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl // C struct/union is POD. 69264b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl return true; 69364b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl } 69464b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl} 69564b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 696ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redlbool Type::isLiteralType() const { 697ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl if (isIncompleteType()) 698ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl return false; 699ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl 700ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl // C++0x [basic.types]p10: 701ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl // A type is a literal type if it is: 702ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl switch (CanonicalType->getTypeClass()) { 703ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl // We're whitelisting 704ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl default: return false; 705ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl 706ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl // -- a scalar type 707ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl case Builtin: 708ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl case Complex: 709ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl case Pointer: 710ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl case MemberPointer: 711ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl case Vector: 712ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl case ExtVector: 713ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl case ObjCObjectPointer: 714ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl case Enum: 715ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl return true; 716ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl 717ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl // -- a class type with ... 718ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl case Record: 719ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl // FIXME: Do the tests 720ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl return false; 721ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl 722ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl // -- an array of literal type 723ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl // Extension: variable arrays cannot be literal types, since they're 724ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl // runtime-sized. 725ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl case ConstantArray: 726ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl return cast<ArrayType>(CanonicalType)->getElementType()->isLiteralType(); 727ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl } 728ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl} 729ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl 7305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isPromotableIntegerType() const { 731183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const BuiltinType *BT = getAs<BuiltinType>()) 7322a18dfe292cf3c406a769c3672080970ac586345Chris Lattner switch (BT->getKind()) { 7332a18dfe292cf3c406a769c3672080970ac586345Chris Lattner case BuiltinType::Bool: 7342a18dfe292cf3c406a769c3672080970ac586345Chris Lattner case BuiltinType::Char_S: 7352a18dfe292cf3c406a769c3672080970ac586345Chris Lattner case BuiltinType::Char_U: 7362a18dfe292cf3c406a769c3672080970ac586345Chris Lattner case BuiltinType::SChar: 7372a18dfe292cf3c406a769c3672080970ac586345Chris Lattner case BuiltinType::UChar: 7382a18dfe292cf3c406a769c3672080970ac586345Chris Lattner case BuiltinType::Short: 7392a18dfe292cf3c406a769c3672080970ac586345Chris Lattner case BuiltinType::UShort: 7402a18dfe292cf3c406a769c3672080970ac586345Chris Lattner return true; 7411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump default: 7422a18dfe292cf3c406a769c3672080970ac586345Chris Lattner return false; 7432a18dfe292cf3c406a769c3672080970ac586345Chris Lattner } 744aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor 745aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor // Enumerated types are promotable to their compatible integer types 746aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor // (C99 6.3.1.1) a.k.a. its underlying type (C++ [conv.prom]p2). 747aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor if (const EnumType *ET = getAs<EnumType>()){ 7481274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor if (this->isDependentType() || ET->getDecl()->getPromotionType().isNull() 7491274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor || ET->getDecl()->isScoped()) 750aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor return false; 751aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor 752aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor const BuiltinType *BT 753aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor = ET->getDecl()->getPromotionType()->getAs<BuiltinType>(); 754aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor return BT->getKind() == BuiltinType::Int 755aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor || BT->getKind() == BuiltinType::UInt; 756aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor } 757aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor 7582a18dfe292cf3c406a769c3672080970ac586345Chris Lattner return false; 7595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 7605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7616e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redlbool Type::isNullPtrType() const { 762183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const BuiltinType *BT = getAs<BuiltinType>()) 7636e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl return BT->getKind() == BuiltinType::NullPtr; 7646e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl return false; 7656e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl} 7666e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl 76722b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedmanbool Type::isSpecifierType() const { 76822b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman // Note that this intentionally does not use the canonical type. 76922b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman switch (getTypeClass()) { 77022b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman case Builtin: 77122b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman case Record: 77222b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman case Enum: 77322b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman case Typedef: 774c8f2c61f4f667c2bc3e4e74b274fa397a4232393Eli Friedman case Complex: 775c8f2c61f4f667c2bc3e4e74b274fa397a4232393Eli Friedman case TypeOfExpr: 776c8f2c61f4f667c2bc3e4e74b274fa397a4232393Eli Friedman case TypeOf: 777c8f2c61f4f667c2bc3e4e74b274fa397a4232393Eli Friedman case TemplateTypeParm: 77849a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall case SubstTemplateTypeParm: 779c8f2c61f4f667c2bc3e4e74b274fa397a4232393Eli Friedman case TemplateSpecialization: 780465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case Elaborated: 7814714c12a1ab759156b78be8f109ea4c12213af57Douglas Gregor case DependentName: 78233500955d731c73717af52088b7fc0e7a85681e7John McCall case DependentTemplateSpecialization: 783c8f2c61f4f667c2bc3e4e74b274fa397a4232393Eli Friedman case ObjCInterface: 784c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall case ObjCObject: 785c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall case ObjCObjectPointer: // FIXME: object pointers aren't really specifiers 78622b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman return true; 78722b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman default: 78822b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman return false; 78922b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman } 79022b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman} 79122b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman 792465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraTypeWithKeyword::~TypeWithKeyword() { 793465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara} 794465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 795465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraElaboratedTypeKeyword 796465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraTypeWithKeyword::getKeywordForTypeSpec(unsigned TypeSpec) { 797465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara switch (TypeSpec) { 798465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara default: return ETK_None; 799465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TST_typename: return ETK_Typename; 800465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TST_class: return ETK_Class; 801465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TST_struct: return ETK_Struct; 802465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TST_union: return ETK_Union; 803465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TST_enum: return ETK_Enum; 804465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara } 805465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara} 806465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 807465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraTagTypeKind 808465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraTypeWithKeyword::getTagTypeKindForTypeSpec(unsigned TypeSpec) { 809465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara switch(TypeSpec) { 810465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TST_class: return TTK_Class; 811465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TST_struct: return TTK_Struct; 812465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TST_union: return TTK_Union; 813465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TST_enum: return TTK_Enum; 814465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara default: llvm_unreachable("Type specifier is not a tag type kind."); 815465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara } 816465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara} 817465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 818465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraElaboratedTypeKeyword 819465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraTypeWithKeyword::getKeywordForTagTypeKind(TagTypeKind Kind) { 820465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara switch (Kind) { 821465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TTK_Class: return ETK_Class; 822465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TTK_Struct: return ETK_Struct; 823465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TTK_Union: return ETK_Union; 824465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TTK_Enum: return ETK_Enum; 825465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara } 826465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara llvm_unreachable("Unknown tag type kind."); 827465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara} 828465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 829465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraTagTypeKind 830465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraTypeWithKeyword::getTagTypeKindForKeyword(ElaboratedTypeKeyword Keyword) { 831465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara switch (Keyword) { 832465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Class: return TTK_Class; 833465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Struct: return TTK_Struct; 834465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Union: return TTK_Union; 835465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Enum: return TTK_Enum; 836465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_None: // Fall through. 837465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Typename: 838465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara llvm_unreachable("Elaborated type keyword is not a tag type kind."); 839465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara } 840465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara llvm_unreachable("Unknown elaborated type keyword."); 841465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara} 842465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 843465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnarabool 844465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraTypeWithKeyword::KeywordIsTagTypeKind(ElaboratedTypeKeyword Keyword) { 845465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara switch (Keyword) { 846465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_None: 847465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Typename: 848465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara return false; 849465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Class: 850465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Struct: 851465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Union: 852465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Enum: 8534033642464e8ba0982f88f34cffad808d247b393Douglas Gregor return true; 8544033642464e8ba0982f88f34cffad808d247b393Douglas Gregor } 855465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara llvm_unreachable("Unknown elaborated type keyword."); 856465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara} 857465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 858465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnaraconst char* 859465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraTypeWithKeyword::getKeywordName(ElaboratedTypeKeyword Keyword) { 860465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara switch (Keyword) { 861465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara default: llvm_unreachable("Unknown elaborated type keyword."); 862465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_None: return ""; 863465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Typename: return "typename"; 864465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Class: return "class"; 865465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Struct: return "struct"; 866465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Union: return "union"; 867465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Enum: return "enum"; 868465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara } 869465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara} 870465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 87133500955d731c73717af52088b7fc0e7a85681e7John McCallElaboratedType::~ElaboratedType() {} 87233500955d731c73717af52088b7fc0e7a85681e7John McCallDependentNameType::~DependentNameType() {} 87333500955d731c73717af52088b7fc0e7a85681e7John McCallDependentTemplateSpecializationType::~DependentTemplateSpecializationType() {} 87433500955d731c73717af52088b7fc0e7a85681e7John McCall 87533500955d731c73717af52088b7fc0e7a85681e7John McCallDependentTemplateSpecializationType::DependentTemplateSpecializationType( 876ef99001908e799c388f1363b1e607dad5f5b57d3John McCall ElaboratedTypeKeyword Keyword, 87733500955d731c73717af52088b7fc0e7a85681e7John McCall NestedNameSpecifier *NNS, const IdentifierInfo *Name, 87833500955d731c73717af52088b7fc0e7a85681e7John McCall unsigned NumArgs, const TemplateArgument *Args, 87933500955d731c73717af52088b7fc0e7a85681e7John McCall QualType Canon) 88035495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor : TypeWithKeyword(Keyword, DependentTemplateSpecialization, Canon, true, 88135495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor false), 882ef99001908e799c388f1363b1e607dad5f5b57d3John McCall NNS(NNS), Name(Name), NumArgs(NumArgs) { 88333500955d731c73717af52088b7fc0e7a85681e7John McCall assert(NNS && NNS->isDependent() && 88433500955d731c73717af52088b7fc0e7a85681e7John McCall "DependentTemplateSpecializatonType requires dependent qualifier"); 88533500955d731c73717af52088b7fc0e7a85681e7John McCall for (unsigned I = 0; I != NumArgs; ++I) 88633500955d731c73717af52088b7fc0e7a85681e7John McCall new (&getArgBuffer()[I]) TemplateArgument(Args[I]); 88733500955d731c73717af52088b7fc0e7a85681e7John McCall} 88833500955d731c73717af52088b7fc0e7a85681e7John McCall 88933500955d731c73717af52088b7fc0e7a85681e7John McCallvoid 89033500955d731c73717af52088b7fc0e7a85681e7John McCallDependentTemplateSpecializationType::Profile(llvm::FoldingSetNodeID &ID, 89133500955d731c73717af52088b7fc0e7a85681e7John McCall ASTContext &Context, 89233500955d731c73717af52088b7fc0e7a85681e7John McCall ElaboratedTypeKeyword Keyword, 89333500955d731c73717af52088b7fc0e7a85681e7John McCall NestedNameSpecifier *Qualifier, 89433500955d731c73717af52088b7fc0e7a85681e7John McCall const IdentifierInfo *Name, 89533500955d731c73717af52088b7fc0e7a85681e7John McCall unsigned NumArgs, 89633500955d731c73717af52088b7fc0e7a85681e7John McCall const TemplateArgument *Args) { 89733500955d731c73717af52088b7fc0e7a85681e7John McCall ID.AddInteger(Keyword); 89833500955d731c73717af52088b7fc0e7a85681e7John McCall ID.AddPointer(Qualifier); 89933500955d731c73717af52088b7fc0e7a85681e7John McCall ID.AddPointer(Name); 90033500955d731c73717af52088b7fc0e7a85681e7John McCall for (unsigned Idx = 0; Idx < NumArgs; ++Idx) 90133500955d731c73717af52088b7fc0e7a85681e7John McCall Args[Idx].Profile(ID, Context); 90233500955d731c73717af52088b7fc0e7a85681e7John McCall} 90333500955d731c73717af52088b7fc0e7a85681e7John McCall 904465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnarabool Type::isElaboratedTypeSpecifier() const { 905465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara ElaboratedTypeKeyword Keyword; 906465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara if (const ElaboratedType *Elab = dyn_cast<ElaboratedType>(this)) 907465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara Keyword = Elab->getKeyword(); 908465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara else if (const DependentNameType *DepName = dyn_cast<DependentNameType>(this)) 909465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara Keyword = DepName->getKeyword(); 91033500955d731c73717af52088b7fc0e7a85681e7John McCall else if (const DependentTemplateSpecializationType *DepTST = 91133500955d731c73717af52088b7fc0e7a85681e7John McCall dyn_cast<DependentTemplateSpecializationType>(this)) 91233500955d731c73717af52088b7fc0e7a85681e7John McCall Keyword = DepTST->getKeyword(); 913465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara else 914465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara return false; 915465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 916465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara return TypeWithKeyword::KeywordIsTagTypeKind(Keyword); 9174033642464e8ba0982f88f34cffad808d247b393Douglas Gregor} 9184033642464e8ba0982f88f34cffad808d247b393Douglas Gregor 919cd01f17358dc8ef19338c0e2321138dd0a6160d9Argyrios Kyrtzidisconst char *Type::getTypeClassName() const { 920cd01f17358dc8ef19338c0e2321138dd0a6160d9Argyrios Kyrtzidis switch (TC) { 921cd01f17358dc8ef19338c0e2321138dd0a6160d9Argyrios Kyrtzidis default: assert(0 && "Type class not in TypeNodes.def!"); 922cd01f17358dc8ef19338c0e2321138dd0a6160d9Argyrios Kyrtzidis#define ABSTRACT_TYPE(Derived, Base) 923cd01f17358dc8ef19338c0e2321138dd0a6160d9Argyrios Kyrtzidis#define TYPE(Derived, Base) case Derived: return #Derived; 924cd01f17358dc8ef19338c0e2321138dd0a6160d9Argyrios Kyrtzidis#include "clang/AST/TypeNodes.def" 925cd01f17358dc8ef19338c0e2321138dd0a6160d9Argyrios Kyrtzidis } 926cd01f17358dc8ef19338c0e2321138dd0a6160d9Argyrios Kyrtzidis} 927cd01f17358dc8ef19338c0e2321138dd0a6160d9Argyrios Kyrtzidis 928e4f2142d00fa5fdb580c4e2413da91882d955381Chris Lattnerconst char *BuiltinType::getName(const LangOptions &LO) const { 9295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer switch (getKind()) { 9305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer default: assert(0 && "Unknown builtin type!"); 9315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Void: return "void"; 932e4f2142d00fa5fdb580c4e2413da91882d955381Chris Lattner case Bool: return LO.Bool ? "bool" : "_Bool"; 9335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Char_S: return "char"; 9345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Char_U: return "char"; 9355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case SChar: return "signed char"; 9365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Short: return "short"; 9375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Int: return "int"; 9385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Long: return "long"; 9395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case LongLong: return "long long"; 9402df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner case Int128: return "__int128_t"; 9415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case UChar: return "unsigned char"; 9425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case UShort: return "unsigned short"; 9435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case UInt: return "unsigned int"; 9445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case ULong: return "unsigned long"; 9455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case ULongLong: return "unsigned long long"; 9462df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner case UInt128: return "__uint128_t"; 9475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Float: return "float"; 9485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Double: return "double"; 9495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case LongDouble: return "long double"; 95046713efe13c89f4ec9cd9546c7b598fe7186089bArgyrios Kyrtzidis case WChar: return "wchar_t"; 951f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith case Char16: return "char16_t"; 952f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith case Char32: return "char32_t"; 9536e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl case NullPtr: return "nullptr_t"; 9548e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor case Overload: return "<overloaded function type>"; 955898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor case Dependent: return "<dependent type>"; 9566a75cd9c1d54625fca7b5477ab9545bcdbd85ea4Anders Carlsson case UndeducedAuto: return "auto"; 957de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff case ObjCId: return "id"; 958de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff case ObjCClass: return "Class"; 959bef0efd11bc4430a3ee437a3213cec5c18af855aChris Lattner case ObjCSel: return "SEL"; 9605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 9615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 9625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 963bef0efd11bc4430a3ee437a3213cec5c18af855aChris Lattnervoid FunctionType::ANCHOR() {} // Key function for FunctionType. 964bef0efd11bc4430a3ee437a3213cec5c18af855aChris Lattner 9656398235d7890a81b785ea5af3b6e66d86bf184ccDouglas GregorQualType QualType::getNonLValueExprType(ASTContext &Context) const { 9665291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor if (const ReferenceType *RefType = getTypePtr()->getAs<ReferenceType>()) 9675291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor return RefType->getPointeeType(); 9685291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor 9695291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor // C++0x [basic.lval]: 9705291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor // Class prvalues can have cv-qualified types; non-class prvalues always 9715291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor // have cv-unqualified types. 9725291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor // 9735291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor // See also C99 6.3.2.1p2. 9745291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor if (!Context.getLangOptions().CPlusPlus || 9756dc1ef87044e6b177d4df0d2b593a94616180b3dChandler Carruth (!getTypePtr()->isDependentType() && !getTypePtr()->isRecordType())) 9765291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor return getUnqualifiedType(); 9775291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor 9785291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor return *this; 9795291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor} 9805291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor 98104a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCallllvm::StringRef FunctionType::getNameForCallConv(CallingConv CC) { 98204a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall switch (CC) { 98304a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall case CC_Default: llvm_unreachable("no name for default cc"); 98404a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall default: return ""; 98504a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall 98604a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall case CC_C: return "cdecl"; 98704a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall case CC_X86StdCall: return "stdcall"; 98804a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall case CC_X86FastCall: return "fastcall"; 989f813a2c03fcb05381b3252010435f557eb6b3cdeDouglas Gregor case CC_X86ThisCall: return "thiscall"; 99052fc314e1b5e1baee6305067cf831763d02bd243Dawn Perchik case CC_X86Pascal: return "pascal"; 99104a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall } 99204a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall} 99304a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall 99435495eb14f22c4e96956912e23ca2a433227ad8cDouglas GregorFunctionProtoType::FunctionProtoType(QualType Result, const QualType *ArgArray, 99535495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor unsigned numArgs, bool isVariadic, 99635495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor unsigned typeQuals, bool hasExs, 99735495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor bool hasAnyExs, const QualType *ExArray, 99835495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor unsigned numExs, QualType Canonical, 99935495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor const ExtInfo &Info) 100035495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor : FunctionType(FunctionProto, Result, isVariadic, typeQuals, Canonical, 100135495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor Result->isDependentType(), 100235495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor Result->isVariablyModifiedType(), 100335495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor Info), 100435495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor NumArgs(numArgs), NumExceptions(numExs), HasExceptionSpec(hasExs), 100535495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor AnyExceptionSpec(hasAnyExs) 100635495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor{ 100735495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor // Fill in the trailing argument array. 100835495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor QualType *ArgInfo = reinterpret_cast<QualType*>(this+1); 100935495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor for (unsigned i = 0; i != numArgs; ++i) { 101035495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor if (ArgArray[i]->isDependentType()) 101135495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor setDependent(); 101235495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor 101335495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor ArgInfo[i] = ArgArray[i]; 101435495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor } 101535495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor 101635495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor // Fill in the exception array. 101735495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor QualType *Ex = ArgInfo + numArgs; 101835495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor for (unsigned i = 0; i != numExs; ++i) 101935495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor Ex[i] = ExArray[i]; 102035495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor} 102135495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor 102235495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor 102372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregorvoid FunctionProtoType::Profile(llvm::FoldingSetNodeID &ID, QualType Result, 1024942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner arg_type_iterator ArgTys, 1025971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis unsigned NumArgs, bool isVariadic, 1026465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl unsigned TypeQuals, bool hasExceptionSpec, 1027465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl bool anyExceptionSpec, unsigned NumExceptions, 1028264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola exception_iterator Exs, 102971c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall FunctionType::ExtInfo Info) { 10305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddPointer(Result.getAsOpaquePtr()); 10315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer for (unsigned i = 0; i != NumArgs; ++i) 10325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddPointer(ArgTys[i].getAsOpaquePtr()); 10335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddInteger(isVariadic); 1034971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis ID.AddInteger(TypeQuals); 1035465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl ID.AddInteger(hasExceptionSpec); 1036465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl if (hasExceptionSpec) { 1037465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl ID.AddInteger(anyExceptionSpec); 10381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump for (unsigned i = 0; i != NumExceptions; ++i) 1039465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl ID.AddPointer(Exs[i].getAsOpaquePtr()); 1040465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl } 104171c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall Info.Profile(ID); 10425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 10435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 104472564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregorvoid FunctionProtoType::Profile(llvm::FoldingSetNodeID &ID) { 1045971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis Profile(ID, getResultType(), arg_type_begin(), NumArgs, isVariadic(), 1046465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl getTypeQuals(), hasExceptionSpec(), hasAnyExceptionSpec(), 1047264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola getNumExceptions(), exception_begin(), 1048264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola getExtInfo()); 10495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 10505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1051a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner/// LookThroughTypedefs - Return the ultimate type this typedef corresponds to 105258f9e13e87e57236fee4b914eea9be6f92a1c345Chris Lattner/// potentially looking through *all* consequtive typedefs. This returns the 1053a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner/// sum of the type qualifiers, so if you have: 1054a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner/// typedef const int A; 1055a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner/// typedef volatile A B; 1056a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner/// looking through the typedefs for B will give you "const volatile A". 1057a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner/// 1058a2c7767ce7d8feb10253f4b650826a20f3324c6fChris LattnerQualType TypedefType::LookThroughTypedefs() const { 1059a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner // Usually, there is only a single level of typedefs, be fast in that case. 1060a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner QualType FirstType = getDecl()->getUnderlyingType(); 1061a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner if (!isa<TypedefType>(FirstType)) 1062a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner return FirstType; 10631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1064a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner // Otherwise, do the fully general loop. 10650953e767ff7817f97b3ab20896b229891eeff45bJohn McCall QualifierCollector Qs; 10661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10670953e767ff7817f97b3ab20896b229891eeff45bJohn McCall QualType CurType; 10680953e767ff7817f97b3ab20896b229891eeff45bJohn McCall const TypedefType *TDT = this; 10690953e767ff7817f97b3ab20896b229891eeff45bJohn McCall do { 10700953e767ff7817f97b3ab20896b229891eeff45bJohn McCall CurType = TDT->getDecl()->getUnderlyingType(); 10710953e767ff7817f97b3ab20896b229891eeff45bJohn McCall TDT = dyn_cast<TypedefType>(Qs.strip(CurType)); 10720953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } while (TDT); 10731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10740953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return Qs.apply(CurType); 1075a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner} 10765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1077bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCallQualType TypedefType::desugar() const { 1078bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall return getDecl()->getUnderlyingType(); 1079bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall} 1080bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 108172564e73277e29f6db3305d1f27ba408abb7ed88Douglas GregorTypeOfExprType::TypeOfExprType(Expr *E, QualType can) 108235495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor : Type(TypeOfExpr, can, E->isTypeDependent(), 108335495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor E->getType()->isVariablyModifiedType()), TOExpr(E) { 1084898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor} 1085898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 1086bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCallQualType TypeOfExprType::desugar() const { 1087bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall return getUnderlyingExpr()->getType(); 1088bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall} 1089bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 10901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpvoid DependentTypeOfExprType::Profile(llvm::FoldingSetNodeID &ID, 1091b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor ASTContext &Context, Expr *E) { 1092b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor E->Profile(ID, Context, true); 1093b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor} 1094b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor 1095563a03b1338d31c2462def43253a722bc885d384Anders CarlssonDecltypeType::DecltypeType(Expr *E, QualType underlyingType, QualType can) 109635495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor : Type(Decltype, can, E->isTypeDependent(), 109735495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor E->getType()->isVariablyModifiedType()), E(E), 1098563a03b1338d31c2462def43253a722bc885d384Anders Carlsson UnderlyingType(underlyingType) { 1099395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson} 1100395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson 11019d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas GregorDependentDecltypeType::DependentDecltypeType(ASTContext &Context, Expr *E) 11029d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor : DecltypeType(E, Context.DependentTy), Context(Context) { } 11039d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor 11041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpvoid DependentDecltypeType::Profile(llvm::FoldingSetNodeID &ID, 11059d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor ASTContext &Context, Expr *E) { 11069d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor E->Profile(ID, Context, true); 11079d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor} 11089d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor 110919c8576b7328f4dc2d07682f5da552875c1912efJohn McCallTagType::TagType(TypeClass TC, const TagDecl *D, QualType can) 111035495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor : Type(TC, can, D->isDependentType(), /*VariablyModified=*/false), 1111ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl decl(const_cast<TagDecl*>(D)) {} 1112ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl 1113ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redlstatic TagDecl *getInterestingTagDecl(TagDecl *decl) { 1114ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl for (TagDecl::redecl_iterator I = decl->redecls_begin(), 1115ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl E = decl->redecls_end(); 1116ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl I != E; ++I) { 1117ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl if (I->isDefinition() || I->isBeingDefined()) 1118ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl return *I; 1119ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl } 1120ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl // If there's no definition (not even in progress), return what we have. 1121ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl return decl; 1122ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl} 1123ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl 1124ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian RedlTagDecl *TagType::getDecl() const { 1125ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl return getInterestingTagDecl(decl); 1126ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl} 1127ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl 1128ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redlbool TagType::isBeingDefined() const { 1129ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl return getDecl()->isBeingDefined(); 1130ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl} 1131ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl 1132ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian RedlCXXRecordDecl *InjectedClassNameType::getDecl() const { 1133ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl return cast<CXXRecordDecl>(getInterestingTagDecl(Decl)); 1134ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl} 11357da97d0f31e1ec16998d3de2cfd2e88fe3736673Douglas Gregor 11362daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattnerbool RecordType::classof(const TagType *TT) { 11372daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner return isa<RecordDecl>(TT->getDecl()); 11385edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner} 11395edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner 11402daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattnerbool EnumType::classof(const TagType *TT) { 11412daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner return isa<EnumDecl>(TT->getDecl()); 11425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 11435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1144833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallstatic bool isDependent(const TemplateArgument &Arg) { 1145833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall switch (Arg.getKind()) { 1146833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall case TemplateArgument::Null: 1147833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall assert(false && "Should not have a NULL template argument"); 1148833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return false; 1149833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 1150833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall case TemplateArgument::Type: 1151833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return Arg.getAsType()->isDependentType(); 1152833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 1153788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor case TemplateArgument::Template: 1154788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor return Arg.getAsTemplate().isDependent(); 1155788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor 1156833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall case TemplateArgument::Declaration: 1157bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor if (DeclContext *DC = dyn_cast<DeclContext>(Arg.getAsDecl())) 1158bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor return DC->isDependentContext(); 1159bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor return Arg.getAsDecl()->getDeclContext()->isDependentContext(); 1160bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor 1161833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall case TemplateArgument::Integral: 1162833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall // Never dependent 1163833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return false; 1164833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 1165833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall case TemplateArgument::Expression: 1166833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return (Arg.getAsExpr()->isTypeDependent() || 1167833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall Arg.getAsExpr()->isValueDependent()); 1168833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 1169833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall case TemplateArgument::Pack: 1170bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor for (TemplateArgument::pack_iterator P = Arg.pack_begin(), 1171bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor PEnd = Arg.pack_end(); 1172bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor P != PEnd; ++P) { 1173bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor if (isDependent(*P)) 1174bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor return true; 1175bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor } 1176bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor 1177833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return false; 117855f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor } 117940808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor 118040808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor return false; 118155f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor} 118255f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 1183833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallbool TemplateSpecializationType:: 1184d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCallanyDependentTemplateArguments(const TemplateArgumentListInfo &Args) { 1185d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall return anyDependentTemplateArguments(Args.getArgumentArray(), Args.size()); 1186d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall} 1187d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall 1188d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCallbool TemplateSpecializationType:: 1189833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallanyDependentTemplateArguments(const TemplateArgumentLoc *Args, unsigned N) { 1190833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall for (unsigned i = 0; i != N; ++i) 1191833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall if (isDependent(Args[i].getArgument())) 1192833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return true; 1193833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return false; 1194833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall} 1195833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 1196833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallbool TemplateSpecializationType:: 1197833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallanyDependentTemplateArguments(const TemplateArgument *Args, unsigned N) { 1198833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall for (unsigned i = 0; i != N; ++i) 1199833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall if (isDependent(Args[i])) 1200833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return true; 1201833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return false; 1202833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall} 1203833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 12047532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas GregorTemplateSpecializationType:: 1205ef99001908e799c388f1363b1e607dad5f5b57d3John McCallTemplateSpecializationType(TemplateName T, 1206828e226ab7ed08b3eb766549e9d3306432137460Douglas Gregor const TemplateArgument *Args, 12077532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor unsigned NumArgs, QualType Canon) 12081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : Type(TemplateSpecialization, 120940808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor Canon.isNull()? QualType(this, 0) : Canon, 121035495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor T.isDependent(), false), 121135495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor Template(T), NumArgs(NumArgs) 121235495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor{ 12131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump assert((!Canon.isNull() || 12147532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor T.isDependent() || anyDependentTemplateArguments(Args, NumArgs)) && 121540808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor "No canonical type for non-dependent class template specialization"); 121655f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 12171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TemplateArgument *TemplateArgs 121840808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor = reinterpret_cast<TemplateArgument *>(this + 1); 121935495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor for (unsigned Arg = 0; Arg < NumArgs; ++Arg) { 122035495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor // Update dependent and variably-modified bits. 122135495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor if (isDependent(Args[Arg])) 122235495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor setDependent(); 122335495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor if (Args[Arg].getKind() == TemplateArgument::Type && 122435495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor Args[Arg].getAsType()->isVariablyModifiedType()) 122535495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor setVariablyModified(); 122635495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor 122740808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor new (&TemplateArgs[Arg]) TemplateArgument(Args[Arg]); 122835495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor } 122955f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor} 123055f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 12311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpvoid 12321eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTemplateSpecializationType::Profile(llvm::FoldingSetNodeID &ID, 12331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TemplateName T, 12341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const TemplateArgument *Args, 1235828e226ab7ed08b3eb766549e9d3306432137460Douglas Gregor unsigned NumArgs, 1236828e226ab7ed08b3eb766549e9d3306432137460Douglas Gregor ASTContext &Context) { 12377532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor T.Profile(ID); 123840808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor for (unsigned Idx = 0; Idx < NumArgs; ++Idx) 1239828e226ab7ed08b3eb766549e9d3306432137460Douglas Gregor Args[Idx].Profile(ID, Context); 124055f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor} 124197e0179f1ae545e07d9f5e7c1d2ef5c5bab06676Anders Carlsson 12420953e767ff7817f97b3ab20896b229891eeff45bJohn McCallQualType QualifierCollector::apply(QualType QT) const { 12430953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (!hasNonFastQualifiers()) 12440953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return QT.withFastQualifiers(getFastQualifiers()); 12451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12460953e767ff7817f97b3ab20896b229891eeff45bJohn McCall assert(Context && "extended qualifiers but no context!"); 12470953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return Context->getQualifiedType(QT, *this); 12485e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor} 12495e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor 12500953e767ff7817f97b3ab20896b229891eeff45bJohn McCallQualType QualifierCollector::apply(const Type *T) const { 12510953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (!hasNonFastQualifiers()) 12520953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return QualType(T, getFastQualifiers()); 12530953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 12540953e767ff7817f97b3ab20896b229891eeff45bJohn McCall assert(Context && "extended qualifiers but no context!"); 12550953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return Context->getQualifiedType(T, *this); 12565e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor} 12575e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor 1258c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallvoid ObjCObjectTypeImpl::Profile(llvm::FoldingSetNodeID &ID, 1259c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall QualType BaseType, 1260c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCProtocolDecl * const *Protocols, 1261c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall unsigned NumProtocols) { 1262c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ID.AddPointer(BaseType.getAsOpaquePtr()); 1263c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff for (unsigned i = 0; i != NumProtocols; i++) 1264c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ID.AddPointer(Protocols[i]); 1265c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff} 1266c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff 1267c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallvoid ObjCObjectTypeImpl::Profile(llvm::FoldingSetNodeID &ID) { 1268c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall Profile(ID, getBaseType(), qual_begin(), getNumProtocols()); 1269c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff} 12700b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 127160e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor/// \brief Determine the linkage of this type. 127260e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas GregorLinkage Type::getLinkage() const { 12730b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor if (this != CanonicalType.getTypePtr()) 12740b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor return CanonicalType->getLinkage(); 127560e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor 127660e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor if (!LinkageKnown) { 1277db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor std::pair<Linkage, bool> Result = getLinkageUnnamedLocalImpl(); 1278db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor CachedLinkage = Result.first; 1279db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor CachedLocalOrUnnamed = Result.second; 128060e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor LinkageKnown = true; 128160e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor } 128260e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor 128360e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor return static_cast<clang::Linkage>(CachedLinkage); 128460e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor} 12850b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 1286db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregorbool Type::hasUnnamedOrLocalType() const { 1287db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor if (this != CanonicalType.getTypePtr()) 1288db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor return CanonicalType->hasUnnamedOrLocalType(); 1289db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor 1290db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor if (!LinkageKnown) { 1291db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor std::pair<Linkage, bool> Result = getLinkageUnnamedLocalImpl(); 1292db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor CachedLinkage = Result.first; 1293db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor CachedLocalOrUnnamed = Result.second; 1294db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor LinkageKnown = true; 1295db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor } 1296db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor 1297db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor return CachedLocalOrUnnamed; 1298db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor} 1299db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor 1300db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregorstd::pair<Linkage, bool> Type::getLinkageUnnamedLocalImpl() const { 130160e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor // C++ [basic.link]p8: 130260e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor // Names not covered by these rules have no linkage. 1303db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor return std::make_pair(NoLinkage, false); 13040b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor} 13050b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 130660e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregorvoid Type::ClearLinkageCache() { 130760e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor if (this != CanonicalType.getTypePtr()) 130860e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor CanonicalType->ClearLinkageCache(); 130960e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor else 131060e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor LinkageKnown = false; 131160e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor} 131260e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor 1313db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregorstd::pair<Linkage, bool> BuiltinType::getLinkageUnnamedLocalImpl() const { 13140b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor // C++ [basic.link]p8: 13150b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor // A type is said to have linkage if and only if: 13160b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor // - it is a fundamental type (3.9.1); or 1317db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor return std::make_pair(ExternalLinkage, false); 13180b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor} 13190b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 1320db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregorstd::pair<Linkage, bool> TagType::getLinkageUnnamedLocalImpl() const { 13210b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor // C++ [basic.link]p8: 13220b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor // - it is a class or enumeration type that is named (or has a name for 13230b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor // linkage purposes (7.1.3)) and the name has linkage; or 13240b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor // - it is a specialization of a class template (14); or 1325db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor return std::make_pair(getDecl()->getLinkage(), 1326db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor getDecl()->getDeclContext()->isFunctionOrMethod() || 1327db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor (!getDecl()->getIdentifier() && 1328db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor !getDecl()->getTypedefForAnonDecl())); 13290b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor} 13300b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 13310b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor// C++ [basic.link]p8: 13320b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor// - it is a compound type (3.9.2) other than a class or enumeration, 13330b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor// compounded exclusively from types that have linkage; or 1334db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregorstd::pair<Linkage, bool> ComplexType::getLinkageUnnamedLocalImpl() const { 1335db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor return std::make_pair(ElementType->getLinkage(), 1336db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor ElementType->hasUnnamedOrLocalType()); 13370b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor} 13380b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 1339db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregorstd::pair<Linkage, bool> PointerType::getLinkageUnnamedLocalImpl() const { 1340db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor return std::make_pair(PointeeType->getLinkage(), 1341db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor PointeeType->hasUnnamedOrLocalType()); 13420b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor} 13430b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 1344db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregorstd::pair<Linkage, bool> BlockPointerType::getLinkageUnnamedLocalImpl() const { 1345db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor return std::make_pair(PointeeType->getLinkage(), 1346db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor PointeeType->hasUnnamedOrLocalType()); 13470b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor} 13480b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 1349db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregorstd::pair<Linkage, bool> ReferenceType::getLinkageUnnamedLocalImpl() const { 1350db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor return std::make_pair(PointeeType->getLinkage(), 1351db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor PointeeType->hasUnnamedOrLocalType()); 13520b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor} 13530b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 1354db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregorstd::pair<Linkage, bool> MemberPointerType::getLinkageUnnamedLocalImpl() const { 1355db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor return std::make_pair(minLinkage(Class->getLinkage(), 1356db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor PointeeType->getLinkage()), 1357db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor Class->hasUnnamedOrLocalType() || 1358db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor PointeeType->hasUnnamedOrLocalType()); 13590b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor} 13600b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 1361db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregorstd::pair<Linkage, bool> ArrayType::getLinkageUnnamedLocalImpl() const { 1362db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor return std::make_pair(ElementType->getLinkage(), 1363db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor ElementType->hasUnnamedOrLocalType()); 13640b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor} 13650b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 1366db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregorstd::pair<Linkage, bool> VectorType::getLinkageUnnamedLocalImpl() const { 1367db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor return std::make_pair(ElementType->getLinkage(), 1368db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor ElementType->hasUnnamedOrLocalType()); 13690b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor} 13700b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 1371db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregorstd::pair<Linkage, bool> 1372db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas GregorFunctionNoProtoType::getLinkageUnnamedLocalImpl() const { 1373db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor return std::make_pair(getResultType()->getLinkage(), 1374db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor getResultType()->hasUnnamedOrLocalType()); 13750b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor} 13760b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 1377db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregorstd::pair<Linkage, bool> FunctionProtoType::getLinkageUnnamedLocalImpl() const { 13780b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor Linkage L = getResultType()->getLinkage(); 1379db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor bool UnnamedOrLocal = getResultType()->hasUnnamedOrLocalType(); 13800b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor for (arg_type_iterator A = arg_type_begin(), AEnd = arg_type_end(); 1381db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor A != AEnd; ++A) { 13820b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor L = minLinkage(L, (*A)->getLinkage()); 1383db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor UnnamedOrLocal = UnnamedOrLocal || (*A)->hasUnnamedOrLocalType(); 1384db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor } 1385db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor 1386db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor return std::make_pair(L, UnnamedOrLocal); 13870b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor} 13880b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 1389db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregorstd::pair<Linkage, bool> ObjCObjectType::getLinkageUnnamedLocalImpl() const { 1390db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor return std::make_pair(ExternalLinkage, false); 13910b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor} 13920b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 1393db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregorstd::pair<Linkage, bool> 1394db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas GregorObjCObjectPointerType::getLinkageUnnamedLocalImpl() const { 1395db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor return std::make_pair(ExternalLinkage, false); 13960b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor} 1397