Type.cpp revision 6398235d7890a81b785ea5af3b6e66d86bf184cc
15f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===--- Type.cpp - Type representation and manipulation ------------------===//
25f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
35f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//                     The LLVM Compiler Infrastructure
45f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
50bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// This file is distributed under the University of Illinois Open Source
60bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// License. See LICENSE.TXT for details.
75f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
85f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
95f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//  This file implements type-related functionality.
115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
14b381aac9bae6d608c72267dd0ed08ec6369e94e4Nuno Lopes#include "clang/AST/ASTContext.h"
155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "clang/AST/Type.h"
1649aa7ff1245abd03e6e998e01302df31e4c6f8f6Argyrios Kyrtzidis#include "clang/AST/DeclCXX.h"
17980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff#include "clang/AST/DeclObjC.h"
18aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor#include "clang/AST/DeclTemplate.h"
195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "clang/AST/Expr.h"
20d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor#include "clang/AST/PrettyPrinter.h"
21465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara#include "clang/Basic/Specifiers.h"
225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "llvm/ADT/StringExtras.h"
23bad351822117eaf280081494e3dbe4a06c0dbfcfDouglas Gregor#include "llvm/Support/raw_ostream.h"
245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing namespace clang;
255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
26bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCallbool QualType::isConstant(QualType T, ASTContext &Ctx) {
27bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  if (T.isConstQualified())
28b381aac9bae6d608c72267dd0ed08ec6369e94e4Nuno Lopes    return true;
29b381aac9bae6d608c72267dd0ed08ec6369e94e4Nuno Lopes
30bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  if (const ArrayType *AT = Ctx.getAsArrayType(T))
31bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall    return AT->getElementType().isConstant(Ctx);
32b381aac9bae6d608c72267dd0ed08ec6369e94e4Nuno Lopes
33b381aac9bae6d608c72267dd0ed08ec6369e94e4Nuno Lopes  return false;
34b381aac9bae6d608c72267dd0ed08ec6369e94e4Nuno Lopes}
35b381aac9bae6d608c72267dd0ed08ec6369e94e4Nuno Lopes
36566c2ba743065ec090f5154d5c30cf593aa12a6eTed Kremenekvoid Type::Destroy(ASTContext& C) {
37566c2ba743065ec090f5154d5c30cf593aa12a6eTed Kremenek  this->~Type();
383e9704981d7691fdd44913bf1786e8d760d8a627Steve Naroff  C.Deallocate(this);
394b05b1dee6cc65ae61d93dab7edff72710f24589Ted Kremenek}
404b05b1dee6cc65ae61d93dab7edff72710f24589Ted Kremenek
414b05b1dee6cc65ae61d93dab7edff72710f24589Ted Kremenekvoid VariableArrayType::Destroy(ASTContext& C) {
42f91f5c8a66ffd812f61819836529f8ad437f7e2bEli Friedman  if (SizeExpr)
43f91f5c8a66ffd812f61819836529f8ad437f7e2bEli Friedman    SizeExpr->Destroy(C);
44566c2ba743065ec090f5154d5c30cf593aa12a6eTed Kremenek  this->~VariableArrayType();
453e9704981d7691fdd44913bf1786e8d760d8a627Steve Naroff  C.Deallocate(this);
464b05b1dee6cc65ae61d93dab7edff72710f24589Ted Kremenek}
475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
48898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorvoid DependentSizedArrayType::Destroy(ASTContext& C) {
49e7f38406a38f453e83000a1e52a5ec0aada66e51Argyrios Kyrtzidis  // FIXME: Resource contention like in ConstantArrayWithExprType ?
50e7f38406a38f453e83000a1e52a5ec0aada66e51Argyrios Kyrtzidis  // May crash, depending on platform or a particular build.
51e7f38406a38f453e83000a1e52a5ec0aada66e51Argyrios Kyrtzidis  // SizeExpr->Destroy(C);
52566c2ba743065ec090f5154d5c30cf593aa12a6eTed Kremenek  this->~DependentSizedArrayType();
533e9704981d7691fdd44913bf1786e8d760d8a627Steve Naroff  C.Deallocate(this);
54898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor}
55c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner
561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpvoid DependentSizedArrayType::Profile(llvm::FoldingSetNodeID &ID,
5704d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor                                      ASTContext &Context,
5804d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor                                      QualType ET,
5904d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor                                      ArraySizeModifier SizeMod,
6004d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor                                      unsigned TypeQuals,
6104d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor                                      Expr *E) {
6204d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor  ID.AddPointer(ET.getAsOpaquePtr());
6304d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor  ID.AddInteger(SizeMod);
6404d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor  ID.AddInteger(TypeQuals);
6504d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor  E->Profile(ID, Context, true);
6604d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor}
6704d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor
681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpvoid
691eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpDependentSizedExtVectorType::Profile(llvm::FoldingSetNodeID &ID,
702ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor                                     ASTContext &Context,
712ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor                                     QualType ElementType, Expr *SizeExpr) {
722ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor  ID.AddPointer(ElementType.getAsOpaquePtr());
732ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor  SizeExpr->Profile(ID, Context, true);
742ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor}
752ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor
769cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregorvoid DependentSizedExtVectorType::Destroy(ASTContext& C) {
77bd1099efde211cbb63fce3feee4ebcc6bac58781Douglas Gregor  // FIXME: Deallocate size expression, once we're cloning properly.
78bd1099efde211cbb63fce3feee4ebcc6bac58781Douglas Gregor//  if (SizeExpr)
79bd1099efde211cbb63fce3feee4ebcc6bac58781Douglas Gregor//    SizeExpr->Destroy(C);
809cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor  this->~DependentSizedExtVectorType();
819cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor  C.Deallocate(this);
829cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor}
839cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor
84c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner/// getArrayElementTypeNoTypeQual - If this is an array type, return the
85c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner/// element type of the array, potentially with type qualifiers missing.
86c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner/// This method should never be used when type qualifiers are meaningful.
87c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattnerconst Type *Type::getArrayElementTypeNoTypeQual() const {
88c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  // If this is directly an array type, return it.
89c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  if (const ArrayType *ATy = dyn_cast<ArrayType>(this))
90c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner    return ATy->getElementType().getTypePtr();
911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
92c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  // If the canonical form of this type isn't the right kind, reject it.
930953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  if (!isa<ArrayType>(CanonicalType))
94c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner    return 0;
951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
96c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  // If this is a typedef for an array type, strip the typedef off without
97c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  // losing all typedef information.
98bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  return cast<ArrayType>(getUnqualifiedDesugaredType())
99bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall    ->getElementType().getTypePtr();
1002fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner}
1012fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner
102fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor/// \brief Retrieve the unqualified variant of the given type, removing as
103fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor/// little sugar as possible.
104fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor///
105fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor/// This routine looks through various kinds of sugar to find the
106fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor/// least-desuraged type that is unqualified. For example, given:
107fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor///
108fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor/// \code
109fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor/// typedef int Integer;
110fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor/// typedef const Integer CInteger;
111fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor/// typedef CInteger DifferenceType;
112fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor/// \endcode
113fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor///
114fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor/// Executing \c getUnqualifiedTypeSlow() on the type \c DifferenceType will
115fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor/// desugar until we hit the type \c Integer, which has no qualifiers on it.
116fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas GregorQualType QualType::getUnqualifiedTypeSlow() const {
117fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  QualType Cur = *this;
118fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  while (true) {
119fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor    if (!Cur.hasQualifiers())
120fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor      return Cur;
121fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor
122fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor    const Type *CurTy = Cur.getTypePtr();
123fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor    switch (CurTy->getTypeClass()) {
124fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor#define ABSTRACT_TYPE(Class, Parent)
125fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor#define TYPE(Class, Parent)                                  \
126fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor    case Type::Class: {                                      \
127fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor      const Class##Type *Ty = cast<Class##Type>(CurTy);      \
128fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor      if (!Ty->isSugared())                                  \
129fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor        return Cur.getLocalUnqualifiedType();                \
130fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor      Cur = Ty->desugar();                                   \
131fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor      break;                                                 \
132fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor    }
133fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor#include "clang/AST/TypeNodes.def"
134fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor    }
135fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  }
136fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor
137fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  return Cur.getUnqualifiedType();
138fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor}
139fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor
1402fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner/// getDesugaredType - Return the specified type with any "sugar" removed from
1412fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner/// the type.  This takes off typedefs, typeof's etc.  If the outer level of
1422fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner/// the type is already concrete, it returns it unmodified.  This is similar
1432fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner/// to getting the canonical type, but it doesn't remove *all* typedefs.  For
1442fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner/// example, it returns "T*" as "T*", (not as "int*"), because the pointer is
1452fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner/// concrete.
146bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCallQualType QualType::getDesugaredType(QualType T) {
1470953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  QualifierCollector Qs;
148c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner
149bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType Cur = T;
150bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  while (true) {
151bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall    const Type *CurTy = Qs.strip(Cur);
152bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall    switch (CurTy->getTypeClass()) {
153bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall#define ABSTRACT_TYPE(Class, Parent)
154bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall#define TYPE(Class, Parent) \
155bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall    case Type::Class: { \
156bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall      const Class##Type *Ty = cast<Class##Type>(CurTy); \
157bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall      if (!Ty->isSugared()) \
158bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall        return Qs.apply(Cur); \
159bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall      Cur = Ty->desugar(); \
160bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall      break; \
161bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall    }
162bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall#include "clang/AST/TypeNodes.def"
163bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall    }
164969c689d893a248eca4f049f5b89f747e66e4bffDouglas Gregor  }
165bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall}
1665cdf82164dd7c2b2320d6735c63ace4331e0716dDouglas Gregor
167bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall/// getUnqualifiedDesugaredType - Pull any qualifiers and syntactic
168bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall/// sugar off the given type.  This should produce an object of the
169bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall/// same dynamic type as the canonical type.
170bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCallconst Type *Type::getUnqualifiedDesugaredType() const {
171bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  const Type *Cur = this;
172bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
173bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  while (true) {
174bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall    switch (Cur->getTypeClass()) {
175bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall#define ABSTRACT_TYPE(Class, Parent)
176bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall#define TYPE(Class, Parent) \
177bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall    case Class: { \
178bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall      const Class##Type *Ty = cast<Class##Type>(Cur); \
179bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall      if (!Ty->isSugared()) return Cur; \
180bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall      Cur = Ty->desugar().getTypePtr(); \
181bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall      break; \
182bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall    }
183bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall#include "clang/AST/TypeNodes.def"
184bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall    }
185bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  }
186c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner}
187c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner
1885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// isVoidType - Helper method to determine if this is the 'void' type.
1895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isVoidType() const {
1905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
1915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return BT->getKind() == BuiltinType::Void;
1925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  return false;
1935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
1945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isObjectType() const {
196bad0e656c3732e3539a9cd6525de721d7e47408bDouglas Gregor  if (isa<FunctionType>(CanonicalType) || isa<ReferenceType>(CanonicalType) ||
197bad0e656c3732e3539a9cd6525de721d7e47408bDouglas Gregor      isa<IncompleteArrayType>(CanonicalType) || isVoidType())
1985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return false;
199bad0e656c3732e3539a9cd6525de721d7e47408bDouglas Gregor  return true;
2005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
2015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isDerivedType() const {
2035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  switch (CanonicalType->getTypeClass()) {
2045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case Pointer:
205fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  case VariableArray:
206fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  case ConstantArray:
207c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman  case IncompleteArray:
2085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case FunctionProto:
2095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case FunctionNoProto:
2107c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  case LValueReference:
2117c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  case RValueReference:
21272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  case Record:
2135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return true;
2145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  default:
2155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return false;
2165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
2175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
2185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
21999dc91422144483c20d1c7381bc9ac634b646b04Chris Lattnerbool Type::isClassType() const {
2206217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek  if (const RecordType *RT = getAs<RecordType>())
221f728a4a05df2455e1c6e62173ab720a92cd4a074Chris Lattner    return RT->getDecl()->isClass();
22299dc91422144483c20d1c7381bc9ac634b646b04Chris Lattner  return false;
22399dc91422144483c20d1c7381bc9ac634b646b04Chris Lattner}
224c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattnerbool Type::isStructureType() const {
2256217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek  if (const RecordType *RT = getAs<RecordType>())
226f728a4a05df2455e1c6e62173ab720a92cd4a074Chris Lattner    return RT->getDecl()->isStruct();
227c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  return false;
228c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner}
229fb87b89fc9eb103e19fb8e4b925c23f0bd091b99Douglas Gregorbool Type::isStructureOrClassType() const {
230fb87b89fc9eb103e19fb8e4b925c23f0bd091b99Douglas Gregor  if (const RecordType *RT = getAs<RecordType>())
231fb87b89fc9eb103e19fb8e4b925c23f0bd091b99Douglas Gregor    return RT->getDecl()->isStruct() || RT->getDecl()->isClass();
232fb87b89fc9eb103e19fb8e4b925c23f0bd091b99Douglas Gregor  return false;
233fb87b89fc9eb103e19fb8e4b925c23f0bd091b99Douglas Gregor}
2347154a77e7c1f23418342d3b72836ab504aa7821eSteve Naroffbool Type::isVoidPointerType() const {
2356217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek  if (const PointerType *PT = getAs<PointerType>())
2367154a77e7c1f23418342d3b72836ab504aa7821eSteve Naroff    return PT->getPointeeType()->isVoidType();
2377154a77e7c1f23418342d3b72836ab504aa7821eSteve Naroff  return false;
2387154a77e7c1f23418342d3b72836ab504aa7821eSteve Naroff}
2397154a77e7c1f23418342d3b72836ab504aa7821eSteve Naroff
240c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattnerbool Type::isUnionType() const {
2416217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek  if (const RecordType *RT = getAs<RecordType>())
242f728a4a05df2455e1c6e62173ab720a92cd4a074Chris Lattner    return RT->getDecl()->isUnion();
243c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  return false;
244c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner}
245c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner
246c6fb90a7246c2d5d3233e70107bf9d8c7c9e535bChris Lattnerbool Type::isComplexType() const {
24702f62a9fedbc370fba081303399410a3afdde29fSteve Naroff  if (const ComplexType *CT = dyn_cast<ComplexType>(CanonicalType))
24802f62a9fedbc370fba081303399410a3afdde29fSteve Naroff    return CT->getElementType()->isFloatingType();
24902f62a9fedbc370fba081303399410a3afdde29fSteve Naroff  return false;
250c6fb90a7246c2d5d3233e70107bf9d8c7c9e535bChris Lattner}
251c6fb90a7246c2d5d3233e70107bf9d8c7c9e535bChris Lattner
2524cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroffbool Type::isComplexIntegerType() const {
2534cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroff  // Check for GCC complex integer extension.
2540953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  return getAsComplexIntegerType();
2554cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroff}
2564cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroff
2574cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroffconst ComplexType *Type::getAsComplexIntegerType() const {
2580953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  if (const ComplexType *Complex = getAs<ComplexType>())
2590953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    if (Complex->getElementType()->isIntegerType())
2600953e767ff7817f97b3ab20896b229891eeff45bJohn McCall      return Complex;
2610953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  return 0;
2624cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroff}
2634cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroff
26414108da7f7fc059772711e4ffee1322a27b152a7Steve NaroffQualType Type::getPointeeType() const {
2656217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek  if (const PointerType *PT = getAs<PointerType>())
26614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff    return PT->getPointeeType();
267183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>())
26814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff    return OPT->getPointeeType();
2696217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek  if (const BlockPointerType *BPT = getAs<BlockPointerType>())
27014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff    return BPT->getPointeeType();
2719c21289a866b677d21ed3d5ecfdfd5ced5a55410Mike Stump  if (const ReferenceType *RT = getAs<ReferenceType>())
2729c21289a866b677d21ed3d5ecfdfd5ced5a55410Mike Stump    return RT->getPointeeType();
27314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  return QualType();
27414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff}
275b77792eabf5882cf9af8cc810599b20432fda6c2Chris Lattner
276d3f2f79fedfef7cae818c55a1f3d7a8f5992e5a0Eli Friedman/// isVariablyModifiedType (C99 6.7.5p3) - Return true for variable length
277d3f2f79fedfef7cae818c55a1f3d7a8f5992e5a0Eli Friedman/// array types and types that contain variable array types in their
278d3f2f79fedfef7cae818c55a1f3d7a8f5992e5a0Eli Friedman/// declarator
279d7444aac1af1c2c1d5e5b7467ecf6006ee2d8abeSteve Naroffbool Type::isVariablyModifiedType() const {
280a481ec4150ad203440852a2bfee0883dd26f7530Douglas Gregor  // FIXME: We should really keep a "variably modified" bit in Type, rather
281a481ec4150ad203440852a2bfee0883dd26f7530Douglas Gregor  // than walking the type hierarchy to recompute it.
282a481ec4150ad203440852a2bfee0883dd26f7530Douglas Gregor
283c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  // A VLA is a variably modified type.
284c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  if (isVariableArrayType())
285d3f2f79fedfef7cae818c55a1f3d7a8f5992e5a0Eli Friedman    return true;
286d3f2f79fedfef7cae818c55a1f3d7a8f5992e5a0Eli Friedman
287d3f2f79fedfef7cae818c55a1f3d7a8f5992e5a0Eli Friedman  // An array can contain a variably modified type
288c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  if (const Type *T = getArrayElementTypeNoTypeQual())
289c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner    return T->isVariablyModifiedType();
290d3f2f79fedfef7cae818c55a1f3d7a8f5992e5a0Eli Friedman
291f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  // A pointer can point to a variably modified type.
292f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  // Also, C++ references and member pointers can point to a variably modified
293f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  // type, where VLAs appear as an extension to C++, and should be treated
294f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  // correctly.
2956217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek  if (const PointerType *PT = getAs<PointerType>())
296d3f2f79fedfef7cae818c55a1f3d7a8f5992e5a0Eli Friedman    return PT->getPointeeType()->isVariablyModifiedType();
2976217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek  if (const ReferenceType *RT = getAs<ReferenceType>())
29868694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar    return RT->getPointeeType()->isVariablyModifiedType();
2996217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek  if (const MemberPointerType *PT = getAs<MemberPointerType>())
3008edef7c31d27fc9d5d163660702a8a7730a0d19fSebastian Redl    return PT->getPointeeType()->isVariablyModifiedType();
301d3f2f79fedfef7cae818c55a1f3d7a8f5992e5a0Eli Friedman
302d3f2f79fedfef7cae818c55a1f3d7a8f5992e5a0Eli Friedman  // A function can return a variably modified type
303d3f2f79fedfef7cae818c55a1f3d7a8f5992e5a0Eli Friedman  // This one isn't completely obvious, but it follows from the
304d3f2f79fedfef7cae818c55a1f3d7a8f5992e5a0Eli Friedman  // definition in C99 6.7.5p3. Because of this rule, it's
305d3f2f79fedfef7cae818c55a1f3d7a8f5992e5a0Eli Friedman  // illegal to declare a function returning a variably modified type.
306183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  if (const FunctionType *FT = getAs<FunctionType>())
307d3f2f79fedfef7cae818c55a1f3d7a8f5992e5a0Eli Friedman    return FT->getResultType()->isVariablyModifiedType();
308d3f2f79fedfef7cae818c55a1f3d7a8f5992e5a0Eli Friedman
309d7444aac1af1c2c1d5e5b7467ecf6006ee2d8abeSteve Naroff  return false;
310d7444aac1af1c2c1d5e5b7467ecf6006ee2d8abeSteve Naroff}
311d7444aac1af1c2c1d5e5b7467ecf6006ee2d8abeSteve Naroff
312c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattnerconst RecordType *Type::getAsStructureType() const {
3137064f5c95bbdb17680d0ea658d4090898c2592d3Steve Naroff  // If this is directly a structure type, return it.
314c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  if (const RecordType *RT = dyn_cast<RecordType>(this)) {
31539ba4aeca296b1c9f04bde7d9d3cbbf129f1abd3Argyrios Kyrtzidis    if (RT->getDecl()->isStruct())
316c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner      return RT;
3177064f5c95bbdb17680d0ea658d4090898c2592d3Steve Naroff  }
318dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner
319dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner  // If the canonical form of this type isn't the right kind, reject it.
320c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  if (const RecordType *RT = dyn_cast<RecordType>(CanonicalType)) {
32139ba4aeca296b1c9f04bde7d9d3cbbf129f1abd3Argyrios Kyrtzidis    if (!RT->getDecl()->isStruct())
322dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner      return 0;
3231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
324dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner    // If this is a typedef for a structure type, strip the typedef off without
325dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner    // losing all typedef information.
326bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall    return cast<RecordType>(getUnqualifiedDesugaredType());
3275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
3287064f5c95bbdb17680d0ea658d4090898c2592d3Steve Naroff  return 0;
3295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
3305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpconst RecordType *Type::getAsUnionType() const {
3327064f5c95bbdb17680d0ea658d4090898c2592d3Steve Naroff  // If this is directly a union type, return it.
333c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  if (const RecordType *RT = dyn_cast<RecordType>(this)) {
33439ba4aeca296b1c9f04bde7d9d3cbbf129f1abd3Argyrios Kyrtzidis    if (RT->getDecl()->isUnion())
335c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner      return RT;
3367064f5c95bbdb17680d0ea658d4090898c2592d3Steve Naroff  }
3371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
338dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner  // If the canonical form of this type isn't the right kind, reject it.
339c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  if (const RecordType *RT = dyn_cast<RecordType>(CanonicalType)) {
34039ba4aeca296b1c9f04bde7d9d3cbbf129f1abd3Argyrios Kyrtzidis    if (!RT->getDecl()->isUnion())
341dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner      return 0;
342dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner
343dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner    // If this is a typedef for a union type, strip the typedef off without
344dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner    // losing all typedef information.
345bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall    return cast<RecordType>(getUnqualifiedDesugaredType());
3465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
3471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3487064f5c95bbdb17680d0ea658d4090898c2592d3Steve Naroff  return 0;
3495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
3505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
351c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallvoid ObjCInterfaceType::Destroy(ASTContext& C) {
352c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  this->~ObjCInterfaceType();
353c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  C.Deallocate(this);
354c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall}
355c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
356c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallObjCObjectType::ObjCObjectType(QualType Canonical, QualType Base,
357c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall                               ObjCProtocolDecl * const *Protocols,
358c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall                               unsigned NumProtocols)
359c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  : Type(ObjCObject, Canonical, false),
360c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    NumProtocols(NumProtocols),
361c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    BaseType(Base) {
362c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  assert(this->NumProtocols == NumProtocols &&
363c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall         "bitfield overflow in protocol count");
364fd6a0887a099256c35a5b23e9afd517ffe95fa0aDouglas Gregor  if (NumProtocols)
365c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    memcpy(getProtocolStorage(), Protocols,
366c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall           NumProtocols * sizeof(ObjCProtocolDecl*));
36771842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek}
36871842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek
369c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallvoid ObjCObjectTypeImpl::Destroy(ASTContext& C) {
370c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  this->~ObjCObjectTypeImpl();
37171842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek  C.Deallocate(this);
37271842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek}
37371842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek
374c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallconst ObjCObjectType *Type::getAsObjCQualifiedInterfaceType() const {
375c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  // There is no sugar for ObjCObjectType's, just return the canonical
376c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff  // type pointer if it is the right class.  There is no typedef information to
377c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff  // return and these cannot be Address-space qualified.
378c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  if (const ObjCObjectType *T = getAs<ObjCObjectType>())
379c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    if (T->getNumProtocols() && T->getInterface())
380c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall      return T;
381c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff  return 0;
382c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff}
383c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff
384c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroffbool Type::isObjCQualifiedInterfaceType() const {
385e61ad0b7063fcd97204b1cce5558685144267eb6Steve Naroff  return getAsObjCQualifiedInterfaceType() != 0;
386c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff}
387c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff
38871842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenekvoid ObjCObjectPointerType::Destroy(ASTContext& C) {
38971842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek  this->~ObjCObjectPointerType();
39071842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek  C.Deallocate(this);
39171842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek}
39271842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek
393d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroffconst ObjCObjectPointerType *Type::getAsObjCQualifiedIdType() const {
394eca7be6b7ebd93682eeaab2c71d59f2995dacdccChris Lattner  // There is no sugar for ObjCQualifiedIdType's, just return the canonical
395eca7be6b7ebd93682eeaab2c71d59f2995dacdccChris Lattner  // type pointer if it is the right class.
396183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) {
397d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff    if (OPT->isObjCQualifiedIdType())
398d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff      return OPT;
399d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff  }
400d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff  return 0;
401368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner}
402368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner
40314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroffconst ObjCObjectPointerType *Type::getAsObjCInterfacePointerType() const {
404183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) {
40514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff    if (OPT->getInterfaceType())
40614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff      return OPT;
40714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  }
40814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  return 0;
40914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff}
41014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff
411a91d6a6619a91d0ca7102d8ab5678d855f04d850Fariborz Jahanianconst CXXRecordDecl *Type::getCXXRecordDeclForPointerType() const {
4126217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek  if (const PointerType *PT = getAs<PointerType>())
4136217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek    if (const RecordType *RT = PT->getPointeeType()->getAs<RecordType>())
414a91d6a6619a91d0ca7102d8ab5678d855f04d850Fariborz Jahanian      return dyn_cast<CXXRecordDecl>(RT->getDecl());
415a91d6a6619a91d0ca7102d8ab5678d855f04d850Fariborz Jahanian  return 0;
416a91d6a6619a91d0ca7102d8ab5678d855f04d850Fariborz Jahanian}
417a91d6a6619a91d0ca7102d8ab5678d855f04d850Fariborz Jahanian
418c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas GregorCXXRecordDecl *Type::getAsCXXRecordDecl() const {
419c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor  if (const RecordType *RT = getAs<RecordType>())
420c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor    return dyn_cast<CXXRecordDecl>(RT->getDecl());
421c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor  else if (const InjectedClassNameType *Injected
422c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor                                  = getAs<InjectedClassNameType>())
423c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor    return Injected->getDecl();
424c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor
425c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor  return 0;
426c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor}
427c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor
4285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isIntegerType() const {
4295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
4305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return BT->getKind() >= BuiltinType::Bool &&
4312df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner           BT->getKind() <= BuiltinType::Int128;
4325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  if (const TagType *TT = dyn_cast<TagType>(CanonicalType))
433834a72ac74cf4ff07ba6215545dba3db578f8a07Chris Lattner    // Incomplete enum types are not treated as integer types.
4348e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor    // FIXME: In C++, enum types are never integer types.
435834a72ac74cf4ff07ba6215545dba3db578f8a07Chris Lattner    if (TT->getDecl()->isEnum() && TT->getDecl()->isDefinition())
4365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      return true;
437c63b96ad706e054a1390dd2ab53af9f05d33bbb1Steve Naroff  if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType))
438c63b96ad706e054a1390dd2ab53af9f05d33bbb1Steve Naroff    return VT->getElementType()->isIntegerType();
4395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  return false;
4405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
4415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4429d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// \brief Determine whether this type is an integral type.
4439d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor///
4449d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// This routine determines whether the given type is an integral type per
4459d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// C++ [basic.fundamental]p7. Although the C standard does not define the
4469d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// term "integral type", it has a similar term "integer type", and in C++
4479d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// the two terms are equivalent. However, C's "integer type" includes
4489d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// enumeration types, while C++'s "integer type" does not. The \c ASTContext
4499d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// parameter is used to determine whether we should be following the C or
4509d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// C++ rules when determining whether this type is an integral/integer type.
4519d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor///
4529d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// For cases where C permits "an integer type" and C++ permits "an integral
4539d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// type", use this routine.
4549d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor///
4559d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// For cases where C permits "an integer type" and C++ permits "an integral
4569d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// or enumeration type", use \c isIntegralOrEnumerationType() instead.
4579d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor///
4589d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// \param Ctx The context in which this type occurs.
4599d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor///
4609d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor/// \returns true if the type is considered an integral type, false otherwise.
4619d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregorbool Type::isIntegralType(ASTContext &Ctx) const {
46233e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian  if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
46333e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian    return BT->getKind() >= BuiltinType::Bool &&
464f5f7d864f5067d1ea4bff7fcf41b53a43b7b48baAnders Carlsson    BT->getKind() <= BuiltinType::Int128;
4659d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor
4669d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor  if (!Ctx.getLangOptions().CPlusPlus)
4679d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor    if (const TagType *TT = dyn_cast<TagType>(CanonicalType))
4689d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor      if (TT->getDecl()->isEnum() && TT->getDecl()->isDefinition())
4699d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor        return true;  // Complete enum types are integral in C.
4709d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor
47133e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian  return false;
47233e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian}
47333e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian
4742ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregorbool Type::isIntegralOrEnumerationType() const {
4752ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor  if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
4762ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor    return BT->getKind() >= BuiltinType::Bool &&
4772ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor           BT->getKind() <= BuiltinType::Int128;
4782ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor
4792ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor  if (isa<EnumType>(CanonicalType))
4802ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor    return true;
4812ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor
4822ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor  return false;
4832ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor}
4842ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor
48513b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroffbool Type::isEnumeralType() const {
48613b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff  if (const TagType *TT = dyn_cast<TagType>(CanonicalType))
48739ba4aeca296b1c9f04bde7d9d3cbbf129f1abd3Argyrios Kyrtzidis    return TT->getDecl()->isEnum();
48813b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff  return false;
48913b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff}
49013b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff
49113b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroffbool Type::isBooleanType() const {
49213b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff  if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
49313b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff    return BT->getKind() == BuiltinType::Bool;
49413b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff  return false;
49513b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff}
49613b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff
49713b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroffbool Type::isCharType() const {
49813b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff  if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
49913b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff    return BT->getKind() == BuiltinType::Char_U ||
50013b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff           BT->getKind() == BuiltinType::UChar ||
501c67ad5f299bb2c09e4567def8ff0d34bd15a42fdAnders Carlsson           BT->getKind() == BuiltinType::Char_S ||
502c67ad5f299bb2c09e4567def8ff0d34bd15a42fdAnders Carlsson           BT->getKind() == BuiltinType::SChar;
50313b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff  return false;
50413b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff}
50513b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff
50677a52233f7c0f162672652051bfe78b65ad4f789Douglas Gregorbool Type::isWideCharType() const {
50777a52233f7c0f162672652051bfe78b65ad4f789Douglas Gregor  if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
50877a52233f7c0f162672652051bfe78b65ad4f789Douglas Gregor    return BT->getKind() == BuiltinType::WChar;
50977a52233f7c0f162672652051bfe78b65ad4f789Douglas Gregor  return false;
51077a52233f7c0f162672652051bfe78b65ad4f789Douglas Gregor}
51177a52233f7c0f162672652051bfe78b65ad4f789Douglas Gregor
51220093b4bf698f292c664676987541d5103b65b15Douglas Gregor/// \brief Determine whether this type is any of the built-in character
51320093b4bf698f292c664676987541d5103b65b15Douglas Gregor/// types.
51420093b4bf698f292c664676987541d5103b65b15Douglas Gregorbool Type::isAnyCharacterType() const {
51520093b4bf698f292c664676987541d5103b65b15Douglas Gregor  if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
51620093b4bf698f292c664676987541d5103b65b15Douglas Gregor    return (BT->getKind() >= BuiltinType::Char_U &&
51720093b4bf698f292c664676987541d5103b65b15Douglas Gregor            BT->getKind() <= BuiltinType::Char32) ||
51820093b4bf698f292c664676987541d5103b65b15Douglas Gregor           (BT->getKind() >= BuiltinType::Char_S &&
51920093b4bf698f292c664676987541d5103b65b15Douglas Gregor            BT->getKind() <= BuiltinType::WChar);
52020093b4bf698f292c664676987541d5103b65b15Douglas Gregor
52120093b4bf698f292c664676987541d5103b65b15Douglas Gregor  return false;
52220093b4bf698f292c664676987541d5103b65b15Douglas Gregor}
52320093b4bf698f292c664676987541d5103b65b15Douglas Gregor
524d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner/// isSignedIntegerType - Return true if this is an integer type that is
525d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner/// signed, according to C99 6.2.5p4 [char, signed char, short, int, long..],
526d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner/// an enum decl which has a signed representation, or a vector of signed
527d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner/// integer element type.
5285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isSignedIntegerType() const {
5295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) {
5305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return BT->getKind() >= BuiltinType::Char_S &&
531f5f7d864f5067d1ea4bff7fcf41b53a43b7b48baAnders Carlsson           BT->getKind() <= BuiltinType::Int128;
5325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
5331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
53437c1b78a20a09b0456aa5caa15e159027010ca22Chris Lattner  if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType))
53537c1b78a20a09b0456aa5caa15e159027010ca22Chris Lattner    return ET->getDecl()->getIntegerType()->isSignedIntegerType();
5361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
537c63b96ad706e054a1390dd2ab53af9f05d33bbb1Steve Naroff  if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType))
538c63b96ad706e054a1390dd2ab53af9f05d33bbb1Steve Naroff    return VT->getElementType()->isSignedIntegerType();
5395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  return false;
5405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
5415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
542d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner/// isUnsignedIntegerType - Return true if this is an integer type that is
543d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner/// unsigned, according to C99 6.2.5p6 [which returns true for _Bool], an enum
544d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner/// decl which has an unsigned representation, or a vector of unsigned integer
545d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner/// element type.
5465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isUnsignedIntegerType() const {
5475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) {
5485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return BT->getKind() >= BuiltinType::Bool &&
5491c03ca30ae962199ef702324b48550f6af7fdc32Anders Carlsson           BT->getKind() <= BuiltinType::UInt128;
5505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
551d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner
55237c1b78a20a09b0456aa5caa15e159027010ca22Chris Lattner  if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType))
55337c1b78a20a09b0456aa5caa15e159027010ca22Chris Lattner    return ET->getDecl()->getIntegerType()->isUnsignedIntegerType();
554d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner
555c63b96ad706e054a1390dd2ab53af9f05d33bbb1Steve Naroff  if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType))
556c63b96ad706e054a1390dd2ab53af9f05d33bbb1Steve Naroff    return VT->getElementType()->isUnsignedIntegerType();
5575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  return false;
5585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
5595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
5605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isFloatingType() const {
5615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
5625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return BT->getKind() >= BuiltinType::Float &&
5635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer           BT->getKind() <= BuiltinType::LongDouble;
5645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  if (const ComplexType *CT = dyn_cast<ComplexType>(CanonicalType))
565729a2131228cb7fcbc00bd8af36bc6f14d12317dChris Lattner    return CT->getElementType()->isFloatingType();
5668eee119bf4f1693dde17b8552c1f9f81bf2b681eDouglas Gregor  return false;
5678eee119bf4f1693dde17b8552c1f9f81bf2b681eDouglas Gregor}
5688eee119bf4f1693dde17b8552c1f9f81bf2b681eDouglas Gregor
5698eee119bf4f1693dde17b8552c1f9f81bf2b681eDouglas Gregorbool Type::hasFloatingRepresentation() const {
570c63b96ad706e054a1390dd2ab53af9f05d33bbb1Steve Naroff  if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType))
571c63b96ad706e054a1390dd2ab53af9f05d33bbb1Steve Naroff    return VT->getElementType()->isFloatingType();
5728eee119bf4f1693dde17b8552c1f9f81bf2b681eDouglas Gregor  else
5738eee119bf4f1693dde17b8552c1f9f81bf2b681eDouglas Gregor    return isFloatingType();
5745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
5755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
5765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isRealFloatingType() const {
5775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
578680523a91dd3351389667c8de17121ba7ae82673John McCall    return BT->isFloatingPoint();
5795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  return false;
5805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
5815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
5825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isRealType() const {
5835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
5845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return BT->getKind() >= BuiltinType::Bool &&
5855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer           BT->getKind() <= BuiltinType::LongDouble;
5865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  if (const TagType *TT = dyn_cast<TagType>(CanonicalType))
587834a72ac74cf4ff07ba6215545dba3db578f8a07Chris Lattner    return TT->getDecl()->isEnum() && TT->getDecl()->isDefinition();
5885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  return false;
5895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
5905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
5915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isArithmeticType() const {
5925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
593a7fbf7282eadebaf1293d9f970b01fb57f4b0ae4Douglas Gregor    return BT->getKind() >= BuiltinType::Bool &&
594a7fbf7282eadebaf1293d9f970b01fb57f4b0ae4Douglas Gregor           BT->getKind() <= BuiltinType::LongDouble;
59537c1b78a20a09b0456aa5caa15e159027010ca22Chris Lattner  if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType))
59637c1b78a20a09b0456aa5caa15e159027010ca22Chris Lattner    // GCC allows forward declaration of enum types (forbid by C99 6.7.2.3p2).
59737c1b78a20a09b0456aa5caa15e159027010ca22Chris Lattner    // If a body isn't seen by the time we get here, return false.
59837c1b78a20a09b0456aa5caa15e159027010ca22Chris Lattner    return ET->getDecl()->isDefinition();
59900619623af0b9d3271e31402ec1a95e84c2c4526Douglas Gregor  return isa<ComplexType>(CanonicalType);
6005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
6015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
6025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isScalarType() const {
6035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
6045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return BT->getKind() != BuiltinType::Void;
6055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  if (const TagType *TT = dyn_cast<TagType>(CanonicalType)) {
606834a72ac74cf4ff07ba6215545dba3db578f8a07Chris Lattner    // Enums are scalar types, but only if they are defined.  Incomplete enums
607834a72ac74cf4ff07ba6215545dba3db578f8a07Chris Lattner    // are not treated as scalar types.
608834a72ac74cf4ff07ba6215545dba3db578f8a07Chris Lattner    if (TT->getDecl()->isEnum() && TT->getDecl()->isDefinition())
6095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      return true;
6105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return false;
6115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
6125618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  return isa<PointerType>(CanonicalType) ||
6135618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff         isa<BlockPointerType>(CanonicalType) ||
614f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl         isa<MemberPointerType>(CanonicalType) ||
6155618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff         isa<ComplexType>(CanonicalType) ||
616d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff         isa<ObjCObjectPointerType>(CanonicalType);
6175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
6185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
619d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor/// \brief Determines whether the type is a C++ aggregate type or C
620d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor/// aggregate or union type.
621d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor///
622d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor/// An aggregate type is an array or a class type (struct, union, or
623d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor/// class) that has no user-declared constructors, no private or
624d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor/// protected non-static data members, no base classes, and no virtual
625d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor/// functions (C++ [dcl.init.aggr]p1). The notion of an aggregate type
626d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor/// subsumes the notion of C aggregates (C99 6.2.5p21) because it also
627d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor/// includes union types.
6285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isAggregateType() const {
629c1efaecf0373f1a55c5ef4c234357cf726fc0600Douglas Gregor  if (const RecordType *Record = dyn_cast<RecordType>(CanonicalType)) {
630c1efaecf0373f1a55c5ef4c234357cf726fc0600Douglas Gregor    if (CXXRecordDecl *ClassDecl = dyn_cast<CXXRecordDecl>(Record->getDecl()))
631c1efaecf0373f1a55c5ef4c234357cf726fc0600Douglas Gregor      return ClassDecl->isAggregate();
632c1efaecf0373f1a55c5ef4c234357cf726fc0600Douglas Gregor
633d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor    return true;
634c1efaecf0373f1a55c5ef4c234357cf726fc0600Douglas Gregor  }
635c1efaecf0373f1a55c5ef4c234357cf726fc0600Douglas Gregor
636c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman  return isa<ArrayType>(CanonicalType);
6375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
6385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
6399bfa73c5ab7bf4b0e749d04f29da6884e8d5bd9fChris Lattner/// isConstantSizeType - Return true if this is not a variable sized type,
6409bfa73c5ab7bf4b0e749d04f29da6884e8d5bd9fChris Lattner/// according to the rules of C99 6.7.5p3.  It is not legal to call this on
641898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// incomplete types or dependent types.
6423c2b3170041f69a92904e3bab9b6d654eaf260acEli Friedmanbool Type::isConstantSizeType() const {
643d52a4578144ab2887912e52eabec58a857a44adbChris Lattner  assert(!isIncompleteType() && "This doesn't make sense for incomplete types");
644898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  assert(!isDependentType() && "This doesn't make sense for dependent types");
6459bfa73c5ab7bf4b0e749d04f29da6884e8d5bd9fChris Lattner  // The VAT must have a size, as it is known to be complete.
6469bfa73c5ab7bf4b0e749d04f29da6884e8d5bd9fChris Lattner  return !isa<VariableArrayType>(CanonicalType);
6475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
6485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
6495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// isIncompleteType - Return true if this is an incomplete type (C99 6.2.5p1)
6505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// - a type that can describe objects, but which lacks information needed to
6515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// determine its size.
6521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpbool Type::isIncompleteType() const {
6531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  switch (CanonicalType->getTypeClass()) {
6545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  default: return false;
6555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case Builtin:
6565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    // Void is the only incomplete builtin type.  Per C99 6.2.5p19, it can never
6575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    // be completed.
6585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return isVoidType();
65972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  case Record:
66072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  case Enum:
6615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    // A tagged type (struct/union/enum/class) is incomplete if the decl is a
6625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    // forward declaration, but not a full definition (C99 6.2.5p22).
6635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return !cast<TagType>(CanonicalType)->getDecl()->isDefinition();
664923d56d436f750bc1f29db50e641078725558a1bSebastian Redl  case ConstantArray:
665923d56d436f750bc1f29db50e641078725558a1bSebastian Redl    // An array is incomplete if its element type is incomplete
666923d56d436f750bc1f29db50e641078725558a1bSebastian Redl    // (C++ [dcl.array]p1).
667923d56d436f750bc1f29db50e641078725558a1bSebastian Redl    // We don't handle variable arrays (they're not allowed in C++) or
668923d56d436f750bc1f29db50e641078725558a1bSebastian Redl    // dependent-sized arrays (dependent types are never treated as incomplete).
669923d56d436f750bc1f29db50e641078725558a1bSebastian Redl    return cast<ArrayType>(CanonicalType)->getElementType()->isIncompleteType();
670c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman  case IncompleteArray:
6715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    // An array of unknown size is an incomplete type (C99 6.2.5p22).
672c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman    return true;
673c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  case ObjCObject:
674c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return cast<ObjCObjectType>(this)->getBaseType()->isIncompleteType();
6751efaa9594a81709a17658fd80ae7e783e1026407Chris Lattner  case ObjCInterface:
6761efaa9594a81709a17658fd80ae7e783e1026407Chris Lattner    // ObjC interfaces are incomplete if they are @class, not @interface.
6771efaa9594a81709a17658fd80ae7e783e1026407Chris Lattner    return cast<ObjCInterfaceType>(this)->getDecl()->isForwardDecl();
6785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
6795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
6805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
68164b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl/// isPODType - Return true if this is a plain-old-data type (C++ 3.9p10)
68264b45f7e0d3167f040841ac2920aead7f080730dSebastian Redlbool Type::isPODType() const {
68364b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  // The compiler shouldn't query this for incomplete types, but the user might.
68464b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  // We return false for that case.
68564b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  if (isIncompleteType())
68664b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl    return false;
68764b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
68864b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  switch (CanonicalType->getTypeClass()) {
68964b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl    // Everything not explicitly mentioned is not POD.
69064b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  default: return false;
69164b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  case VariableArray:
69264b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  case ConstantArray:
69364b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl    // IncompleteArray is caught by isIncompleteType() above.
69464b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl    return cast<ArrayType>(CanonicalType)->getElementType()->isPODType();
69564b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
69664b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  case Builtin:
69764b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  case Complex:
69864b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  case Pointer:
699f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  case MemberPointer:
70064b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  case Vector:
70164b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  case ExtVector:
702d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff  case ObjCObjectPointer:
7032263f822c31d0855ca8c48bfd9624322bf776f0bFariborz Jahanian  case BlockPointer:
70464b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl    return true;
70564b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
70672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  case Enum:
70772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor    return true;
70872564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor
70972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  case Record:
7101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    if (CXXRecordDecl *ClassDecl
711c1efaecf0373f1a55c5ef4c234357cf726fc0600Douglas Gregor          = dyn_cast<CXXRecordDecl>(cast<RecordType>(CanonicalType)->getDecl()))
712c1efaecf0373f1a55c5ef4c234357cf726fc0600Douglas Gregor      return ClassDecl->isPOD();
713c1efaecf0373f1a55c5ef4c234357cf726fc0600Douglas Gregor
71464b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl    // C struct/union is POD.
71564b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl    return true;
71664b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  }
71764b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl}
71864b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
719ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redlbool Type::isLiteralType() const {
720ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl  if (isIncompleteType())
721ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl    return false;
722ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl
723ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl  // C++0x [basic.types]p10:
724ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl  //   A type is a literal type if it is:
725ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl  switch (CanonicalType->getTypeClass()) {
726ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl    // We're whitelisting
727ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl  default: return false;
728ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl
729ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl    //   -- a scalar type
730ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl  case Builtin:
731ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl  case Complex:
732ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl  case Pointer:
733ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl  case MemberPointer:
734ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl  case Vector:
735ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl  case ExtVector:
736ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl  case ObjCObjectPointer:
737ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl  case Enum:
738ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl    return true;
739ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl
740ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl    //   -- a class type with ...
741ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl  case Record:
742ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl    // FIXME: Do the tests
743ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl    return false;
744ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl
745ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl    //   -- an array of literal type
746ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl    // Extension: variable arrays cannot be literal types, since they're
747ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl    // runtime-sized.
748ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl  case ConstantArray:
749ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl    return cast<ArrayType>(CanonicalType)->getElementType()->isLiteralType();
750ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl  }
751ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl}
752ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl
7535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Type::isPromotableIntegerType() const {
754183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  if (const BuiltinType *BT = getAs<BuiltinType>())
7552a18dfe292cf3c406a769c3672080970ac586345Chris Lattner    switch (BT->getKind()) {
7562a18dfe292cf3c406a769c3672080970ac586345Chris Lattner    case BuiltinType::Bool:
7572a18dfe292cf3c406a769c3672080970ac586345Chris Lattner    case BuiltinType::Char_S:
7582a18dfe292cf3c406a769c3672080970ac586345Chris Lattner    case BuiltinType::Char_U:
7592a18dfe292cf3c406a769c3672080970ac586345Chris Lattner    case BuiltinType::SChar:
7602a18dfe292cf3c406a769c3672080970ac586345Chris Lattner    case BuiltinType::UChar:
7612a18dfe292cf3c406a769c3672080970ac586345Chris Lattner    case BuiltinType::Short:
7622a18dfe292cf3c406a769c3672080970ac586345Chris Lattner    case BuiltinType::UShort:
7632a18dfe292cf3c406a769c3672080970ac586345Chris Lattner      return true;
7641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    default:
7652a18dfe292cf3c406a769c3672080970ac586345Chris Lattner      return false;
7662a18dfe292cf3c406a769c3672080970ac586345Chris Lattner    }
767aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor
768aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor  // Enumerated types are promotable to their compatible integer types
769aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor  // (C99 6.3.1.1) a.k.a. its underlying type (C++ [conv.prom]p2).
770aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor  if (const EnumType *ET = getAs<EnumType>()){
771aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor    if (this->isDependentType() || ET->getDecl()->getPromotionType().isNull())
772aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor      return false;
773aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor
774aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor    const BuiltinType *BT
775aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor      = ET->getDecl()->getPromotionType()->getAs<BuiltinType>();
776aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor    return BT->getKind() == BuiltinType::Int
777aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor           || BT->getKind() == BuiltinType::UInt;
778aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor  }
779aa74a1e49f7c4b89539830290f76fe2c3e97187fDouglas Gregor
7802a18dfe292cf3c406a769c3672080970ac586345Chris Lattner  return false;
7815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
7825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7836e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redlbool Type::isNullPtrType() const {
784183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  if (const BuiltinType *BT = getAs<BuiltinType>())
7856e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl    return BT->getKind() == BuiltinType::NullPtr;
7866e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl  return false;
7876e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl}
7886e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl
78922b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedmanbool Type::isSpecifierType() const {
79022b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman  // Note that this intentionally does not use the canonical type.
79122b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman  switch (getTypeClass()) {
79222b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman  case Builtin:
79322b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman  case Record:
79422b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman  case Enum:
79522b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman  case Typedef:
796c8f2c61f4f667c2bc3e4e74b274fa397a4232393Eli Friedman  case Complex:
797c8f2c61f4f667c2bc3e4e74b274fa397a4232393Eli Friedman  case TypeOfExpr:
798c8f2c61f4f667c2bc3e4e74b274fa397a4232393Eli Friedman  case TypeOf:
799c8f2c61f4f667c2bc3e4e74b274fa397a4232393Eli Friedman  case TemplateTypeParm:
80049a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  case SubstTemplateTypeParm:
801c8f2c61f4f667c2bc3e4e74b274fa397a4232393Eli Friedman  case TemplateSpecialization:
802465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  case Elaborated:
8034714c12a1ab759156b78be8f109ea4c12213af57Douglas Gregor  case DependentName:
80433500955d731c73717af52088b7fc0e7a85681e7John McCall  case DependentTemplateSpecialization:
805c8f2c61f4f667c2bc3e4e74b274fa397a4232393Eli Friedman  case ObjCInterface:
806c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  case ObjCObject:
807c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  case ObjCObjectPointer: // FIXME: object pointers aren't really specifiers
80822b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman    return true;
80922b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman  default:
81022b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman    return false;
81122b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman  }
81222b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman}
81322b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman
814465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraTypeWithKeyword::~TypeWithKeyword() {
815465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara}
816465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
817465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraElaboratedTypeKeyword
818465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraTypeWithKeyword::getKeywordForTypeSpec(unsigned TypeSpec) {
819465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  switch (TypeSpec) {
820465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  default: return ETK_None;
821465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  case TST_typename: return ETK_Typename;
822465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  case TST_class: return ETK_Class;
823465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  case TST_struct: return ETK_Struct;
824465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  case TST_union: return ETK_Union;
825465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  case TST_enum: return ETK_Enum;
826465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  }
827465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara}
828465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
829465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraTagTypeKind
830465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraTypeWithKeyword::getTagTypeKindForTypeSpec(unsigned TypeSpec) {
831465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  switch(TypeSpec) {
832465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  case TST_class: return TTK_Class;
833465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  case TST_struct: return TTK_Struct;
834465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  case TST_union: return TTK_Union;
835465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  case TST_enum: return TTK_Enum;
836465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  default: llvm_unreachable("Type specifier is not a tag type kind.");
837465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  }
838465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara}
839465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
840465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraElaboratedTypeKeyword
841465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraTypeWithKeyword::getKeywordForTagTypeKind(TagTypeKind Kind) {
842465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  switch (Kind) {
843465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  case TTK_Class: return ETK_Class;
844465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  case TTK_Struct: return ETK_Struct;
845465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  case TTK_Union: return ETK_Union;
846465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  case TTK_Enum: return ETK_Enum;
847465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  }
848465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  llvm_unreachable("Unknown tag type kind.");
849465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara}
850465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
851465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraTagTypeKind
852465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraTypeWithKeyword::getTagTypeKindForKeyword(ElaboratedTypeKeyword Keyword) {
853465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  switch (Keyword) {
854465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  case ETK_Class: return TTK_Class;
855465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  case ETK_Struct: return TTK_Struct;
856465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  case ETK_Union: return TTK_Union;
857465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  case ETK_Enum: return TTK_Enum;
858465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  case ETK_None: // Fall through.
859465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  case ETK_Typename:
860465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    llvm_unreachable("Elaborated type keyword is not a tag type kind.");
861465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  }
862465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  llvm_unreachable("Unknown elaborated type keyword.");
863465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara}
864465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
865465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnarabool
866465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraTypeWithKeyword::KeywordIsTagTypeKind(ElaboratedTypeKeyword Keyword) {
867465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  switch (Keyword) {
868465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  case ETK_None:
869465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  case ETK_Typename:
870465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    return false;
871465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  case ETK_Class:
872465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  case ETK_Struct:
873465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  case ETK_Union:
874465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  case ETK_Enum:
8754033642464e8ba0982f88f34cffad808d247b393Douglas Gregor    return true;
8764033642464e8ba0982f88f34cffad808d247b393Douglas Gregor  }
877465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  llvm_unreachable("Unknown elaborated type keyword.");
878465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara}
879465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
880465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnaraconst char*
881465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraTypeWithKeyword::getKeywordName(ElaboratedTypeKeyword Keyword) {
882465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  switch (Keyword) {
883465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  default: llvm_unreachable("Unknown elaborated type keyword.");
884465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  case ETK_None: return "";
885465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  case ETK_Typename: return "typename";
886465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  case ETK_Class:  return "class";
887465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  case ETK_Struct: return "struct";
888465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  case ETK_Union:  return "union";
889465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  case ETK_Enum:   return "enum";
890465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  }
891465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara}
892465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
89333500955d731c73717af52088b7fc0e7a85681e7John McCallElaboratedType::~ElaboratedType() {}
89433500955d731c73717af52088b7fc0e7a85681e7John McCallDependentNameType::~DependentNameType() {}
89533500955d731c73717af52088b7fc0e7a85681e7John McCallDependentTemplateSpecializationType::~DependentTemplateSpecializationType() {}
89633500955d731c73717af52088b7fc0e7a85681e7John McCall
89733500955d731c73717af52088b7fc0e7a85681e7John McCallvoid DependentTemplateSpecializationType::Destroy(ASTContext &C) {
89833500955d731c73717af52088b7fc0e7a85681e7John McCall  for (unsigned Arg = 0; Arg < NumArgs; ++Arg) {
89933500955d731c73717af52088b7fc0e7a85681e7John McCall    // FIXME: Not all expressions get cloned, so we can't yet perform
90033500955d731c73717af52088b7fc0e7a85681e7John McCall    // this destruction.
90133500955d731c73717af52088b7fc0e7a85681e7John McCall    //    if (Expr *E = getArg(Arg).getAsExpr())
90233500955d731c73717af52088b7fc0e7a85681e7John McCall    //      E->Destroy(C);
90333500955d731c73717af52088b7fc0e7a85681e7John McCall  }
90433500955d731c73717af52088b7fc0e7a85681e7John McCall}
90533500955d731c73717af52088b7fc0e7a85681e7John McCall
90633500955d731c73717af52088b7fc0e7a85681e7John McCallDependentTemplateSpecializationType::DependentTemplateSpecializationType(
907ef99001908e799c388f1363b1e607dad5f5b57d3John McCall                         ElaboratedTypeKeyword Keyword,
90833500955d731c73717af52088b7fc0e7a85681e7John McCall                         NestedNameSpecifier *NNS, const IdentifierInfo *Name,
90933500955d731c73717af52088b7fc0e7a85681e7John McCall                         unsigned NumArgs, const TemplateArgument *Args,
91033500955d731c73717af52088b7fc0e7a85681e7John McCall                         QualType Canon)
91133500955d731c73717af52088b7fc0e7a85681e7John McCall  : TypeWithKeyword(Keyword, DependentTemplateSpecialization, Canon, true),
912ef99001908e799c388f1363b1e607dad5f5b57d3John McCall    NNS(NNS), Name(Name), NumArgs(NumArgs) {
91333500955d731c73717af52088b7fc0e7a85681e7John McCall  assert(NNS && NNS->isDependent() &&
91433500955d731c73717af52088b7fc0e7a85681e7John McCall         "DependentTemplateSpecializatonType requires dependent qualifier");
91533500955d731c73717af52088b7fc0e7a85681e7John McCall  for (unsigned I = 0; I != NumArgs; ++I)
91633500955d731c73717af52088b7fc0e7a85681e7John McCall    new (&getArgBuffer()[I]) TemplateArgument(Args[I]);
91733500955d731c73717af52088b7fc0e7a85681e7John McCall}
91833500955d731c73717af52088b7fc0e7a85681e7John McCall
91933500955d731c73717af52088b7fc0e7a85681e7John McCallvoid
92033500955d731c73717af52088b7fc0e7a85681e7John McCallDependentTemplateSpecializationType::Profile(llvm::FoldingSetNodeID &ID,
92133500955d731c73717af52088b7fc0e7a85681e7John McCall                                             ASTContext &Context,
92233500955d731c73717af52088b7fc0e7a85681e7John McCall                                             ElaboratedTypeKeyword Keyword,
92333500955d731c73717af52088b7fc0e7a85681e7John McCall                                             NestedNameSpecifier *Qualifier,
92433500955d731c73717af52088b7fc0e7a85681e7John McCall                                             const IdentifierInfo *Name,
92533500955d731c73717af52088b7fc0e7a85681e7John McCall                                             unsigned NumArgs,
92633500955d731c73717af52088b7fc0e7a85681e7John McCall                                             const TemplateArgument *Args) {
92733500955d731c73717af52088b7fc0e7a85681e7John McCall  ID.AddInteger(Keyword);
92833500955d731c73717af52088b7fc0e7a85681e7John McCall  ID.AddPointer(Qualifier);
92933500955d731c73717af52088b7fc0e7a85681e7John McCall  ID.AddPointer(Name);
93033500955d731c73717af52088b7fc0e7a85681e7John McCall  for (unsigned Idx = 0; Idx < NumArgs; ++Idx)
93133500955d731c73717af52088b7fc0e7a85681e7John McCall    Args[Idx].Profile(ID, Context);
93233500955d731c73717af52088b7fc0e7a85681e7John McCall}
93333500955d731c73717af52088b7fc0e7a85681e7John McCall
934465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnarabool Type::isElaboratedTypeSpecifier() const {
935465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  ElaboratedTypeKeyword Keyword;
936465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  if (const ElaboratedType *Elab = dyn_cast<ElaboratedType>(this))
937465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    Keyword = Elab->getKeyword();
938465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  else if (const DependentNameType *DepName = dyn_cast<DependentNameType>(this))
939465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    Keyword = DepName->getKeyword();
94033500955d731c73717af52088b7fc0e7a85681e7John McCall  else if (const DependentTemplateSpecializationType *DepTST =
94133500955d731c73717af52088b7fc0e7a85681e7John McCall             dyn_cast<DependentTemplateSpecializationType>(this))
94233500955d731c73717af52088b7fc0e7a85681e7John McCall    Keyword = DepTST->getKeyword();
943465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  else
944465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    return false;
945465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
946465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  return TypeWithKeyword::KeywordIsTagTypeKind(Keyword);
9474033642464e8ba0982f88f34cffad808d247b393Douglas Gregor}
9484033642464e8ba0982f88f34cffad808d247b393Douglas Gregor
949cd01f17358dc8ef19338c0e2321138dd0a6160d9Argyrios Kyrtzidisconst char *Type::getTypeClassName() const {
950cd01f17358dc8ef19338c0e2321138dd0a6160d9Argyrios Kyrtzidis  switch (TC) {
951cd01f17358dc8ef19338c0e2321138dd0a6160d9Argyrios Kyrtzidis  default: assert(0 && "Type class not in TypeNodes.def!");
952cd01f17358dc8ef19338c0e2321138dd0a6160d9Argyrios Kyrtzidis#define ABSTRACT_TYPE(Derived, Base)
953cd01f17358dc8ef19338c0e2321138dd0a6160d9Argyrios Kyrtzidis#define TYPE(Derived, Base) case Derived: return #Derived;
954cd01f17358dc8ef19338c0e2321138dd0a6160d9Argyrios Kyrtzidis#include "clang/AST/TypeNodes.def"
955cd01f17358dc8ef19338c0e2321138dd0a6160d9Argyrios Kyrtzidis  }
956cd01f17358dc8ef19338c0e2321138dd0a6160d9Argyrios Kyrtzidis}
957cd01f17358dc8ef19338c0e2321138dd0a6160d9Argyrios Kyrtzidis
958e4f2142d00fa5fdb580c4e2413da91882d955381Chris Lattnerconst char *BuiltinType::getName(const LangOptions &LO) const {
9595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  switch (getKind()) {
9605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  default: assert(0 && "Unknown builtin type!");
9615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case Void:              return "void";
962e4f2142d00fa5fdb580c4e2413da91882d955381Chris Lattner  case Bool:              return LO.Bool ? "bool" : "_Bool";
9635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case Char_S:            return "char";
9645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case Char_U:            return "char";
9655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case SChar:             return "signed char";
9665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case Short:             return "short";
9675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case Int:               return "int";
9685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case Long:              return "long";
9695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case LongLong:          return "long long";
9702df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner  case Int128:            return "__int128_t";
9715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case UChar:             return "unsigned char";
9725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case UShort:            return "unsigned short";
9735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case UInt:              return "unsigned int";
9745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case ULong:             return "unsigned long";
9755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case ULongLong:         return "unsigned long long";
9762df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner  case UInt128:           return "__uint128_t";
9775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case Float:             return "float";
9785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case Double:            return "double";
9795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case LongDouble:        return "long double";
98046713efe13c89f4ec9cd9546c7b598fe7186089bArgyrios Kyrtzidis  case WChar:             return "wchar_t";
981f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith  case Char16:            return "char16_t";
982f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith  case Char32:            return "char32_t";
9836e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl  case NullPtr:           return "nullptr_t";
9848e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor  case Overload:          return "<overloaded function type>";
985898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  case Dependent:         return "<dependent type>";
9866a75cd9c1d54625fca7b5477ab9545bcdbd85ea4Anders Carlsson  case UndeducedAuto:     return "auto";
987de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff  case ObjCId:            return "id";
988de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff  case ObjCClass:         return "Class";
989bef0efd11bc4430a3ee437a3213cec5c18af855aChris Lattner  case ObjCSel:           return "SEL";
9905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
9915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
9925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
993bef0efd11bc4430a3ee437a3213cec5c18af855aChris Lattnervoid FunctionType::ANCHOR() {} // Key function for FunctionType.
994bef0efd11bc4430a3ee437a3213cec5c18af855aChris Lattner
9956398235d7890a81b785ea5af3b6e66d86bf184ccDouglas GregorQualType QualType::getNonLValueExprType(ASTContext &Context) const {
9965291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor  if (const ReferenceType *RefType = getTypePtr()->getAs<ReferenceType>())
9975291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor    return RefType->getPointeeType();
9985291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor
9995291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor  // C++0x [basic.lval]:
10005291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor  //   Class prvalues can have cv-qualified types; non-class prvalues always
10015291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor  //   have cv-unqualified types.
10025291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor  //
10035291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor  // See also C99 6.3.2.1p2.
10045291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor  if (!Context.getLangOptions().CPlusPlus ||
10056dc1ef87044e6b177d4df0d2b593a94616180b3dChandler Carruth      (!getTypePtr()->isDependentType() && !getTypePtr()->isRecordType()))
10065291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor    return getUnqualifiedType();
10075291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor
10085291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor  return *this;
10095291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor}
10105291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor
101104a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCallllvm::StringRef FunctionType::getNameForCallConv(CallingConv CC) {
101204a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall  switch (CC) {
101304a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall  case CC_Default: llvm_unreachable("no name for default cc");
101404a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall  default: return "";
101504a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall
101604a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall  case CC_C: return "cdecl";
101704a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall  case CC_X86StdCall: return "stdcall";
101804a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall  case CC_X86FastCall: return "fastcall";
1019f813a2c03fcb05381b3252010435f557eb6b3cdeDouglas Gregor  case CC_X86ThisCall: return "thiscall";
102004a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall  }
102104a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall}
102204a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall
102372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregorvoid FunctionProtoType::Profile(llvm::FoldingSetNodeID &ID, QualType Result,
1024942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner                                arg_type_iterator ArgTys,
1025971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis                                unsigned NumArgs, bool isVariadic,
1026465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl                                unsigned TypeQuals, bool hasExceptionSpec,
1027465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl                                bool anyExceptionSpec, unsigned NumExceptions,
1028264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola                                exception_iterator Exs,
1029264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola                                const FunctionType::ExtInfo &Info) {
10305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ID.AddPointer(Result.getAsOpaquePtr());
10315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  for (unsigned i = 0; i != NumArgs; ++i)
10325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ID.AddPointer(ArgTys[i].getAsOpaquePtr());
10335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ID.AddInteger(isVariadic);
1034971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis  ID.AddInteger(TypeQuals);
1035465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  ID.AddInteger(hasExceptionSpec);
1036465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  if (hasExceptionSpec) {
1037465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl    ID.AddInteger(anyExceptionSpec);
10381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    for (unsigned i = 0; i != NumExceptions; ++i)
1039465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl      ID.AddPointer(Exs[i].getAsOpaquePtr());
1040465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  }
1041264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola  ID.AddInteger(Info.getNoReturn());
1042425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola  ID.AddInteger(Info.getRegParm());
1043264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola  ID.AddInteger(Info.getCC());
10445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
10455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
104672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregorvoid FunctionProtoType::Profile(llvm::FoldingSetNodeID &ID) {
1047971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis  Profile(ID, getResultType(), arg_type_begin(), NumArgs, isVariadic(),
1048465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl          getTypeQuals(), hasExceptionSpec(), hasAnyExceptionSpec(),
1049264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola          getNumExceptions(), exception_begin(),
1050264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola          getExtInfo());
10515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
10525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1053a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner/// LookThroughTypedefs - Return the ultimate type this typedef corresponds to
1054a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner/// potentially looking through *all* consequtive typedefs.  This returns the
1055a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner/// sum of the type qualifiers, so if you have:
1056a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner///   typedef const int A;
1057a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner///   typedef volatile A B;
1058a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner/// looking through the typedefs for B will give you "const volatile A".
1059a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner///
1060a2c7767ce7d8feb10253f4b650826a20f3324c6fChris LattnerQualType TypedefType::LookThroughTypedefs() const {
1061a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner  // Usually, there is only a single level of typedefs, be fast in that case.
1062a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner  QualType FirstType = getDecl()->getUnderlyingType();
1063a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner  if (!isa<TypedefType>(FirstType))
1064a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner    return FirstType;
10651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1066a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner  // Otherwise, do the fully general loop.
10670953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  QualifierCollector Qs;
10681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
10690953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  QualType CurType;
10700953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  const TypedefType *TDT = this;
10710953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  do {
10720953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    CurType = TDT->getDecl()->getUnderlyingType();
10730953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    TDT = dyn_cast<TypedefType>(Qs.strip(CurType));
10740953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  } while (TDT);
10751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
10760953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  return Qs.apply(CurType);
1077a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner}
10785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1079bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCallQualType TypedefType::desugar() const {
1080bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  return getDecl()->getUnderlyingType();
1081bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall}
1082bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
108372564e73277e29f6db3305d1f27ba408abb7ed88Douglas GregorTypeOfExprType::TypeOfExprType(Expr *E, QualType can)
108472564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  : Type(TypeOfExpr, can, E->isTypeDependent()), TOExpr(E) {
1085898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor}
1086898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
1087bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCallQualType TypeOfExprType::desugar() const {
1088bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  return getUnderlyingExpr()->getType();
1089bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall}
1090bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
10911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpvoid DependentTypeOfExprType::Profile(llvm::FoldingSetNodeID &ID,
1092b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor                                      ASTContext &Context, Expr *E) {
1093b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor  E->Profile(ID, Context, true);
1094b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor}
1095b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor
1096563a03b1338d31c2462def43253a722bc885d384Anders CarlssonDecltypeType::DecltypeType(Expr *E, QualType underlyingType, QualType can)
10971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  : Type(Decltype, can, E->isTypeDependent()), E(E),
1098563a03b1338d31c2462def43253a722bc885d384Anders Carlsson  UnderlyingType(underlyingType) {
1099395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson}
1100395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson
11019d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas GregorDependentDecltypeType::DependentDecltypeType(ASTContext &Context, Expr *E)
11029d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor  : DecltypeType(E, Context.DependentTy), Context(Context) { }
11039d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor
11041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpvoid DependentDecltypeType::Profile(llvm::FoldingSetNodeID &ID,
11059d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor                                    ASTContext &Context, Expr *E) {
11069d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor  E->Profile(ID, Context, true);
11079d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor}
11089d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor
110919c8576b7328f4dc2d07682f5da552875c1912efJohn McCallTagType::TagType(TypeClass TC, const TagDecl *D, QualType can)
111019c8576b7328f4dc2d07682f5da552875c1912efJohn McCall  : Type(TC, can, D->isDependentType()),
111119c8576b7328f4dc2d07682f5da552875c1912efJohn McCall    decl(const_cast<TagDecl*>(D), 0) {}
11127da97d0f31e1ec16998d3de2cfd2e88fe3736673Douglas Gregor
11132daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattnerbool RecordType::classof(const TagType *TT) {
11142daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner  return isa<RecordDecl>(TT->getDecl());
11155edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner}
11165edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner
11172daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattnerbool EnumType::classof(const TagType *TT) {
11182daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner  return isa<EnumDecl>(TT->getDecl());
11195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
11205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1121833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallstatic bool isDependent(const TemplateArgument &Arg) {
1122833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  switch (Arg.getKind()) {
1123833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  case TemplateArgument::Null:
1124833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    assert(false && "Should not have a NULL template argument");
1125833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    return false;
1126833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
1127833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  case TemplateArgument::Type:
1128833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    return Arg.getAsType()->isDependentType();
1129833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
1130788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor  case TemplateArgument::Template:
1131788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor    return Arg.getAsTemplate().isDependent();
1132788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor
1133833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  case TemplateArgument::Declaration:
1134bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor    if (DeclContext *DC = dyn_cast<DeclContext>(Arg.getAsDecl()))
1135bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor      return DC->isDependentContext();
1136bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor    return Arg.getAsDecl()->getDeclContext()->isDependentContext();
1137bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor
1138833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  case TemplateArgument::Integral:
1139833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    // Never dependent
1140833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    return false;
1141833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
1142833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  case TemplateArgument::Expression:
1143833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    return (Arg.getAsExpr()->isTypeDependent() ||
1144833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall            Arg.getAsExpr()->isValueDependent());
1145833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
1146833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  case TemplateArgument::Pack:
1147bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor    for (TemplateArgument::pack_iterator P = Arg.pack_begin(),
1148bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor                                      PEnd = Arg.pack_end();
1149bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor         P != PEnd; ++P) {
1150bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor      if (isDependent(*P))
1151bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor        return true;
1152bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor    }
1153bb6e73fcf60fa5a4cc36c14744dc366b658443b5Douglas Gregor
1154833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    return false;
115555f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  }
115640808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor
115740808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  return false;
115855f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor}
115955f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
1160833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallbool TemplateSpecializationType::
1161d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCallanyDependentTemplateArguments(const TemplateArgumentListInfo &Args) {
1162d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  return anyDependentTemplateArguments(Args.getArgumentArray(), Args.size());
1163d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall}
1164d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall
1165d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCallbool TemplateSpecializationType::
1166833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallanyDependentTemplateArguments(const TemplateArgumentLoc *Args, unsigned N) {
1167833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  for (unsigned i = 0; i != N; ++i)
1168833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    if (isDependent(Args[i].getArgument()))
1169833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall      return true;
1170833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  return false;
1171833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall}
1172833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
1173833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallbool TemplateSpecializationType::
1174833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallanyDependentTemplateArguments(const TemplateArgument *Args, unsigned N) {
1175833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  for (unsigned i = 0; i != N; ++i)
1176833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    if (isDependent(Args[i]))
1177833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall      return true;
1178833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  return false;
1179833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall}
1180833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
11817532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas GregorTemplateSpecializationType::
1182ef99001908e799c388f1363b1e607dad5f5b57d3John McCallTemplateSpecializationType(TemplateName T,
1183828e226ab7ed08b3eb766549e9d3306432137460Douglas Gregor                           const TemplateArgument *Args,
11847532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor                           unsigned NumArgs, QualType Canon)
11851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  : Type(TemplateSpecialization,
118640808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor         Canon.isNull()? QualType(this, 0) : Canon,
11877532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor         T.isDependent() || anyDependentTemplateArguments(Args, NumArgs)),
11881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    Template(T), NumArgs(NumArgs) {
11891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  assert((!Canon.isNull() ||
11907532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor          T.isDependent() || anyDependentTemplateArguments(Args, NumArgs)) &&
119140808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor         "No canonical type for non-dependent class template specialization");
119255f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
11931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  TemplateArgument *TemplateArgs
119440808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor    = reinterpret_cast<TemplateArgument *>(this + 1);
119555f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  for (unsigned Arg = 0; Arg < NumArgs; ++Arg)
119640808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor    new (&TemplateArgs[Arg]) TemplateArgument(Args[Arg]);
119755f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor}
119855f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
11997532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregorvoid TemplateSpecializationType::Destroy(ASTContext& C) {
1200ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor  for (unsigned Arg = 0; Arg < NumArgs; ++Arg) {
1201ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor    // FIXME: Not all expressions get cloned, so we can't yet perform
1202ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor    // this destruction.
1203ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor    //    if (Expr *E = getArg(Arg).getAsExpr())
1204ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor    //      E->Destroy(C);
1205ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor  }
120640808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor}
120740808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor
12081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpvoid
12091eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTemplateSpecializationType::Profile(llvm::FoldingSetNodeID &ID,
12101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                    TemplateName T,
12111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                    const TemplateArgument *Args,
1212828e226ab7ed08b3eb766549e9d3306432137460Douglas Gregor                                    unsigned NumArgs,
1213828e226ab7ed08b3eb766549e9d3306432137460Douglas Gregor                                    ASTContext &Context) {
12147532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor  T.Profile(ID);
121540808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  for (unsigned Idx = 0; Idx < NumArgs; ++Idx)
1216828e226ab7ed08b3eb766549e9d3306432137460Douglas Gregor    Args[Idx].Profile(ID, Context);
121755f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor}
121897e0179f1ae545e07d9f5e7c1d2ef5c5bab06676Anders Carlsson
12190953e767ff7817f97b3ab20896b229891eeff45bJohn McCallQualType QualifierCollector::apply(QualType QT) const {
12200953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  if (!hasNonFastQualifiers())
12210953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return QT.withFastQualifiers(getFastQualifiers());
12221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12230953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  assert(Context && "extended qualifiers but no context!");
12240953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  return Context->getQualifiedType(QT, *this);
12255e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor}
12265e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor
12270953e767ff7817f97b3ab20896b229891eeff45bJohn McCallQualType QualifierCollector::apply(const Type *T) const {
12280953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  if (!hasNonFastQualifiers())
12290953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return QualType(T, getFastQualifiers());
12300953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
12310953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  assert(Context && "extended qualifiers but no context!");
12320953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  return Context->getQualifiedType(T, *this);
12335e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor}
12345e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor
1235c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallvoid ObjCObjectTypeImpl::Profile(llvm::FoldingSetNodeID &ID,
1236c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall                                 QualType BaseType,
1237c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall                                 ObjCProtocolDecl * const *Protocols,
1238c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall                                 unsigned NumProtocols) {
1239c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  ID.AddPointer(BaseType.getAsOpaquePtr());
1240c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff  for (unsigned i = 0; i != NumProtocols; i++)
1241c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    ID.AddPointer(Protocols[i]);
1242c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff}
1243c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff
1244c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallvoid ObjCObjectTypeImpl::Profile(llvm::FoldingSetNodeID &ID) {
1245c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  Profile(ID, getBaseType(), qual_begin(), getNumProtocols());
1246c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff}
12470b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor
124860e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor/// \brief Determine the linkage of this type.
124960e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas GregorLinkage Type::getLinkage() const {
12500b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor  if (this != CanonicalType.getTypePtr())
12510b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor    return CanonicalType->getLinkage();
125260e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
125360e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor  if (!LinkageKnown) {
125460e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor    CachedLinkage = getLinkageImpl();
125560e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor    LinkageKnown = true;
125660e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor  }
125760e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
125860e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor  return static_cast<clang::Linkage>(CachedLinkage);
125960e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor}
12600b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor
126160e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas GregorLinkage Type::getLinkageImpl() const {
126260e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor  // C++ [basic.link]p8:
126360e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor  //   Names not covered by these rules have no linkage.
12640b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor  return NoLinkage;
12650b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor}
12660b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor
126760e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregorvoid Type::ClearLinkageCache() {
126860e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor  if (this != CanonicalType.getTypePtr())
126960e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor    CanonicalType->ClearLinkageCache();
127060e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor  else
127160e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor    LinkageKnown = false;
127260e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor}
127360e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
127460e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas GregorLinkage BuiltinType::getLinkageImpl() const {
12750b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor  // C++ [basic.link]p8:
12760b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor  //   A type is said to have linkage if and only if:
12770b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor  //     - it is a fundamental type (3.9.1); or
12780b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor  return ExternalLinkage;
12790b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor}
12800b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor
128160e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas GregorLinkage TagType::getLinkageImpl() const {
12820b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor  // C++ [basic.link]p8:
12830b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor  //     - it is a class or enumeration type that is named (or has a name for
12840b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor  //       linkage purposes (7.1.3)) and the name has linkage; or
12850b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor  //     -  it is a specialization of a class template (14); or
12860b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor  return getDecl()->getLinkage();
12870b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor}
12880b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor
12890b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor// C++ [basic.link]p8:
12900b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor//   - it is a compound type (3.9.2) other than a class or enumeration,
12910b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor//     compounded exclusively from types that have linkage; or
129260e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas GregorLinkage ComplexType::getLinkageImpl() const {
12930b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor  return ElementType->getLinkage();
12940b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor}
12950b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor
129660e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas GregorLinkage PointerType::getLinkageImpl() const {
12970b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor  return PointeeType->getLinkage();
12980b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor}
12990b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor
130060e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas GregorLinkage BlockPointerType::getLinkageImpl() const {
13010b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor  return PointeeType->getLinkage();
13020b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor}
13030b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor
130460e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas GregorLinkage ReferenceType::getLinkageImpl() const {
13050b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor  return PointeeType->getLinkage();
13060b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor}
13070b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor
130860e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas GregorLinkage MemberPointerType::getLinkageImpl() const {
13090b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor  return minLinkage(Class->getLinkage(), PointeeType->getLinkage());
13100b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor}
13110b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor
131260e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas GregorLinkage ArrayType::getLinkageImpl() const {
13130b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor  return ElementType->getLinkage();
13140b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor}
13150b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor
131660e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas GregorLinkage VectorType::getLinkageImpl() const {
13170b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor  return ElementType->getLinkage();
13180b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor}
13190b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor
132060e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas GregorLinkage FunctionNoProtoType::getLinkageImpl() const {
13210b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor  return getResultType()->getLinkage();
13220b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor}
13230b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor
132460e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas GregorLinkage FunctionProtoType::getLinkageImpl() const {
13250b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor  Linkage L = getResultType()->getLinkage();
13260b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor  for (arg_type_iterator A = arg_type_begin(), AEnd = arg_type_end();
13270b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor       A != AEnd; ++A)
13280b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor    L = minLinkage(L, (*A)->getLinkage());
13290b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor
13300b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor  return L;
13310b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor}
13320b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor
133360e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas GregorLinkage ObjCObjectType::getLinkageImpl() const {
13340b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor  return ExternalLinkage;
13350b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor}
13360b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor
133760e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas GregorLinkage ObjCObjectPointerType::getLinkageImpl() const {
13380b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor  return ExternalLinkage;
13390b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor}
1340