Type.cpp revision 34fd628d22f54baddf30cf80c401b2f862a31b23
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 271d3f2f79fedfef7cae818c55a1f3d7a8f5992e5a0Eli Friedman/// isVariablyModifiedType (C99 6.7.5p3) - Return true for variable length 272d3f2f79fedfef7cae818c55a1f3d7a8f5992e5a0Eli Friedman/// array types and types that contain variable array types in their 273d3f2f79fedfef7cae818c55a1f3d7a8f5992e5a0Eli Friedman/// declarator 274d7444aac1af1c2c1d5e5b7467ecf6006ee2d8abeSteve Naroffbool Type::isVariablyModifiedType() const { 275a481ec4150ad203440852a2bfee0883dd26f7530Douglas Gregor // FIXME: We should really keep a "variably modified" bit in Type, rather 276a481ec4150ad203440852a2bfee0883dd26f7530Douglas Gregor // than walking the type hierarchy to recompute it. 277a481ec4150ad203440852a2bfee0883dd26f7530Douglas Gregor 278c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // A VLA is a variably modified type. 279c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner if (isVariableArrayType()) 280d3f2f79fedfef7cae818c55a1f3d7a8f5992e5a0Eli Friedman return true; 281d3f2f79fedfef7cae818c55a1f3d7a8f5992e5a0Eli Friedman 282d3f2f79fedfef7cae818c55a1f3d7a8f5992e5a0Eli Friedman // An array can contain a variably modified type 283c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner if (const Type *T = getArrayElementTypeNoTypeQual()) 284c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return T->isVariablyModifiedType(); 285d3f2f79fedfef7cae818c55a1f3d7a8f5992e5a0Eli Friedman 286f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl // A pointer can point to a variably modified type. 287f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl // Also, C++ references and member pointers can point to a variably modified 288f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl // type, where VLAs appear as an extension to C++, and should be treated 289f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl // correctly. 2906217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const PointerType *PT = getAs<PointerType>()) 291d3f2f79fedfef7cae818c55a1f3d7a8f5992e5a0Eli Friedman return PT->getPointeeType()->isVariablyModifiedType(); 2926217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const ReferenceType *RT = getAs<ReferenceType>()) 29368694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar return RT->getPointeeType()->isVariablyModifiedType(); 2946217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const MemberPointerType *PT = getAs<MemberPointerType>()) 2958edef7c31d27fc9d5d163660702a8a7730a0d19fSebastian Redl return PT->getPointeeType()->isVariablyModifiedType(); 296d3f2f79fedfef7cae818c55a1f3d7a8f5992e5a0Eli Friedman 297d3f2f79fedfef7cae818c55a1f3d7a8f5992e5a0Eli Friedman // A function can return a variably modified type 298d3f2f79fedfef7cae818c55a1f3d7a8f5992e5a0Eli Friedman // This one isn't completely obvious, but it follows from the 299d3f2f79fedfef7cae818c55a1f3d7a8f5992e5a0Eli Friedman // definition in C99 6.7.5p3. Because of this rule, it's 300d3f2f79fedfef7cae818c55a1f3d7a8f5992e5a0Eli Friedman // illegal to declare a function returning a variably modified type. 301183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const FunctionType *FT = getAs<FunctionType>()) 302d3f2f79fedfef7cae818c55a1f3d7a8f5992e5a0Eli Friedman return FT->getResultType()->isVariablyModifiedType(); 303d3f2f79fedfef7cae818c55a1f3d7a8f5992e5a0Eli Friedman 304d7444aac1af1c2c1d5e5b7467ecf6006ee2d8abeSteve Naroff return false; 305d7444aac1af1c2c1d5e5b7467ecf6006ee2d8abeSteve Naroff} 306d7444aac1af1c2c1d5e5b7467ecf6006ee2d8abeSteve Naroff 307c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattnerconst RecordType *Type::getAsStructureType() const { 3087064f5c95bbdb17680d0ea658d4090898c2592d3Steve Naroff // If this is directly a structure type, return it. 309c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner if (const RecordType *RT = dyn_cast<RecordType>(this)) { 31039ba4aeca296b1c9f04bde7d9d3cbbf129f1abd3Argyrios Kyrtzidis if (RT->getDecl()->isStruct()) 311c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner return RT; 3127064f5c95bbdb17680d0ea658d4090898c2592d3Steve Naroff } 313dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner 314dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner // If the canonical form of this type isn't the right kind, reject it. 315c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner if (const RecordType *RT = dyn_cast<RecordType>(CanonicalType)) { 31639ba4aeca296b1c9f04bde7d9d3cbbf129f1abd3Argyrios Kyrtzidis if (!RT->getDecl()->isStruct()) 317dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner return 0; 3181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 319dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner // If this is a typedef for a structure type, strip the typedef off without 320dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner // losing all typedef information. 321bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall return cast<RecordType>(getUnqualifiedDesugaredType()); 3225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 3237064f5c95bbdb17680d0ea658d4090898c2592d3Steve Naroff return 0; 3245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 3255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpconst RecordType *Type::getAsUnionType() const { 3277064f5c95bbdb17680d0ea658d4090898c2592d3Steve Naroff // If this is directly a union type, return it. 328c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner if (const RecordType *RT = dyn_cast<RecordType>(this)) { 32939ba4aeca296b1c9f04bde7d9d3cbbf129f1abd3Argyrios Kyrtzidis if (RT->getDecl()->isUnion()) 330c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner return RT; 3317064f5c95bbdb17680d0ea658d4090898c2592d3Steve Naroff } 3321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 333dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner // If the canonical form of this type isn't the right kind, reject it. 334c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner if (const RecordType *RT = dyn_cast<RecordType>(CanonicalType)) { 33539ba4aeca296b1c9f04bde7d9d3cbbf129f1abd3Argyrios Kyrtzidis if (!RT->getDecl()->isUnion()) 336dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner return 0; 337dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner 338dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner // If this is a typedef for a union type, strip the typedef off without 339dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner // losing all typedef information. 340bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall return cast<RecordType>(getUnqualifiedDesugaredType()); 3415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 3421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3437064f5c95bbdb17680d0ea658d4090898c2592d3Steve Naroff return 0; 3445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 3455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 346c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallObjCObjectType::ObjCObjectType(QualType Canonical, QualType Base, 347c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCProtocolDecl * const *Protocols, 348c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall unsigned NumProtocols) 349c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall : Type(ObjCObject, Canonical, false), 350c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall NumProtocols(NumProtocols), 351c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall BaseType(Base) { 352c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall assert(this->NumProtocols == NumProtocols && 353c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall "bitfield overflow in protocol count"); 354fd6a0887a099256c35a5b23e9afd517ffe95fa0aDouglas Gregor if (NumProtocols) 355c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall memcpy(getProtocolStorage(), Protocols, 356c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall NumProtocols * sizeof(ObjCProtocolDecl*)); 35771842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek} 35871842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek 359c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallconst ObjCObjectType *Type::getAsObjCQualifiedInterfaceType() const { 360c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall // There is no sugar for ObjCObjectType's, just return the canonical 361c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff // type pointer if it is the right class. There is no typedef information to 362c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff // return and these cannot be Address-space qualified. 363c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall if (const ObjCObjectType *T = getAs<ObjCObjectType>()) 364c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall if (T->getNumProtocols() && T->getInterface()) 365c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return T; 366c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff return 0; 367c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff} 368c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff 369c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroffbool Type::isObjCQualifiedInterfaceType() const { 370e61ad0b7063fcd97204b1cce5558685144267eb6Steve Naroff return getAsObjCQualifiedInterfaceType() != 0; 371c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff} 372c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff 373d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroffconst ObjCObjectPointerType *Type::getAsObjCQualifiedIdType() const { 374eca7be6b7ebd93682eeaab2c71d59f2995dacdccChris Lattner // There is no sugar for ObjCQualifiedIdType's, just return the canonical 375eca7be6b7ebd93682eeaab2c71d59f2995dacdccChris Lattner // type pointer if it is the right class. 376183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) { 377d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff if (OPT->isObjCQualifiedIdType()) 378d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff return OPT; 379d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff } 380d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff return 0; 381368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner} 382368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner 38314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroffconst ObjCObjectPointerType *Type::getAsObjCInterfacePointerType() const { 384183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) { 38514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff if (OPT->getInterfaceType()) 38614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return OPT; 38714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff } 38814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return 0; 38914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff} 39014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff 391a91d6a6619a91d0ca7102d8ab5678d855f04d850Fariborz Jahanianconst CXXRecordDecl *Type::getCXXRecordDeclForPointerType() const { 3926217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const PointerType *PT = getAs<PointerType>()) 3936217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const RecordType *RT = PT->getPointeeType()->getAs<RecordType>()) 394a91d6a6619a91d0ca7102d8ab5678d855f04d850Fariborz Jahanian return dyn_cast<CXXRecordDecl>(RT->getDecl()); 395a91d6a6619a91d0ca7102d8ab5678d855f04d850Fariborz Jahanian return 0; 396a91d6a6619a91d0ca7102d8ab5678d855f04d850Fariborz Jahanian} 397a91d6a6619a91d0ca7102d8ab5678d855f04d850Fariborz Jahanian 398c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas GregorCXXRecordDecl *Type::getAsCXXRecordDecl() const { 399c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor if (const RecordType *RT = getAs<RecordType>()) 400c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor return dyn_cast<CXXRecordDecl>(RT->getDecl()); 401c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor else if (const InjectedClassNameType *Injected 402c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor = getAs<InjectedClassNameType>()) 403c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor return Injected->getDecl(); 404c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor 405c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor return 0; 406c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor} 407c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor 4085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isIntegerType() const { 4095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 4105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return BT->getKind() >= BuiltinType::Bool && 4112df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner BT->getKind() <= BuiltinType::Int128; 4125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (const TagType *TT = dyn_cast<TagType>(CanonicalType)) 413834a72ac74cf4ff07ba6215545dba3db578f8a07Chris Lattner // Incomplete enum types are not treated as integer types. 4148e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor // FIXME: In C++, enum types are never integer types. 415834a72ac74cf4ff07ba6215545dba3db578f8a07Chris Lattner if (TT->getDecl()->isEnum() && TT->getDecl()->isDefinition()) 4165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return true; 417f60946222721d9ba3c059563935c17b84703187aDouglas Gregor return false; 418f60946222721d9ba3c059563935c17b84703187aDouglas Gregor} 419f60946222721d9ba3c059563935c17b84703187aDouglas Gregor 420f60946222721d9ba3c059563935c17b84703187aDouglas Gregorbool Type::hasIntegerRepresentation() const { 421c63b96ad706e054a1390dd2ab53af9f05d33bbb1Steve Naroff if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType)) 422c63b96ad706e054a1390dd2ab53af9f05d33bbb1Steve Naroff return VT->getElementType()->isIntegerType(); 423f60946222721d9ba3c059563935c17b84703187aDouglas Gregor else 424f60946222721d9ba3c059563935c17b84703187aDouglas Gregor return isIntegerType(); 4255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 4265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4279d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// \brief Determine whether this type is an integral type. 4289d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// 4299d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// This routine determines whether the given type is an integral type per 4309d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// C++ [basic.fundamental]p7. Although the C standard does not define the 4319d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// term "integral type", it has a similar term "integer type", and in C++ 4329d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// the two terms are equivalent. However, C's "integer type" includes 4339d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// enumeration types, while C++'s "integer type" does not. The \c ASTContext 4349d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// parameter is used to determine whether we should be following the C or 4359d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// C++ rules when determining whether this type is an integral/integer type. 4369d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// 4379d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// For cases where C permits "an integer type" and C++ permits "an integral 4389d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// type", use this routine. 4399d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// 4409d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// For cases where C permits "an integer type" and C++ permits "an integral 4419d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// or enumeration type", use \c isIntegralOrEnumerationType() instead. 4429d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// 4439d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// \param Ctx The context in which this type occurs. 4449d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// 4459d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// \returns true if the type is considered an integral type, false otherwise. 4469d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregorbool Type::isIntegralType(ASTContext &Ctx) const { 44733e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 44833e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian return BT->getKind() >= BuiltinType::Bool && 449f5f7d864f5067d1ea4bff7fcf41b53a43b7b48baAnders Carlsson BT->getKind() <= BuiltinType::Int128; 4509d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor 4519d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor if (!Ctx.getLangOptions().CPlusPlus) 4529d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor if (const TagType *TT = dyn_cast<TagType>(CanonicalType)) 4539d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor if (TT->getDecl()->isEnum() && TT->getDecl()->isDefinition()) 4549d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor return true; // Complete enum types are integral in C. 4559d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor 45633e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian return false; 45733e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian} 45833e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian 4592ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregorbool Type::isIntegralOrEnumerationType() const { 4602ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 4612ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor return BT->getKind() >= BuiltinType::Bool && 4622ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor BT->getKind() <= BuiltinType::Int128; 46334fd628d22f54baddf30cf80c401b2f862a31b23Eli Friedman 46434fd628d22f54baddf30cf80c401b2f862a31b23Eli Friedman // Check for a complete enum type; incomplete enum types are not properly an 46534fd628d22f54baddf30cf80c401b2f862a31b23Eli Friedman // enumeration type in the sense required here. 46634fd628d22f54baddf30cf80c401b2f862a31b23Eli Friedman if (const TagType *TT = dyn_cast<TagType>(CanonicalType)) 46734fd628d22f54baddf30cf80c401b2f862a31b23Eli Friedman if (TT->getDecl()->isEnum() && TT->getDecl()->isDefinition()) 46834fd628d22f54baddf30cf80c401b2f862a31b23Eli Friedman return true; 46934fd628d22f54baddf30cf80c401b2f862a31b23Eli Friedman 4702ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor return false; 4712ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor} 4722ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor 47313b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroffbool Type::isEnumeralType() const { 47413b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff if (const TagType *TT = dyn_cast<TagType>(CanonicalType)) 47539ba4aeca296b1c9f04bde7d9d3cbbf129f1abd3Argyrios Kyrtzidis return TT->getDecl()->isEnum(); 47613b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff return false; 47713b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff} 47813b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff 47913b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroffbool Type::isBooleanType() const { 48013b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 48113b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff return BT->getKind() == BuiltinType::Bool; 48213b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff return false; 48313b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff} 48413b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff 48513b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroffbool Type::isCharType() const { 48613b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 48713b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff return BT->getKind() == BuiltinType::Char_U || 48813b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff BT->getKind() == BuiltinType::UChar || 489c67ad5f299bb2c09e4567def8ff0d34bd15a42fdAnders Carlsson BT->getKind() == BuiltinType::Char_S || 490c67ad5f299bb2c09e4567def8ff0d34bd15a42fdAnders Carlsson BT->getKind() == BuiltinType::SChar; 49113b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff return false; 49213b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff} 49313b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff 49477a52233f7c0f162672652051bfe78b65ad4f789Douglas Gregorbool Type::isWideCharType() const { 49577a52233f7c0f162672652051bfe78b65ad4f789Douglas Gregor if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 49677a52233f7c0f162672652051bfe78b65ad4f789Douglas Gregor return BT->getKind() == BuiltinType::WChar; 49777a52233f7c0f162672652051bfe78b65ad4f789Douglas Gregor return false; 49877a52233f7c0f162672652051bfe78b65ad4f789Douglas Gregor} 49977a52233f7c0f162672652051bfe78b65ad4f789Douglas Gregor 50020093b4bf698f292c664676987541d5103b65b15Douglas Gregor/// \brief Determine whether this type is any of the built-in character 50120093b4bf698f292c664676987541d5103b65b15Douglas Gregor/// types. 50220093b4bf698f292c664676987541d5103b65b15Douglas Gregorbool Type::isAnyCharacterType() const { 50320093b4bf698f292c664676987541d5103b65b15Douglas Gregor if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 50420093b4bf698f292c664676987541d5103b65b15Douglas Gregor return (BT->getKind() >= BuiltinType::Char_U && 50520093b4bf698f292c664676987541d5103b65b15Douglas Gregor BT->getKind() <= BuiltinType::Char32) || 50620093b4bf698f292c664676987541d5103b65b15Douglas Gregor (BT->getKind() >= BuiltinType::Char_S && 50720093b4bf698f292c664676987541d5103b65b15Douglas Gregor BT->getKind() <= BuiltinType::WChar); 50820093b4bf698f292c664676987541d5103b65b15Douglas Gregor 50920093b4bf698f292c664676987541d5103b65b15Douglas Gregor return false; 51020093b4bf698f292c664676987541d5103b65b15Douglas Gregor} 51120093b4bf698f292c664676987541d5103b65b15Douglas Gregor 512d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner/// isSignedIntegerType - Return true if this is an integer type that is 513d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner/// signed, according to C99 6.2.5p4 [char, signed char, short, int, long..], 514f60946222721d9ba3c059563935c17b84703187aDouglas Gregor/// an enum decl which has a signed representation 5155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isSignedIntegerType() const { 5165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) { 5175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return BT->getKind() >= BuiltinType::Char_S && 518f5f7d864f5067d1ea4bff7fcf41b53a43b7b48baAnders Carlsson BT->getKind() <= BuiltinType::Int128; 5195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 5201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 52137c1b78a20a09b0456aa5caa15e159027010ca22Chris Lattner if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) 52237c1b78a20a09b0456aa5caa15e159027010ca22Chris Lattner return ET->getDecl()->getIntegerType()->isSignedIntegerType(); 5231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 524f60946222721d9ba3c059563935c17b84703187aDouglas Gregor return false; 525f60946222721d9ba3c059563935c17b84703187aDouglas Gregor} 526f60946222721d9ba3c059563935c17b84703187aDouglas Gregor 527f60946222721d9ba3c059563935c17b84703187aDouglas Gregorbool Type::hasSignedIntegerRepresentation() const { 528c63b96ad706e054a1390dd2ab53af9f05d33bbb1Steve Naroff if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType)) 529c63b96ad706e054a1390dd2ab53af9f05d33bbb1Steve Naroff return VT->getElementType()->isSignedIntegerType(); 530f60946222721d9ba3c059563935c17b84703187aDouglas Gregor else 531f60946222721d9ba3c059563935c17b84703187aDouglas Gregor return isSignedIntegerType(); 5325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 5335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 534d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner/// isUnsignedIntegerType - Return true if this is an integer type that is 535d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner/// unsigned, according to C99 6.2.5p6 [which returns true for _Bool], an enum 536f60946222721d9ba3c059563935c17b84703187aDouglas Gregor/// decl which has an unsigned representation 5375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isUnsignedIntegerType() const { 5385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) { 5395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return BT->getKind() >= BuiltinType::Bool && 5401c03ca30ae962199ef702324b48550f6af7fdc32Anders Carlsson BT->getKind() <= BuiltinType::UInt128; 5415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 542d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner 54337c1b78a20a09b0456aa5caa15e159027010ca22Chris Lattner if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) 54437c1b78a20a09b0456aa5caa15e159027010ca22Chris Lattner return ET->getDecl()->getIntegerType()->isUnsignedIntegerType(); 545d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner 546f60946222721d9ba3c059563935c17b84703187aDouglas Gregor return false; 547f60946222721d9ba3c059563935c17b84703187aDouglas Gregor} 548f60946222721d9ba3c059563935c17b84703187aDouglas Gregor 549f60946222721d9ba3c059563935c17b84703187aDouglas Gregorbool Type::hasUnsignedIntegerRepresentation() const { 550c63b96ad706e054a1390dd2ab53af9f05d33bbb1Steve Naroff if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType)) 551c63b96ad706e054a1390dd2ab53af9f05d33bbb1Steve Naroff return VT->getElementType()->isUnsignedIntegerType(); 552f60946222721d9ba3c059563935c17b84703187aDouglas Gregor else 553f60946222721d9ba3c059563935c17b84703187aDouglas Gregor return isUnsignedIntegerType(); 5545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 5555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isFloatingType() const { 5575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 5585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return BT->getKind() >= BuiltinType::Float && 5595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer BT->getKind() <= BuiltinType::LongDouble; 5605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (const ComplexType *CT = dyn_cast<ComplexType>(CanonicalType)) 561729a2131228cb7fcbc00bd8af36bc6f14d12317dChris Lattner return CT->getElementType()->isFloatingType(); 5628eee119bf4f1693dde17b8552c1f9f81bf2b681eDouglas Gregor return false; 5638eee119bf4f1693dde17b8552c1f9f81bf2b681eDouglas Gregor} 5648eee119bf4f1693dde17b8552c1f9f81bf2b681eDouglas Gregor 5658eee119bf4f1693dde17b8552c1f9f81bf2b681eDouglas Gregorbool Type::hasFloatingRepresentation() const { 566c63b96ad706e054a1390dd2ab53af9f05d33bbb1Steve Naroff if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType)) 567c63b96ad706e054a1390dd2ab53af9f05d33bbb1Steve Naroff return VT->getElementType()->isFloatingType(); 5688eee119bf4f1693dde17b8552c1f9f81bf2b681eDouglas Gregor else 5698eee119bf4f1693dde17b8552c1f9f81bf2b681eDouglas Gregor return isFloatingType(); 5705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 5715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isRealFloatingType() const { 5735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 574680523a91dd3351389667c8de17121ba7ae82673John McCall return BT->isFloatingPoint(); 5755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return false; 5765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 5775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isRealType() const { 5795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 5805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return BT->getKind() >= BuiltinType::Bool && 5815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer BT->getKind() <= BuiltinType::LongDouble; 5825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (const TagType *TT = dyn_cast<TagType>(CanonicalType)) 583834a72ac74cf4ff07ba6215545dba3db578f8a07Chris Lattner return TT->getDecl()->isEnum() && TT->getDecl()->isDefinition(); 5845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return false; 5855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 5865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isArithmeticType() const { 5885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 589a7fbf7282eadebaf1293d9f970b01fb57f4b0ae4Douglas Gregor return BT->getKind() >= BuiltinType::Bool && 590a7fbf7282eadebaf1293d9f970b01fb57f4b0ae4Douglas Gregor BT->getKind() <= BuiltinType::LongDouble; 59137c1b78a20a09b0456aa5caa15e159027010ca22Chris Lattner if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) 59237c1b78a20a09b0456aa5caa15e159027010ca22Chris Lattner // GCC allows forward declaration of enum types (forbid by C99 6.7.2.3p2). 59337c1b78a20a09b0456aa5caa15e159027010ca22Chris Lattner // If a body isn't seen by the time we get here, return false. 59437c1b78a20a09b0456aa5caa15e159027010ca22Chris Lattner return ET->getDecl()->isDefinition(); 59500619623af0b9d3271e31402ec1a95e84c2c4526Douglas Gregor return isa<ComplexType>(CanonicalType); 5965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 5975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isScalarType() const { 5995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) 6005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return BT->getKind() != BuiltinType::Void; 6015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (const TagType *TT = dyn_cast<TagType>(CanonicalType)) { 602834a72ac74cf4ff07ba6215545dba3db578f8a07Chris Lattner // Enums are scalar types, but only if they are defined. Incomplete enums 603834a72ac74cf4ff07ba6215545dba3db578f8a07Chris Lattner // are not treated as scalar types. 604834a72ac74cf4ff07ba6215545dba3db578f8a07Chris Lattner if (TT->getDecl()->isEnum() && TT->getDecl()->isDefinition()) 6055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return true; 6065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return false; 6075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 6085618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff return isa<PointerType>(CanonicalType) || 6095618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff isa<BlockPointerType>(CanonicalType) || 610f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl isa<MemberPointerType>(CanonicalType) || 6115618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff isa<ComplexType>(CanonicalType) || 612d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff isa<ObjCObjectPointerType>(CanonicalType); 6135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 6145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 615d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor/// \brief Determines whether the type is a C++ aggregate type or C 616d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor/// aggregate or union type. 617d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor/// 618d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor/// An aggregate type is an array or a class type (struct, union, or 619d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor/// class) that has no user-declared constructors, no private or 620d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor/// protected non-static data members, no base classes, and no virtual 621d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor/// functions (C++ [dcl.init.aggr]p1). The notion of an aggregate type 622d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor/// subsumes the notion of C aggregates (C99 6.2.5p21) because it also 623d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor/// includes union types. 6245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isAggregateType() const { 625c1efaecf0373f1a55c5ef4c234357cf726fc0600Douglas Gregor if (const RecordType *Record = dyn_cast<RecordType>(CanonicalType)) { 626c1efaecf0373f1a55c5ef4c234357cf726fc0600Douglas Gregor if (CXXRecordDecl *ClassDecl = dyn_cast<CXXRecordDecl>(Record->getDecl())) 627c1efaecf0373f1a55c5ef4c234357cf726fc0600Douglas Gregor return ClassDecl->isAggregate(); 628c1efaecf0373f1a55c5ef4c234357cf726fc0600Douglas Gregor 629d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor return true; 630c1efaecf0373f1a55c5ef4c234357cf726fc0600Douglas Gregor } 631c1efaecf0373f1a55c5ef4c234357cf726fc0600Douglas Gregor 632c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman return isa<ArrayType>(CanonicalType); 6335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 6345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6359bfa73c5ab7bf4b0e749d04f29da6884e8d5bd9fChris Lattner/// isConstantSizeType - Return true if this is not a variable sized type, 6369bfa73c5ab7bf4b0e749d04f29da6884e8d5bd9fChris Lattner/// according to the rules of C99 6.7.5p3. It is not legal to call this on 637898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// incomplete types or dependent types. 6383c2b3170041f69a92904e3bab9b6d654eaf260acEli Friedmanbool Type::isConstantSizeType() const { 639d52a4578144ab2887912e52eabec58a857a44adbChris Lattner assert(!isIncompleteType() && "This doesn't make sense for incomplete types"); 640898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor assert(!isDependentType() && "This doesn't make sense for dependent types"); 6419bfa73c5ab7bf4b0e749d04f29da6884e8d5bd9fChris Lattner // The VAT must have a size, as it is known to be complete. 6429bfa73c5ab7bf4b0e749d04f29da6884e8d5bd9fChris Lattner return !isa<VariableArrayType>(CanonicalType); 6435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 6445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// isIncompleteType - Return true if this is an incomplete type (C99 6.2.5p1) 6465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// - a type that can describe objects, but which lacks information needed to 6475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// determine its size. 6481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpbool Type::isIncompleteType() const { 6491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump switch (CanonicalType->getTypeClass()) { 6505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer default: return false; 6515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Builtin: 6525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Void is the only incomplete builtin type. Per C99 6.2.5p19, it can never 6535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // be completed. 6545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return isVoidType(); 65572564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor case Record: 65672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor case Enum: 6575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // A tagged type (struct/union/enum/class) is incomplete if the decl is a 6585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // forward declaration, but not a full definition (C99 6.2.5p22). 6595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return !cast<TagType>(CanonicalType)->getDecl()->isDefinition(); 660923d56d436f750bc1f29db50e641078725558a1bSebastian Redl case ConstantArray: 661923d56d436f750bc1f29db50e641078725558a1bSebastian Redl // An array is incomplete if its element type is incomplete 662923d56d436f750bc1f29db50e641078725558a1bSebastian Redl // (C++ [dcl.array]p1). 663923d56d436f750bc1f29db50e641078725558a1bSebastian Redl // We don't handle variable arrays (they're not allowed in C++) or 664923d56d436f750bc1f29db50e641078725558a1bSebastian Redl // dependent-sized arrays (dependent types are never treated as incomplete). 665923d56d436f750bc1f29db50e641078725558a1bSebastian Redl return cast<ArrayType>(CanonicalType)->getElementType()->isIncompleteType(); 666c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman case IncompleteArray: 6675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // An array of unknown size is an incomplete type (C99 6.2.5p22). 668c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman return true; 669c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall case ObjCObject: 670d0221526bcc81f49eff5c992978176e83ada3bc7Douglas Gregor return cast<ObjCObjectType>(CanonicalType)->getBaseType() 671d0221526bcc81f49eff5c992978176e83ada3bc7Douglas Gregor ->isIncompleteType(); 6721efaa9594a81709a17658fd80ae7e783e1026407Chris Lattner case ObjCInterface: 6731efaa9594a81709a17658fd80ae7e783e1026407Chris Lattner // ObjC interfaces are incomplete if they are @class, not @interface. 674d0221526bcc81f49eff5c992978176e83ada3bc7Douglas Gregor return cast<ObjCInterfaceType>(CanonicalType)->getDecl()->isForwardDecl(); 6755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 6765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 6775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 67864b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl/// isPODType - Return true if this is a plain-old-data type (C++ 3.9p10) 67964b45f7e0d3167f040841ac2920aead7f080730dSebastian Redlbool Type::isPODType() const { 68064b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl // The compiler shouldn't query this for incomplete types, but the user might. 68164b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl // We return false for that case. 68264b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl if (isIncompleteType()) 68364b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl return false; 68464b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 68564b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl switch (CanonicalType->getTypeClass()) { 68664b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl // Everything not explicitly mentioned is not POD. 68764b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl default: return false; 68864b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl case VariableArray: 68964b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl case ConstantArray: 69064b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl // IncompleteArray is caught by isIncompleteType() above. 69164b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl return cast<ArrayType>(CanonicalType)->getElementType()->isPODType(); 69264b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 69364b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl case Builtin: 69464b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl case Complex: 69564b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl case Pointer: 696f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl case MemberPointer: 69764b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl case Vector: 69864b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl case ExtVector: 699d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff case ObjCObjectPointer: 7002263f822c31d0855ca8c48bfd9624322bf776f0bFariborz Jahanian case BlockPointer: 70164b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl return true; 70264b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 70372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor case Enum: 70472564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor return true; 70572564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor 70672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor case Record: 7071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (CXXRecordDecl *ClassDecl 708c1efaecf0373f1a55c5ef4c234357cf726fc0600Douglas Gregor = dyn_cast<CXXRecordDecl>(cast<RecordType>(CanonicalType)->getDecl())) 709c1efaecf0373f1a55c5ef4c234357cf726fc0600Douglas Gregor return ClassDecl->isPOD(); 710c1efaecf0373f1a55c5ef4c234357cf726fc0600Douglas Gregor 71164b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl // C struct/union is POD. 71264b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl return true; 71364b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl } 71464b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl} 71564b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 716ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redlbool Type::isLiteralType() const { 717ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl if (isIncompleteType()) 718ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl return false; 719ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl 720ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl // C++0x [basic.types]p10: 721ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl // A type is a literal type if it is: 722ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl switch (CanonicalType->getTypeClass()) { 723ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl // We're whitelisting 724ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl default: return false; 725ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl 726ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl // -- a scalar type 727ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl case Builtin: 728ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl case Complex: 729ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl case Pointer: 730ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl case MemberPointer: 731ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl case Vector: 732ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl case ExtVector: 733ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl case ObjCObjectPointer: 734ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl case Enum: 735ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl return true; 736ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl 737ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl // -- a class type with ... 738ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl case Record: 739ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl // FIXME: Do the tests 740ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl return false; 741ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl 742ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl // -- an array of literal type 743ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl // Extension: variable arrays cannot be literal types, since they're 744ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl // runtime-sized. 745ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl case ConstantArray: 746ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl return cast<ArrayType>(CanonicalType)->getElementType()->isLiteralType(); 747ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl } 748ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl} 749ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl 7505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isPromotableIntegerType() const { 751183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const BuiltinType *BT = getAs<BuiltinType>()) 7522a18dfe292cf3c406a769c3672080970ac586345Chris Lattner switch (BT->getKind()) { 7532a18dfe292cf3c406a769c3672080970ac586345Chris Lattner case BuiltinType::Bool: 7542a18dfe292cf3c406a769c3672080970ac586345Chris Lattner case BuiltinType::Char_S: 7552a18dfe292cf3c406a769c3672080970ac586345Chris Lattner case BuiltinType::Char_U: 7562a18dfe292cf3c406a769c3672080970ac586345Chris Lattner case BuiltinType::SChar: 7572a18dfe292cf3c406a769c3672080970ac586345Chris Lattner case BuiltinType::UChar: 7582a18dfe292cf3c406a769c3672080970ac586345Chris Lattner case BuiltinType::Short: 7592a18dfe292cf3c406a769c3672080970ac586345Chris Lattner case BuiltinType::UShort: 7602a18dfe292cf3c406a769c3672080970ac586345Chris Lattner return true; 7611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump default: 7622a18dfe292cf3c406a769c3672080970ac586345Chris Lattner return false; 7632a18dfe292cf3c406a769c3672080970ac586345Chris Lattner } 764aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor 765aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor // Enumerated types are promotable to their compatible integer types 766aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor // (C99 6.3.1.1) a.k.a. its underlying type (C++ [conv.prom]p2). 767aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor if (const EnumType *ET = getAs<EnumType>()){ 768aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor if (this->isDependentType() || ET->getDecl()->getPromotionType().isNull()) 769aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor return false; 770aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor 771aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor const BuiltinType *BT 772aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor = ET->getDecl()->getPromotionType()->getAs<BuiltinType>(); 773aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor return BT->getKind() == BuiltinType::Int 774aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor || BT->getKind() == BuiltinType::UInt; 775aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor } 776aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor 7772a18dfe292cf3c406a769c3672080970ac586345Chris Lattner return false; 7785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 7795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7806e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redlbool Type::isNullPtrType() const { 781183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const BuiltinType *BT = getAs<BuiltinType>()) 7826e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl return BT->getKind() == BuiltinType::NullPtr; 7836e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl return false; 7846e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl} 7856e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl 78622b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedmanbool Type::isSpecifierType() const { 78722b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman // Note that this intentionally does not use the canonical type. 78822b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman switch (getTypeClass()) { 78922b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman case Builtin: 79022b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman case Record: 79122b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman case Enum: 79222b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman case Typedef: 793c8f2c61f4f667c2bc3e4e74b274fa397a4232393Eli Friedman case Complex: 794c8f2c61f4f667c2bc3e4e74b274fa397a4232393Eli Friedman case TypeOfExpr: 795c8f2c61f4f667c2bc3e4e74b274fa397a4232393Eli Friedman case TypeOf: 796c8f2c61f4f667c2bc3e4e74b274fa397a4232393Eli Friedman case TemplateTypeParm: 79749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall case SubstTemplateTypeParm: 798c8f2c61f4f667c2bc3e4e74b274fa397a4232393Eli Friedman case TemplateSpecialization: 799465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case Elaborated: 8004714c12a1ab759156b78be8f109ea4c12213af57Douglas Gregor case DependentName: 80133500955d731c73717af52088b7fc0e7a85681e7John McCall case DependentTemplateSpecialization: 802c8f2c61f4f667c2bc3e4e74b274fa397a4232393Eli Friedman case ObjCInterface: 803c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall case ObjCObject: 804c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall case ObjCObjectPointer: // FIXME: object pointers aren't really specifiers 80522b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman return true; 80622b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman default: 80722b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman return false; 80822b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman } 80922b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman} 81022b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman 811465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraTypeWithKeyword::~TypeWithKeyword() { 812465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara} 813465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 814465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraElaboratedTypeKeyword 815465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraTypeWithKeyword::getKeywordForTypeSpec(unsigned TypeSpec) { 816465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara switch (TypeSpec) { 817465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara default: return ETK_None; 818465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TST_typename: return ETK_Typename; 819465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TST_class: return ETK_Class; 820465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TST_struct: return ETK_Struct; 821465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TST_union: return ETK_Union; 822465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TST_enum: return ETK_Enum; 823465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara } 824465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara} 825465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 826465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraTagTypeKind 827465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraTypeWithKeyword::getTagTypeKindForTypeSpec(unsigned TypeSpec) { 828465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara switch(TypeSpec) { 829465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TST_class: return TTK_Class; 830465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TST_struct: return TTK_Struct; 831465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TST_union: return TTK_Union; 832465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TST_enum: return TTK_Enum; 833465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara default: llvm_unreachable("Type specifier is not a tag type kind."); 834465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara } 835465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara} 836465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 837465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraElaboratedTypeKeyword 838465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraTypeWithKeyword::getKeywordForTagTypeKind(TagTypeKind Kind) { 839465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara switch (Kind) { 840465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TTK_Class: return ETK_Class; 841465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TTK_Struct: return ETK_Struct; 842465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TTK_Union: return ETK_Union; 843465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case TTK_Enum: return ETK_Enum; 844465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara } 845465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara llvm_unreachable("Unknown tag type kind."); 846465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara} 847465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 848465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraTagTypeKind 849465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraTypeWithKeyword::getTagTypeKindForKeyword(ElaboratedTypeKeyword Keyword) { 850465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara switch (Keyword) { 851465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Class: return TTK_Class; 852465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Struct: return TTK_Struct; 853465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Union: return TTK_Union; 854465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Enum: return TTK_Enum; 855465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_None: // Fall through. 856465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Typename: 857465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara llvm_unreachable("Elaborated type keyword is not a tag type kind."); 858465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara } 859465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara llvm_unreachable("Unknown elaborated type keyword."); 860465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara} 861465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 862465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnarabool 863465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraTypeWithKeyword::KeywordIsTagTypeKind(ElaboratedTypeKeyword Keyword) { 864465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara switch (Keyword) { 865465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_None: 866465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Typename: 867465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara return false; 868465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Class: 869465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Struct: 870465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Union: 871465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Enum: 8724033642464e8ba0982f88f34cffad808d247b393Douglas Gregor return true; 8734033642464e8ba0982f88f34cffad808d247b393Douglas Gregor } 874465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara llvm_unreachable("Unknown elaborated type keyword."); 875465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara} 876465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 877465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnaraconst char* 878465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraTypeWithKeyword::getKeywordName(ElaboratedTypeKeyword Keyword) { 879465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara switch (Keyword) { 880465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara default: llvm_unreachable("Unknown elaborated type keyword."); 881465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_None: return ""; 882465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Typename: return "typename"; 883465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Class: return "class"; 884465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Struct: return "struct"; 885465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Union: return "union"; 886465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case ETK_Enum: return "enum"; 887465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara } 888465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara} 889465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 89033500955d731c73717af52088b7fc0e7a85681e7John McCallElaboratedType::~ElaboratedType() {} 89133500955d731c73717af52088b7fc0e7a85681e7John McCallDependentNameType::~DependentNameType() {} 89233500955d731c73717af52088b7fc0e7a85681e7John McCallDependentTemplateSpecializationType::~DependentTemplateSpecializationType() {} 89333500955d731c73717af52088b7fc0e7a85681e7John McCall 89433500955d731c73717af52088b7fc0e7a85681e7John McCallDependentTemplateSpecializationType::DependentTemplateSpecializationType( 895ef99001908e799c388f1363b1e607dad5f5b57d3John McCall ElaboratedTypeKeyword Keyword, 89633500955d731c73717af52088b7fc0e7a85681e7John McCall NestedNameSpecifier *NNS, const IdentifierInfo *Name, 89733500955d731c73717af52088b7fc0e7a85681e7John McCall unsigned NumArgs, const TemplateArgument *Args, 89833500955d731c73717af52088b7fc0e7a85681e7John McCall QualType Canon) 89933500955d731c73717af52088b7fc0e7a85681e7John McCall : TypeWithKeyword(Keyword, DependentTemplateSpecialization, Canon, true), 900ef99001908e799c388f1363b1e607dad5f5b57d3John McCall NNS(NNS), Name(Name), NumArgs(NumArgs) { 90133500955d731c73717af52088b7fc0e7a85681e7John McCall assert(NNS && NNS->isDependent() && 90233500955d731c73717af52088b7fc0e7a85681e7John McCall "DependentTemplateSpecializatonType requires dependent qualifier"); 90333500955d731c73717af52088b7fc0e7a85681e7John McCall for (unsigned I = 0; I != NumArgs; ++I) 90433500955d731c73717af52088b7fc0e7a85681e7John McCall new (&getArgBuffer()[I]) TemplateArgument(Args[I]); 90533500955d731c73717af52088b7fc0e7a85681e7John McCall} 90633500955d731c73717af52088b7fc0e7a85681e7John McCall 90733500955d731c73717af52088b7fc0e7a85681e7John McCallvoid 90833500955d731c73717af52088b7fc0e7a85681e7John McCallDependentTemplateSpecializationType::Profile(llvm::FoldingSetNodeID &ID, 90933500955d731c73717af52088b7fc0e7a85681e7John McCall ASTContext &Context, 91033500955d731c73717af52088b7fc0e7a85681e7John McCall ElaboratedTypeKeyword Keyword, 91133500955d731c73717af52088b7fc0e7a85681e7John McCall NestedNameSpecifier *Qualifier, 91233500955d731c73717af52088b7fc0e7a85681e7John McCall const IdentifierInfo *Name, 91333500955d731c73717af52088b7fc0e7a85681e7John McCall unsigned NumArgs, 91433500955d731c73717af52088b7fc0e7a85681e7John McCall const TemplateArgument *Args) { 91533500955d731c73717af52088b7fc0e7a85681e7John McCall ID.AddInteger(Keyword); 91633500955d731c73717af52088b7fc0e7a85681e7John McCall ID.AddPointer(Qualifier); 91733500955d731c73717af52088b7fc0e7a85681e7John McCall ID.AddPointer(Name); 91833500955d731c73717af52088b7fc0e7a85681e7John McCall for (unsigned Idx = 0; Idx < NumArgs; ++Idx) 91933500955d731c73717af52088b7fc0e7a85681e7John McCall Args[Idx].Profile(ID, Context); 92033500955d731c73717af52088b7fc0e7a85681e7John McCall} 92133500955d731c73717af52088b7fc0e7a85681e7John McCall 922465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnarabool Type::isElaboratedTypeSpecifier() const { 923465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara ElaboratedTypeKeyword Keyword; 924465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara if (const ElaboratedType *Elab = dyn_cast<ElaboratedType>(this)) 925465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara Keyword = Elab->getKeyword(); 926465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara else if (const DependentNameType *DepName = dyn_cast<DependentNameType>(this)) 927465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara Keyword = DepName->getKeyword(); 92833500955d731c73717af52088b7fc0e7a85681e7John McCall else if (const DependentTemplateSpecializationType *DepTST = 92933500955d731c73717af52088b7fc0e7a85681e7John McCall dyn_cast<DependentTemplateSpecializationType>(this)) 93033500955d731c73717af52088b7fc0e7a85681e7John McCall Keyword = DepTST->getKeyword(); 931465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara else 932465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara return false; 933465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 934465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara return TypeWithKeyword::KeywordIsTagTypeKind(Keyword); 9354033642464e8ba0982f88f34cffad808d247b393Douglas Gregor} 9364033642464e8ba0982f88f34cffad808d247b393Douglas Gregor 937cd01f17358dc8ef19338c0e2321138dd0a6160d9Argyrios Kyrtzidisconst char *Type::getTypeClassName() const { 938cd01f17358dc8ef19338c0e2321138dd0a6160d9Argyrios Kyrtzidis switch (TC) { 939cd01f17358dc8ef19338c0e2321138dd0a6160d9Argyrios Kyrtzidis default: assert(0 && "Type class not in TypeNodes.def!"); 940cd01f17358dc8ef19338c0e2321138dd0a6160d9Argyrios Kyrtzidis#define ABSTRACT_TYPE(Derived, Base) 941cd01f17358dc8ef19338c0e2321138dd0a6160d9Argyrios Kyrtzidis#define TYPE(Derived, Base) case Derived: return #Derived; 942cd01f17358dc8ef19338c0e2321138dd0a6160d9Argyrios Kyrtzidis#include "clang/AST/TypeNodes.def" 943cd01f17358dc8ef19338c0e2321138dd0a6160d9Argyrios Kyrtzidis } 944cd01f17358dc8ef19338c0e2321138dd0a6160d9Argyrios Kyrtzidis} 945cd01f17358dc8ef19338c0e2321138dd0a6160d9Argyrios Kyrtzidis 946e4f2142d00fa5fdb580c4e2413da91882d955381Chris Lattnerconst char *BuiltinType::getName(const LangOptions &LO) const { 9475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer switch (getKind()) { 9485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer default: assert(0 && "Unknown builtin type!"); 9495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Void: return "void"; 950e4f2142d00fa5fdb580c4e2413da91882d955381Chris Lattner case Bool: return LO.Bool ? "bool" : "_Bool"; 9515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Char_S: return "char"; 9525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Char_U: return "char"; 9535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case SChar: return "signed char"; 9545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Short: return "short"; 9555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Int: return "int"; 9565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Long: return "long"; 9575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case LongLong: return "long long"; 9582df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner case Int128: return "__int128_t"; 9595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case UChar: return "unsigned char"; 9605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case UShort: return "unsigned short"; 9615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case UInt: return "unsigned int"; 9625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case ULong: return "unsigned long"; 9635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case ULongLong: return "unsigned long long"; 9642df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner case UInt128: return "__uint128_t"; 9655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Float: return "float"; 9665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Double: return "double"; 9675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case LongDouble: return "long double"; 96846713efe13c89f4ec9cd9546c7b598fe7186089bArgyrios Kyrtzidis case WChar: return "wchar_t"; 969f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith case Char16: return "char16_t"; 970f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith case Char32: return "char32_t"; 9716e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl case NullPtr: return "nullptr_t"; 9728e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor case Overload: return "<overloaded function type>"; 973898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor case Dependent: return "<dependent type>"; 9746a75cd9c1d54625fca7b5477ab9545bcdbd85ea4Anders Carlsson case UndeducedAuto: return "auto"; 975de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff case ObjCId: return "id"; 976de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff case ObjCClass: return "Class"; 977bef0efd11bc4430a3ee437a3213cec5c18af855aChris Lattner case ObjCSel: return "SEL"; 9785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 9795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 9805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 981bef0efd11bc4430a3ee437a3213cec5c18af855aChris Lattnervoid FunctionType::ANCHOR() {} // Key function for FunctionType. 982bef0efd11bc4430a3ee437a3213cec5c18af855aChris Lattner 9836398235d7890a81b785ea5af3b6e66d86bf184ccDouglas GregorQualType QualType::getNonLValueExprType(ASTContext &Context) const { 9845291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor if (const ReferenceType *RefType = getTypePtr()->getAs<ReferenceType>()) 9855291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor return RefType->getPointeeType(); 9865291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor 9875291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor // C++0x [basic.lval]: 9885291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor // Class prvalues can have cv-qualified types; non-class prvalues always 9895291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor // have cv-unqualified types. 9905291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor // 9915291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor // See also C99 6.3.2.1p2. 9925291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor if (!Context.getLangOptions().CPlusPlus || 9936dc1ef87044e6b177d4df0d2b593a94616180b3dChandler Carruth (!getTypePtr()->isDependentType() && !getTypePtr()->isRecordType())) 9945291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor return getUnqualifiedType(); 9955291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor 9965291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor return *this; 9975291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor} 9985291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor 99904a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCallllvm::StringRef FunctionType::getNameForCallConv(CallingConv CC) { 100004a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall switch (CC) { 100104a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall case CC_Default: llvm_unreachable("no name for default cc"); 100204a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall default: return ""; 100304a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall 100404a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall case CC_C: return "cdecl"; 100504a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall case CC_X86StdCall: return "stdcall"; 100604a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall case CC_X86FastCall: return "fastcall"; 1007f813a2c03fcb05381b3252010435f557eb6b3cdeDouglas Gregor case CC_X86ThisCall: return "thiscall"; 100804a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall } 100904a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall} 101004a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall 101172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregorvoid FunctionProtoType::Profile(llvm::FoldingSetNodeID &ID, QualType Result, 1012942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner arg_type_iterator ArgTys, 1013971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis unsigned NumArgs, bool isVariadic, 1014465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl unsigned TypeQuals, bool hasExceptionSpec, 1015465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl bool anyExceptionSpec, unsigned NumExceptions, 1016264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola exception_iterator Exs, 1017264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola const FunctionType::ExtInfo &Info) { 10185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddPointer(Result.getAsOpaquePtr()); 10195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer for (unsigned i = 0; i != NumArgs; ++i) 10205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddPointer(ArgTys[i].getAsOpaquePtr()); 10215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddInteger(isVariadic); 1022971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis ID.AddInteger(TypeQuals); 1023465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl ID.AddInteger(hasExceptionSpec); 1024465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl if (hasExceptionSpec) { 1025465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl ID.AddInteger(anyExceptionSpec); 10261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump for (unsigned i = 0; i != NumExceptions; ++i) 1027465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl ID.AddPointer(Exs[i].getAsOpaquePtr()); 1028465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl } 1029264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola ID.AddInteger(Info.getNoReturn()); 1030425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola ID.AddInteger(Info.getRegParm()); 1031264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola ID.AddInteger(Info.getCC()); 10325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 10335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 103472564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregorvoid FunctionProtoType::Profile(llvm::FoldingSetNodeID &ID) { 1035971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis Profile(ID, getResultType(), arg_type_begin(), NumArgs, isVariadic(), 1036465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl getTypeQuals(), hasExceptionSpec(), hasAnyExceptionSpec(), 1037264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola getNumExceptions(), exception_begin(), 1038264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola getExtInfo()); 10395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 10405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1041a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner/// LookThroughTypedefs - Return the ultimate type this typedef corresponds to 1042a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner/// potentially looking through *all* consequtive typedefs. This returns the 1043a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner/// sum of the type qualifiers, so if you have: 1044a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner/// typedef const int A; 1045a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner/// typedef volatile A B; 1046a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner/// looking through the typedefs for B will give you "const volatile A". 1047a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner/// 1048a2c7767ce7d8feb10253f4b650826a20f3324c6fChris LattnerQualType TypedefType::LookThroughTypedefs() const { 1049a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner // Usually, there is only a single level of typedefs, be fast in that case. 1050a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner QualType FirstType = getDecl()->getUnderlyingType(); 1051a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner if (!isa<TypedefType>(FirstType)) 1052a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner return FirstType; 10531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1054a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner // Otherwise, do the fully general loop. 10550953e767ff7817f97b3ab20896b229891eeff45bJohn McCall QualifierCollector Qs; 10561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10570953e767ff7817f97b3ab20896b229891eeff45bJohn McCall QualType CurType; 10580953e767ff7817f97b3ab20896b229891eeff45bJohn McCall const TypedefType *TDT = this; 10590953e767ff7817f97b3ab20896b229891eeff45bJohn McCall do { 10600953e767ff7817f97b3ab20896b229891eeff45bJohn McCall CurType = TDT->getDecl()->getUnderlyingType(); 10610953e767ff7817f97b3ab20896b229891eeff45bJohn McCall TDT = dyn_cast<TypedefType>(Qs.strip(CurType)); 10620953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } while (TDT); 10631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10640953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return Qs.apply(CurType); 1065a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner} 10665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1067bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCallQualType TypedefType::desugar() const { 1068bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall return getDecl()->getUnderlyingType(); 1069bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall} 1070bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 107172564e73277e29f6db3305d1f27ba408abb7ed88Douglas GregorTypeOfExprType::TypeOfExprType(Expr *E, QualType can) 107272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor : Type(TypeOfExpr, can, E->isTypeDependent()), TOExpr(E) { 1073898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor} 1074898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 1075bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCallQualType TypeOfExprType::desugar() const { 1076bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall return getUnderlyingExpr()->getType(); 1077bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall} 1078bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall 10791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpvoid DependentTypeOfExprType::Profile(llvm::FoldingSetNodeID &ID, 1080b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor ASTContext &Context, Expr *E) { 1081b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor E->Profile(ID, Context, true); 1082b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor} 1083b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor 1084563a03b1338d31c2462def43253a722bc885d384Anders CarlssonDecltypeType::DecltypeType(Expr *E, QualType underlyingType, QualType can) 10851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : Type(Decltype, can, E->isTypeDependent()), E(E), 1086563a03b1338d31c2462def43253a722bc885d384Anders Carlsson UnderlyingType(underlyingType) { 1087395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson} 1088395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson 10899d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas GregorDependentDecltypeType::DependentDecltypeType(ASTContext &Context, Expr *E) 10909d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor : DecltypeType(E, Context.DependentTy), Context(Context) { } 10919d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor 10921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpvoid DependentDecltypeType::Profile(llvm::FoldingSetNodeID &ID, 10939d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor ASTContext &Context, Expr *E) { 10949d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor E->Profile(ID, Context, true); 10959d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor} 10969d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor 109719c8576b7328f4dc2d07682f5da552875c1912efJohn McCallTagType::TagType(TypeClass TC, const TagDecl *D, QualType can) 109819c8576b7328f4dc2d07682f5da552875c1912efJohn McCall : Type(TC, can, D->isDependentType()), 1099ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl decl(const_cast<TagDecl*>(D)) {} 1100ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl 1101ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redlstatic TagDecl *getInterestingTagDecl(TagDecl *decl) { 1102ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl for (TagDecl::redecl_iterator I = decl->redecls_begin(), 1103ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl E = decl->redecls_end(); 1104ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl I != E; ++I) { 1105ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl if (I->isDefinition() || I->isBeingDefined()) 1106ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl return *I; 1107ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl } 1108ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl // If there's no definition (not even in progress), return what we have. 1109ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl return decl; 1110ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl} 1111ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl 1112ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian RedlTagDecl *TagType::getDecl() const { 1113ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl return getInterestingTagDecl(decl); 1114ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl} 1115ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl 1116ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redlbool TagType::isBeingDefined() const { 1117ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl return getDecl()->isBeingDefined(); 1118ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl} 1119ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl 1120ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian RedlCXXRecordDecl *InjectedClassNameType::getDecl() const { 1121ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl return cast<CXXRecordDecl>(getInterestingTagDecl(Decl)); 1122ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl} 11237da97d0f31e1ec16998d3de2cfd2e88fe3736673Douglas Gregor 11242daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattnerbool RecordType::classof(const TagType *TT) { 11252daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner return isa<RecordDecl>(TT->getDecl()); 11265edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner} 11275edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner 11282daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattnerbool EnumType::classof(const TagType *TT) { 11292daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner return isa<EnumDecl>(TT->getDecl()); 11305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 11315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1132833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallstatic bool isDependent(const TemplateArgument &Arg) { 1133833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall switch (Arg.getKind()) { 1134833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall case TemplateArgument::Null: 1135833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall assert(false && "Should not have a NULL template argument"); 1136833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return false; 1137833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 1138833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall case TemplateArgument::Type: 1139833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return Arg.getAsType()->isDependentType(); 1140833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 1141788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor case TemplateArgument::Template: 1142788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor return Arg.getAsTemplate().isDependent(); 1143788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor 1144833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall case TemplateArgument::Declaration: 1145bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor if (DeclContext *DC = dyn_cast<DeclContext>(Arg.getAsDecl())) 1146bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor return DC->isDependentContext(); 1147bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor return Arg.getAsDecl()->getDeclContext()->isDependentContext(); 1148bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor 1149833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall case TemplateArgument::Integral: 1150833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall // Never dependent 1151833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return false; 1152833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 1153833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall case TemplateArgument::Expression: 1154833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return (Arg.getAsExpr()->isTypeDependent() || 1155833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall Arg.getAsExpr()->isValueDependent()); 1156833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 1157833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall case TemplateArgument::Pack: 1158bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor for (TemplateArgument::pack_iterator P = Arg.pack_begin(), 1159bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor PEnd = Arg.pack_end(); 1160bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor P != PEnd; ++P) { 1161bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor if (isDependent(*P)) 1162bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor return true; 1163bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor } 1164bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor 1165833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return false; 116655f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor } 116740808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor 116840808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor return false; 116955f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor} 117055f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 1171833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallbool TemplateSpecializationType:: 1172d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCallanyDependentTemplateArguments(const TemplateArgumentListInfo &Args) { 1173d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall return anyDependentTemplateArguments(Args.getArgumentArray(), Args.size()); 1174d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall} 1175d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall 1176d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCallbool TemplateSpecializationType:: 1177833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallanyDependentTemplateArguments(const TemplateArgumentLoc *Args, unsigned N) { 1178833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall for (unsigned i = 0; i != N; ++i) 1179833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall if (isDependent(Args[i].getArgument())) 1180833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return true; 1181833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return false; 1182833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall} 1183833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 1184833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallbool TemplateSpecializationType:: 1185833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallanyDependentTemplateArguments(const TemplateArgument *Args, unsigned N) { 1186833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall for (unsigned i = 0; i != N; ++i) 1187833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall if (isDependent(Args[i])) 1188833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return true; 1189833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return false; 1190833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall} 1191833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 11927532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas GregorTemplateSpecializationType:: 1193ef99001908e799c388f1363b1e607dad5f5b57d3John McCallTemplateSpecializationType(TemplateName T, 1194828e226ab7ed08b3eb766549e9d3306432137460Douglas Gregor const TemplateArgument *Args, 11957532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor unsigned NumArgs, QualType Canon) 11961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : Type(TemplateSpecialization, 119740808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor Canon.isNull()? QualType(this, 0) : Canon, 11987532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor T.isDependent() || anyDependentTemplateArguments(Args, NumArgs)), 11991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Template(T), NumArgs(NumArgs) { 12001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump assert((!Canon.isNull() || 12017532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor T.isDependent() || anyDependentTemplateArguments(Args, NumArgs)) && 120240808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor "No canonical type for non-dependent class template specialization"); 120355f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 12041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TemplateArgument *TemplateArgs 120540808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor = reinterpret_cast<TemplateArgument *>(this + 1); 120655f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor for (unsigned Arg = 0; Arg < NumArgs; ++Arg) 120740808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor new (&TemplateArgs[Arg]) TemplateArgument(Args[Arg]); 120855f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor} 120955f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 12101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpvoid 12111eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTemplateSpecializationType::Profile(llvm::FoldingSetNodeID &ID, 12121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TemplateName T, 12131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const TemplateArgument *Args, 1214828e226ab7ed08b3eb766549e9d3306432137460Douglas Gregor unsigned NumArgs, 1215828e226ab7ed08b3eb766549e9d3306432137460Douglas Gregor ASTContext &Context) { 12167532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor T.Profile(ID); 121740808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor for (unsigned Idx = 0; Idx < NumArgs; ++Idx) 1218828e226ab7ed08b3eb766549e9d3306432137460Douglas Gregor Args[Idx].Profile(ID, Context); 121955f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor} 122097e0179f1ae545e07d9f5e7c1d2ef5c5bab06676Anders Carlsson 12210953e767ff7817f97b3ab20896b229891eeff45bJohn McCallQualType QualifierCollector::apply(QualType QT) const { 12220953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (!hasNonFastQualifiers()) 12230953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return QT.withFastQualifiers(getFastQualifiers()); 12241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12250953e767ff7817f97b3ab20896b229891eeff45bJohn McCall assert(Context && "extended qualifiers but no context!"); 12260953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return Context->getQualifiedType(QT, *this); 12275e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor} 12285e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor 12290953e767ff7817f97b3ab20896b229891eeff45bJohn McCallQualType QualifierCollector::apply(const Type *T) const { 12300953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (!hasNonFastQualifiers()) 12310953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return QualType(T, getFastQualifiers()); 12320953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 12330953e767ff7817f97b3ab20896b229891eeff45bJohn McCall assert(Context && "extended qualifiers but no context!"); 12340953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return Context->getQualifiedType(T, *this); 12355e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor} 12365e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor 1237c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallvoid ObjCObjectTypeImpl::Profile(llvm::FoldingSetNodeID &ID, 1238c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall QualType BaseType, 1239c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCProtocolDecl * const *Protocols, 1240c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall unsigned NumProtocols) { 1241c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ID.AddPointer(BaseType.getAsOpaquePtr()); 1242c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff for (unsigned i = 0; i != NumProtocols; i++) 1243c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ID.AddPointer(Protocols[i]); 1244c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff} 1245c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff 1246c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallvoid ObjCObjectTypeImpl::Profile(llvm::FoldingSetNodeID &ID) { 1247c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall Profile(ID, getBaseType(), qual_begin(), getNumProtocols()); 1248c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff} 12490b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 125060e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor/// \brief Determine the linkage of this type. 125160e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas GregorLinkage Type::getLinkage() const { 12520b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor if (this != CanonicalType.getTypePtr()) 12530b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor return CanonicalType->getLinkage(); 125460e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor 125560e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor if (!LinkageKnown) { 125660e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor CachedLinkage = getLinkageImpl(); 125760e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor LinkageKnown = true; 125860e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor } 125960e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor 126060e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor return static_cast<clang::Linkage>(CachedLinkage); 126160e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor} 12620b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 126360e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas GregorLinkage Type::getLinkageImpl() const { 126460e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor // C++ [basic.link]p8: 126560e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor // Names not covered by these rules have no linkage. 12660b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor return NoLinkage; 12670b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor} 12680b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 126960e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregorvoid Type::ClearLinkageCache() { 127060e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor if (this != CanonicalType.getTypePtr()) 127160e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor CanonicalType->ClearLinkageCache(); 127260e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor else 127360e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor LinkageKnown = false; 127460e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor} 127560e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor 127660e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas GregorLinkage BuiltinType::getLinkageImpl() const { 12770b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor // C++ [basic.link]p8: 12780b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor // A type is said to have linkage if and only if: 12790b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor // - it is a fundamental type (3.9.1); or 12800b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor return ExternalLinkage; 12810b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor} 12820b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 128360e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas GregorLinkage TagType::getLinkageImpl() const { 12840b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor // C++ [basic.link]p8: 12850b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor // - it is a class or enumeration type that is named (or has a name for 12860b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor // linkage purposes (7.1.3)) and the name has linkage; or 12870b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor // - it is a specialization of a class template (14); or 12880b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor return getDecl()->getLinkage(); 12890b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor} 12900b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 12910b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor// C++ [basic.link]p8: 12920b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor// - it is a compound type (3.9.2) other than a class or enumeration, 12930b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor// compounded exclusively from types that have linkage; or 129460e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas GregorLinkage ComplexType::getLinkageImpl() const { 12950b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor return ElementType->getLinkage(); 12960b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor} 12970b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 129860e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas GregorLinkage PointerType::getLinkageImpl() const { 12990b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor return PointeeType->getLinkage(); 13000b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor} 13010b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 130260e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas GregorLinkage BlockPointerType::getLinkageImpl() const { 13030b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor return PointeeType->getLinkage(); 13040b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor} 13050b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 130660e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas GregorLinkage ReferenceType::getLinkageImpl() const { 13070b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor return PointeeType->getLinkage(); 13080b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor} 13090b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 131060e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas GregorLinkage MemberPointerType::getLinkageImpl() const { 13110b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor return minLinkage(Class->getLinkage(), PointeeType->getLinkage()); 13120b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor} 13130b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 131460e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas GregorLinkage ArrayType::getLinkageImpl() const { 13150b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor return ElementType->getLinkage(); 13160b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor} 13170b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 131860e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas GregorLinkage VectorType::getLinkageImpl() const { 13190b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor return ElementType->getLinkage(); 13200b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor} 13210b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 132260e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas GregorLinkage FunctionNoProtoType::getLinkageImpl() const { 13230b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor return getResultType()->getLinkage(); 13240b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor} 13250b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 132660e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas GregorLinkage FunctionProtoType::getLinkageImpl() const { 13270b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor Linkage L = getResultType()->getLinkage(); 13280b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor for (arg_type_iterator A = arg_type_begin(), AEnd = arg_type_end(); 13290b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor A != AEnd; ++A) 13300b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor L = minLinkage(L, (*A)->getLinkage()); 13310b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 13320b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor return L; 13330b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor} 13340b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 133560e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas GregorLinkage ObjCObjectType::getLinkageImpl() const { 13360b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor return ExternalLinkage; 13370b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor} 13380b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor 133960e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas GregorLinkage ObjCObjectPointerType::getLinkageImpl() const { 13400b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor return ExternalLinkage; 13410b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor} 1342