Type.h revision 7536dd5e6c99584481b7dab68b7e7d8df9c54054
15f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===--- Type.h - C Language Family Type Representation ---------*- C++ -*-===//
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 defines the Type interface and subclasses.
115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#ifndef LLVM_CLANG_AST_TYPE_H
155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#define LLVM_CLANG_AST_TYPE_H
165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1722caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner#include "clang/Basic/Diagnostic.h"
181734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor#include "clang/Basic/IdentifierTable.h"
190b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor#include "clang/Basic/Linkage.h"
2047c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth#include "clang/Basic/PartialDiagnostic.h"
211fb0caaa7bef765b85972274e3b434af2572c141John McCall#include "clang/Basic/Visibility.h"
22e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor#include "clang/AST/NestedNameSpecifier.h"
237532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor#include "clang/AST/TemplateName.h"
245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "llvm/Support/Casting.h"
2550d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor#include "llvm/Support/type_traits.h"
26fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff#include "llvm/ADT/APSInt.h"
275cf243a883872441d73ca49cea7e20de5802629bChris Lattner#include "llvm/ADT/FoldingSet.h"
285cf243a883872441d73ca49cea7e20de5802629bChris Lattner#include "llvm/ADT/PointerIntPair.h"
291734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor#include "llvm/ADT/PointerUnion.h"
307532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor
315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing llvm::isa;
325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing llvm::cast;
335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing llvm::cast_or_null;
345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing llvm::dyn_cast;
355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing llvm::dyn_cast_or_null;
366b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCallnamespace clang {
376b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall  enum {
38f7616b9067790757f4e12e834b216c53c8c04ebeDouglas Gregor    TypeAlignmentInBits = 4,
396b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall    TypeAlignment = 1 << TypeAlignmentInBits
406b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall  };
41aed1df80bf64228e1429c1edc408397f9174847cChris Lattner  class Type;
42aed1df80bf64228e1429c1edc408397f9174847cChris Lattner  class ExtQuals;
43aed1df80bf64228e1429c1edc408397f9174847cChris Lattner  class QualType;
446b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall}
455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
464e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattnernamespace llvm {
474e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner  template <typename T>
48daae940507f2e93c6fa12e8062fa958e34cc2d1cChris Lattner  class PointerLikeTypeTraits;
49bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner  template<>
50bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner  class PointerLikeTypeTraits< ::clang::Type*> {
51bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner  public:
52bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner    static inline void *getAsVoidPointer(::clang::Type *P) { return P; }
53bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner    static inline ::clang::Type *getFromVoidPointer(void *P) {
54bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner      return static_cast< ::clang::Type*>(P);
55bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner    }
566b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall    enum { NumLowBitsAvailable = clang::TypeAlignmentInBits };
57bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner  };
580953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  template<>
590953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  class PointerLikeTypeTraits< ::clang::ExtQuals*> {
600953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  public:
610953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    static inline void *getAsVoidPointer(::clang::ExtQuals *P) { return P; }
620953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    static inline ::clang::ExtQuals *getFromVoidPointer(void *P) {
630953e767ff7817f97b3ab20896b229891eeff45bJohn McCall      return static_cast< ::clang::ExtQuals*>(P);
640953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    }
656b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall    enum { NumLowBitsAvailable = clang::TypeAlignmentInBits };
660953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  };
67aed1df80bf64228e1429c1edc408397f9174847cChris Lattner
68aed1df80bf64228e1429c1edc408397f9174847cChris Lattner  template <>
69aed1df80bf64228e1429c1edc408397f9174847cChris Lattner  struct isPodLike<clang::QualType> { static const bool value = true; };
704e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner}
714e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner
725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang {
735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class ASTContext;
745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class TypedefDecl;
7555f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  class TemplateDecl;
7672c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor  class TemplateTypeParmDecl;
77aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor  class NonTypeTemplateParmDecl;
787532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor  class TemplateTemplateParmDecl;
795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class TagDecl;
805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class RecordDecl;
8149aa7ff1245abd03e6e998e01302df31e4c6f8f6Argyrios Kyrtzidis  class CXXRecordDecl;
825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class EnumDecl;
8321d50e12c3c412d8457071dc419363b7a7e8b855Ted Kremenek  class FieldDecl;
84a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  class ObjCInterfaceDecl;
85a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  class ObjCProtocolDecl;
86a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  class ObjCMethodDecl;
87ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  class UnresolvedUsingTypenameDecl;
885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class Expr;
89b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek  class Stmt;
905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class SourceLocation;
9192866e2e90f6d93fb95e25a7ac4438e239d89ce6Ted Kremenek  class StmtIteratorBase;
9240808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  class TemplateArgument;
93833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  class TemplateArgumentLoc;
94d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  class TemplateArgumentListInfo;
95465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  class ElaboratedType;
963b4ea54acf01f72f6eb74d96689dda86d950228fDaniel Dunbar  struct PrintingPolicy;
9772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor
98ead608af31b6c9abeae1ca6d0b75094dac4641c0John McCall  template <typename> class CanQual;
99ead608af31b6c9abeae1ca6d0b75094dac4641c0John McCall  typedef CanQual<Type> CanQualType;
100ead608af31b6c9abeae1ca6d0b75094dac4641c0John McCall
10172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  // Provide forward declarations for all of the *Type classes
10272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#define TYPE(Class, Base) class Class##Type;
10372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#include "clang/AST/TypeNodes.def"
104f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl
1050953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// Qualifiers - The collection of all-type qualifiers we support.
1060953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// Clang supports five independent qualifiers:
1070953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// * C99: const, volatile, and restrict
1080953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// * Embedded C (TR18037): address spaces
1090953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// * Objective C: the GC attributes (none, weak, or strong)
1100953e767ff7817f97b3ab20896b229891eeff45bJohn McCallclass Qualifiers {
1115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
1120953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  enum TQ { // NOTE: These flags must be kept in sync with DeclSpec::TQ.
1135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Const    = 0x1,
1145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Restrict = 0x2,
1155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Volatile = 0x4,
1160953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    CVRMask = Const | Volatile | Restrict
1175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
1181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1190953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  enum GC {
120d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian    GCNone = 0,
121d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian    Weak,
122d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian    Strong
123d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian  };
124efadb7768e7c7418185f5a4010ecd8b21ca9731bJohn McCall
1250953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  enum {
1260953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    /// The maximum supported address space number.
1270953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    /// 24 bits should be enough for anyone.
1280953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    MaxAddressSpace = 0xffffffu,
1290953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
1300953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    /// The width of the "fast" qualifier mask.
131f7616b9067790757f4e12e834b216c53c8c04ebeDouglas Gregor    FastWidth = 3,
1320953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
1330953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    /// The fast qualifier mask.
1340953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    FastMask = (1 << FastWidth) - 1
1350953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  };
1360953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
1370953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  Qualifiers() : Mask(0) {}
1380953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
1390953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  static Qualifiers fromFastMask(unsigned Mask) {
1400953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Qualifiers Qs;
1410953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Qs.addFastQualifiers(Mask);
1420953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return Qs;
1430953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
1440953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
1450953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  static Qualifiers fromCVRMask(unsigned CVR) {
1460953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Qualifiers Qs;
1470953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Qs.addCVRQualifiers(CVR);
1480953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return Qs;
1490953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
1500953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
1510953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Deserialize qualifiers from an opaque representation.
1520953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  static Qualifiers fromOpaqueValue(unsigned opaque) {
1530953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Qualifiers Qs;
1540953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Qs.Mask = opaque;
1550953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return Qs;
1560953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
1570953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
1580953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Serialize these qualifiers into an opaque representation.
1590953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  unsigned getAsOpaqueValue() const {
1600953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return Mask;
1610953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
1620953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
1630953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool hasConst() const { return Mask & Const; }
1640953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void setConst(bool flag) {
1650953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask = (Mask & ~Const) | (flag ? Const : 0);
1660953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
1670953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void removeConst() { Mask &= ~Const; }
1680953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void addConst() { Mask |= Const; }
1690953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
1700953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool hasVolatile() const { return Mask & Volatile; }
1710953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void setVolatile(bool flag) {
1720953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask = (Mask & ~Volatile) | (flag ? Volatile : 0);
1730953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
1740953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void removeVolatile() { Mask &= ~Volatile; }
1750953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void addVolatile() { Mask |= Volatile; }
1760953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
1770953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool hasRestrict() const { return Mask & Restrict; }
1780953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void setRestrict(bool flag) {
1790953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask = (Mask & ~Restrict) | (flag ? Restrict : 0);
1800953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
1810953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void removeRestrict() { Mask &= ~Restrict; }
1820953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void addRestrict() { Mask |= Restrict; }
1830953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
1840953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool hasCVRQualifiers() const { return getCVRQualifiers(); }
1850953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  unsigned getCVRQualifiers() const { return Mask & CVRMask; }
1860953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void setCVRQualifiers(unsigned mask) {
1870953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(!(mask & ~CVRMask) && "bitmask contains non-CVR bits");
1880953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask = (Mask & ~CVRMask) | mask;
1890953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
1900953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void removeCVRQualifiers(unsigned mask) {
1910953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(!(mask & ~CVRMask) && "bitmask contains non-CVR bits");
1920953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask &= ~mask;
1930953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
1940953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void removeCVRQualifiers() {
1950953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    removeCVRQualifiers(CVRMask);
1960953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
1970953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void addCVRQualifiers(unsigned mask) {
1980953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(!(mask & ~CVRMask) && "bitmask contains non-CVR bits");
1990953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask |= mask;
2000953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2010953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
2020953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool hasObjCGCAttr() const { return Mask & GCAttrMask; }
2030953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  GC getObjCGCAttr() const { return GC((Mask & GCAttrMask) >> GCAttrShift); }
2040953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void setObjCGCAttr(GC type) {
2050953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask = (Mask & ~GCAttrMask) | (type << GCAttrShift);
2060953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2070953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void removeObjCGCAttr() { setObjCGCAttr(GCNone); }
2080953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void addObjCGCAttr(GC type) {
2090953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(type);
2100953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    setObjCGCAttr(type);
2110953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2120953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
2130953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool hasAddressSpace() const { return Mask & AddressSpaceMask; }
2140953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  unsigned getAddressSpace() const { return Mask >> AddressSpaceShift; }
2150953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void setAddressSpace(unsigned space) {
2160953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(space <= MaxAddressSpace);
2170953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask = (Mask & ~AddressSpaceMask)
2180953e767ff7817f97b3ab20896b229891eeff45bJohn McCall         | (((uint32_t) space) << AddressSpaceShift);
2190953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2200953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void removeAddressSpace() { setAddressSpace(0); }
2210953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void addAddressSpace(unsigned space) {
2220953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(space);
2230953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    setAddressSpace(space);
2240953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2250953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
2260953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Fast qualifiers are those that can be allocated directly
2270953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // on a QualType object.
2280953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool hasFastQualifiers() const { return getFastQualifiers(); }
2290953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  unsigned getFastQualifiers() const { return Mask & FastMask; }
2300953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void setFastQualifiers(unsigned mask) {
2310953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(!(mask & ~FastMask) && "bitmask contains non-fast qualifier bits");
2320953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask = (Mask & ~FastMask) | mask;
2330953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2340953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void removeFastQualifiers(unsigned mask) {
2350953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(!(mask & ~FastMask) && "bitmask contains non-fast qualifier bits");
2360953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask &= ~mask;
2370953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2380953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void removeFastQualifiers() {
2390953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    removeFastQualifiers(FastMask);
2400953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2410953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void addFastQualifiers(unsigned mask) {
2420953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(!(mask & ~FastMask) && "bitmask contains non-fast qualifier bits");
2430953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask |= mask;
2440953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2450953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
2460953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// hasNonFastQualifiers - Return true if the set contains any
2470953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// qualifiers which require an ExtQuals node to be allocated.
2480953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool hasNonFastQualifiers() const { return Mask & ~FastMask; }
2490953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  Qualifiers getNonFastQualifiers() const {
2500953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Qualifiers Quals = *this;
2510953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Quals.setFastQualifiers(0);
2520953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return Quals;
2530953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2540953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
2550953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// hasQualifiers - Return true if the set contains any qualifiers.
2560953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool hasQualifiers() const { return Mask; }
2570953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool empty() const { return !Mask; }
2580953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
2590953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// \brief Add the qualifiers from the given set to this set.
2600953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void addQualifiers(Qualifiers Q) {
2610953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    // If the other set doesn't have any non-boolean qualifiers, just
2620953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    // bit-or it in.
2630953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    if (!(Q.Mask & ~CVRMask))
2640953e767ff7817f97b3ab20896b229891eeff45bJohn McCall      Mask |= Q.Mask;
2650953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    else {
2660953e767ff7817f97b3ab20896b229891eeff45bJohn McCall      Mask |= (Q.Mask & CVRMask);
2670953e767ff7817f97b3ab20896b229891eeff45bJohn McCall      if (Q.hasAddressSpace())
2680953e767ff7817f97b3ab20896b229891eeff45bJohn McCall        addAddressSpace(Q.getAddressSpace());
2690953e767ff7817f97b3ab20896b229891eeff45bJohn McCall      if (Q.hasObjCGCAttr())
2700953e767ff7817f97b3ab20896b229891eeff45bJohn McCall        addObjCGCAttr(Q.getObjCGCAttr());
2710953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    }
2720953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2730953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
274b87786f045d798b070980c108c922e1475d27b15Douglas Gregor  bool isSupersetOf(Qualifiers Other) const;
275b87786f045d798b070980c108c922e1475d27b15Douglas Gregor
2760953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool operator==(Qualifiers Other) const { return Mask == Other.Mask; }
2770953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool operator!=(Qualifiers Other) const { return Mask != Other.Mask; }
2780953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
2790953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  operator bool() const { return hasQualifiers(); }
2800953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
2810953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  Qualifiers &operator+=(Qualifiers R) {
2820953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    addQualifiers(R);
2830953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return *this;
2840953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2850953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
2860953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Union two qualifier sets.  If an enumerated qualifier appears
2870953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // in both sets, use the one from the right.
2880953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  friend Qualifiers operator+(Qualifiers L, Qualifiers R) {
2890953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    L += R;
2900953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return L;
2910953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2923cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor
2933cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor  Qualifiers &operator-=(Qualifiers R) {
2943cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor    Mask = Mask & ~(R.Mask);
2953cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor    return *this;
2963cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor  }
2970953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
2983cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor  /// \brief Compute the difference between two qualifier sets.
2993cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor  friend Qualifiers operator-(Qualifiers L, Qualifiers R) {
3003cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor    L -= R;
3013cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor    return L;
3023cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor  }
3033cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor
3040953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  std::string getAsString() const;
3050953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  std::string getAsString(const PrintingPolicy &Policy) const {
3060953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    std::string Buffer;
3070953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    getAsStringInternal(Buffer, Policy);
3080953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return Buffer;
3090953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
3100953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void getAsStringInternal(std::string &S, const PrintingPolicy &Policy) const;
3110953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3120953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void Profile(llvm::FoldingSetNodeID &ID) const {
3130953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    ID.AddInteger(Mask);
3140953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
3150953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3160953e767ff7817f97b3ab20896b229891eeff45bJohn McCallprivate:
3170953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3180953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // bits:     |0 1 2|3 .. 4|5  ..  31|
3190953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  //           |C R V|GCAttr|AddrSpace|
3200953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  uint32_t Mask;
3210953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3220953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  static const uint32_t GCAttrMask = 0x18;
3230953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  static const uint32_t GCAttrShift = 3;
3240953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  static const uint32_t AddressSpaceMask = ~(CVRMask | GCAttrMask);
3250953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  static const uint32_t AddressSpaceShift = 5;
3260953e767ff7817f97b3ab20896b229891eeff45bJohn McCall};
3270953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3281ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor/// \brief Base class that is common to both the \c ExtQuals and \c Type
3291ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor/// classes, which allows \c QualType to access the common fields between the
3301ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor/// two.
3311ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor///
3321ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregorclass ExtQualsTypeCommonBase {
3331ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregorprotected:
3341ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor  ExtQualsTypeCommonBase(const Type *BaseType) : BaseType(BaseType) { }
3351ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor
3361ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor  /// \brief The "base" type of an extended qualifiers type (\c ExtQuals) or
3371ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor  /// a self-referential pointer (for \c Type).
3381ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor  ///
3391ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor  /// This pointer allows an efficient mapping from a QualType to its
3401ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor  /// underlying type pointer.
3411ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor  const Type *BaseType;
3421ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor
3431ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor  friend class QualType;
3441ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor};
3451ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor
34655270e4bde91bd30d16086ae71f0f65caf3b8a51Douglas Gregor/// ExtQuals - We can encode up to four bits in the low bits of a
3470953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// type pointer, but there are many more type qualifiers that we want
3480953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// to be able to apply to an arbitrary type.  Therefore we have this
3490953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// struct, intended to be heap-allocated and used by QualType to
3500953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// store qualifiers.
3510953e767ff7817f97b3ab20896b229891eeff45bJohn McCall///
35255270e4bde91bd30d16086ae71f0f65caf3b8a51Douglas Gregor/// The current design tags the 'const', 'restrict', and 'volatile' qualifiers
35355270e4bde91bd30d16086ae71f0f65caf3b8a51Douglas Gregor/// in three low bits on the QualType pointer; a fourth bit records whether
35455270e4bde91bd30d16086ae71f0f65caf3b8a51Douglas Gregor/// the pointer is an ExtQuals node. The extended qualifiers (address spaces,
35555270e4bde91bd30d16086ae71f0f65caf3b8a51Douglas Gregor/// Objective-C GC attributes) are much more rare.
3561ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregorclass ExtQuals : public ExtQualsTypeCommonBase, public llvm::FoldingSetNode {
3570953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // NOTE: changing the fast qualifiers should be straightforward as
3580953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // long as you don't make 'const' non-fast.
3590953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // 1. Qualifiers:
3600953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  //    a) Modify the bitmasks (Qualifiers::TQ and DeclSpec::TQ).
3610953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  //       Fast qualifiers must occupy the low-order bits.
3620953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  //    b) Update Qualifiers::FastWidth and FastMask.
3630953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // 2. QualType:
3640953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  //    a) Update is{Volatile,Restrict}Qualified(), defined inline.
3650953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  //    b) Update remove{Volatile,Restrict}, defined near the end of
3660953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  //       this header.
3670953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // 3. ASTContext:
3680953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  //    a) Update get{Volatile,Restrict}Type.
3690953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3700953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// Quals - the immutable set of qualifiers applied by this
3710953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// node;  always contains extended qualifiers.
3720953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  Qualifiers Quals;
3730953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3740953e767ff7817f97b3ab20896b229891eeff45bJohn McCallpublic:
3751ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor  ExtQuals(const Type *Base, Qualifiers Quals)
3761ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor    : ExtQualsTypeCommonBase(Base), Quals(Quals)
3770953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  {
3780953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(Quals.hasNonFastQualifiers()
3790953e767ff7817f97b3ab20896b229891eeff45bJohn McCall           && "ExtQuals created with no fast qualifiers");
3800953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(!Quals.hasFastQualifiers()
3810953e767ff7817f97b3ab20896b229891eeff45bJohn McCall           && "ExtQuals created with fast qualifiers");
3820953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
3830953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3840953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  Qualifiers getQualifiers() const { return Quals; }
3850953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3860953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool hasObjCGCAttr() const { return Quals.hasObjCGCAttr(); }
3870953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  Qualifiers::GC getObjCGCAttr() const { return Quals.getObjCGCAttr(); }
3880953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3890953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool hasAddressSpace() const { return Quals.hasAddressSpace(); }
3900953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  unsigned getAddressSpace() const { return Quals.getAddressSpace(); }
3910953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3920953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  const Type *getBaseType() const { return BaseType; }
3931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3940953e767ff7817f97b3ab20896b229891eeff45bJohn McCallpublic:
3950953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void Profile(llvm::FoldingSetNodeID &ID) const {
3960953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Profile(ID, getBaseType(), Quals);
3970953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
3980953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  static void Profile(llvm::FoldingSetNodeID &ID,
3990953e767ff7817f97b3ab20896b229891eeff45bJohn McCall                      const Type *BaseType,
4000953e767ff7817f97b3ab20896b229891eeff45bJohn McCall                      Qualifiers Quals) {
4010953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(!Quals.hasFastQualifiers() && "fast qualifiers in ExtQuals hash!");
4020953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    ID.AddPointer(BaseType);
4030953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Quals.Profile(ID);
4040953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
4050953e767ff7817f97b3ab20896b229891eeff45bJohn McCall};
4060953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
407ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor/// CallingConv - Specifies the calling convention that a function uses.
408ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregorenum CallingConv {
409ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor  CC_Default,
410ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor  CC_C,           // __attribute__((cdecl))
411ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor  CC_X86StdCall,  // __attribute__((stdcall))
412f813a2c03fcb05381b3252010435f557eb6b3cdeDouglas Gregor  CC_X86FastCall, // __attribute__((fastcall))
41352fc314e1b5e1baee6305067cf831763d02bd243Dawn Perchik  CC_X86ThisCall, // __attribute__((thiscall))
41452fc314e1b5e1baee6305067cf831763d02bd243Dawn Perchik  CC_X86Pascal    // __attribute__((pascal))
415ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor};
416ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor
41749f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCalltypedef std::pair<const Type*, Qualifiers> SplitQualType;
4180953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
4190953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// QualType - For efficiency, we don't store CV-qualified types as nodes on
4200953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// their own: instead each reference to a type stores the qualifiers.  This
4210953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// greatly reduces the number of nodes we need to allocate for types (for
4220953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// example we only need one for 'int', 'const int', 'volatile int',
4230953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// 'const volatile int', etc).
4240953e767ff7817f97b3ab20896b229891eeff45bJohn McCall///
4250953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// As an added efficiency bonus, instead of making this a pair, we
4260953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// just store the two bits we care about in the low bits of the
4270953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// pointer.  To handle the packing/unpacking, we make QualType be a
4280953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// simple wrapper class that acts like a smart pointer.  A third bit
4290953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// indicates whether there are extended qualifiers present, in which
4300953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// case the pointer points to a special structure.
4310953e767ff7817f97b3ab20896b229891eeff45bJohn McCallclass QualType {
4320953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Thankfully, these are efficiently composable.
4330953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  llvm::PointerIntPair<llvm::PointerUnion<const Type*,const ExtQuals*>,
4340953e767ff7817f97b3ab20896b229891eeff45bJohn McCall                       Qualifiers::FastWidth> Value;
4350953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
4360953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  const ExtQuals *getExtQualsUnsafe() const {
4370953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return Value.getPointer().get<const ExtQuals*>();
4380953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
4390953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
4400953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  const Type *getTypePtrUnsafe() const {
4410953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return Value.getPointer().get<const Type*>();
4420953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
4430953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
444fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  QualType getUnqualifiedTypeSlow() const;
445fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor
4460953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  friend class QualifierCollector;
4470953e767ff7817f97b3ab20896b229891eeff45bJohn McCallpublic:
4485cf243a883872441d73ca49cea7e20de5802629bChris Lattner  QualType() {}
4491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4505cf243a883872441d73ca49cea7e20de5802629bChris Lattner  QualType(const Type *Ptr, unsigned Quals)
4510953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    : Value(Ptr, Quals) {}
4520953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  QualType(const ExtQuals *Ptr, unsigned Quals)
4530953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    : Value(Ptr, Quals) {}
4540953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
455a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  unsigned getLocalFastQualifiers() const { return Value.getInt(); }
456a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  void setLocalFastQualifiers(unsigned Quals) { Value.setInt(Quals); }
4575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4580953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// Retrieves a pointer to the underlying (unqualified) type.
4590953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// This should really return a const Type, but it's not worth
4600953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// changing all the users right now.
4611ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor  ///
4621ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor  /// This function requires that the type not be NULL. If the type might be
4631ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor  /// NULL, use the (slightly less efficient) \c getTypePtrOrNull().
4640953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  Type *getTypePtr() const {
4651ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor    assert(!isNull() && "Cannot retrieve a NULL type pointer");
4661ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor    uintptr_t CommonPtrVal
4671ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor      = reinterpret_cast<uintptr_t>(Value.getOpaqueValue());
4681ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor    CommonPtrVal &= ~(uintptr_t)((1 << TypeAlignmentInBits) - 1);
4691ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor    ExtQualsTypeCommonBase *CommonPtr
4701ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor      = reinterpret_cast<ExtQualsTypeCommonBase*>(CommonPtrVal);
4711ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor    return const_cast<Type *>(CommonPtr->BaseType);
4721ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor  }
4731ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor
4741ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor  Type *getTypePtrOrNull() const {
4751ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor    uintptr_t TypePtrPtrVal
4761ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor      = reinterpret_cast<uintptr_t>(Value.getOpaqueValue());
4771ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor    TypePtrPtrVal &= ~(uintptr_t)((1 << TypeAlignmentInBits) - 1);
4781ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor    Type **TypePtrPtr = reinterpret_cast<Type**>(TypePtrPtrVal);
4791ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor    return TypePtrPtr? *TypePtrPtr : 0;
4800953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
4811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
48249f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  /// Divides a QualType into its unqualified type and a set of local
48349f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  /// qualifiers.
48449f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  SplitQualType split() const {
48549f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall    if (!hasLocalNonFastQualifiers())
48649f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall      return SplitQualType(getTypePtrUnsafe(),
48749f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall                           Qualifiers::fromFastMask(getLocalFastQualifiers()));
48849f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall
48949f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall    const ExtQuals *eq = getExtQualsUnsafe();
49049f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall    Qualifiers qs = eq->getQualifiers();
49149f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall    qs.addFastQualifiers(getLocalFastQualifiers());
49249f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall    return SplitQualType(eq->getBaseType(), qs);
49349f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  }
49449f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall
4955cf243a883872441d73ca49cea7e20de5802629bChris Lattner  void *getAsOpaquePtr() const { return Value.getOpaqueValue(); }
4965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static QualType getFromOpaquePtr(void *Ptr) {
4975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    QualType T;
4985cf243a883872441d73ca49cea7e20de5802629bChris Lattner    T.Value.setFromOpaqueValue(Ptr);
4995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T;
5005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
5011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Type &operator*() const {
5035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return *getTypePtr();
5045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
5055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
5065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Type *operator->() const {
5075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return getTypePtr();
5085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
5091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
510467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall  bool isCanonical() const;
51154e14c4db764c0636160d26c5bbf491637c83a76John McCall  bool isCanonicalAsParam() const;
512467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall
5135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isNull - Return true if this QualType doesn't point to a type yet.
5145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isNull() const {
5150953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return Value.getPointer().isNull();
5165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
5175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
518a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Determine whether this particular QualType instance has the
519a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// "const" qualifier set, without looking through typedefs that may have
520a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// added "const" at a different level.
521a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  bool isLocalConstQualified() const {
522a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor    return (getLocalFastQualifiers() & Qualifiers::Const);
5230953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
524a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor
525a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Determine whether this type is const-qualified.
526fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  bool isConstQualified() const;
527a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor
528a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Determine whether this particular QualType instance has the
529a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// "restrict" qualifier set, without looking through typedefs that may have
530a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// added "restrict" at a different level.
531a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  bool isLocalRestrictQualified() const {
532a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor    return (getLocalFastQualifiers() & Qualifiers::Restrict);
533a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  }
534a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor
535a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Determine whether this type is restrict-qualified.
536fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  bool isRestrictQualified() const;
537a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor
538a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Determine whether this particular QualType instance has the
539a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// "volatile" qualifier set, without looking through typedefs that may have
540a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// added "volatile" at a different level.
541a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  bool isLocalVolatileQualified() const {
542f7616b9067790757f4e12e834b216c53c8c04ebeDouglas Gregor    return (getLocalFastQualifiers() & Qualifiers::Volatile);
5435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
5440953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
545a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Determine whether this type is volatile-qualified.
546fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  bool isVolatileQualified() const;
547a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor
548a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Determine whether this particular QualType instance has any
549a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// qualifiers, without looking through any typedefs that might add
550a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// qualifiers at a different level.
551a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  bool hasLocalQualifiers() const {
552a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor    return getLocalFastQualifiers() || hasLocalNonFastQualifiers();
5530953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
5540953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
555a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Determine whether this type has any qualifiers.
556fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  bool hasQualifiers() const;
557a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor
558a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Determine whether this particular QualType instance has any
559a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// "non-fast" qualifiers, e.g., those that are stored in an ExtQualType
560a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// instance.
561a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  bool hasLocalNonFastQualifiers() const {
562a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor    return Value.getPointer().is<const ExtQuals*>();
5630953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
5640953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
565a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Retrieve the set of qualifiers local to this particular QualType
566a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// instance, not including any qualifiers acquired through typedefs or
567a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// other sugar.
568a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  Qualifiers getLocalQualifiers() const {
5690953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Qualifiers Quals;
570a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor    if (hasLocalNonFastQualifiers())
5710953e767ff7817f97b3ab20896b229891eeff45bJohn McCall      Quals = getExtQualsUnsafe()->getQualifiers();
572a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor    Quals.addFastQualifiers(getLocalFastQualifiers());
5730953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return Quals;
5740953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
5750953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
576a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Retrieve the set of qualifiers applied to this type.
577fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  Qualifiers getQualifiers() const;
578a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor
579a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Retrieve the set of CVR (const-volatile-restrict) qualifiers
580a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// local to this particular QualType instance, not including any qualifiers
581a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// acquired through typedefs or other sugar.
582a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  unsigned getLocalCVRQualifiers() const {
583f7616b9067790757f4e12e834b216c53c8c04ebeDouglas Gregor    return getLocalFastQualifiers();
5845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
585b381aac9bae6d608c72267dd0ed08ec6369e94e4Nuno Lopes
586a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Retrieve the set of CVR (const-volatile-restrict) qualifiers
587a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// applied to this type.
588fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  unsigned getCVRQualifiers() const;
589e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth
590e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth  /// \brief Retrieve the set of CVR (const-volatile-restrict) qualifiers
591e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth  /// applied to this type, looking through any number of unqualified array
592e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth  /// types to their element types' qualifiers.
593e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth  unsigned getCVRQualifiersThroughArrayTypes() const;
594e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth
595bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isConstant(ASTContext& Ctx) const {
596bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall    return QualType::isConstant(*this, Ctx);
597bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  }
5981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5990953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Don't promise in the API that anything besides 'const' can be
6000953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // easily added.
6010953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
6020953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// addConst - add the specified type qualifier to this QualType.
6030953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void addConst() {
6040953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    addFastQualifiers(Qualifiers::Const);
6050953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
6060953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  QualType withConst() const {
6070953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return withFastQualifiers(Qualifiers::Const);
6080953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
6090953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
6100953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void addFastQualifiers(unsigned TQs) {
6110953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(!(TQs & ~Qualifiers::FastMask)
6120953e767ff7817f97b3ab20896b229891eeff45bJohn McCall           && "non-fast qualifier bits set in mask!");
6130953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Value.setInt(Value.getInt() | TQs);
6140953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
6150953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
61649f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  void removeLocalConst();
61749f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  void removeLocalVolatile();
61849f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  void removeLocalRestrict();
61949f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  void removeLocalCVRQualifiers(unsigned Mask);
6200953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
62149f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  void removeLocalFastQualifiers() { Value.setInt(0); }
62249f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  void removeLocalFastQualifiers(unsigned Mask) {
6230953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(!(Mask & ~Qualifiers::FastMask) && "mask has non-fast qualifiers");
6240953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Value.setInt(Value.getInt() & ~Mask);
6250953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
6265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
6270953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Creates a type with the given qualifiers in addition to any
6280953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // qualifiers already on this type.
6290953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  QualType withFastQualifiers(unsigned TQs) const {
6300953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    QualType T = *this;
6310953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    T.addFastQualifiers(TQs);
6320953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return T;
6330953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
6341c6a38bcea17801e9a4738753aee845381af2b6cSanjiv Gupta
6350953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Creates a type with exactly the given fast qualifiers, removing
6360953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // any existing fast qualifiers.
63749f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  QualType withExactLocalFastQualifiers(unsigned TQs) const {
63849f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall    return withoutLocalFastQualifiers().withFastQualifiers(TQs);
6395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
6400953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
6410953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Removes fast qualifiers, but leaves any extended qualifiers in place.
64249f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  QualType withoutLocalFastQualifiers() const {
6430953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    QualType T = *this;
64449f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall    T.removeLocalFastQualifiers();
6450953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return T;
646c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  }
647971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis
648a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Return this type with all of the instance-specific qualifiers
649a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// removed, but without removing any qualifiers that may have been applied
650a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// through typedefs.
651a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  QualType getLocalUnqualifiedType() const { return QualType(getTypePtr(), 0); }
6521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
653a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Return the unqualified form of the given type, which might be
654a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// desugared to eliminate qualifiers introduced via typedefs.
655fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  QualType getUnqualifiedType() const {
656fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor    QualType T = getLocalUnqualifiedType();
657fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor    if (!T.hasQualifiers())
658fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor      return T;
659fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor
660fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor    return getUnqualifiedTypeSlow();
661a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  }
662a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor
663e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor  bool isMoreQualifiedThan(QualType Other) const;
664e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor  bool isAtLeastAsQualifiedAs(QualType Other) const;
665e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor  QualType getNonReferenceType() const;
6661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6676398235d7890a81b785ea5af3b6e66d86bf184ccDouglas Gregor  /// \brief Determine the type of a (typically non-lvalue) expression with the
6686398235d7890a81b785ea5af3b6e66d86bf184ccDouglas Gregor  /// specified result type.
6695291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor  ///
6706398235d7890a81b785ea5af3b6e66d86bf184ccDouglas Gregor  /// This routine should be used for expressions for which the return type is
6716398235d7890a81b785ea5af3b6e66d86bf184ccDouglas Gregor  /// explicitly specified (e.g., in a cast or call) and isn't necessarily
6726398235d7890a81b785ea5af3b6e66d86bf184ccDouglas Gregor  /// an lvalue. It removes a top-level reference (since there are no
6735291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor  /// expressions of reference type) and deletes top-level cvr-qualifiers
6745291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor  /// from non-class types (in C++) or all types (in C).
6756398235d7890a81b785ea5af3b6e66d86bf184ccDouglas Gregor  QualType getNonLValueExprType(ASTContext &Context) const;
6765291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor
6772fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner  /// getDesugaredType - Return the specified type with any "sugar" removed from
6782fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner  /// the type.  This takes off typedefs, typeof's etc.  If the outer level of
6792fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner  /// the type is already concrete, it returns it unmodified.  This is similar
6802fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner  /// to getting the canonical type, but it doesn't remove *all* typedefs.  For
6812fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner  /// example, it returns "T*" as "T*", (not as "int*"), because the pointer is
6822fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner  /// concrete.
6830953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  ///
6840953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// Qualifiers are left in place.
68549f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  QualType getDesugaredType(ASTContext &Context) const {
68649f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall    return getDesugaredType(*this, Context);
68749f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  }
68849f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall
68949f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  SplitQualType getSplitDesugaredType() const {
69049f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall    return getSplitDesugaredType(*this);
691bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  }
69298cd599ee8a9b259ed7388ee2921a20d97658864Douglas Gregor
693075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  /// IgnoreParens - Returns the specified type after dropping any
694075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  /// outer-level parentheses.
695075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  QualType IgnoreParens() const {
696723df245307a530da5433dfb43accf187dc3e243Abramo Bagnara    if (isa<ParenType>(*this))
697723df245307a530da5433dfb43accf187dc3e243Abramo Bagnara      return QualType::IgnoreParens(*this);
698723df245307a530da5433dfb43accf187dc3e243Abramo Bagnara    return *this;
699075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  }
700075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
7015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// operator==/!= - Indicate whether the specified types and qualifiers are
7025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// identical.
70350d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor  friend bool operator==(const QualType &LHS, const QualType &RHS) {
70450d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor    return LHS.Value == RHS.Value;
7055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
70650d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor  friend bool operator!=(const QualType &LHS, const QualType &RHS) {
70750d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor    return LHS.Value != RHS.Value;
7085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
70949f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  std::string getAsString() const {
71049f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall    return getAsString(split());
71149f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  }
71249f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  static std::string getAsString(SplitQualType split) {
71349f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall    return getAsString(split.first, split.second);
71449f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  }
71549f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  static std::string getAsString(const Type *ty, Qualifiers qs);
716d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor
717d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor  std::string getAsString(const PrintingPolicy &Policy) const {
7185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    std::string S;
719d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor    getAsStringInternal(S, Policy);
7205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return S;
7215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
722e4f2142d00fa5fdb580c4e2413da91882d955381Chris Lattner  void getAsStringInternal(std::string &Str,
72349f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall                           const PrintingPolicy &Policy) const {
72449f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall    return getAsStringInternal(split(), Str, Policy);
72549f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  }
72649f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  static void getAsStringInternal(SplitQualType split, std::string &out,
72749f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall                                  const PrintingPolicy &policy) {
72849f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall    return getAsStringInternal(split.first, split.second, out, policy);
72949f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  }
73049f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  static void getAsStringInternal(const Type *ty, Qualifiers qs,
73149f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall                                  std::string &out,
73249f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall                                  const PrintingPolicy &policy);
7331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
734c36d405a02fab41f6c45cb2bc750d64949742903Chris Lattner  void dump(const char *s) const;
735c36d405a02fab41f6c45cb2bc750d64949742903Chris Lattner  void dump() const;
7361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7373f2dcb1ca8bd2d5d3ccc5c80f4ab06f949d88a89Ted Kremenek  void Profile(llvm::FoldingSetNodeID &ID) const {
7383f2dcb1ca8bd2d5d3ccc5c80f4ab06f949d88a89Ted Kremenek    ID.AddPointer(getAsOpaquePtr());
7393f2dcb1ca8bd2d5d3ccc5c80f4ab06f949d88a89Ted Kremenek  }
7405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
741ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb  /// getAddressSpace - Return the address space of this type.
742ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb  inline unsigned getAddressSpace() const;
7431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
744d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian  /// GCAttrTypesAttr - Returns gc attribute of this type.
7450953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  inline Qualifiers::GC getObjCGCAttr() const;
746f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian
747f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian  /// isObjCGCWeak true when Type is objc's weak.
748f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian  bool isObjCGCWeak() const {
7490953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return getObjCGCAttr() == Qualifiers::Weak;
750f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian  }
751f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian
752f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian  /// isObjCGCStrong true when Type is objc's strong.
753f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian  bool isObjCGCStrong() const {
7540953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return getObjCGCAttr() == Qualifiers::Strong;
755f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian  }
7562455636163fdd18581d7fdae816433f886d88213Mike Stump
757bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCallprivate:
758bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  // These methods are implemented in a separate translation unit;
759bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  // "static"-ize them to avoid creating temporary QualTypes in the
760bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  // caller.
761bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  static bool isConstant(QualType T, ASTContext& Ctx);
76249f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  static QualType getDesugaredType(QualType T, ASTContext &Context);
76349f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  static SplitQualType getSplitDesugaredType(QualType T);
764075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  static QualType IgnoreParens(QualType T);
7655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
7665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end clang.
7685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace llvm {
7705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Implement simplify_type for QualType, so that we can dyn_cast from QualType
7715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// to a specific Type class.
7725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencertemplate<> struct simplify_type<const ::clang::QualType> {
7735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  typedef ::clang::Type* SimpleType;
7745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static SimpleType getSimplifiedValue(const ::clang::QualType &Val) {
7754472fc641ea3069463798fb56a04043c28ea2910Douglas Gregor    return Val.getTypePtr();
7765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
7775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
7785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencertemplate<> struct simplify_type< ::clang::QualType>
7795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  : public simplify_type<const ::clang::QualType> {};
7801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7814e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner// Teach SmallPtrSet that QualType is "basically a pointer".
7824e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattnertemplate<>
783daae940507f2e93c6fa12e8062fa958e34cc2d1cChris Lattnerclass PointerLikeTypeTraits<clang::QualType> {
7844e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattnerpublic:
7854e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner  static inline void *getAsVoidPointer(clang::QualType P) {
7864e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner    return P.getAsOpaquePtr();
7874e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner  }
7884e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner  static inline clang::QualType getFromVoidPointer(void *P) {
7894e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner    return clang::QualType::getFromOpaquePtr(P);
7904e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner  }
7910953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Various qualifiers go in low bits.
7920eda3b31a672ea486fa92b9bc49a2c91be856b53Chris Lattner  enum { NumLowBitsAvailable = 0 };
7934e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner};
7941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
79573af669633e13c813f80cd15ecf3e6414778aee4Ted Kremenek} // end namespace llvm
7965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang {
7985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Type - This is the base class of the type hierarchy.  A central concept
8005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// with types is that each type always has a canonical type.  A canonical type
8015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// is the type with any typedef names stripped out of it or the types it
8025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// references.  For example, consider:
8035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
8045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///  typedef int  foo;
8055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///  typedef foo* bar;
8065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///    'int *'    'foo *'    'bar'
8075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
8085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// There will be a Type object created for 'int'.  Since int is canonical, its
8095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// canonicaltype pointer points to itself.  There is also a Type for 'foo' (a
81072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// TypedefType).  Its CanonicalType pointer points to the 'int' Type.  Next
8115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// there is a PointerType that represents 'int*', which, like 'int', is
8125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// canonical.  Finally, there is a PointerType type for 'foo*' whose canonical
81372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// type is 'int*', and there is a TypedefType for 'bar', whose canonical type
8145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// is also 'int*'.
8155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
8165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Non-canonical types are useful for emitting diagnostics, without losing
8175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// information about typedefs being used.  Canonical types are useful for type
8185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// comparisons (they allow by-pointer equality tests) and useful for reasoning
8195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// about whether something has a particular form (e.g. is a function type),
8205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// because they implicitly, recursively, strip all typedefs out of a type.
8215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
8225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Types, once created, are immutable.
8235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
8241ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregorclass Type : public ExtQualsTypeCommonBase {
8255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
8265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  enum TypeClass {
82772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#define TYPE(Class, Base) Class,
82827935ee59c30b0d8b610ab676aab8e65350af932John McCall#define LAST_TYPE(Class) TypeLast = Class,
82972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#define ABSTRACT_TYPE(Class, Base)
83072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#include "clang/AST/TypeNodes.def"
83172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor    TagFirst = Record, TagLast = Enum
8325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
8331bb8a45f7386a23871598d05141a07af03067925Argyrios Kyrtzidis
8345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate:
835c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  Type(const Type&);           // DO NOT IMPLEMENT.
836c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  void operator=(const Type&); // DO NOT IMPLEMENT.
837c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
8385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType CanonicalType;
8395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
840b870b88df784c2940efce448ebfaf54dece14666John McCall  /// Bitfields required by the Type class.
841b870b88df784c2940efce448ebfaf54dece14666John McCall  class TypeBitfields {
842b870b88df784c2940efce448ebfaf54dece14666John McCall    friend class Type;
843b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall    template <class T> friend class TypePropertyCache;
84427935ee59c30b0d8b610ab676aab8e65350af932John McCall
845b870b88df784c2940efce448ebfaf54dece14666John McCall    /// TypeClass bitfield - Enum that specifies what subclass this belongs to.
846b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned TC : 8;
847b870b88df784c2940efce448ebfaf54dece14666John McCall
848b870b88df784c2940efce448ebfaf54dece14666John McCall    /// Dependent - Whether this type is a dependent type (C++ [temp.dep.type]).
849b870b88df784c2940efce448ebfaf54dece14666John McCall    /// Note that this should stay at the end of the ivars for Type so that
850b870b88df784c2940efce448ebfaf54dece14666John McCall    /// subclasses can pack their bitfields into the same word.
851bdb5b0e8ad8ed297ad01eb2ccd0d6d5ed6058033Francois Pichet    unsigned Dependent : 1;
85260e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
853b870b88df784c2940efce448ebfaf54dece14666John McCall    /// \brief Whether this type is a variably-modified type (C99 6.7.5).
854bdb5b0e8ad8ed297ad01eb2ccd0d6d5ed6058033Francois Pichet    unsigned VariablyModified : 1;
855d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor
856d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    /// \brief Whether this type contains an unexpanded parameter pack
857d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    /// (for C++0x variadic templates).
858d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    unsigned ContainsUnexpandedParameterPack : 1;
85935495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor
8601fb0caaa7bef765b85972274e3b434af2572c141John McCall    /// \brief Nonzero if the cache (i.e. the bitfields here starting
8611fb0caaa7bef765b85972274e3b434af2572c141John McCall    /// with 'Cache') is valid.  If so, then this is a
8621fb0caaa7bef765b85972274e3b434af2572c141John McCall    /// LangOptions::VisibilityMode+1.
8631fb0caaa7bef765b85972274e3b434af2572c141John McCall    mutable unsigned CacheValidAndVisibility : 2;
86460e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
865b870b88df784c2940efce448ebfaf54dece14666John McCall    /// \brief Linkage of this type.
866b870b88df784c2940efce448ebfaf54dece14666John McCall    mutable unsigned CachedLinkage : 2;
86707a353c2af3a3c557205466d4f4ed2513462ebfeSebastian Redl
868b870b88df784c2940efce448ebfaf54dece14666John McCall    /// \brief Whether this type involves and local or unnamed types.
869bdb5b0e8ad8ed297ad01eb2ccd0d6d5ed6058033Francois Pichet    mutable unsigned CachedLocalOrUnnamed : 1;
870db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor
871b870b88df784c2940efce448ebfaf54dece14666John McCall    /// \brief FromAST - Whether this type comes from an AST file.
872bdb5b0e8ad8ed297ad01eb2ccd0d6d5ed6058033Francois Pichet    mutable unsigned FromAST : 1;
873b870b88df784c2940efce448ebfaf54dece14666John McCall
8741fb0caaa7bef765b85972274e3b434af2572c141John McCall    bool isCacheValid() const {
8751fb0caaa7bef765b85972274e3b434af2572c141John McCall      return (CacheValidAndVisibility != 0);
8761fb0caaa7bef765b85972274e3b434af2572c141John McCall    }
8771fb0caaa7bef765b85972274e3b434af2572c141John McCall    Visibility getVisibility() const {
8781fb0caaa7bef765b85972274e3b434af2572c141John McCall      assert(isCacheValid() && "getting linkage from invalid cache");
8791fb0caaa7bef765b85972274e3b434af2572c141John McCall      return static_cast<Visibility>(CacheValidAndVisibility-1);
8801fb0caaa7bef765b85972274e3b434af2572c141John McCall    }
8811fb0caaa7bef765b85972274e3b434af2572c141John McCall    Linkage getLinkage() const {
8821fb0caaa7bef765b85972274e3b434af2572c141John McCall      assert(isCacheValid() && "getting linkage from invalid cache");
8831fb0caaa7bef765b85972274e3b434af2572c141John McCall      return static_cast<Linkage>(CachedLinkage);
8841fb0caaa7bef765b85972274e3b434af2572c141John McCall    }
8851fb0caaa7bef765b85972274e3b434af2572c141John McCall    bool hasLocalOrUnnamedType() const {
8861fb0caaa7bef765b85972274e3b434af2572c141John McCall      assert(isCacheValid() && "getting linkage from invalid cache");
8871fb0caaa7bef765b85972274e3b434af2572c141John McCall      return CachedLocalOrUnnamed;
8881fb0caaa7bef765b85972274e3b434af2572c141John McCall    }
889b870b88df784c2940efce448ebfaf54dece14666John McCall  };
890d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  enum { NumTypeBits = 17 };
891b870b88df784c2940efce448ebfaf54dece14666John McCall
892b870b88df784c2940efce448ebfaf54dece14666John McCallprotected:
893b870b88df784c2940efce448ebfaf54dece14666John McCall  // These classes allow subclasses to somewhat cleanly pack bitfields
894b870b88df784c2940efce448ebfaf54dece14666John McCall  // into Type.
895b870b88df784c2940efce448ebfaf54dece14666John McCall
896b870b88df784c2940efce448ebfaf54dece14666John McCall  class ArrayTypeBitfields {
897b870b88df784c2940efce448ebfaf54dece14666John McCall    friend class ArrayType;
898b870b88df784c2940efce448ebfaf54dece14666John McCall
899b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned : NumTypeBits;
900b870b88df784c2940efce448ebfaf54dece14666John McCall
901b870b88df784c2940efce448ebfaf54dece14666John McCall    /// IndexTypeQuals - CVR qualifiers from declarations like
902b870b88df784c2940efce448ebfaf54dece14666John McCall    /// 'int X[static restrict 4]'. For function parameters only.
903b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned IndexTypeQuals : 3;
904b870b88df784c2940efce448ebfaf54dece14666John McCall
905b870b88df784c2940efce448ebfaf54dece14666John McCall    /// SizeModifier - storage class qualifiers from declarations like
906b870b88df784c2940efce448ebfaf54dece14666John McCall    /// 'int X[static restrict 4]'. For function parameters only.
907b870b88df784c2940efce448ebfaf54dece14666John McCall    /// Actually an ArrayType::ArraySizeModifier.
908b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned SizeModifier : 3;
909b870b88df784c2940efce448ebfaf54dece14666John McCall  };
910b870b88df784c2940efce448ebfaf54dece14666John McCall
911b870b88df784c2940efce448ebfaf54dece14666John McCall  class BuiltinTypeBitfields {
912b870b88df784c2940efce448ebfaf54dece14666John McCall    friend class BuiltinType;
913b870b88df784c2940efce448ebfaf54dece14666John McCall
914b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned : NumTypeBits;
915b870b88df784c2940efce448ebfaf54dece14666John McCall
916b870b88df784c2940efce448ebfaf54dece14666John McCall    /// The kind (BuiltinType::Kind) of builtin type this is.
917b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned Kind : 8;
918b870b88df784c2940efce448ebfaf54dece14666John McCall  };
919b870b88df784c2940efce448ebfaf54dece14666John McCall
920b870b88df784c2940efce448ebfaf54dece14666John McCall  class FunctionTypeBitfields {
921b870b88df784c2940efce448ebfaf54dece14666John McCall    friend class FunctionType;
922b870b88df784c2940efce448ebfaf54dece14666John McCall
923b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned : NumTypeBits;
924b870b88df784c2940efce448ebfaf54dece14666John McCall
925b870b88df784c2940efce448ebfaf54dece14666John McCall    /// Extra information which affects how the function is called, like
926b870b88df784c2940efce448ebfaf54dece14666John McCall    /// regparm and the calling convention.
927b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned ExtInfo : 8;
928b870b88df784c2940efce448ebfaf54dece14666John McCall
929e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall    /// Whether the function is variadic.  Only used by FunctionProtoType.
930e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall    unsigned Variadic : 1;
931b870b88df784c2940efce448ebfaf54dece14666John McCall
932b870b88df784c2940efce448ebfaf54dece14666John McCall    /// TypeQuals - Used only by FunctionProtoType, put here to pack with the
933b870b88df784c2940efce448ebfaf54dece14666John McCall    /// other bitfields.
934b870b88df784c2940efce448ebfaf54dece14666John McCall    /// The qualifiers are part of FunctionProtoType because...
935b870b88df784c2940efce448ebfaf54dece14666John McCall    ///
936b870b88df784c2940efce448ebfaf54dece14666John McCall    /// C++ 8.3.5p4: The return type, the parameter type list and the
937b870b88df784c2940efce448ebfaf54dece14666John McCall    /// cv-qualifier-seq, [...], are part of the function type.
938b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned TypeQuals : 3;
939b870b88df784c2940efce448ebfaf54dece14666John McCall  };
940b870b88df784c2940efce448ebfaf54dece14666John McCall
941b870b88df784c2940efce448ebfaf54dece14666John McCall  class ObjCObjectTypeBitfields {
942b870b88df784c2940efce448ebfaf54dece14666John McCall    friend class ObjCObjectType;
943b870b88df784c2940efce448ebfaf54dece14666John McCall
944b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned : NumTypeBits;
945b870b88df784c2940efce448ebfaf54dece14666John McCall
946b870b88df784c2940efce448ebfaf54dece14666John McCall    /// NumProtocols - The number of protocols stored directly on this
947b870b88df784c2940efce448ebfaf54dece14666John McCall    /// object type.
948b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned NumProtocols : 32 - NumTypeBits;
949b870b88df784c2940efce448ebfaf54dece14666John McCall  };
950b870b88df784c2940efce448ebfaf54dece14666John McCall
951b870b88df784c2940efce448ebfaf54dece14666John McCall  class ReferenceTypeBitfields {
952b870b88df784c2940efce448ebfaf54dece14666John McCall    friend class ReferenceType;
953b870b88df784c2940efce448ebfaf54dece14666John McCall
954b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned : NumTypeBits;
955b870b88df784c2940efce448ebfaf54dece14666John McCall
956b870b88df784c2940efce448ebfaf54dece14666John McCall    /// True if the type was originally spelled with an lvalue sigil.
957b870b88df784c2940efce448ebfaf54dece14666John McCall    /// This is never true of rvalue references but can also be false
958b870b88df784c2940efce448ebfaf54dece14666John McCall    /// on lvalue references because of C++0x [dcl.typedef]p9,
959b870b88df784c2940efce448ebfaf54dece14666John McCall    /// as follows:
960b870b88df784c2940efce448ebfaf54dece14666John McCall    ///
961b870b88df784c2940efce448ebfaf54dece14666John McCall    ///   typedef int &ref;    // lvalue, spelled lvalue
962b870b88df784c2940efce448ebfaf54dece14666John McCall    ///   typedef int &&rvref; // rvalue
963b870b88df784c2940efce448ebfaf54dece14666John McCall    ///   ref &a;              // lvalue, inner ref, spelled lvalue
964b870b88df784c2940efce448ebfaf54dece14666John McCall    ///   ref &&a;             // lvalue, inner ref
965b870b88df784c2940efce448ebfaf54dece14666John McCall    ///   rvref &a;            // lvalue, inner ref, spelled lvalue
966b870b88df784c2940efce448ebfaf54dece14666John McCall    ///   rvref &&a;           // rvalue, inner ref
967bdb5b0e8ad8ed297ad01eb2ccd0d6d5ed6058033Francois Pichet    unsigned SpelledAsLValue : 1;
968b870b88df784c2940efce448ebfaf54dece14666John McCall
969b870b88df784c2940efce448ebfaf54dece14666John McCall    /// True if the inner type is a reference type.  This only happens
970b870b88df784c2940efce448ebfaf54dece14666John McCall    /// in non-canonical forms.
971bdb5b0e8ad8ed297ad01eb2ccd0d6d5ed6058033Francois Pichet    unsigned InnerRef : 1;
972b870b88df784c2940efce448ebfaf54dece14666John McCall  };
973b870b88df784c2940efce448ebfaf54dece14666John McCall
97477be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall  class TypeWithKeywordBitfields {
97577be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall    friend class TypeWithKeyword;
97677be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall
97777be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall    unsigned : NumTypeBits;
97877be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall
97977be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall    /// An ElaboratedTypeKeyword.  8 bits for efficient access.
98077be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall    unsigned Keyword : 8;
98177be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall  };
98277be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall
983b870b88df784c2940efce448ebfaf54dece14666John McCall  class VectorTypeBitfields {
984b870b88df784c2940efce448ebfaf54dece14666John McCall    friend class VectorType;
98507a353c2af3a3c557205466d4f4ed2513462ebfeSebastian Redl
986b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned : NumTypeBits;
98771c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall
988e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson    /// VecKind - The kind of vector, either a generic vector type or some
989e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson    /// target-specific vector type such as for AltiVec or Neon.
990cc3b946c35c4372272034e6f0663089477a9a5bdBob Wilson    unsigned VecKind : 3;
991b870b88df784c2940efce448ebfaf54dece14666John McCall
992b870b88df784c2940efce448ebfaf54dece14666John McCall    /// NumElements - The number of elements in the vector.
993cc3b946c35c4372272034e6f0663089477a9a5bdBob Wilson    unsigned NumElements : 29 - NumTypeBits;
994b870b88df784c2940efce448ebfaf54dece14666John McCall  };
995b870b88df784c2940efce448ebfaf54dece14666John McCall
996b870b88df784c2940efce448ebfaf54dece14666John McCall  union {
997b870b88df784c2940efce448ebfaf54dece14666John McCall    TypeBitfields TypeBits;
998b870b88df784c2940efce448ebfaf54dece14666John McCall    ArrayTypeBitfields ArrayTypeBits;
999b870b88df784c2940efce448ebfaf54dece14666John McCall    BuiltinTypeBitfields BuiltinTypeBits;
1000b870b88df784c2940efce448ebfaf54dece14666John McCall    FunctionTypeBitfields FunctionTypeBits;
1001b870b88df784c2940efce448ebfaf54dece14666John McCall    ObjCObjectTypeBitfields ObjCObjectTypeBits;
1002b870b88df784c2940efce448ebfaf54dece14666John McCall    ReferenceTypeBitfields ReferenceTypeBits;
100377be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall    TypeWithKeywordBitfields TypeWithKeywordBits;
1004b870b88df784c2940efce448ebfaf54dece14666John McCall    VectorTypeBitfields VectorTypeBits;
1005b870b88df784c2940efce448ebfaf54dece14666John McCall  };
1006b870b88df784c2940efce448ebfaf54dece14666John McCall
1007b870b88df784c2940efce448ebfaf54dece14666John McCallprivate:
10083c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief Set whether this type comes from an AST file.
10093c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  void setFromAST(bool V = true) const {
1010b870b88df784c2940efce448ebfaf54dece14666John McCall    TypeBits.FromAST = V;
101107a353c2af3a3c557205466d4f4ed2513462ebfeSebastian Redl  }
101207a353c2af3a3c557205466d4f4ed2513462ebfeSebastian Redl
1013b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall  template <class T> friend class TypePropertyCache;
10141fb0caaa7bef765b85972274e3b434af2572c141John McCall
10155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprotected:
1016124dd7b5777e29ecac006822bd4d4623f0dc4264Hartmut Kaiser  // silence VC++ warning C4355: 'this' : used in base member initializer list
1017124dd7b5777e29ecac006822bd4d4623f0dc4264Hartmut Kaiser  Type *this_() { return this; }
1018d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  Type(TypeClass tc, QualType Canonical, bool Dependent, bool VariablyModified,
1019d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor       bool ContainsUnexpandedParameterPack)
10201ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor    : ExtQualsTypeCommonBase(this),
10211ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor      CanonicalType(Canonical.isNull() ? QualType(this_(), 0) : Canonical) {
1022b870b88df784c2940efce448ebfaf54dece14666John McCall    TypeBits.TC = tc;
1023b870b88df784c2940efce448ebfaf54dece14666John McCall    TypeBits.Dependent = Dependent;
1024b870b88df784c2940efce448ebfaf54dece14666John McCall    TypeBits.VariablyModified = VariablyModified;
1025d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    TypeBits.ContainsUnexpandedParameterPack = ContainsUnexpandedParameterPack;
10261fb0caaa7bef765b85972274e3b434af2572c141John McCall    TypeBits.CacheValidAndVisibility = 0;
1027b870b88df784c2940efce448ebfaf54dece14666John McCall    TypeBits.CachedLocalOrUnnamed = false;
1028b870b88df784c2940efce448ebfaf54dece14666John McCall    TypeBits.CachedLinkage = NoLinkage;
1029b870b88df784c2940efce448ebfaf54dece14666John McCall    TypeBits.FromAST = false;
1030b870b88df784c2940efce448ebfaf54dece14666John McCall  }
10315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;
10321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1033b870b88df784c2940efce448ebfaf54dece14666John McCall  void setDependent(bool D = true) { TypeBits.Dependent = D; }
1034b870b88df784c2940efce448ebfaf54dece14666John McCall  void setVariablyModified(bool VM = true) { TypeBits.VariablyModified = VM; }
1035d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  void setContainsUnexpandedParameterPack(bool PP = true) {
1036d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    TypeBits.ContainsUnexpandedParameterPack = PP;
1037d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  }
1038d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor
10398b9023ba35a86838789e2c9034a6128728c547aaChris Lattnerpublic:
1040b870b88df784c2940efce448ebfaf54dece14666John McCall  TypeClass getTypeClass() const { return static_cast<TypeClass>(TypeBits.TC); }
10411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
10423c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief Whether this type comes from an AST file.
1043b870b88df784c2940efce448ebfaf54dece14666John McCall  bool isFromAST() const { return TypeBits.FromAST; }
104407a353c2af3a3c557205466d4f4ed2513462ebfeSebastian Redl
1045d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// \brief Whether this type is or contains an unexpanded parameter
1046d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// pack, used to support C++0x variadic templates.
1047d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  ///
1048d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// A type that contains a parameter pack shall be expanded by the
1049d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// ellipsis operator at some point. For example, the typedef in the
1050d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// following example contains an unexpanded parameter pack 'T':
1051d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  ///
1052d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// \code
1053d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// template<typename ...T>
1054d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// struct X {
1055d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  ///   typedef T* pointer_types; // ill-formed; T is a parameter pack.
1056d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// };
1057d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// \endcode
1058d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  ///
1059d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// Note that this routine does not specify which
1060d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  bool containsUnexpandedParameterPack() const {
1061d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    return TypeBits.ContainsUnexpandedParameterPack;
1062d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  }
1063d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor
1064467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall  bool isCanonicalUnqualified() const {
1065467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall    return CanonicalType.getTypePtr() == this;
1066467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall  }
10675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
10681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// Types are partitioned into 3 broad categories (C99 6.2.5p1):
10695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// object types, function types, and incomplete types.
10701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
10715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isIncompleteType - Return true if this is an incomplete type.
10725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// A type that can describe objects, but which lacks information needed to
10735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// determine its size (e.g. void, or a fwd declared struct). Clients of this
10741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// routine will need to determine if the size is actually required.
10755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isIncompleteType() const;
1076d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner
1077d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner  /// isIncompleteOrObjectType - Return true if this is an incomplete or object
1078d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner  /// type, in other words, not a function type.
1079d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner  bool isIncompleteOrObjectType() const {
1080d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner    return !isFunctionType();
1081d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner  }
108264b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
108364b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  /// isPODType - Return true if this is a plain-old-data type (C++ 3.9p10).
108464b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  bool isPODType() const;
108564b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
1086ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl  /// isLiteralType - Return true if this is a literal type
1087ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl  /// (C++0x [basic.types]p10)
1088ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl  bool isLiteralType() const;
1089ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl
10905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// Helper methods to distinguish type categories. All type predicates
1091ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb  /// operate on the canonical type, ignoring typedefs and qualifiers.
1092e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar
10939b065ddabf572772991a4aadad5bf4921fac5069Tom Care  /// isBuiltinType - returns true if the type is a builtin type.
10949b065ddabf572772991a4aadad5bf4921fac5069Tom Care  bool isBuiltinType() const;
10959b065ddabf572772991a4aadad5bf4921fac5069Tom Care
1096e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar  /// isSpecificBuiltinType - Test for a particular builtin type.
1097e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar  bool isSpecificBuiltinType(unsigned K) const;
10981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
10992a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  /// isPlaceholderType - Test for a type which does not represent an
11002a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  /// actual type-system type but is instead used as a placeholder for
11012a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  /// various convenient purposes within Clang.  All such types are
11022a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  /// BuiltinTypes.
11032a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  bool isPlaceholderType() const;
11042a984cad5ac3fdceeff2bd99daa7b90979313475John McCall
110596d2c438f5c9ada8229f7f2ac049d2e9957bc954Steve Naroff  /// isIntegerType() does *not* include complex integers (a GCC extension).
110696d2c438f5c9ada8229f7f2ac049d2e9957bc954Steve Naroff  /// isComplexIntegerType() can be used to test for complex integers.
11075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isIntegerType() const;     // C99 6.2.5p17 (int, char, bool, enum)
110813b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff  bool isEnumeralType() const;
110913b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff  bool isBooleanType() const;
111013b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff  bool isCharType() const;
111177a52233f7c0f162672652051bfe78b65ad4f789Douglas Gregor  bool isWideCharType() const;
111220093b4bf698f292c664676987541d5103b65b15Douglas Gregor  bool isAnyCharacterType() const;
11139d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor  bool isIntegralType(ASTContext &Ctx) const;
111420093b4bf698f292c664676987541d5103b65b15Douglas Gregor
11152ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor  /// \brief Determine whether this type is an integral or enumeration type.
11162ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor  bool isIntegralOrEnumerationType() const;
11171274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor  /// \brief Determine whether this type is an integral or unscoped enumeration
11181274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor  /// type.
11191274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor  bool isIntegralOrUnscopedEnumerationType() const;
11202ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor
11215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// Floating point categories.
11225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isRealFloatingType() const; // C99 6.2.5p10 (float, double, long double)
112302f62a9fedbc370fba081303399410a3afdde29fSteve Naroff  /// isComplexType() does *not* include complex integers (a GCC extension).
112402f62a9fedbc370fba081303399410a3afdde29fSteve Naroff  /// isComplexIntegerType() can be used to test for complex integers.
11255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isComplexType() const;      // C99 6.2.5p11 (complex)
1126f23d364084d1aabea688222780d6fc1dd8c7f78cChris Lattner  bool isAnyComplexType() const;   // C99 6.2.5p11 (complex) + Complex Int.
11275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isFloatingType() const;     // C99 6.2.5p11 (real floating + complex)
11285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isRealType() const;         // C99 6.2.5p17 (real floating + integer)
11295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isArithmeticType() const;   // C99 6.2.5p18 (integer + floating)
1130c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  bool isVoidType() const;         // C99 6.2.5p19
1131c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  bool isDerivedType() const;      // C99 6.2.5p20
1132c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  bool isScalarType() const;       // C99 6.2.5p21 (arithmetic + pointers)
1133d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor  bool isAggregateType() const;
11341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1135c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  // Type Predicates: Check to see if this type is structurally the specified
1136ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb  // type, ignoring typedefs and qualifiers.
1137c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  bool isFunctionType() const;
1138183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  bool isFunctionNoProtoType() const { return getAs<FunctionNoProtoType>(); }
1139183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  bool isFunctionProtoType() const { return getAs<FunctionProtoType>(); }
1140befee48ff2a1dab236c5700f00ecca1cfdcd5837Chris Lattner  bool isPointerType() const;
114158f9f2c884af6b72d036b746a016d8031d31cb7aSteve Naroff  bool isAnyPointerType() const;   // Any C pointer or ObjC object pointer
11425618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  bool isBlockPointerType() const;
11437154a77e7c1f23418342d3b72836ab504aa7821eSteve Naroff  bool isVoidPointerType() const;
1144a1d9fdea79ba7bbd71862b9f9f78f5f117331fc7Chris Lattner  bool isReferenceType() const;
11457c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  bool isLValueReferenceType() const;
11467c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  bool isRValueReferenceType() const;
1147bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner  bool isFunctionPointerType() const;
1148f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  bool isMemberPointerType() const;
1149f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  bool isMemberFunctionPointerType() const;
1150db68e28c05a67735211e688009890cf834c22e75Douglas Gregor  bool isMemberDataPointerType() const;
1151c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  bool isArrayType() const;
1152c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  bool isConstantArrayType() const;
1153c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  bool isIncompleteArrayType() const;
1154c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  bool isVariableArrayType() const;
1155898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  bool isDependentSizedArrayType() const;
1156c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  bool isRecordType() const;
11571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  bool isClassType() const;
11581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  bool isStructureType() const;
1159fb87b89fc9eb103e19fb8e4b925c23f0bd091b99Douglas Gregor  bool isStructureOrClassType() const;
11604cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroff  bool isUnionType() const;
1161368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner  bool isComplexIntegerType() const;            // GCC _Complex integer type.
1162368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner  bool isVectorType() const;                    // GCC vector type.
1163213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman  bool isExtVectorType() const;                 // Extended vector type.
1164d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff  bool isObjCObjectPointerType() const;         // Pointer to *any* ObjC object.
116514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  // FIXME: change this to 'raw' interface type, so we can used 'interface' type
116614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  // for the common case.
1167c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool isObjCObjectType() const;                // NSString or typeof(*(id)0)
1168368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner  bool isObjCQualifiedInterfaceType() const;    // NSString<foo>
1169368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner  bool isObjCQualifiedIdType() const;           // id<foo>
1170470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroff  bool isObjCQualifiedClassType() const;        // Class<foo>
1171569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor  bool isObjCObjectOrInterfaceType() const;
117214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  bool isObjCIdType() const;                    // id
117314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  bool isObjCClassType() const;                 // Class
117413dcd00615de5c4279d97bdf63cd5f0a14fd9dccFariborz Jahanian  bool isObjCSelType() const;                 // Class
1175de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff  bool isObjCBuiltinType() const;               // 'id' or 'Class'
117672c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor  bool isTemplateTypeParmType() const;          // C++ template type parameter
11776e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl  bool isNullPtrType() const;                   // C++0x nullptr_t
1178898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
1179daa8e4e888758d55a7a759dd4a91b83921cef222John McCall  enum ScalarTypeKind {
1180daa8e4e888758d55a7a759dd4a91b83921cef222John McCall    STK_Pointer,
1181daa8e4e888758d55a7a759dd4a91b83921cef222John McCall    STK_MemberPointer,
1182daa8e4e888758d55a7a759dd4a91b83921cef222John McCall    STK_Bool,
1183daa8e4e888758d55a7a759dd4a91b83921cef222John McCall    STK_Integral,
1184daa8e4e888758d55a7a759dd4a91b83921cef222John McCall    STK_Floating,
1185daa8e4e888758d55a7a759dd4a91b83921cef222John McCall    STK_IntegralComplex,
1186daa8e4e888758d55a7a759dd4a91b83921cef222John McCall    STK_FloatingComplex
1187daa8e4e888758d55a7a759dd4a91b83921cef222John McCall  };
1188daa8e4e888758d55a7a759dd4a91b83921cef222John McCall  /// getScalarTypeKind - Given that this is a scalar type, classify it.
1189daa8e4e888758d55a7a759dd4a91b83921cef222John McCall  ScalarTypeKind getScalarTypeKind() const;
1190daa8e4e888758d55a7a759dd4a91b83921cef222John McCall
1191898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// isDependentType - Whether this type is a dependent type, meaning
11921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// that its definition somehow depends on a template parameter
1193898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// (C++ [temp.dep.type]).
1194b870b88df784c2940efce448ebfaf54dece14666John McCall  bool isDependentType() const { return TypeBits.Dependent; }
119535495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor
119635495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor  /// \brief Whether this type is a variably-modified type (C99 6.7.5).
1197b870b88df784c2940efce448ebfaf54dece14666John McCall  bool isVariablyModifiedType() const { return TypeBits.VariablyModified; }
119835495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor
1199db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor  /// \brief Whether this type is or contains a local or unnamed type.
1200db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor  bool hasUnnamedOrLocalType() const;
1201db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor
1202063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  bool isOverloadableType() const;
120372c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor
12044033642464e8ba0982f88f34cffad808d247b393Douglas Gregor  /// \brief Determine wither this type is a C++ elaborated-type-specifier.
12054033642464e8ba0982f88f34cffad808d247b393Douglas Gregor  bool isElaboratedTypeSpecifier() const;
12064033642464e8ba0982f88f34cffad808d247b393Douglas Gregor
12078958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar  /// hasPointerRepresentation - Whether this type is represented
12088958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar  /// natively as a pointer; this includes pointers, references, block
12098958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar  /// pointers, and Objective-C interface, qualified id, and qualified
12106e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl  /// interface types, as well as nullptr_t.
12118958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar  bool hasPointerRepresentation() const;
12128958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar
1213820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian  /// hasObjCPointerRepresentation - Whether this type can represent
1214820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian  /// an objective pointer type for the purpose of GC'ability
12151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  bool hasObjCPointerRepresentation() const;
1216820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian
1217f60946222721d9ba3c059563935c17b84703187aDouglas Gregor  /// \brief Determine whether this type has an integer representation
1218f60946222721d9ba3c059563935c17b84703187aDouglas Gregor  /// of some sort, e.g., it is an integer type or a vector.
1219f60946222721d9ba3c059563935c17b84703187aDouglas Gregor  bool hasIntegerRepresentation() const;
1220f60946222721d9ba3c059563935c17b84703187aDouglas Gregor
1221f60946222721d9ba3c059563935c17b84703187aDouglas Gregor  /// \brief Determine whether this type has an signed integer representation
1222f60946222721d9ba3c059563935c17b84703187aDouglas Gregor  /// of some sort, e.g., it is an signed integer type or a vector.
1223f60946222721d9ba3c059563935c17b84703187aDouglas Gregor  bool hasSignedIntegerRepresentation() const;
1224f60946222721d9ba3c059563935c17b84703187aDouglas Gregor
1225f60946222721d9ba3c059563935c17b84703187aDouglas Gregor  /// \brief Determine whether this type has an unsigned integer representation
1226f60946222721d9ba3c059563935c17b84703187aDouglas Gregor  /// of some sort, e.g., it is an unsigned integer type or a vector.
1227f60946222721d9ba3c059563935c17b84703187aDouglas Gregor  bool hasUnsignedIntegerRepresentation() const;
1228f60946222721d9ba3c059563935c17b84703187aDouglas Gregor
12298eee119bf4f1693dde17b8552c1f9f81bf2b681eDouglas Gregor  /// \brief Determine whether this type has a floating-point representation
12308eee119bf4f1693dde17b8552c1f9f81bf2b681eDouglas Gregor  /// of some sort, e.g., it is a floating-point type or a vector thereof.
12318eee119bf4f1693dde17b8552c1f9f81bf2b681eDouglas Gregor  bool hasFloatingRepresentation() const;
1232f60946222721d9ba3c059563935c17b84703187aDouglas Gregor
1233c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  // Type Checking Functions: Check to see if this type is structurally the
1234f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner  // specified type, ignoring typedefs and qualifiers, and return a pointer to
1235f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner  // the best type we can.
1236769c9cfc6e06bd9d8ffe7a4397b939f19b0e4dc3Ted Kremenek  const RecordType *getAsStructureType() const;
1237898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// NOTE: getAs*ArrayType are methods on ASTContext.
1238c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  const RecordType *getAsUnionType() const;
12394cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroff  const ComplexType *getAsComplexIntegerType() const; // GCC complex int type.
124014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  // The following is a convenience method that returns an ObjCObjectPointerType
124114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  // for object declared using an interface.
124214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  const ObjCObjectPointerType *getAsObjCInterfacePointerType() const;
124314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  const ObjCObjectPointerType *getAsObjCQualifiedIdType() const;
1244c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  const ObjCObjectType *getAsObjCQualifiedInterfaceType() const;
1245a91d6a6619a91d0ca7102d8ab5678d855f04d850Fariborz Jahanian  const CXXRecordDecl *getCXXRecordDeclForPointerType() const;
12461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1247c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor  /// \brief Retrieves the CXXRecordDecl that this type refers to, either
1248c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor  /// because the type is a RecordType or because it is the injected-class-name
1249c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor  /// type of a class template or class template partial specialization.
1250c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor  CXXRecordDecl *getAsCXXRecordDecl() const;
1251c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor
1252fa78c91c54dd99ec61a9e27e6b74a549f5c9fa9cDan Gohman  // Member-template getAs<specific type>'.  Look through sugar for
1253fa78c91c54dd99ec61a9e27e6b74a549f5c9fa9cDan Gohman  // an instance of <specific type>.   This scheme will eventually
12541a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek  // replace the specific getAsXXXX methods above.
1255183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  //
1256183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  // There are some specializations of this member template listed
1257183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  // immediately following this class.
12581a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek  template <typename T> const T *getAs() const;
12591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1260c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  /// getArrayElementTypeNoTypeQual - If this is an array type, return the
1261c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  /// element type of the array, potentially with type qualifiers missing.
1262c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  /// This method should never be used when type qualifiers are meaningful.
1263c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  const Type *getArrayElementTypeNoTypeQual() const;
12641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1265f8910df57799256c1897a8610dc52685729ae90eSteve Naroff  /// getPointeeType - If this is a pointer, ObjC object pointer, or block
1266f8910df57799256c1897a8610dc52685729ae90eSteve Naroff  /// pointer, this returns the respective pointee.
126714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  QualType getPointeeType() const;
12681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1269bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// getUnqualifiedDesugaredType() - Return the specified type with
1270bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// any "sugar" removed from the type, removing any typedefs,
1271bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// typeofs, etc., as well as any qualifiers.
1272bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  const Type *getUnqualifiedDesugaredType() const;
12731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// More type predicates useful for type checking/promotion
12755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isPromotableIntegerType() const; // C99 6.3.1.1p2
12765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
12775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isSignedIntegerType - Return true if this is an integer type that is
1278d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner  /// signed, according to C99 6.2.5p4 [char, signed char, short, int, long..],
1279d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner  /// an enum decl which has a signed representation, or a vector of signed
1280d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner  /// integer element type.
12815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isSignedIntegerType() const;
12825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
12835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isUnsignedIntegerType - Return true if this is an integer type that is
1284d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner  /// unsigned, according to C99 6.2.5p6 [which returns true for _Bool], an enum
1285d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner  /// decl which has an unsigned representation, or a vector of unsigned integer
1286d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner  /// element type.
12875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isUnsignedIntegerType() const;
1288d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner
12895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isConstantSizeType - Return true if this is not a variable sized type,
12909bfa73c5ab7bf4b0e749d04f29da6884e8d5bd9fChris Lattner  /// according to the rules of C99 6.7.5p3.  It is not legal to call this on
12919bfa73c5ab7bf4b0e749d04f29da6884e8d5bd9fChris Lattner  /// incomplete types.
12923c2b3170041f69a92904e3bab9b6d654eaf260acEli Friedman  bool isConstantSizeType() const;
1293c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner
129422b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman  /// isSpecifierType - Returns true if this type can be represented by some
129522b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman  /// set of type specifiers.
129622b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman  bool isSpecifierType() const;
129722b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman
12980b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor  /// \brief Determine the linkage of this type.
129960e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor  Linkage getLinkage() const;
13001fb0caaa7bef765b85972274e3b434af2572c141John McCall
13011fb0caaa7bef765b85972274e3b434af2572c141John McCall  /// \brief Determine the visibility of this type.
13021fb0caaa7bef765b85972274e3b434af2572c141John McCall  Visibility getVisibility() const;
13031fb0caaa7bef765b85972274e3b434af2572c141John McCall
13041fb0caaa7bef765b85972274e3b434af2572c141John McCall  /// \brief Determine the linkage and visibility of this type.
13051fb0caaa7bef765b85972274e3b434af2572c141John McCall  std::pair<Linkage,Visibility> getLinkageAndVisibility() const;
130660e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
130760e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor  /// \brief Note that the linkage is no longer known.
130860e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor  void ClearLinkageCache();
130960e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
131060e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor  const char *getTypeClassName() const;
13110b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor
1312ead608af31b6c9abeae1ca6d0b75094dac4641c0John McCall  QualType getCanonicalTypeInternal() const {
1313ead608af31b6c9abeae1ca6d0b75094dac4641c0John McCall    return CanonicalType;
1314ead608af31b6c9abeae1ca6d0b75094dac4641c0John McCall  }
1315ead608af31b6c9abeae1ca6d0b75094dac4641c0John McCall  CanQualType getCanonicalTypeUnqualified() const; // in CanonicalType.h
1316c36d405a02fab41f6c45cb2bc750d64949742903Chris Lattner  void dump() const;
13175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *) { return true; }
1318be191100e034b23a3e13053757a57b7f5068c24aArgyrios Kyrtzidis
1319c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl  friend class ASTReader;
1320a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian Redl  friend class ASTWriter;
13215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
13225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1323183700f494ec9b6701b6efe82bcb25f4c79ba561John McCalltemplate <> inline const TypedefType *Type::getAs() const {
1324183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  return dyn_cast<TypedefType>(this);
1325183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall}
1326183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall
1327183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall// We can do canonical leaf types faster, because we don't have to
1328183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall// worry about preserving child type decoration.
1329183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall#define TYPE(Class, Base)
1330183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall#define LEAF_TYPE(Class) \
1331183700f494ec9b6701b6efe82bcb25f4c79ba561John McCalltemplate <> inline const Class##Type *Type::getAs() const { \
13320953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  return dyn_cast<Class##Type>(CanonicalType); \
1333183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall}
1334183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall#include "clang/AST/TypeNodes.def"
1335183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall
1336183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall
13375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// BuiltinType - This class is used for builtin types like 'int'.  Builtin
13385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// types are always canonical and have a literal name field.
13395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass BuiltinType : public Type {
13405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
13415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  enum Kind {
13425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Void,
13431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
13445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Bool,     // This is bool and/or _Bool.
13455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Char_U,   // This is 'char' for targets where char is unsigned.
13465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    UChar,    // This is explicitly qualified unsigned char.
1347f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith    Char16,   // This is 'char16_t' for C++.
1348f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith    Char32,   // This is 'char32_t' for C++.
13495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    UShort,
13505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    UInt,
13515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ULong,
13525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ULongLong,
13532df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner    UInt128,  // __uint128_t
13541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
13555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Char_S,   // This is 'char' for targets where char is signed.
13565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    SChar,    // This is explicitly qualified signed char.
13572ff9b4c7c8fed9233a0b8de2e9507368c451aab6Argyrios Kyrtzidis    WChar,    // This is 'wchar_t' for C++.
13585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Short,
13595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Int,
13605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Long,
13615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    LongLong,
13622df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner    Int128,   // __int128_t
13631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
13648e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor    Float, Double, LongDouble,
13658e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor
13666e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl    NullPtr,  // This is the type of C++0x 'nullptr'.
13676e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl
13682a984cad5ac3fdceeff2bd99daa7b90979313475John McCall    /// This represents the type of an expression whose type is
13692a984cad5ac3fdceeff2bd99daa7b90979313475John McCall    /// totally unknown, e.g. 'T::foo'.  It is permitted for this to
13702a984cad5ac3fdceeff2bd99daa7b90979313475John McCall    /// appear in situations where the structure of the type is
13712a984cad5ac3fdceeff2bd99daa7b90979313475John McCall    /// theoretically deducible.
13722a984cad5ac3fdceeff2bd99daa7b90979313475John McCall    Dependent,
13732a984cad5ac3fdceeff2bd99daa7b90979313475John McCall
1374898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    Overload,  // This represents the type of an overloaded function declaration.
13751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1376de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff    UndeducedAuto, // In C++0x, this represents the type of an auto variable
1377e89d15944dd3be750a09805ad21222d2fa9321faAnders Carlsson                   // that has not been deduced yet.
1378e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall
1379e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall    /// The primitive Objective C 'id' type.  The type pointed to by the
1380e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall    /// user-visible 'id' type.  Only ever shows up in an AST as the base
1381e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall    /// type of an ObjCObjectType.
1382e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall    ObjCId,
1383e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall
1384e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall    /// The primitive Objective C 'Class' type.  The type pointed to by the
1385e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall    /// user-visible 'Class' type.  Only ever shows up in an AST as the
1386e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall    /// base type of an ObjCObjectType.
1387e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall    ObjCClass,
1388e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall
138913dcd00615de5c4279d97bdf63cd5f0a14fd9dccFariborz Jahanian    ObjCSel    // This represents the ObjC 'SEL' type.
13905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
139171c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall
13925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
13931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  BuiltinType(Kind K)
139435495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    : Type(Builtin, QualType(), /*Dependent=*/(K == Dependent),
1395d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor           /*VariablyModified=*/false,
1396d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor           /*Unexpanded paramter pack=*/false) {
1397b870b88df784c2940efce448ebfaf54dece14666John McCall    BuiltinTypeBits.Kind = K;
139871c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  }
13991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1400b870b88df784c2940efce448ebfaf54dece14666John McCall  Kind getKind() const { return static_cast<Kind>(BuiltinTypeBits.Kind); }
1401e4f2142d00fa5fdb580c4e2413da91882d955381Chris Lattner  const char *getName(const LangOptions &LO) const;
14021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1403bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1404bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1405bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
1406680523a91dd3351389667c8de17121ba7ae82673John McCall  bool isInteger() const {
140771c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    return getKind() >= Bool && getKind() <= Int128;
1408680523a91dd3351389667c8de17121ba7ae82673John McCall  }
1409680523a91dd3351389667c8de17121ba7ae82673John McCall
1410680523a91dd3351389667c8de17121ba7ae82673John McCall  bool isSignedInteger() const {
141171c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    return getKind() >= Char_S && getKind() <= Int128;
1412680523a91dd3351389667c8de17121ba7ae82673John McCall  }
1413680523a91dd3351389667c8de17121ba7ae82673John McCall
1414680523a91dd3351389667c8de17121ba7ae82673John McCall  bool isUnsignedInteger() const {
141571c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    return getKind() >= Bool && getKind() <= UInt128;
1416680523a91dd3351389667c8de17121ba7ae82673John McCall  }
1417680523a91dd3351389667c8de17121ba7ae82673John McCall
1418680523a91dd3351389667c8de17121ba7ae82673John McCall  bool isFloatingPoint() const {
141971c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    return getKind() >= Float && getKind() <= LongDouble;
1420680523a91dd3351389667c8de17121ba7ae82673John McCall  }
1421680523a91dd3351389667c8de17121ba7ae82673John McCall
14222a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  /// Determines whether this type is a "forbidden" placeholder type,
14232a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  /// i.e. a type which cannot appear in arbitrary positions in a
14242a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  /// fully-formed expression.
14252a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  bool isPlaceholderType() const {
142671c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    return getKind() == Overload ||
142771c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall           getKind() == UndeducedAuto;
14282a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  }
14292a984cad5ac3fdceeff2bd99daa7b90979313475John McCall
14305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T) { return T->getTypeClass() == Builtin; }
14315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const BuiltinType *) { return true; }
14325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
14335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
14345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ComplexType - C99 6.2.5p11 - Complex values.  This supports the C99 complex
14355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// types (_Complex float etc) as well as the GCC integer complex extensions.
14365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
14375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ComplexType : public Type, public llvm::FoldingSetNode {
14385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType ElementType;
14395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ComplexType(QualType Element, QualType CanonicalPtr) :
144035495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    Type(Complex, CanonicalPtr, Element->isDependentType(),
1441d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor         Element->isVariablyModifiedType(),
1442d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor         Element->containsUnexpandedParameterPack()),
1443898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    ElementType(Element) {
14445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
14455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
144660e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
14475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
14485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType getElementType() const { return ElementType; }
14491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1450bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1451bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1452bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
14535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void Profile(llvm::FoldingSetNodeID &ID) {
14545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Profile(ID, getElementType());
14555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
14565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static void Profile(llvm::FoldingSetNodeID &ID, QualType Element) {
14575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ID.AddPointer(Element.getAsOpaquePtr());
14585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
14591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
14605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T) { return T->getTypeClass() == Complex; }
14615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const ComplexType *) { return true; }
14625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
14635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1464075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara/// ParenType - Sugar for parentheses used when specifying types.
1465075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara///
1466075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnaraclass ParenType : public Type, public llvm::FoldingSetNode {
1467075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  QualType Inner;
1468075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
1469075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  ParenType(QualType InnerType, QualType CanonType) :
1470075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara    Type(Paren, CanonType, InnerType->isDependentType(),
1471d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor         InnerType->isVariablyModifiedType(),
1472d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor         InnerType->containsUnexpandedParameterPack()),
1473075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara    Inner(InnerType) {
1474075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  }
1475075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  friend class ASTContext;  // ASTContext creates these.
1476075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
1477075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnarapublic:
1478075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
1479075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  QualType getInnerType() const { return Inner; }
1480075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
1481075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  bool isSugared() const { return true; }
1482075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  QualType desugar() const { return getInnerType(); }
1483075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
1484075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  void Profile(llvm::FoldingSetNodeID &ID) {
1485075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara    Profile(ID, getInnerType());
1486075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  }
1487075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  static void Profile(llvm::FoldingSetNodeID &ID, QualType Inner) {
1488075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara    Inner.Profile(ID);
1489075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  }
1490075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
1491075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  static bool classof(const Type *T) { return T->getTypeClass() == Paren; }
1492075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  static bool classof(const ParenType *) { return true; }
1493075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara};
1494075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
149568694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar/// PointerType - C99 6.7.5.1 - Pointer Declarators.
1496bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner///
149768694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbarclass PointerType : public Type, public llvm::FoldingSetNode {
1498bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner  QualType PointeeType;
14995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
15005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  PointerType(QualType Pointee, QualType CanonicalPtr) :
150135495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    Type(Pointer, CanonicalPtr, Pointee->isDependentType(),
1502d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor         Pointee->isVariablyModifiedType(),
1503d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor         Pointee->containsUnexpandedParameterPack()),
150435495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    PointeeType(Pointee) {
15055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
15065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
150760e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
15085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
15091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
151068694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar  QualType getPointeeType() const { return PointeeType; }
151168694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar
1512bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1513bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1514bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
15155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void Profile(llvm::FoldingSetNodeID &ID) {
15165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Profile(ID, getPointeeType());
15175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
15185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) {
15195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ID.AddPointer(Pointee.getAsOpaquePtr());
15205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
15211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
15225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T) { return T->getTypeClass() == Pointer; }
15235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const PointerType *) { return true; }
15245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
15255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
15265618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff/// BlockPointerType - pointer to a block type.
15275618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff/// This type is to represent types syntactically represented as
15285618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff/// "void (^)(int)", etc. Pointee is required to always be a function type.
15295618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff///
15305618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroffclass BlockPointerType : public Type, public llvm::FoldingSetNode {
15315618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  QualType PointeeType;  // Block is some kind of pointer type
15325618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  BlockPointerType(QualType Pointee, QualType CanonicalCls) :
153335495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    Type(BlockPointer, CanonicalCls, Pointee->isDependentType(),
1534d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor         Pointee->isVariablyModifiedType(),
1535d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor         Pointee->containsUnexpandedParameterPack()),
1536898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    PointeeType(Pointee) {
15375618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  }
15385618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  friend class ASTContext;  // ASTContext creates these.
153960e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
15405618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroffpublic:
15411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
15425618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  // Get the pointee type. Pointee is required to always be a function type.
15435618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  QualType getPointeeType() const { return PointeeType; }
15445618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff
1545bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1546bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1547bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
15485618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  void Profile(llvm::FoldingSetNodeID &ID) {
15495618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff      Profile(ID, getPointeeType());
15505618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  }
15515618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) {
15525618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff      ID.AddPointer(Pointee.getAsOpaquePtr());
15535618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  }
15541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
15551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
15561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == BlockPointer;
15575618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  }
15585618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  static bool classof(const BlockPointerType *) { return true; }
15595618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff};
15605618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff
15617c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// ReferenceType - Base for LValueReferenceType and RValueReferenceType
15625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
156368694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbarclass ReferenceType : public Type, public llvm::FoldingSetNode {
156468694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar  QualType PointeeType;
156568694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar
15667c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlprotected:
156754e14c4db764c0636160d26c5bbf491637c83a76John McCall  ReferenceType(TypeClass tc, QualType Referencee, QualType CanonicalRef,
156854e14c4db764c0636160d26c5bbf491637c83a76John McCall                bool SpelledAsLValue) :
156935495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    Type(tc, CanonicalRef, Referencee->isDependentType(),
1570d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor         Referencee->isVariablyModifiedType(),
1571d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor         Referencee->containsUnexpandedParameterPack()),
1572d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    PointeeType(Referencee)
1573d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  {
1574b870b88df784c2940efce448ebfaf54dece14666John McCall    ReferenceTypeBits.SpelledAsLValue = SpelledAsLValue;
1575b870b88df784c2940efce448ebfaf54dece14666John McCall    ReferenceTypeBits.InnerRef = Referencee->isReferenceType();
15765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
157760e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
15785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
1579b870b88df784c2940efce448ebfaf54dece14666John McCall  bool isSpelledAsLValue() const { return ReferenceTypeBits.SpelledAsLValue; }
1580b870b88df784c2940efce448ebfaf54dece14666John McCall  bool isInnerRef() const { return ReferenceTypeBits.InnerRef; }
158173dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor
158254e14c4db764c0636160d26c5bbf491637c83a76John McCall  QualType getPointeeTypeAsWritten() const { return PointeeType; }
158354e14c4db764c0636160d26c5bbf491637c83a76John McCall  QualType getPointeeType() const {
158454e14c4db764c0636160d26c5bbf491637c83a76John McCall    // FIXME: this might strip inner qualifiers; okay?
158554e14c4db764c0636160d26c5bbf491637c83a76John McCall    const ReferenceType *T = this;
158671c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    while (T->isInnerRef())
158754e14c4db764c0636160d26c5bbf491637c83a76John McCall      T = T->PointeeType->getAs<ReferenceType>();
158854e14c4db764c0636160d26c5bbf491637c83a76John McCall    return T->PointeeType;
158954e14c4db764c0636160d26c5bbf491637c83a76John McCall  }
159068694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar
15915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void Profile(llvm::FoldingSetNodeID &ID) {
159271c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    Profile(ID, PointeeType, isSpelledAsLValue());
15935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
159454e14c4db764c0636160d26c5bbf491637c83a76John McCall  static void Profile(llvm::FoldingSetNodeID &ID,
159554e14c4db764c0636160d26c5bbf491637c83a76John McCall                      QualType Referencee,
159654e14c4db764c0636160d26c5bbf491637c83a76John McCall                      bool SpelledAsLValue) {
15975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ID.AddPointer(Referencee.getAsOpaquePtr());
159854e14c4db764c0636160d26c5bbf491637c83a76John McCall    ID.AddBoolean(SpelledAsLValue);
15995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
16005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
16017c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  static bool classof(const Type *T) {
16027c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl    return T->getTypeClass() == LValueReference ||
16037c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl           T->getTypeClass() == RValueReference;
16047c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  }
16055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const ReferenceType *) { return true; }
16067c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl};
16077c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl
16087c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// LValueReferenceType - C++ [dcl.ref] - Lvalue reference
16097c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl///
16107c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlclass LValueReferenceType : public ReferenceType {
161154e14c4db764c0636160d26c5bbf491637c83a76John McCall  LValueReferenceType(QualType Referencee, QualType CanonicalRef,
161254e14c4db764c0636160d26c5bbf491637c83a76John McCall                      bool SpelledAsLValue) :
161354e14c4db764c0636160d26c5bbf491637c83a76John McCall    ReferenceType(LValueReference, Referencee, CanonicalRef, SpelledAsLValue)
161454e14c4db764c0636160d26c5bbf491637c83a76John McCall  {}
16157c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  friend class ASTContext; // ASTContext creates these
16167c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlpublic:
1617bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1618bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1619bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
16207c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  static bool classof(const Type *T) {
16217c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl    return T->getTypeClass() == LValueReference;
16227c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  }
16237c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  static bool classof(const LValueReferenceType *) { return true; }
16247c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl};
16257c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl
16267c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// RValueReferenceType - C++0x [dcl.ref] - Rvalue reference
16277c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl///
16287c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlclass RValueReferenceType : public ReferenceType {
16297c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  RValueReferenceType(QualType Referencee, QualType CanonicalRef) :
163054e14c4db764c0636160d26c5bbf491637c83a76John McCall    ReferenceType(RValueReference, Referencee, CanonicalRef, false) {
16317c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  }
16327c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  friend class ASTContext; // ASTContext creates these
16337c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlpublic:
1634bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1635bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1636bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
16377c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  static bool classof(const Type *T) {
16387c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl    return T->getTypeClass() == RValueReference;
16397c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  }
16407c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  static bool classof(const RValueReferenceType *) { return true; }
1641f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl};
1642f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl
1643f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl/// MemberPointerType - C++ 8.3.3 - Pointers to members
1644f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl///
1645f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlclass MemberPointerType : public Type, public llvm::FoldingSetNode {
1646f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  QualType PointeeType;
1647f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  /// The class of which the pointee is a member. Must ultimately be a
1648f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  /// RecordType, but could be a typedef or a template parameter too.
1649f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  const Type *Class;
1650f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl
1651f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  MemberPointerType(QualType Pointee, const Type *Cls, QualType CanonicalPtr) :
1652f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    Type(MemberPointer, CanonicalPtr,
165335495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor         Cls->isDependentType() || Pointee->isDependentType(),
1654d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor         Pointee->isVariablyModifiedType(),
1655d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor         (Cls->containsUnexpandedParameterPack() ||
1656d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor          Pointee->containsUnexpandedParameterPack())),
1657f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    PointeeType(Pointee), Class(Cls) {
1658f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  }
1659f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  friend class ASTContext; // ASTContext creates these.
166060e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
1661f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlpublic:
1662f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  QualType getPointeeType() const { return PointeeType; }
1663f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl
16640bab0cdab751248ca389a5592bcb70eac5d39260John McCall  /// Returns true if the member type (i.e. the pointee type) is a
16650bab0cdab751248ca389a5592bcb70eac5d39260John McCall  /// function type rather than a data-member type.
16660bab0cdab751248ca389a5592bcb70eac5d39260John McCall  bool isMemberFunctionPointer() const {
16670bab0cdab751248ca389a5592bcb70eac5d39260John McCall    return PointeeType->isFunctionProtoType();
16680bab0cdab751248ca389a5592bcb70eac5d39260John McCall  }
16690bab0cdab751248ca389a5592bcb70eac5d39260John McCall
16700bab0cdab751248ca389a5592bcb70eac5d39260John McCall  /// Returns true if the member type (i.e. the pointee type) is a
16710bab0cdab751248ca389a5592bcb70eac5d39260John McCall  /// data type rather than a function type.
16720bab0cdab751248ca389a5592bcb70eac5d39260John McCall  bool isMemberDataPointer() const {
16730bab0cdab751248ca389a5592bcb70eac5d39260John McCall    return !PointeeType->isFunctionProtoType();
16740bab0cdab751248ca389a5592bcb70eac5d39260John McCall  }
16750bab0cdab751248ca389a5592bcb70eac5d39260John McCall
1676f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  const Type *getClass() const { return Class; }
1677f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl
1678bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1679bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1680bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
1681f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  void Profile(llvm::FoldingSetNodeID &ID) {
1682f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    Profile(ID, getPointeeType(), getClass());
1683f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  }
1684f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee,
1685f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl                      const Type *Class) {
1686f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    ID.AddPointer(Pointee.getAsOpaquePtr());
1687f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    ID.AddPointer(Class);
1688f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  }
1689f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl
1690f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  static bool classof(const Type *T) {
1691f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    return T->getTypeClass() == MemberPointer;
1692f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  }
1693f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  static bool classof(const MemberPointerType *) { return true; }
16945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
16955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
16965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ArrayType - C99 6.7.5.2 - Array Declarators.
16975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
16982e7d352dbec06755105237afba183492d31d03cbTed Kremenekclass ArrayType : public Type, public llvm::FoldingSetNode {
16995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
17005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// ArraySizeModifier - Capture whether this is a normal array (e.g. int X[4])
1701898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// an array with a static size (e.g. int X[static 4]), or an array
1702898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// with a star size (e.g. int X[*]).
1703898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// 'static' is only allowed on function parameters.
17045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  enum ArraySizeModifier {
17055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Normal, Static, Star
17065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
17075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate:
1708fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  /// ElementType - The element type of the array.
1709fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  QualType ElementType;
17101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1711fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroffprotected:
1712898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  // C++ [temp.dep.type]p1:
1713898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  //   A type is dependent if it is...
1714898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  //     - an array type constructed from any dependent type or whose
1715898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  //       size is specified by a constant expression that is
1716898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  //       value-dependent,
1717c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff  ArrayType(TypeClass tc, QualType et, QualType can,
1718d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor            ArraySizeModifier sm, unsigned tq,
1719d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor            bool ContainsUnexpandedParameterPack)
172035495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    : Type(tc, can, et->isDependentType() || tc == DependentSizedArray,
1721d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor           (tc == VariableArray || et->isVariablyModifiedType()),
1722d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor           ContainsUnexpandedParameterPack),
172371c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall      ElementType(et) {
1724b870b88df784c2940efce448ebfaf54dece14666John McCall    ArrayTypeBits.IndexTypeQuals = tq;
1725b870b88df784c2940efce448ebfaf54dece14666John McCall    ArrayTypeBits.SizeModifier = sm;
172671c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  }
1727898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
1728fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  friend class ASTContext;  // ASTContext creates these.
172960e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
1730fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroffpublic:
1731fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  QualType getElementType() const { return ElementType; }
1732ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek  ArraySizeModifier getSizeModifier() const {
1733b870b88df784c2940efce448ebfaf54dece14666John McCall    return ArraySizeModifier(ArrayTypeBits.SizeModifier);
1734ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek  }
17350953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  Qualifiers getIndexTypeQualifiers() const {
173671c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    return Qualifiers::fromCVRMask(getIndexTypeCVRQualifiers());
173771c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  }
173871c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  unsigned getIndexTypeCVRQualifiers() const {
1739b870b88df784c2940efce448ebfaf54dece14666John McCall    return ArrayTypeBits.IndexTypeQuals;
17400953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
17411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1742fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  static bool classof(const Type *T) {
1743fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff    return T->getTypeClass() == ConstantArray ||
1744c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman           T->getTypeClass() == VariableArray ||
1745898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor           T->getTypeClass() == IncompleteArray ||
1746898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor           T->getTypeClass() == DependentSizedArray;
1747fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  }
1748fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  static bool classof(const ArrayType *) { return true; }
1749fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff};
1750fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff
17517e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// ConstantArrayType - This class represents the canonical version of
17527e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// C arrays with a specified constant size.  For example, the canonical
17537e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// type for 'int A[4 + 4*100]' is a ConstantArrayType where the element
17547e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// type is 'int' and the size is 404.
17552e7d352dbec06755105237afba183492d31d03cbTed Kremenekclass ConstantArrayType : public ArrayType {
1756fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  llvm::APInt Size; // Allows us to unique the type.
17571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
17580be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner  ConstantArrayType(QualType et, QualType can, const llvm::APInt &size,
1759c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff                    ArraySizeModifier sm, unsigned tq)
1760d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    : ArrayType(ConstantArray, et, can, sm, tq,
1761d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor                et->containsUnexpandedParameterPack()),
17627e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor      Size(size) {}
17637e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregorprotected:
17647e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  ConstantArrayType(TypeClass tc, QualType et, QualType can,
17657e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor                    const llvm::APInt &size, ArraySizeModifier sm, unsigned tq)
1766d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    : ArrayType(tc, et, can, sm, tq, et->containsUnexpandedParameterPack()),
1767d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor      Size(size) {}
1768fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  friend class ASTContext;  // ASTContext creates these.
1769fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroffpublic:
1770c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  const llvm::APInt &getSize() const { return Size; }
1771bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1772bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1773bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
17742767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor
17752767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor  /// \brief Determine the number of bits required to address a member of
17762767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor  // an array with the given element type and number of elements.
17772767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor  static unsigned getNumAddressingBits(ASTContext &Context,
17782767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor                                       QualType ElementType,
17792767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor                                       const llvm::APInt &NumElements);
17802767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor
17812767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor  /// \brief Determine the maximum number of active bits that an array's size
17822767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor  /// can require, which limits the maximum size of the array.
17832767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor  static unsigned getMaxSizeBits(ASTContext &Context);
17842767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor
1785fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  void Profile(llvm::FoldingSetNodeID &ID) {
17861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    Profile(ID, getElementType(), getSize(),
17870953e767ff7817f97b3ab20896b229891eeff45bJohn McCall            getSizeModifier(), getIndexTypeCVRQualifiers());
1788fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  }
1789fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  static void Profile(llvm::FoldingSetNodeID &ID, QualType ET,
17900be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner                      const llvm::APInt &ArraySize, ArraySizeModifier SizeMod,
17910be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner                      unsigned TypeQuals) {
1792fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff    ID.AddPointer(ET.getAsOpaquePtr());
1793fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff    ID.AddInteger(ArraySize.getZExtValue());
17940be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner    ID.AddInteger(SizeMod);
17950be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner    ID.AddInteger(TypeQuals);
1796fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  }
17977e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  static bool classof(const Type *T) {
179846a617a792bfab0d9b1e057371ea3b9540802226John McCall    return T->getTypeClass() == ConstantArray;
1799fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  }
1800fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  static bool classof(const ConstantArrayType *) { return true; }
1801fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff};
1802fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff
1803da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// IncompleteArrayType - This class represents C arrays with an unspecified
1804da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// size.  For example 'int A[]' has an IncompleteArrayType where the element
1805da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// type is 'int' and the size is unspecified.
1806c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedmanclass IncompleteArrayType : public ArrayType {
18077e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor
1808c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman  IncompleteArrayType(QualType et, QualType can,
18097e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor                      ArraySizeModifier sm, unsigned tq)
1810d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    : ArrayType(IncompleteArray, et, can, sm, tq,
1811d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor                et->containsUnexpandedParameterPack()) {}
1812c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman  friend class ASTContext;  // ASTContext creates these.
1813c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedmanpublic:
1814bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1815bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1816bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
18171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
18181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == IncompleteArray;
1819c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman  }
1820c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman  static bool classof(const IncompleteArrayType *) { return true; }
18211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1822c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman  friend class StmtIteratorBase;
18231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1824c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman  void Profile(llvm::FoldingSetNodeID &ID) {
18250953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Profile(ID, getElementType(), getSizeModifier(),
18260953e767ff7817f97b3ab20896b229891eeff45bJohn McCall            getIndexTypeCVRQualifiers());
1827c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman  }
18281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
18290be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner  static void Profile(llvm::FoldingSetNodeID &ID, QualType ET,
18300be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner                      ArraySizeModifier SizeMod, unsigned TypeQuals) {
1831c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman    ID.AddPointer(ET.getAsOpaquePtr());
18320be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner    ID.AddInteger(SizeMod);
18330be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner    ID.AddInteger(TypeQuals);
1834c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman  }
1835c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman};
1836c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman
1837da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// VariableArrayType - This class represents C arrays with a specified size
1838da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// which is not an integer-constant-expression.  For example, 'int s[x+foo()]'.
1839da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// Since the size expression is an arbitrary expression, we store it as such.
1840da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner///
1841da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// Note: VariableArrayType's aren't uniqued (since the expressions aren't) and
1842da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// should not be: two lexically equivalent variable array types could mean
1843da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// different things, for example, these variables do not have the same type
1844da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// dynamically:
1845da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner///
1846da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// void foo(int x) {
1847da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner///   int Y[x];
1848da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner///   ++x;
1849da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner///   int Z[x];
1850da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// }
1851da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner///
18522e7d352dbec06755105237afba183492d31d03cbTed Kremenekclass VariableArrayType : public ArrayType {
18531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// SizeExpr - An assignment expression. VLA's are only permitted within
18541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// a function block.
1855b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek  Stmt *SizeExpr;
18567e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  /// Brackets - The left and right array brackets.
18577e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  SourceRange Brackets;
18587e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor
1859c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff  VariableArrayType(QualType et, QualType can, Expr *e,
18607e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor                    ArraySizeModifier sm, unsigned tq,
18617e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor                    SourceRange brackets)
1862d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    : ArrayType(VariableArray, et, can, sm, tq,
1863d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor                et->containsUnexpandedParameterPack()),
18647e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor      SizeExpr((Stmt*) e), Brackets(brackets) {}
18655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
18664b05b1dee6cc65ae61d93dab7edff72710f24589Ted Kremenek
18675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
18681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Expr *getSizeExpr() const {
1869b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek    // We use C-style casts instead of cast<> here because we do not wish
1870b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek    // to have a dependency of Type.h on Stmt.h/Expr.h.
1871b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek    return (Expr*) SizeExpr;
1872b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek  }
18737e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  SourceRange getBracketsRange() const { return Brackets; }
18747e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  SourceLocation getLBracketLoc() const { return Brackets.getBegin(); }
18757e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  SourceLocation getRBracketLoc() const { return Brackets.getEnd(); }
18761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1877bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1878bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1879bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
18801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
18811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == VariableArray;
18825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
1883fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  static bool classof(const VariableArrayType *) { return true; }
18841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
188592866e2e90f6d93fb95e25a7ac4438e239d89ce6Ted Kremenek  friend class StmtIteratorBase;
18861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
18872bd24ba6d10f8c811c8e2a57c8397e07082ba497Ted Kremenek  void Profile(llvm::FoldingSetNodeID &ID) {
1888bc5e150b6d94cf131f7d01bc715571b741c5b408Chris Lattner    assert(0 && "Cannnot unique VariableArrayTypes.");
18892bd24ba6d10f8c811c8e2a57c8397e07082ba497Ted Kremenek  }
18905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
18915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1892898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// DependentSizedArrayType - This type represents an array type in
1893898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// C++ whose size is a value-dependent expression. For example:
1894cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor///
1895cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor/// \code
18961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// template<typename T, int Size>
1897898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// class array {
1898898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor///   T data[Size];
1899898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// };
1900cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor/// \endcode
1901cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor///
1902898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// For these types, we won't actually know what the array bound is
1903898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// until template instantiation occurs, at which point this will
1904898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// become either a ConstantArrayType or a VariableArrayType.
1905898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorclass DependentSizedArrayType : public ArrayType {
190604d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor  ASTContext &Context;
19071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1908cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor  /// \brief An assignment expression that will instantiate to the
1909898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// size of the array.
1910cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor  ///
1911cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor  /// The expression itself might be NULL, in which case the array
1912cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor  /// type will have its size deduced from an initializer.
1913898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  Stmt *SizeExpr;
1914cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor
19157e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  /// Brackets - The left and right array brackets.
19167e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  SourceRange Brackets;
19171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
19181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  DependentSizedArrayType(ASTContext &Context, QualType et, QualType can,
191904d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor                          Expr *e, ArraySizeModifier sm, unsigned tq,
1920d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor                          SourceRange brackets);
1921d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor
1922898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  friend class ASTContext;  // ASTContext creates these.
1923898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
1924898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorpublic:
19251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Expr *getSizeExpr() const {
1926898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    // We use C-style casts instead of cast<> here because we do not wish
1927898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    // to have a dependency of Type.h on Stmt.h/Expr.h.
1928898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    return (Expr*) SizeExpr;
1929898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  }
19307e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  SourceRange getBracketsRange() const { return Brackets; }
19317e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  SourceLocation getLBracketLoc() const { return Brackets.getBegin(); }
19327e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  SourceLocation getRBracketLoc() const { return Brackets.getEnd(); }
19331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1934bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1935bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1936bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
19371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
19381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == DependentSizedArray;
1939898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  }
1940898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  static bool classof(const DependentSizedArrayType *) { return true; }
19411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1942898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  friend class StmtIteratorBase;
19431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
19441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1945898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  void Profile(llvm::FoldingSetNodeID &ID) {
19461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    Profile(ID, Context, getElementType(),
19470953e767ff7817f97b3ab20896b229891eeff45bJohn McCall            getSizeModifier(), getIndexTypeCVRQualifiers(), getSizeExpr());
1948898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  }
19491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
19501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static void Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context,
19511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                      QualType ET, ArraySizeModifier SizeMod,
195204d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor                      unsigned TypeQuals, Expr *E);
1953898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor};
1954898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
1955f6ddb737cb882ffbf0b75a9abd50b930cc2b9068Douglas Gregor/// DependentSizedExtVectorType - This type represent an extended vector type
19569cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// where either the type or size is dependent. For example:
19579cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// @code
19589cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// template<typename T, int Size>
19599cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// class vector {
19609cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor///   typedef T __attribute__((ext_vector_type(Size))) type;
19619cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// }
19629cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// @endcode
19632ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregorclass DependentSizedExtVectorType : public Type, public llvm::FoldingSetNode {
19642ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor  ASTContext &Context;
19659cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor  Expr *SizeExpr;
19669cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor  /// ElementType - The element type of the array.
19679cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor  QualType ElementType;
19689cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor  SourceLocation loc;
19691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
19701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  DependentSizedExtVectorType(ASTContext &Context, QualType ElementType,
1971d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor                              QualType can, Expr *SizeExpr, SourceLocation loc);
1972d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor
19739cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor  friend class ASTContext;
19749cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor
19759cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregorpublic:
19762ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor  Expr *getSizeExpr() const { return SizeExpr; }
19779cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor  QualType getElementType() const { return ElementType; }
19789cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor  SourceLocation getAttributeLoc() const { return loc; }
19799cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor
1980bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1981bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1982bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
19831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
19841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == DependentSizedExtVector;
19859cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor  }
19861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const DependentSizedExtVectorType *) { return true; }
19872ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor
19882ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor  void Profile(llvm::FoldingSetNodeID &ID) {
19892ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor    Profile(ID, Context, getElementType(), getSizeExpr());
19902ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor  }
19911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
19922ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor  static void Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context,
19932ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor                      QualType ElementType, Expr *SizeExpr);
19949cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor};
19951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
19969cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor
199773322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// VectorType - GCC generic vector type. This type is created using
19981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// __attribute__((vector_size(n)), where "n" specifies the vector size in
199982287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson/// bytes; or from an Altivec __vector or vector declaration.
200082287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson/// Since the constructor takes the number of vector elements, the
200173322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// client is responsible for converting the size into the number of elements.
20025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass VectorType : public Type, public llvm::FoldingSetNode {
2003788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattnerpublic:
2004e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson  enum VectorKind {
2005e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson    GenericVector,  // not a target-specific vector type
2006e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson    AltiVecVector,  // is AltiVec vector
2007e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson    AltiVecPixel,   // is AltiVec 'vector Pixel'
2008e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson    AltiVecBool,    // is AltiVec 'vector bool ...'
2009491328c90c00ecad6ad27fa0ab3cdf9195a4a820Bob Wilson    NeonVector,     // is ARM Neon vector
2010491328c90c00ecad6ad27fa0ab3cdf9195a4a820Bob Wilson    NeonPolyVector  // is ARM Neon polynomial vector
2011788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner  };
201273322924127c873c13101b705dd823f5539ffa5fSteve Naroffprotected:
20135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// ElementType - The element type of the vector.
20145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType ElementType;
20151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
201682287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson  VectorType(QualType vecType, unsigned nElements, QualType canonType,
2017d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor             VectorKind vecKind);
201835495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor
20191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  VectorType(TypeClass tc, QualType vecType, unsigned nElements,
2020d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor             QualType canonType, VectorKind vecKind);
2021d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor
20225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
202360e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
20245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
20251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
20265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType getElementType() const { return ElementType; }
2027b870b88df784c2940efce448ebfaf54dece14666John McCall  unsigned getNumElements() const { return VectorTypeBits.NumElements; }
20285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2029bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2030bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2031bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
2032e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson  VectorKind getVectorKind() const {
2033e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson    return VectorKind(VectorTypeBits.VecKind);
203471c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  }
2035788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner
20365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void Profile(llvm::FoldingSetNodeID &ID) {
203771c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    Profile(ID, getElementType(), getNumElements(),
2038e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson            getTypeClass(), getVectorKind());
20395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
20401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static void Profile(llvm::FoldingSetNodeID &ID, QualType ElementType,
204182287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson                      unsigned NumElements, TypeClass TypeClass,
2042e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson                      VectorKind VecKind) {
20435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ID.AddPointer(ElementType.getAsOpaquePtr());
20445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ID.AddInteger(NumElements);
204573322924127c873c13101b705dd823f5539ffa5fSteve Naroff    ID.AddInteger(TypeClass);
2046e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson    ID.AddInteger(VecKind);
204773322924127c873c13101b705dd823f5539ffa5fSteve Naroff  }
20480b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor
20491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
20501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == Vector || T->getTypeClass() == ExtVector;
20515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
20525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const VectorType *) { return true; }
20535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
20545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2055213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman/// ExtVectorType - Extended vector type. This type is created using
2056213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman/// __attribute__((ext_vector_type(n)), where "n" is the number of elements.
2057213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman/// Unlike vector_size, ext_vector_type is only allowed on typedef's. This
2058fcac0fff877a461bc5d5a57e6c6727a4c819d95aSteve Naroff/// class enables syntactic extensions, like Vector Components for accessing
2059fcac0fff877a461bc5d5a57e6c6727a4c819d95aSteve Naroff/// points, colors, and textures (modeled after OpenGL Shading Language).
2060213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begemanclass ExtVectorType : public VectorType {
2061213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman  ExtVectorType(QualType vecType, unsigned nElements, QualType canonType) :
2062e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson    VectorType(ExtVector, vecType, nElements, canonType, GenericVector) {}
206373322924127c873c13101b705dd823f5539ffa5fSteve Naroff  friend class ASTContext;  // ASTContext creates these.
206473322924127c873c13101b705dd823f5539ffa5fSteve Naroffpublic:
206588dca0464804b8b26ae605f89784c927e8493dddChris Lattner  static int getPointAccessorIdx(char c) {
206688dca0464804b8b26ae605f89784c927e8493dddChris Lattner    switch (c) {
206788dca0464804b8b26ae605f89784c927e8493dddChris Lattner    default: return -1;
206888dca0464804b8b26ae605f89784c927e8493dddChris Lattner    case 'x': return 0;
206988dca0464804b8b26ae605f89784c927e8493dddChris Lattner    case 'y': return 1;
207088dca0464804b8b26ae605f89784c927e8493dddChris Lattner    case 'z': return 2;
207188dca0464804b8b26ae605f89784c927e8493dddChris Lattner    case 'w': return 3;
207288dca0464804b8b26ae605f89784c927e8493dddChris Lattner    }
2073e1b31fedbc006e6e4071bbb4f74c6116b56cfa9fSteve Naroff  }
2074353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman  static int getNumericAccessorIdx(char c) {
207588dca0464804b8b26ae605f89784c927e8493dddChris Lattner    switch (c) {
2076353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      default: return -1;
2077353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '0': return 0;
2078353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '1': return 1;
2079353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '2': return 2;
2080353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '3': return 3;
2081353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '4': return 4;
2082353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '5': return 5;
2083353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '6': return 6;
2084353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '7': return 7;
2085353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '8': return 8;
2086353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '9': return 9;
2087131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman      case 'A':
2088353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case 'a': return 10;
2089131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman      case 'B':
2090353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case 'b': return 11;
2091131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman      case 'C':
2092353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case 'c': return 12;
2093131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman      case 'D':
2094353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case 'd': return 13;
2095131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman      case 'E':
2096353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case 'e': return 14;
2097131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman      case 'F':
2098353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case 'f': return 15;
209988dca0464804b8b26ae605f89784c927e8493dddChris Lattner    }
2100e1b31fedbc006e6e4071bbb4f74c6116b56cfa9fSteve Naroff  }
21011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2102b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner  static int getAccessorIdx(char c) {
2103b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner    if (int idx = getPointAccessorIdx(c)+1) return idx-1;
2104353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman    return getNumericAccessorIdx(c);
2105b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner  }
21061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
210788dca0464804b8b26ae605f89784c927e8493dddChris Lattner  bool isAccessorWithinNumElements(char c) const {
2108b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner    if (int idx = getAccessorIdx(c)+1)
210971c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall      return unsigned(idx-1) < getNumElements();
211088dca0464804b8b26ae605f89784c927e8493dddChris Lattner    return false;
2111e1b31fedbc006e6e4071bbb4f74c6116b56cfa9fSteve Naroff  }
2112bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2113bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2114bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
21151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
21161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == ExtVector;
211773322924127c873c13101b705dd823f5539ffa5fSteve Naroff  }
2118213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman  static bool classof(const ExtVectorType *) { return true; }
211973322924127c873c13101b705dd823f5539ffa5fSteve Naroff};
212073322924127c873c13101b705dd823f5539ffa5fSteve Naroff
21215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// FunctionType - C99 6.7.5.3 - Function Declarators.  This is the common base
212272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// class of FunctionNoProtoType and FunctionProtoType.
21235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
21245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass FunctionType : public Type {
21255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // The type returned by the function.
21265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType ResultType;
2127264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola
2128264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola public:
2129373920bd733b1d28fe7bf209945a62eb9248d948John McCall  /// ExtInfo - A class which abstracts out some details necessary for
2130373920bd733b1d28fe7bf209945a62eb9248d948John McCall  /// making a call.
2131373920bd733b1d28fe7bf209945a62eb9248d948John McCall  ///
2132373920bd733b1d28fe7bf209945a62eb9248d948John McCall  /// It is not actually used directly for storing this information in
2133373920bd733b1d28fe7bf209945a62eb9248d948John McCall  /// a FunctionType, although FunctionType does currently use the
2134373920bd733b1d28fe7bf209945a62eb9248d948John McCall  /// same bit-pattern.
2135373920bd733b1d28fe7bf209945a62eb9248d948John McCall  ///
2136075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  // If you add a field (say Foo), other than the obvious places (both,
2137075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  // constructors, compile failures), what you need to update is
2138075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  // * Operator==
2139425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola  // * getFoo
2140425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola  // * withFoo
2141425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola  // * functionType. Add Foo, getFoo.
2142425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola  // * ASTContext::getFooType
2143425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola  // * ASTContext::mergeFunctionTypes
2144425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola  // * FunctionNoProtoType::Profile
2145425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola  // * FunctionProtoType::Profile
2146425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola  // * TypePrinter::PrintFunctionProto
21473c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  // * AST read and write
2148425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola  // * Codegen
2149264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola  class ExtInfo {
2150373920bd733b1d28fe7bf209945a62eb9248d948John McCall    // Feel free to rearrange or add bits, but if you go over 8,
2151373920bd733b1d28fe7bf209945a62eb9248d948John McCall    // you'll need to adjust both the Bits field below and
2152373920bd733b1d28fe7bf209945a62eb9248d948John McCall    // Type::FunctionTypeBitfields.
2153373920bd733b1d28fe7bf209945a62eb9248d948John McCall
2154373920bd733b1d28fe7bf209945a62eb9248d948John McCall    //   |  CC  |noreturn|regparm
2155373920bd733b1d28fe7bf209945a62eb9248d948John McCall    //   |0 .. 2|   3    |4 ..  6
2156b870b88df784c2940efce448ebfaf54dece14666John McCall    enum { CallConvMask = 0x7 };
2157b870b88df784c2940efce448ebfaf54dece14666John McCall    enum { NoReturnMask = 0x8 };
2158b870b88df784c2940efce448ebfaf54dece14666John McCall    enum { RegParmMask = ~(CallConvMask | NoReturnMask),
2159b870b88df784c2940efce448ebfaf54dece14666John McCall           RegParmOffset = 4 };
2160b870b88df784c2940efce448ebfaf54dece14666John McCall
2161373920bd733b1d28fe7bf209945a62eb9248d948John McCall    unsigned char Bits;
216271c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall
2163373920bd733b1d28fe7bf209945a62eb9248d948John McCall    ExtInfo(unsigned Bits) : Bits(static_cast<unsigned char>(Bits)) {}
216471c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall
216571c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    friend class FunctionType;
216671c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall
2167264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola   public:
2168264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    // Constructor with no defaults. Use this when you know that you
21693c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl    // have all the elements (when reading an AST file for example).
217071c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    ExtInfo(bool noReturn, unsigned regParm, CallingConv cc) {
2171b870b88df784c2940efce448ebfaf54dece14666John McCall      Bits = ((unsigned) cc) |
2172b870b88df784c2940efce448ebfaf54dece14666John McCall             (noReturn ? NoReturnMask : 0) |
2173b870b88df784c2940efce448ebfaf54dece14666John McCall             (regParm << RegParmOffset);
217471c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    }
2175264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola
2176264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    // Constructor with all defaults. Use when for example creating a
2177264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    // function know to use defaults.
217871c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    ExtInfo() : Bits(0) {}
2179264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola
2180b870b88df784c2940efce448ebfaf54dece14666John McCall    bool getNoReturn() const { return Bits & NoReturnMask; }
2181b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned getRegParm() const { return Bits >> RegParmOffset; }
2182b870b88df784c2940efce448ebfaf54dece14666John McCall    CallingConv getCC() const { return CallingConv(Bits & CallConvMask); }
2183264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola
218471c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    bool operator==(ExtInfo Other) const {
218571c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall      return Bits == Other.Bits;
2186264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    }
218771c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    bool operator!=(ExtInfo Other) const {
218871c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall      return Bits != Other.Bits;
2189264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    }
2190264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola
2191264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    // Note that we don't have setters. That is by design, use
2192264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    // the following with methods instead of mutating these objects.
2193264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola
2194264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    ExtInfo withNoReturn(bool noReturn) const {
219571c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall      if (noReturn)
219671c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall        return ExtInfo(Bits | NoReturnMask);
219771c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall      else
219871c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall        return ExtInfo(Bits & ~NoReturnMask);
2199425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola    }
2200425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola
2201425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola    ExtInfo withRegParm(unsigned RegParm) const {
2202b870b88df784c2940efce448ebfaf54dece14666John McCall      return ExtInfo((Bits & ~RegParmMask) | (RegParm << RegParmOffset));
2203264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    }
2204264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola
2205264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    ExtInfo withCallingConv(CallingConv cc) const {
2206b870b88df784c2940efce448ebfaf54dece14666John McCall      return ExtInfo((Bits & ~CallConvMask) | (unsigned) cc);
2207264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    }
2208264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola
2209e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall    void Profile(llvm::FoldingSetNodeID &ID) const {
221071c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall      ID.AddInteger(Bits);
221171c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    }
2212264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola  };
2213264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola
22145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprotected:
2215e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall  FunctionType(TypeClass tc, QualType res, bool variadic,
22162455636163fdd18581d7fdae816433f886d88213Mike Stump               unsigned typeQuals, QualType Canonical, bool Dependent,
2217d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor               bool VariablyModified, bool ContainsUnexpandedParameterPack,
2218d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor               ExtInfo Info)
2219d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    : Type(tc, Canonical, Dependent, VariablyModified,
2220d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor           ContainsUnexpandedParameterPack),
2221d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor      ResultType(res) {
2222b870b88df784c2940efce448ebfaf54dece14666John McCall    FunctionTypeBits.ExtInfo = Info.Bits;
2223e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall    FunctionTypeBits.Variadic = variadic;
2224b870b88df784c2940efce448ebfaf54dece14666John McCall    FunctionTypeBits.TypeQuals = typeQuals;
222571c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  }
2226e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall  bool isVariadic() const { return FunctionTypeBits.Variadic; }
2227b870b88df784c2940efce448ebfaf54dece14666John McCall  unsigned getTypeQuals() const { return FunctionTypeBits.TypeQuals; }
22285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
22291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
22305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType getResultType() const { return ResultType; }
22315291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor
2232b870b88df784c2940efce448ebfaf54dece14666John McCall  unsigned getRegParmType() const { return getExtInfo().getRegParm(); }
2233b870b88df784c2940efce448ebfaf54dece14666John McCall  bool getNoReturnAttr() const { return getExtInfo().getNoReturn(); }
2234b870b88df784c2940efce448ebfaf54dece14666John McCall  CallingConv getCallConv() const { return getExtInfo().getCC(); }
2235b870b88df784c2940efce448ebfaf54dece14666John McCall  ExtInfo getExtInfo() const { return ExtInfo(FunctionTypeBits.ExtInfo); }
22365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
22375291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor  /// \brief Determine the type of an expression that calls a function of
22385291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor  /// this type.
22395291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor  QualType getCallResultType(ASTContext &Context) const {
22406398235d7890a81b785ea5af3b6e66d86bf184ccDouglas Gregor    return getResultType().getNonLValueExprType(Context);
22415291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor  }
22425291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor
224304a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall  static llvm::StringRef getNameForCallConv(CallingConv CC);
224404a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall
22455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T) {
22465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T->getTypeClass() == FunctionNoProto ||
22475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer           T->getTypeClass() == FunctionProto;
22485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
22495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const FunctionType *) { return true; }
22505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
22515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
225272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// FunctionNoProtoType - Represents a K&R-style 'int foo()' function, which has
22535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// no information available about its arguments.
225472564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregorclass FunctionNoProtoType : public FunctionType, public llvm::FoldingSetNode {
225571c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  FunctionNoProtoType(QualType Result, QualType Canonical, ExtInfo Info)
22561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    : FunctionType(FunctionNoProto, Result, false, 0, Canonical,
225735495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor                   /*Dependent=*/false, Result->isVariablyModifiedType(),
2258d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor                   /*ContainsUnexpandedParameterPack=*/false, Info) {}
2259d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor
22605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
226160e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
22625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
22635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // No additional state past what FunctionType provides.
22641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2265bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2266bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2267bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
22685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void Profile(llvm::FoldingSetNodeID &ID) {
2269264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    Profile(ID, getResultType(), getExtInfo());
22705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
22712455636163fdd18581d7fdae816433f886d88213Mike Stump  static void Profile(llvm::FoldingSetNodeID &ID, QualType ResultType,
227271c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall                      ExtInfo Info) {
227371c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    Info.Profile(ID);
22745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ID.AddPointer(ResultType.getAsOpaquePtr());
22755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
22761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
22775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T) {
22785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T->getTypeClass() == FunctionNoProto;
22795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
228072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  static bool classof(const FunctionNoProtoType *) { return true; }
22815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
22825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
228372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// FunctionProtoType - Represents a prototype with argument type info, e.g.
22845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 'int foo(int)' or 'int foo(void)'.  'void' is represented as having no
2285465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl/// arguments, not as having a single void argument. Such a type can have an
2286465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl/// exception specification, but this specification is not part of the canonical
2287465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl/// type.
228872564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregorclass FunctionProtoType : public FunctionType, public llvm::FoldingSetNode {
2289e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCallpublic:
2290e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall  /// ExtProtoInfo - Extra information about a function prototype.
2291e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall  struct ExtProtoInfo {
2292e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall    ExtProtoInfo() :
2293e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall      Variadic(false), HasExceptionSpec(false), HasAnyExceptionSpec(false),
2294e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall      TypeQuals(0), NumExceptions(0), Exceptions(0) {}
2295e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall
2296e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall    FunctionType::ExtInfo ExtInfo;
2297e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall    bool Variadic;
2298e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall    bool HasExceptionSpec;
2299e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall    bool HasAnyExceptionSpec;
2300e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall    unsigned char TypeQuals;
2301e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall    unsigned NumExceptions;
2302e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall    const QualType *Exceptions;
2303e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall  };
2304e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall
2305e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCallprivate:
2306d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// \brief Determine whether there are any argument types that
2307d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// contain an unexpanded parameter pack.
2308d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  static bool containsAnyUnexpandedParameterPack(const QualType *ArgArray,
2309d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor                                                 unsigned numArgs) {
2310d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    for (unsigned Idx = 0; Idx < numArgs; ++Idx)
2311d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor      if (ArgArray[Idx]->containsUnexpandedParameterPack())
2312d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor        return true;
2313d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor
2314d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    return false;
2315d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  }
2316d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor
2317e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall  FunctionProtoType(QualType result, const QualType *args, unsigned numArgs,
2318e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall                    QualType canonical, const ExtProtoInfo &epi);
2319465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
23205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// NumArgs - The number of arguments this function has, not counting '...'.
2321465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  unsigned NumArgs : 20;
2322465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
2323465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  /// NumExceptions - The number of types in the exception spec, if any.
2324465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  unsigned NumExceptions : 10;
2325465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
2326465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  /// HasExceptionSpec - Whether this function has an exception spec at all.
232734e80e94a21eb1ac2a9405d918e711e8b12256a9John McCall  unsigned HasExceptionSpec : 1;
2328465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
2329e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall  /// HasAnyExceptionSpec - Whether this function has a throw(...) spec.
2330e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall  unsigned HasAnyExceptionSpec : 1;
2331465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
2332942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner  /// ArgInfo - There is an variable size array after the class in memory that
2333942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner  /// holds the argument types.
2334465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
2335465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  /// Exceptions - There is another variable size array after ArgInfo that
2336465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  /// holds the exception types.
2337465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
23385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
23394b05b1dee6cc65ae61d93dab7edff72710f24589Ted Kremenek
23405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
23415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned getNumArgs() const { return NumArgs; }
23425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType getArgType(unsigned i) const {
23435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    assert(i < NumArgs && "Invalid argument number!");
2344942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner    return arg_type_begin()[i];
23455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
2346465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
2347e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall  ExtProtoInfo getExtProtoInfo() const {
2348e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall    ExtProtoInfo EPI;
2349e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall    EPI.ExtInfo = getExtInfo();
2350e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall    EPI.Variadic = isVariadic();
2351e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall    EPI.HasExceptionSpec = hasExceptionSpec();
2352e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall    EPI.HasAnyExceptionSpec = hasAnyExceptionSpec();
2353e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall    EPI.TypeQuals = static_cast<unsigned char>(getTypeQuals());
2354e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall    EPI.NumExceptions = NumExceptions;
2355e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall    EPI.Exceptions = exception_begin();
2356e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall    return EPI;
2357e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall  }
2358e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall
2359465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  bool hasExceptionSpec() const { return HasExceptionSpec; }
2360e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall  bool hasAnyExceptionSpec() const { return HasAnyExceptionSpec; }
2361465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  unsigned getNumExceptions() const { return NumExceptions; }
2362465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  QualType getExceptionType(unsigned i) const {
2363465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl    assert(i < NumExceptions && "Invalid exception number!");
2364465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl    return exception_begin()[i];
2365465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  }
23661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  bool hasEmptyExceptionSpec() const {
23671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return hasExceptionSpec() && !hasAnyExceptionSpec() &&
2368a12823f6c0ec9e0e644a9d0ee153e973f49c63fcAnders Carlsson      getNumExceptions() == 0;
2369d3fd6bad1249d3f34d71b73e2333fab0db51cce4Anders Carlsson  }
2370465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
2371e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall  using FunctionType::isVariadic;
2372971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis  unsigned getTypeQuals() const { return FunctionType::getTypeQuals(); }
23731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
23745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  typedef const QualType *arg_type_iterator;
2375942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner  arg_type_iterator arg_type_begin() const {
2376942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner    return reinterpret_cast<const QualType *>(this+1);
2377942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner  }
2378942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner  arg_type_iterator arg_type_end() const { return arg_type_begin()+NumArgs; }
2379465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
2380465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  typedef const QualType *exception_iterator;
2381465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  exception_iterator exception_begin() const {
2382465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl    // exceptions begin where arguments end
2383465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl    return arg_type_end();
2384465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  }
2385465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  exception_iterator exception_end() const {
2386465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl    return exception_begin() + NumExceptions;
2387465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  }
2388465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
2389bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2390bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2391bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
23925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T) {
23935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T->getTypeClass() == FunctionProto;
23945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
239572564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  static bool classof(const FunctionProtoType *) { return true; }
2396465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
23975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void Profile(llvm::FoldingSetNodeID &ID);
23985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static void Profile(llvm::FoldingSetNodeID &ID, QualType Result,
2399942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner                      arg_type_iterator ArgTys, unsigned NumArgs,
2400e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall                      const ExtProtoInfo &EPI);
24015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
24025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
24035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2404ed97649e9574b9d854fa4d6109c9333ae0993554John McCall/// \brief Represents the dependent type named by a dependently-scoped
2405ed97649e9574b9d854fa4d6109c9333ae0993554John McCall/// typename using declaration, e.g.
2406ed97649e9574b9d854fa4d6109c9333ae0993554John McCall///   using typename Base<T>::foo;
2407ed97649e9574b9d854fa4d6109c9333ae0993554John McCall/// Template instantiation turns these into the underlying type.
2408ed97649e9574b9d854fa4d6109c9333ae0993554John McCallclass UnresolvedUsingType : public Type {
2409ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  UnresolvedUsingTypenameDecl *Decl;
2410ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
241119c8576b7328f4dc2d07682f5da552875c1912efJohn McCall  UnresolvedUsingType(const UnresolvedUsingTypenameDecl *D)
2412d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    : Type(UnresolvedUsing, QualType(), true, false,
2413d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor           /*ContainsUnexpandedParameterPack=*/false),
241419c8576b7328f4dc2d07682f5da552875c1912efJohn McCall      Decl(const_cast<UnresolvedUsingTypenameDecl*>(D)) {}
2415ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  friend class ASTContext; // ASTContext creates these.
2416ed97649e9574b9d854fa4d6109c9333ae0993554John McCallpublic:
2417ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
2418ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  UnresolvedUsingTypenameDecl *getDecl() const { return Decl; }
2419ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
2420ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  bool isSugared() const { return false; }
2421ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  QualType desugar() const { return QualType(this, 0); }
2422ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
2423ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  static bool classof(const Type *T) {
2424ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    return T->getTypeClass() == UnresolvedUsing;
2425ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  }
2426ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  static bool classof(const UnresolvedUsingType *) { return true; }
2427ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
2428ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  void Profile(llvm::FoldingSetNodeID &ID) {
2429ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    return Profile(ID, Decl);
2430ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  }
2431ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  static void Profile(llvm::FoldingSetNodeID &ID,
2432ed97649e9574b9d854fa4d6109c9333ae0993554John McCall                      UnresolvedUsingTypenameDecl *D) {
2433ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    ID.AddPointer(D);
2434ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  }
2435ed97649e9574b9d854fa4d6109c9333ae0993554John McCall};
2436ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
2437ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
24385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass TypedefType : public Type {
24395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  TypedefDecl *Decl;
2440c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanianprotected:
244119c8576b7328f4dc2d07682f5da552875c1912efJohn McCall  TypedefType(TypeClass tc, const TypedefDecl *D, QualType can)
2442d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    : Type(tc, can, can->isDependentType(), can->isVariablyModifiedType(),
2443d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor           /*ContainsUnexpandedParameterPack=*/false),
244419c8576b7328f4dc2d07682f5da552875c1912efJohn McCall      Decl(const_cast<TypedefDecl*>(D)) {
24455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    assert(!isa<TypedefType>(can) && "Invalid canonical type");
24465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
24475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
24485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
24491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
24505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  TypedefDecl *getDecl() const { return Decl; }
24511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2452bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return true; }
2453bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const;
2454bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
245572564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  static bool classof(const Type *T) { return T->getTypeClass() == Typedef; }
24565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const TypedefType *) { return true; }
24575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
24585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
245972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// TypeOfExprType (GCC extension).
246072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregorclass TypeOfExprType : public Type {
2461d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  Expr *TOExpr;
24621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2463b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregorprotected:
2464dd0257c77719a13d4acd513df40b04300cbfc871Douglas Gregor  TypeOfExprType(Expr *E, QualType can = QualType());
2465d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  friend class ASTContext;  // ASTContext creates these.
2466d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroffpublic:
2467d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  Expr *getUnderlyingExpr() const { return TOExpr; }
24681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2469bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// \brief Remove a single level of sugar.
2470bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const;
2471bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
2472bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// \brief Returns whether this type directly provides sugar.
2473bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return true; }
2474bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
247572564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  static bool classof(const Type *T) { return T->getTypeClass() == TypeOfExpr; }
247672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  static bool classof(const TypeOfExprType *) { return true; }
2477d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff};
2478d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff
2479c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// \brief Internal representation of canonical, dependent
24801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// typeof(expr) types.
2481c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor///
2482c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// This class is used internally by the ASTContext to manage
2483c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// canonical, dependent types, only. Clients will only see instances
2484c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// of this class via TypeOfExprType nodes.
24851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpclass DependentTypeOfExprType
2486b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor  : public TypeOfExprType, public llvm::FoldingSetNode {
2487b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor  ASTContext &Context;
24881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2489b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregorpublic:
24901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  DependentTypeOfExprType(ASTContext &Context, Expr *E)
2491b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor    : TypeOfExprType(E), Context(Context) { }
24921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2493bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2494bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2495bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
2496b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor  void Profile(llvm::FoldingSetNodeID &ID) {
2497b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor    Profile(ID, Context, getUnderlyingExpr());
2498b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor  }
24991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2500b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor  static void Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context,
2501b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor                      Expr *E);
2502b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor};
25031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2504d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff/// TypeOfType (GCC extension).
2505d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroffclass TypeOfType : public Type {
2506d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  QualType TOType;
25071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  TypeOfType(QualType T, QualType can)
2508d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    : Type(TypeOf, can, T->isDependentType(), T->isVariablyModifiedType(),
2509d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor           T->containsUnexpandedParameterPack()),
251035495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor      TOType(T) {
2511d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff    assert(!isa<TypedefType>(can) && "Invalid canonical type");
2512d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  }
2513d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  friend class ASTContext;  // ASTContext creates these.
2514d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroffpublic:
2515d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  QualType getUnderlyingType() const { return TOType; }
25161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2517bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// \brief Remove a single level of sugar.
2518bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return getUnderlyingType(); }
2519bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
2520bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// \brief Returns whether this type directly provides sugar.
2521bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return true; }
2522bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
252372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  static bool classof(const Type *T) { return T->getTypeClass() == TypeOf; }
2524d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  static bool classof(const TypeOfType *) { return true; }
2525d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff};
25265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2527395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson/// DecltypeType (C++0x)
2528395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlssonclass DecltypeType : public Type {
2529395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson  Expr *E;
25301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2531563a03b1338d31c2462def43253a722bc885d384Anders Carlsson  // FIXME: We could get rid of UnderlyingType if we wanted to: We would have to
2532563a03b1338d31c2462def43253a722bc885d384Anders Carlsson  // Move getDesugaredType to ASTContext so that it can call getDecltypeForExpr
2533563a03b1338d31c2462def43253a722bc885d384Anders Carlsson  // from it.
2534563a03b1338d31c2462def43253a722bc885d384Anders Carlsson  QualType UnderlyingType;
25351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
25369d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregorprotected:
2537563a03b1338d31c2462def43253a722bc885d384Anders Carlsson  DecltypeType(Expr *E, QualType underlyingType, QualType can = QualType());
2538395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson  friend class ASTContext;  // ASTContext creates these.
2539395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlssonpublic:
2540395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson  Expr *getUnderlyingExpr() const { return E; }
2541563a03b1338d31c2462def43253a722bc885d384Anders Carlsson  QualType getUnderlyingType() const { return UnderlyingType; }
2542563a03b1338d31c2462def43253a722bc885d384Anders Carlsson
2543bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// \brief Remove a single level of sugar.
2544bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return getUnderlyingType(); }
2545bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
2546bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// \brief Returns whether this type directly provides sugar.
2547bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return !isDependentType(); }
2548bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
2549395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson  static bool classof(const Type *T) { return T->getTypeClass() == Decltype; }
2550395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson  static bool classof(const DecltypeType *) { return true; }
2551395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson};
25521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2553c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// \brief Internal representation of canonical, dependent
2554c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// decltype(expr) types.
2555c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor///
2556c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// This class is used internally by the ASTContext to manage
2557c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// canonical, dependent types, only. Clients will only see instances
2558c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// of this class via DecltypeType nodes.
25599d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregorclass DependentDecltypeType : public DecltypeType, public llvm::FoldingSetNode {
25609d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor  ASTContext &Context;
25611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
25629d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregorpublic:
25639d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor  DependentDecltypeType(ASTContext &Context, Expr *E);
25641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2565bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2566bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2567bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
25689d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor  void Profile(llvm::FoldingSetNodeID &ID) {
25699d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor    Profile(ID, Context, getUnderlyingExpr());
25709d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor  }
25711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
25729d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor  static void Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context,
25731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                      Expr *E);
25749d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor};
25751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
25765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass TagType : public Type {
2577ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl  /// Stores the TagDecl associated with this type. The decl may point to any
2578ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl  /// TagDecl that declares the entity.
2579ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl  TagDecl * decl;
25802ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor
25812ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregorprotected:
258219c8576b7328f4dc2d07682f5da552875c1912efJohn McCall  TagType(TypeClass TC, const TagDecl *D, QualType can);
25832ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor
25841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic:
2585ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl  TagDecl *getDecl() const;
25861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
25870b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor  /// @brief Determines whether this type is in the process of being
25881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// defined.
2589ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl  bool isBeingDefined() const;
25900b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor
25911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
259272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor    return T->getTypeClass() >= TagFirst && T->getTypeClass() <= TagLast;
259372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  }
25945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const TagType *) { return true; }
259572564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  static bool classof(const RecordType *) { return true; }
259672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  static bool classof(const EnumType *) { return true; }
25975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
25985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
25995edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner/// RecordType - This is a helper class that allows the use of isa/cast/dyncast
26005edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner/// to detect TagType objects of structs/unions/classes.
26015edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattnerclass RecordType : public TagType {
260249aa7ff1245abd03e6e998e01302df31e4c6f8f6Argyrios Kyrtzidisprotected:
260319c8576b7328f4dc2d07682f5da552875c1912efJohn McCall  explicit RecordType(const RecordDecl *D)
260419c8576b7328f4dc2d07682f5da552875c1912efJohn McCall    : TagType(Record, reinterpret_cast<const TagDecl*>(D), QualType()) { }
260572564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  explicit RecordType(TypeClass TC, RecordDecl *D)
260619c8576b7328f4dc2d07682f5da552875c1912efJohn McCall    : TagType(TC, reinterpret_cast<const TagDecl*>(D), QualType()) { }
26072ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor  friend class ASTContext;   // ASTContext creates these.
26085edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattnerpublic:
26091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
26105edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner  RecordDecl *getDecl() const {
26115edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner    return reinterpret_cast<RecordDecl*>(TagType::getDecl());
26125edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner  }
26131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
26141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  // FIXME: This predicate is a helper to QualType/Type. It needs to
26155edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner  // recursively check all fields for const-ness. If any field is declared
26161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  // const, it needs to return false.
26175edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner  bool hasConstFields() const { return false; }
26185edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner
26195edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner  // FIXME: RecordType needs to check when it is created that all fields are in
26205edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner  // the same address space, and return that.
26215edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner  unsigned getAddressSpace() const { return 0; }
26221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2623bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2624bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2625bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
26262daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner  static bool classof(const TagType *T);
26272daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner  static bool classof(const Type *T) {
26282daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner    return isa<TagType>(T) && classof(cast<TagType>(T));
26292daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner  }
26305edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner  static bool classof(const RecordType *) { return true; }
26315edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner};
26325edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner
26335edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner/// EnumType - This is a helper class that allows the use of isa/cast/dyncast
26345edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner/// to detect TagType objects of enums.
26355edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattnerclass EnumType : public TagType {
263619c8576b7328f4dc2d07682f5da552875c1912efJohn McCall  explicit EnumType(const EnumDecl *D)
263719c8576b7328f4dc2d07682f5da552875c1912efJohn McCall    : TagType(Enum, reinterpret_cast<const TagDecl*>(D), QualType()) { }
26382ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor  friend class ASTContext;   // ASTContext creates these.
26395edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattnerpublic:
26401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
26415edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner  EnumDecl *getDecl() const {
26425edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner    return reinterpret_cast<EnumDecl*>(TagType::getDecl());
26435edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner  }
26441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2645bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2646bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2647bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
26482daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner  static bool classof(const TagType *T);
26492daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner  static bool classof(const Type *T) {
26502daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner    return isa<TagType>(T) && classof(cast<TagType>(T));
26512daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner  }
26525edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner  static bool classof(const EnumType *) { return true; }
26535edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner};
26545edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner
2655fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregorclass TemplateTypeParmType : public Type, public llvm::FoldingSetNode {
2656efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor  unsigned Depth : 15;
2657efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor  unsigned ParameterPack : 1;
265877be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall  unsigned Index : 16;
2659efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor  IdentifierInfo *Name;
266072c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor
2661efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor  TemplateTypeParmType(unsigned D, unsigned I, bool PP, IdentifierInfo *N,
2662efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor                       QualType Canon)
266335495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    : Type(TemplateTypeParm, Canon, /*Dependent=*/true,
2664d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor           /*VariablyModified=*/false, PP),
266577be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall      Depth(D), ParameterPack(PP), Index(I), Name(N) { }
266672c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor
26671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  TemplateTypeParmType(unsigned D, unsigned I, bool PP)
266835495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    : Type(TemplateTypeParm, QualType(this, 0), /*Dependent=*/true,
2669d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor           /*VariablyModified=*/false, PP),
267077be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall      Depth(D), ParameterPack(PP), Index(I), Name(0) { }
267172c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor
2672fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor  friend class ASTContext;  // ASTContext creates these
267372c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor
2674fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregorpublic:
2675efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor  unsigned getDepth() const { return Depth; }
2676efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor  unsigned getIndex() const { return Index; }
2677efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor  bool isParameterPack() const { return ParameterPack; }
2678efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor  IdentifierInfo *getName() const { return Name; }
26791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2680bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2681bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2682bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
2683fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor  void Profile(llvm::FoldingSetNodeID &ID) {
2684efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor    Profile(ID, Depth, Index, ParameterPack, Name);
2685fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor  }
2686fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor
26871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static void Profile(llvm::FoldingSetNodeID &ID, unsigned Depth,
26881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                      unsigned Index, bool ParameterPack,
2689efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor                      IdentifierInfo *Name) {
2690fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor    ID.AddInteger(Depth);
2691fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor    ID.AddInteger(Index);
269276e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson    ID.AddBoolean(ParameterPack);
2693efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor    ID.AddPointer(Name);
2694fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor  }
2695fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor
26961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
26971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == TemplateTypeParm;
269872c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor  }
269972c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor  static bool classof(const TemplateTypeParmType *T) { return true; }
270072c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor};
2701fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor
270249a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// \brief Represents the result of substituting a type for a template
270349a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// type parameter.
270449a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall///
270549a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// Within an instantiated template, all template type parameters have
270649a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// been replaced with these.  They are used solely to record that a
270749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// type was originally written as a template type parameter;
270849a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// therefore they are never canonical.
270949a832bd499d6f61c23655f1fac99f0dd229756eJohn McCallclass SubstTemplateTypeParmType : public Type, public llvm::FoldingSetNode {
271049a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  // The original type parameter.
271149a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  const TemplateTypeParmType *Replaced;
271249a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall
271349a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  SubstTemplateTypeParmType(const TemplateTypeParmType *Param, QualType Canon)
271435495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    : Type(SubstTemplateTypeParm, Canon, Canon->isDependentType(),
2715d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor           Canon->isVariablyModifiedType(),
2716d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor           Canon->containsUnexpandedParameterPack()),
271749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall      Replaced(Param) { }
271849a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall
271949a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  friend class ASTContext;
272049a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall
272149a832bd499d6f61c23655f1fac99f0dd229756eJohn McCallpublic:
2722efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor  IdentifierInfo *getName() const { return Replaced->getName(); }
2723efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor
272449a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  /// Gets the template parameter that was substituted for.
272549a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  const TemplateTypeParmType *getReplacedParameter() const {
272649a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall    return Replaced;
272749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  }
272849a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall
272949a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  /// Gets the type that was substituted for the template
273049a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  /// parameter.
273149a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  QualType getReplacementType() const {
273249a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall    return getCanonicalTypeInternal();
273349a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  }
273449a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall
273549a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  bool isSugared() const { return true; }
273649a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  QualType desugar() const { return getReplacementType(); }
273749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall
273849a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  void Profile(llvm::FoldingSetNodeID &ID) {
273949a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall    Profile(ID, getReplacedParameter(), getReplacementType());
274049a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  }
274149a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  static void Profile(llvm::FoldingSetNodeID &ID,
274249a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall                      const TemplateTypeParmType *Replaced,
274349a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall                      QualType Replacement) {
274449a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall    ID.AddPointer(Replaced);
274549a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall    ID.AddPointer(Replacement.getAsOpaquePtr());
274649a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  }
274749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall
274849a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  static bool classof(const Type *T) {
274949a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall    return T->getTypeClass() == SubstTemplateTypeParm;
275049a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  }
275149a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  static bool classof(const SubstTemplateTypeParmType *T) { return true; }
275249a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall};
275349a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall
27547532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// \brief Represents the type of a template specialization as written
27557532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// in the source code.
275655f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor///
27577532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// Template specialization types represent the syntactic form of a
27587532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// template-id that refers to a type, e.g., @c vector<int>. Some
27597532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// template specialization types are syntactic sugar, whose canonical
27607532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// type will point to some other type node that represents the
27617532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// instantiation or class template specialization. For example, a
276255f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor/// class template specialization type of @c vector<int> will refer to
27631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// a tag type for the instantiation
276455f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor/// @c std::vector<int, std::allocator<int>>.
27657532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor///
27667532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// Other template specialization types, for which the template name
27677532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// is dependent, may be canonical types. These types are always
27687532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// dependent.
27691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpclass TemplateSpecializationType
277055f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  : public Type, public llvm::FoldingSetNode {
277133500955d731c73717af52088b7fc0e7a85681e7John McCall  /// \brief The name of the template being specialized.
27727532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor  TemplateName Template;
277355f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
277440808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  /// \brief - The number of template arguments named in this class
277540808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  /// template specialization.
277655f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  unsigned NumArgs;
277755f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
2778ef99001908e799c388f1363b1e607dad5f5b57d3John McCall  TemplateSpecializationType(TemplateName T,
27797532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor                             const TemplateArgument *Args,
27807532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor                             unsigned NumArgs, QualType Canon);
278155f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
278255f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  friend class ASTContext;  // ASTContext creates these
278355f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
278455f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregorpublic:
278540808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  /// \brief Determine whether any of the given template arguments are
278640808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  /// dependent.
278740808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  static bool anyDependentTemplateArguments(const TemplateArgument *Args,
27881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                            unsigned NumArgs);
278940808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor
2790833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  static bool anyDependentTemplateArguments(const TemplateArgumentLoc *Args,
2791833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                            unsigned NumArgs);
2792833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
2793d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  static bool anyDependentTemplateArguments(const TemplateArgumentListInfo &);
2794d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall
2795df667e71b1daadeacb230cf94fc717843f1a138aDouglas Gregor  /// \brief Print a template argument list, including the '<' and '>'
2796df667e71b1daadeacb230cf94fc717843f1a138aDouglas Gregor  /// enclosing the template arguments.
2797df667e71b1daadeacb230cf94fc717843f1a138aDouglas Gregor  static std::string PrintTemplateArgumentList(const TemplateArgument *Args,
2798d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor                                               unsigned NumArgs,
2799d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor                                               const PrintingPolicy &Policy);
2800df667e71b1daadeacb230cf94fc717843f1a138aDouglas Gregor
2801833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  static std::string PrintTemplateArgumentList(const TemplateArgumentLoc *Args,
2802833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                               unsigned NumArgs,
2803833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                               const PrintingPolicy &Policy);
2804833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
2805d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  static std::string PrintTemplateArgumentList(const TemplateArgumentListInfo &,
2806d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall                                               const PrintingPolicy &Policy);
2807d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall
280831f17ecbef57b5679c017c375db330546b7b5145John McCall  /// True if this template specialization type matches a current
280931f17ecbef57b5679c017c375db330546b7b5145John McCall  /// instantiation in the context in which it is found.
281031f17ecbef57b5679c017c375db330546b7b5145John McCall  bool isCurrentInstantiation() const {
281171d74bc0d6e522ce7c21a599db8e19d3883b518fJohn McCall    return isa<InjectedClassNameType>(getCanonicalTypeInternal());
281231f17ecbef57b5679c017c375db330546b7b5145John McCall  }
281331f17ecbef57b5679c017c375db330546b7b5145John McCall
281440808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  typedef const TemplateArgument * iterator;
281540808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor
281640808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  iterator begin() const { return getArgs(); }
281733500955d731c73717af52088b7fc0e7a85681e7John McCall  iterator end() const; // defined inline in TemplateBase.h
281840808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor
28197532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor  /// \brief Retrieve the name of the template that we are specializing.
28207532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor  TemplateName getTemplateName() const { return Template; }
282155f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
282240808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  /// \brief Retrieve the template arguments.
28231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  const TemplateArgument *getArgs() const {
282440808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor    return reinterpret_cast<const TemplateArgument *>(this + 1);
282540808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  }
282640808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor
282740808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  /// \brief Retrieve the number of template arguments.
282855f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  unsigned getNumArgs() const { return NumArgs; }
282955f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
283055f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  /// \brief Retrieve a specific template argument as a type.
283155f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  /// \precondition @c isArgType(Arg)
283233500955d731c73717af52088b7fc0e7a85681e7John McCall  const TemplateArgument &getArg(unsigned Idx) const; // in TemplateBase.h
283355f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
283431f17ecbef57b5679c017c375db330546b7b5145John McCall  bool isSugared() const {
283531f17ecbef57b5679c017c375db330546b7b5145John McCall    return !isDependentType() || isCurrentInstantiation();
283631f17ecbef57b5679c017c375db330546b7b5145John McCall  }
2837bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return getCanonicalTypeInternal(); }
2838bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
2839ef99001908e799c388f1363b1e607dad5f5b57d3John McCall  void Profile(llvm::FoldingSetNodeID &ID, ASTContext &Ctx) {
284071d74bc0d6e522ce7c21a599db8e19d3883b518fJohn McCall    Profile(ID, Template, getArgs(), NumArgs, Ctx);
284155f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  }
284255f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
28437532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor  static void Profile(llvm::FoldingSetNodeID &ID, TemplateName T,
284431f17ecbef57b5679c017c375db330546b7b5145John McCall                      const TemplateArgument *Args,
284531f17ecbef57b5679c017c375db330546b7b5145John McCall                      unsigned NumArgs,
2846828e226ab7ed08b3eb766549e9d3306432137460Douglas Gregor                      ASTContext &Context);
284755f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
28481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
28491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == TemplateSpecialization;
285055f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  }
28517532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor  static bool classof(const TemplateSpecializationType *T) { return true; }
285255f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor};
285355f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
285431f17ecbef57b5679c017c375db330546b7b5145John McCall/// \brief The injected class name of a C++ class template or class
285531f17ecbef57b5679c017c375db330546b7b5145John McCall/// template partial specialization.  Used to record that a type was
285631f17ecbef57b5679c017c375db330546b7b5145John McCall/// spelled with a bare identifier rather than as a template-id; the
285731f17ecbef57b5679c017c375db330546b7b5145John McCall/// equivalent for non-templated classes is just RecordType.
28583cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall///
285931f17ecbef57b5679c017c375db330546b7b5145John McCall/// Injected class name types are always dependent.  Template
286031f17ecbef57b5679c017c375db330546b7b5145John McCall/// instantiation turns these into RecordTypes.
28613cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall///
286231f17ecbef57b5679c017c375db330546b7b5145John McCall/// Injected class name types are always canonical.  This works
286331f17ecbef57b5679c017c375db330546b7b5145John McCall/// because it is impossible to compare an injected class name type
286431f17ecbef57b5679c017c375db330546b7b5145John McCall/// with the corresponding non-injected template type, for the same
286531f17ecbef57b5679c017c375db330546b7b5145John McCall/// reason that it is impossible to directly compare template
286631f17ecbef57b5679c017c375db330546b7b5145John McCall/// parameters from different dependent contexts: injected class name
286731f17ecbef57b5679c017c375db330546b7b5145John McCall/// types can only occur within the scope of a particular templated
286831f17ecbef57b5679c017c375db330546b7b5145John McCall/// declaration, and within that scope every template specialization
286931f17ecbef57b5679c017c375db330546b7b5145John McCall/// will canonicalize to the injected class name (when appropriate
287031f17ecbef57b5679c017c375db330546b7b5145John McCall/// according to the rules of the language).
28713cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCallclass InjectedClassNameType : public Type {
28723cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  CXXRecordDecl *Decl;
28733cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall
287431f17ecbef57b5679c017c375db330546b7b5145John McCall  /// The template specialization which this type represents.
287531f17ecbef57b5679c017c375db330546b7b5145John McCall  /// For example, in
287631f17ecbef57b5679c017c375db330546b7b5145John McCall  ///   template <class T> class A { ... };
287731f17ecbef57b5679c017c375db330546b7b5145John McCall  /// this is A<T>, whereas in
287831f17ecbef57b5679c017c375db330546b7b5145John McCall  ///   template <class X, class Y> class A<B<X,Y> > { ... };
287931f17ecbef57b5679c017c375db330546b7b5145John McCall  /// this is A<B<X,Y> >.
288031f17ecbef57b5679c017c375db330546b7b5145John McCall  ///
288131f17ecbef57b5679c017c375db330546b7b5145John McCall  /// It is always unqualified, always a template specialization type,
288231f17ecbef57b5679c017c375db330546b7b5145John McCall  /// and always dependent.
288331f17ecbef57b5679c017c375db330546b7b5145John McCall  QualType InjectedType;
28843cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall
28853cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  friend class ASTContext; // ASTContext creates these.
2886c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl  friend class ASTReader; // FIXME: ASTContext::getInjectedClassNameType is not
2887c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl                          // currently suitable for AST reading, too much
288843921b53b582145f0d1b7c48223bd4d9f0a9d1beArgyrios Kyrtzidis                          // interdependencies.
288931f17ecbef57b5679c017c375db330546b7b5145John McCall  InjectedClassNameType(CXXRecordDecl *D, QualType TST)
289035495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    : Type(InjectedClassName, QualType(), /*Dependent=*/true,
2891d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor           /*VariablyModified=*/false,
2892d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor           /*ContainsUnexpandedParameterPack=*/false),
289331f17ecbef57b5679c017c375db330546b7b5145John McCall      Decl(D), InjectedType(TST) {
28943cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall    assert(isa<TemplateSpecializationType>(TST));
28953cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall    assert(!TST.hasQualifiers());
289631f17ecbef57b5679c017c375db330546b7b5145John McCall    assert(TST->isDependentType());
28973cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  }
28983cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall
28993cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCallpublic:
290031f17ecbef57b5679c017c375db330546b7b5145John McCall  QualType getInjectedSpecializationType() const { return InjectedType; }
290131f17ecbef57b5679c017c375db330546b7b5145John McCall  const TemplateSpecializationType *getInjectedTST() const {
290231f17ecbef57b5679c017c375db330546b7b5145John McCall    return cast<TemplateSpecializationType>(InjectedType.getTypePtr());
29033cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  }
29043cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall
2905ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl  CXXRecordDecl *getDecl() const;
29063cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall
290731f17ecbef57b5679c017c375db330546b7b5145John McCall  bool isSugared() const { return false; }
290831f17ecbef57b5679c017c375db330546b7b5145John McCall  QualType desugar() const { return QualType(this, 0); }
29093cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall
29103cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  static bool classof(const Type *T) {
29113cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall    return T->getTypeClass() == InjectedClassName;
29123cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  }
29133cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  static bool classof(const InjectedClassNameType *T) { return true; }
29143cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall};
29153cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall
2916465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// \brief The kind of a tag type.
2917465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnaraenum TagTypeKind {
2918465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// \brief The "struct" keyword.
2919465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  TTK_Struct,
2920465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// \brief The "union" keyword.
2921465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  TTK_Union,
2922465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// \brief The "class" keyword.
2923465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  TTK_Class,
2924465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// \brief The "enum" keyword.
2925465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  TTK_Enum
2926465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara};
2927465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
29284a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// \brief The elaboration keyword that precedes a qualified type name or
29294a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// introduces an elaborated-type-specifier.
29304a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregorenum ElaboratedTypeKeyword {
29314a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor  /// \brief The "struct" keyword introduces the elaborated-type-specifier.
29324a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor  ETK_Struct,
29334a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor  /// \brief The "union" keyword introduces the elaborated-type-specifier.
29344a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor  ETK_Union,
2935465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// \brief The "class" keyword introduces the elaborated-type-specifier.
2936465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  ETK_Class,
29374a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor  /// \brief The "enum" keyword introduces the elaborated-type-specifier.
2938465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  ETK_Enum,
2939465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// \brief The "typename" keyword precedes the qualified type name, e.g.,
2940465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// \c typename T::type.
2941465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  ETK_Typename,
2942465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// \brief No keyword precedes the qualified type name.
2943465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  ETK_None
29444a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor};
2945465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
2946465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// A helper class for Type nodes having an ElaboratedTypeKeyword.
2947465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// The keyword in stored in the free bits of the base class.
2948465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// Also provides a few static helpers for converting and printing
2949465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// elaborated type keyword and tag type kind enumerations.
2950465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnaraclass TypeWithKeyword : public Type {
2951465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnaraprotected:
2952465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  TypeWithKeyword(ElaboratedTypeKeyword Keyword, TypeClass tc,
2953d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor                  QualType Canonical, bool Dependent, bool VariablyModified,
2954d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor                  bool ContainsUnexpandedParameterPack)
2955d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  : Type(tc, Canonical, Dependent, VariablyModified,
2956d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor         ContainsUnexpandedParameterPack) {
295777be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall    TypeWithKeywordBits.Keyword = Keyword;
295877be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall  }
2959465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
2960465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnarapublic:
2961465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  ElaboratedTypeKeyword getKeyword() const {
296277be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall    return static_cast<ElaboratedTypeKeyword>(TypeWithKeywordBits.Keyword);
2963465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  }
2964465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
2965465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// getKeywordForTypeSpec - Converts a type specifier (DeclSpec::TST)
2966465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// into an elaborated type keyword.
2967465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  static ElaboratedTypeKeyword getKeywordForTypeSpec(unsigned TypeSpec);
2968465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
2969465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// getTagTypeKindForTypeSpec - Converts a type specifier (DeclSpec::TST)
2970465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// into a tag type kind.  It is an error to provide a type specifier
2971465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// which *isn't* a tag kind here.
2972465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  static TagTypeKind getTagTypeKindForTypeSpec(unsigned TypeSpec);
2973465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
2974465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// getKeywordForTagDeclKind - Converts a TagTypeKind into an
2975465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// elaborated type keyword.
2976465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  static ElaboratedTypeKeyword getKeywordForTagTypeKind(TagTypeKind Tag);
2977465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
2978465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// getTagTypeKindForKeyword - Converts an elaborated type keyword into
2979465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  // a TagTypeKind. It is an error to provide an elaborated type keyword
2980465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// which *isn't* a tag kind here.
2981465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  static TagTypeKind getTagTypeKindForKeyword(ElaboratedTypeKeyword Keyword);
2982465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
2983465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  static bool KeywordIsTagTypeKind(ElaboratedTypeKeyword Keyword);
2984465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
2985465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  static const char *getKeywordName(ElaboratedTypeKeyword Keyword);
2986465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
2987465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  static const char *getTagTypeKindName(TagTypeKind Kind) {
2988465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    return getKeywordName(getKeywordForTagTypeKind(Kind));
2989465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  }
2990465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
2991465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  class CannotCastToThisType {};
2992465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  static CannotCastToThisType classof(const Type *);
2993465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara};
2994465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
2995465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// \brief Represents a type that was referred to using an elaborated type
2996465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// keyword, e.g., struct S, or via a qualified name, e.g., N::M::type,
2997465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// or both.
2998e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor///
2999e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor/// This type is used to keep track of a type name as written in the
3000465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// source code, including tag keywords and any nested-name-specifiers.
3001465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// The type itself is always "sugar", used to express what was written
3002465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// in the source code but containing no additional semantic information.
3003465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnaraclass ElaboratedType : public TypeWithKeyword, public llvm::FoldingSetNode {
3004465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
3005ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor  /// \brief The nested name specifier containing the qualifier.
3006ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor  NestedNameSpecifier *NNS;
3007e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor
3008e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor  /// \brief The type that this qualified name refers to.
3009e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor  QualType NamedType;
3010e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor
3011465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  ElaboratedType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS,
3012465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara                 QualType NamedType, QualType CanonType)
3013465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    : TypeWithKeyword(Keyword, Elaborated, CanonType,
301435495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor                      NamedType->isDependentType(),
3015d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor                      NamedType->isVariablyModifiedType(),
3016d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor                      NamedType->containsUnexpandedParameterPack()),
3017465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara      NNS(NNS), NamedType(NamedType) {
3018465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    assert(!(Keyword == ETK_None && NNS == 0) &&
3019465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara           "ElaboratedType cannot have elaborated type keyword "
3020465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara           "and name qualifier both null.");
3021465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  }
3022e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor
3023e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor  friend class ASTContext;  // ASTContext creates these
3024e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor
3025e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregorpublic:
302633500955d731c73717af52088b7fc0e7a85681e7John McCall  ~ElaboratedType();
3027465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
3028ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor  /// \brief Retrieve the qualification on this type.
3029ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor  NestedNameSpecifier *getQualifier() const { return NNS; }
3030e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor
3031e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor  /// \brief Retrieve the type named by the qualified-id.
3032e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor  QualType getNamedType() const { return NamedType; }
3033e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor
3034bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// \brief Remove a single level of sugar.
3035bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return getNamedType(); }
3036bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
3037bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// \brief Returns whether this type directly provides sugar.
3038bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return true; }
3039bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
3040e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor  void Profile(llvm::FoldingSetNodeID &ID) {
3041465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    Profile(ID, getKeyword(), NNS, NamedType);
3042e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor  }
3043e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor
3044465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  static void Profile(llvm::FoldingSetNodeID &ID, ElaboratedTypeKeyword Keyword,
3045465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara                      NestedNameSpecifier *NNS, QualType NamedType) {
3046465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    ID.AddInteger(Keyword);
3047ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor    ID.AddPointer(NNS);
3048ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor    NamedType.Profile(ID);
3049ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor  }
3050e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor
30511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
3052465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    return T->getTypeClass() == Elaborated;
3053e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor  }
3054465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  static bool classof(const ElaboratedType *T) { return true; }
3055e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor};
3056e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor
30574a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// \brief Represents a qualified type name for which the type name is
30584a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// dependent.
3059d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor///
30604a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// DependentNameType represents a class of dependent types that involve a
30614a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// dependent nested-name-specifier (e.g., "T::") followed by a (dependent)
30624a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// name of a type. The DependentNameType may start with a "typename" (for a
30634a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// typename-specifier), "class", "struct", "union", or "enum" (for a
30644a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// dependent elaborated-type-specifier), or nothing (in contexts where we
30654a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// know that we must be referring to a type, e.g., in a base class specifier).
3066465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnaraclass DependentNameType : public TypeWithKeyword, public llvm::FoldingSetNode {
3067465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
3068d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  /// \brief The nested name specifier containing the qualifier.
3069d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  NestedNameSpecifier *NNS;
3070d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor
3071d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  /// \brief The type that this typename specifier refers to.
307233500955d731c73717af52088b7fc0e7a85681e7John McCall  const IdentifierInfo *Name;
3073d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor
30744a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor  DependentNameType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS,
30754a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor                    const IdentifierInfo *Name, QualType CanonType)
307635495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    : TypeWithKeyword(Keyword, DependentName, CanonType, /*Dependent=*/true,
3077d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor                      /*VariablyModified=*/false,
3078d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor                      NNS->containsUnexpandedParameterPack()),
3079465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara      NNS(NNS), Name(Name) {
30801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    assert(NNS->isDependent() &&
30814714c12a1ab759156b78be8f109ea4c12213af57Douglas Gregor           "DependentNameType requires a dependent nested-name-specifier");
3082d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  }
3083d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor
3084d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  friend class ASTContext;  // ASTContext creates these
3085d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor
3086d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregorpublic:
3087d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  /// \brief Retrieve the qualification on this type.
3088d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  NestedNameSpecifier *getQualifier() const { return NNS; }
3089d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor
30901734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor  /// \brief Retrieve the type named by the typename specifier as an
30911734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor  /// identifier.
30921734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor  ///
30931734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor  /// This routine will return a non-NULL identifier pointer when the
30941734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor  /// form of the original typename was terminated by an identifier,
30951734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor  /// e.g., "typename T::type".
30961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  const IdentifierInfo *getIdentifier() const {
309733500955d731c73717af52088b7fc0e7a85681e7John McCall    return Name;
30981734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor  }
3099d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor
3100bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
3101bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
3102bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
3103d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  void Profile(llvm::FoldingSetNodeID &ID) {
3104465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    Profile(ID, getKeyword(), NNS, Name);
3105d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  }
3106d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor
31074a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor  static void Profile(llvm::FoldingSetNodeID &ID, ElaboratedTypeKeyword Keyword,
310833500955d731c73717af52088b7fc0e7a85681e7John McCall                      NestedNameSpecifier *NNS, const IdentifierInfo *Name) {
31094a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor    ID.AddInteger(Keyword);
3110d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor    ID.AddPointer(NNS);
311133500955d731c73717af52088b7fc0e7a85681e7John McCall    ID.AddPointer(Name);
3112d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  }
3113d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor
31141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
31154714c12a1ab759156b78be8f109ea4c12213af57Douglas Gregor    return T->getTypeClass() == DependentName;
3116d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  }
31174714c12a1ab759156b78be8f109ea4c12213af57Douglas Gregor  static bool classof(const DependentNameType *T) { return true; }
3118d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor};
3119d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor
312033500955d731c73717af52088b7fc0e7a85681e7John McCall/// DependentTemplateSpecializationType - Represents a template
312133500955d731c73717af52088b7fc0e7a85681e7John McCall/// specialization type whose template cannot be resolved, e.g.
312233500955d731c73717af52088b7fc0e7a85681e7John McCall///   A<T>::template B<T>
312333500955d731c73717af52088b7fc0e7a85681e7John McCallclass DependentTemplateSpecializationType :
312433500955d731c73717af52088b7fc0e7a85681e7John McCall  public TypeWithKeyword, public llvm::FoldingSetNode {
312533500955d731c73717af52088b7fc0e7a85681e7John McCall
312633500955d731c73717af52088b7fc0e7a85681e7John McCall  /// \brief The nested name specifier containing the qualifier.
312733500955d731c73717af52088b7fc0e7a85681e7John McCall  NestedNameSpecifier *NNS;
312833500955d731c73717af52088b7fc0e7a85681e7John McCall
312933500955d731c73717af52088b7fc0e7a85681e7John McCall  /// \brief The identifier of the template.
313033500955d731c73717af52088b7fc0e7a85681e7John McCall  const IdentifierInfo *Name;
313133500955d731c73717af52088b7fc0e7a85681e7John McCall
313233500955d731c73717af52088b7fc0e7a85681e7John McCall  /// \brief - The number of template arguments named in this class
313333500955d731c73717af52088b7fc0e7a85681e7John McCall  /// template specialization.
313433500955d731c73717af52088b7fc0e7a85681e7John McCall  unsigned NumArgs;
313533500955d731c73717af52088b7fc0e7a85681e7John McCall
313633500955d731c73717af52088b7fc0e7a85681e7John McCall  const TemplateArgument *getArgBuffer() const {
313733500955d731c73717af52088b7fc0e7a85681e7John McCall    return reinterpret_cast<const TemplateArgument*>(this+1);
313833500955d731c73717af52088b7fc0e7a85681e7John McCall  }
313933500955d731c73717af52088b7fc0e7a85681e7John McCall  TemplateArgument *getArgBuffer() {
314033500955d731c73717af52088b7fc0e7a85681e7John McCall    return reinterpret_cast<TemplateArgument*>(this+1);
314133500955d731c73717af52088b7fc0e7a85681e7John McCall  }
314233500955d731c73717af52088b7fc0e7a85681e7John McCall
3143ef99001908e799c388f1363b1e607dad5f5b57d3John McCall  DependentTemplateSpecializationType(ElaboratedTypeKeyword Keyword,
314433500955d731c73717af52088b7fc0e7a85681e7John McCall                                      NestedNameSpecifier *NNS,
314533500955d731c73717af52088b7fc0e7a85681e7John McCall                                      const IdentifierInfo *Name,
314633500955d731c73717af52088b7fc0e7a85681e7John McCall                                      unsigned NumArgs,
314733500955d731c73717af52088b7fc0e7a85681e7John McCall                                      const TemplateArgument *Args,
314833500955d731c73717af52088b7fc0e7a85681e7John McCall                                      QualType Canon);
314933500955d731c73717af52088b7fc0e7a85681e7John McCall
315033500955d731c73717af52088b7fc0e7a85681e7John McCall  friend class ASTContext;  // ASTContext creates these
315133500955d731c73717af52088b7fc0e7a85681e7John McCall
315233500955d731c73717af52088b7fc0e7a85681e7John McCallpublic:
315333500955d731c73717af52088b7fc0e7a85681e7John McCall  NestedNameSpecifier *getQualifier() const { return NNS; }
315433500955d731c73717af52088b7fc0e7a85681e7John McCall  const IdentifierInfo *getIdentifier() const { return Name; }
315533500955d731c73717af52088b7fc0e7a85681e7John McCall
315633500955d731c73717af52088b7fc0e7a85681e7John McCall  /// \brief Retrieve the template arguments.
315733500955d731c73717af52088b7fc0e7a85681e7John McCall  const TemplateArgument *getArgs() const {
315833500955d731c73717af52088b7fc0e7a85681e7John McCall    return getArgBuffer();
315933500955d731c73717af52088b7fc0e7a85681e7John McCall  }
316033500955d731c73717af52088b7fc0e7a85681e7John McCall
316133500955d731c73717af52088b7fc0e7a85681e7John McCall  /// \brief Retrieve the number of template arguments.
316233500955d731c73717af52088b7fc0e7a85681e7John McCall  unsigned getNumArgs() const { return NumArgs; }
316333500955d731c73717af52088b7fc0e7a85681e7John McCall
316433500955d731c73717af52088b7fc0e7a85681e7John McCall  const TemplateArgument &getArg(unsigned Idx) const; // in TemplateBase.h
316533500955d731c73717af52088b7fc0e7a85681e7John McCall
316633500955d731c73717af52088b7fc0e7a85681e7John McCall  typedef const TemplateArgument * iterator;
316733500955d731c73717af52088b7fc0e7a85681e7John McCall  iterator begin() const { return getArgs(); }
316833500955d731c73717af52088b7fc0e7a85681e7John McCall  iterator end() const; // inline in TemplateBase.h
316933500955d731c73717af52088b7fc0e7a85681e7John McCall
317033500955d731c73717af52088b7fc0e7a85681e7John McCall  bool isSugared() const { return false; }
317133500955d731c73717af52088b7fc0e7a85681e7John McCall  QualType desugar() const { return QualType(this, 0); }
317233500955d731c73717af52088b7fc0e7a85681e7John McCall
3173ef99001908e799c388f1363b1e607dad5f5b57d3John McCall  void Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context) {
317433500955d731c73717af52088b7fc0e7a85681e7John McCall    Profile(ID, Context, getKeyword(), NNS, Name, NumArgs, getArgs());
317533500955d731c73717af52088b7fc0e7a85681e7John McCall  }
317633500955d731c73717af52088b7fc0e7a85681e7John McCall
317733500955d731c73717af52088b7fc0e7a85681e7John McCall  static void Profile(llvm::FoldingSetNodeID &ID,
317833500955d731c73717af52088b7fc0e7a85681e7John McCall                      ASTContext &Context,
317933500955d731c73717af52088b7fc0e7a85681e7John McCall                      ElaboratedTypeKeyword Keyword,
318033500955d731c73717af52088b7fc0e7a85681e7John McCall                      NestedNameSpecifier *Qualifier,
318133500955d731c73717af52088b7fc0e7a85681e7John McCall                      const IdentifierInfo *Name,
318233500955d731c73717af52088b7fc0e7a85681e7John McCall                      unsigned NumArgs,
318333500955d731c73717af52088b7fc0e7a85681e7John McCall                      const TemplateArgument *Args);
318433500955d731c73717af52088b7fc0e7a85681e7John McCall
318533500955d731c73717af52088b7fc0e7a85681e7John McCall  static bool classof(const Type *T) {
318633500955d731c73717af52088b7fc0e7a85681e7John McCall    return T->getTypeClass() == DependentTemplateSpecialization;
318733500955d731c73717af52088b7fc0e7a85681e7John McCall  }
318833500955d731c73717af52088b7fc0e7a85681e7John McCall  static bool classof(const DependentTemplateSpecializationType *T) {
318933500955d731c73717af52088b7fc0e7a85681e7John McCall    return true;
319033500955d731c73717af52088b7fc0e7a85681e7John McCall  }
319133500955d731c73717af52088b7fc0e7a85681e7John McCall};
319233500955d731c73717af52088b7fc0e7a85681e7John McCall
31937536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// \brief Represents a pack expansion of types.
31947536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor///
31957536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// Pack expansions are part of C++0x variadic templates. A pack
31967536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// expansion contains a pattern, which itself contains one or more
31977536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// "unexpanded" parameter packs. When instantiated, a pack expansion
31987536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// produces a series of types, each instantiated from the pattern of
31997536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// the expansion, where the Ith instantiation of the pattern uses the
32007536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// Ith arguments bound to each of the unexpanded parameter packs. The
32017536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// pack expansion is considered to "expand" these unexpanded
32027536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// parameter packs.
32037536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor///
32047536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// \code
32057536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// template<typename ...Types> struct tuple;
32067536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor///
32077536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// template<typename ...Types>
32087536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// struct tuple_of_references {
32097536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor///   typedef tuple<Types&...> type;
32107536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// };
32117536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// \endcode
32127536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor///
32137536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// Here, the pack expansion \c Types&... is represented via a
32147536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// PackExpansionType whose pattern is Types&.
32157536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregorclass PackExpansionType : public Type, public llvm::FoldingSetNode {
32167536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  /// \brief The pattern of the pack expansion.
32177536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  QualType Pattern;
32187536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor
32197536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  PackExpansionType(QualType Pattern, QualType Canon)
32207536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor    : Type(PackExpansion, Canon, /*Dependent=*/true,
32217536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor           /*VariableModified=*/Pattern->isVariablyModifiedType(),
32227536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor           /*ContainsUnexpandedParameterPack=*/false),
32237536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor      Pattern(Pattern) { }
32247536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor
32257536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  friend class ASTContext;  // ASTContext creates these
32267536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor
32277536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregorpublic:
32287536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  /// \brief Retrieve the pattern of this pack expansion, which is the
32297536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  /// type that will be repeatedly instantiated when instantiating the
32307536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  /// pack expansion itself.
32317536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  QualType getPattern() const { return Pattern; }
32327536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor
32337536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  bool isSugared() const { return false; }
32347536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  QualType desugar() const { return QualType(this, 0); }
32357536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor
32367536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  void Profile(llvm::FoldingSetNodeID &ID) {
32377536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor    Profile(ID, getPattern());
32387536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  }
32397536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor
32407536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  static void Profile(llvm::FoldingSetNodeID &ID, QualType Pattern) {
32417536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor    ID.AddPointer(Pattern.getAsOpaquePtr());
32427536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  }
32437536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor
32447536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  static bool classof(const Type *T) {
32457536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor    return T->getTypeClass() == PackExpansion;
32467536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  }
32477536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  static bool classof(const PackExpansionType *T) {
32487536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor    return true;
32497536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  }
32507536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor};
32517536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor
3252c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// ObjCObjectType - Represents a class type in Objective C.
3253c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// Every Objective C type is a combination of a base type and a
3254c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// list of protocols.
3255c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall///
3256c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// Given the following declarations:
3257c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall///   @class C;
3258c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall///   @protocol P;
3259c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall///
3260c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// 'C' is an ObjCInterfaceType C.  It is sugar for an ObjCObjectType
3261c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// with base C and no protocols.
3262c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall///
3263c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// 'C<P>' is an ObjCObjectType with base C and protocol list [P].
3264c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall///
3265e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// 'id' is a TypedefType which is sugar for an ObjCPointerType whose
3266e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// pointee is an ObjCObjectType with base BuiltinType::ObjCIdType
3267e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// and no protocols.
3268c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall///
3269e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// 'id<P>' is an ObjCPointerType whose pointee is an ObjCObjecType
3270e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// with base BuiltinType::ObjCIdType and protocol list [P].  Eventually
3271e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// this should get its own sugar class to better represent the source.
3272c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallclass ObjCObjectType : public Type {
3273b870b88df784c2940efce448ebfaf54dece14666John McCall  // ObjCObjectType.NumProtocols - the number of protocols stored
3274b870b88df784c2940efce448ebfaf54dece14666John McCall  // after the ObjCObjectPointerType node.
327571c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  //
327671c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  // These protocols are those written directly on the type.  If
327771c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  // protocol qualifiers ever become additive, the iterators will need
327871c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  // to get kindof complicated.
327971c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  //
328071c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  // In the canonical object type, these are sorted alphabetically
328171c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  // and uniqued.
3282c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff
3283c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  /// Either a BuiltinType or an InterfaceType or sugar for either.
3284c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  QualType BaseType;
3285c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3286c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  ObjCProtocolDecl * const *getProtocolStorage() const {
3287c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return const_cast<ObjCObjectType*>(this)->getProtocolStorage();
3288c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  }
3289c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3290c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  ObjCProtocolDecl **getProtocolStorage();
3291c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3292c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallprotected:
3293c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  ObjCObjectType(QualType Canonical, QualType Base,
3294c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall                 ObjCProtocolDecl * const *Protocols, unsigned NumProtocols);
3295c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3296c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  enum Nonce_ObjCInterface { Nonce_ObjCInterface };
3297c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  ObjCObjectType(enum Nonce_ObjCInterface)
3298d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor        : Type(ObjCInterface, QualType(), false, false, false),
329971c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall      BaseType(QualType(this_(), 0)) {
3300b870b88df784c2940efce448ebfaf54dece14666John McCall    ObjCObjectTypeBits.NumProtocols = 0;
330171c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  }
3302c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff
33033536b443bc50d58a79f14fca9b6842541a434854Steve Naroffpublic:
3304e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// getBaseType - Gets the base type of this object type.  This is
3305e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// always (possibly sugar for) one of:
3306e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///  - the 'id' builtin type (as opposed to the 'id' type visible to the
3307e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///    user, which is a typedef for an ObjCPointerType)
3308e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///  - the 'Class' builtin type (same caveat)
3309e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///  - an ObjCObjectType (currently always an ObjCInterfaceType)
3310c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  QualType getBaseType() const { return BaseType; }
331171842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek
3312c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool isObjCId() const {
3313c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getBaseType()->isSpecificBuiltinType(BuiltinType::ObjCId);
3314c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  }
3315c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool isObjCClass() const {
3316c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getBaseType()->isSpecificBuiltinType(BuiltinType::ObjCClass);
3317c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  }
3318c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool isObjCUnqualifiedId() const { return qual_empty() && isObjCId(); }
3319c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool isObjCUnqualifiedClass() const { return qual_empty() && isObjCClass(); }
3320c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool isObjCUnqualifiedIdOrClass() const {
3321c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    if (!qual_empty()) return false;
3322c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    if (const BuiltinType *T = getBaseType()->getAs<BuiltinType>())
3323c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall      return T->getKind() == BuiltinType::ObjCId ||
3324c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall             T->getKind() == BuiltinType::ObjCClass;
3325c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return false;
3326c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  }
3327c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool isObjCQualifiedId() const { return !qual_empty() && isObjCId(); }
3328c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool isObjCQualifiedClass() const { return !qual_empty() && isObjCClass(); }
3329c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3330c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  /// Gets the interface declaration for this object type, if the base type
3331c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  /// really is an interface.
3332c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  ObjCInterfaceDecl *getInterface() const;
3333c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3334c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  typedef ObjCProtocolDecl * const *qual_iterator;
3335c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3336c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  qual_iterator qual_begin() const { return getProtocolStorage(); }
3337c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  qual_iterator qual_end() const { return qual_begin() + getNumProtocols(); }
3338c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3339c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool qual_empty() const { return getNumProtocols() == 0; }
33401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3341c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff  /// getNumProtocols - Return the number of qualifying protocols in this
3342c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff  /// interface type, or 0 if there are none.
3343b870b88df784c2940efce448ebfaf54dece14666John McCall  unsigned getNumProtocols() const { return ObjCObjectTypeBits.NumProtocols; }
334414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff
3345c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  /// \brief Fetch a protocol by index.
334673dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor  ObjCProtocolDecl *getProtocol(unsigned I) const {
334773dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor    assert(I < getNumProtocols() && "Out-of-range protocol access");
334873dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor    return qual_begin()[I];
334973dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor  }
335073dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor
3351bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
3352bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
3353bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
3354c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  static bool classof(const Type *T) {
3355c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return T->getTypeClass() == ObjCObject ||
3356c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall           T->getTypeClass() == ObjCInterface;
3357c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  }
3358c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  static bool classof(const ObjCObjectType *) { return true; }
3359c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall};
3360c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3361c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// ObjCObjectTypeImpl - A class providing a concrete implementation
3362c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// of ObjCObjectType, so as to not increase the footprint of
3363c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// ObjCInterfaceType.  Code outside of ASTContext and the core type
3364c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// system should not reference this type.
3365c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallclass ObjCObjectTypeImpl : public ObjCObjectType, public llvm::FoldingSetNode {
3366c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  friend class ASTContext;
3367c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3368c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  // If anyone adds fields here, ObjCObjectType::getProtocolStorage()
3369c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  // will need to be modified.
3370c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3371c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  ObjCObjectTypeImpl(QualType Canonical, QualType Base,
3372c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall                     ObjCProtocolDecl * const *Protocols,
3373c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall                     unsigned NumProtocols)
3374c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    : ObjCObjectType(Canonical, Base, Protocols, NumProtocols) {}
3375c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3376c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallpublic:
3377c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff  void Profile(llvm::FoldingSetNodeID &ID);
33781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static void Profile(llvm::FoldingSetNodeID &ID,
3379c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall                      QualType Base,
3380c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall                      ObjCProtocolDecl *const *protocols,
3381c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall                      unsigned NumProtocols);
3382c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall};
33831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3384c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallinline ObjCProtocolDecl **ObjCObjectType::getProtocolStorage() {
3385c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  return reinterpret_cast<ObjCProtocolDecl**>(
3386c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall            static_cast<ObjCObjectTypeImpl*>(this) + 1);
3387c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall}
3388c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3389c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// ObjCInterfaceType - Interfaces are the core concept in Objective-C for
3390c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// object oriented design.  They basically correspond to C++ classes.  There
3391c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// are two kinds of interface types, normal interfaces like "NSString" and
3392c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// qualified interfaces, which are qualified with a protocol list like
3393c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// "NSString<NSCopyable, NSAmazing>".
3394e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall///
3395e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// ObjCInterfaceType guarantees the following properties when considered
3396e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// as a subtype of its superclass, ObjCObjectType:
3397e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall///   - There are no protocol qualifiers.  To reinforce this, code which
3398e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall///     tries to invoke the protocol methods via an ObjCInterfaceType will
3399e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall///     fail to compile.
3400e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall///   - It is its own base type.  That is, if T is an ObjCInterfaceType*,
3401e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall///     T->getBaseType() == QualType(T, 0).
3402c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallclass ObjCInterfaceType : public ObjCObjectType {
3403c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  ObjCInterfaceDecl *Decl;
3404c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3405c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  ObjCInterfaceType(const ObjCInterfaceDecl *D)
3406c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    : ObjCObjectType(Nonce_ObjCInterface),
3407c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall      Decl(const_cast<ObjCInterfaceDecl*>(D)) {}
3408c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  friend class ASTContext;  // ASTContext creates these.
34091fb0caaa7bef765b85972274e3b434af2572c141John McCall
3410c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallpublic:
3411e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// getDecl - Get the declaration of this interface.
3412deacbdca554298ccdf636f19c6094a8825ec6b34Douglas Gregor  ObjCInterfaceDecl *getDecl() const { return Decl; }
3413c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3414c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool isSugared() const { return false; }
3415c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  QualType desugar() const { return QualType(this, 0); }
34160b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor
34171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
34181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == ObjCInterface;
34193536b443bc50d58a79f14fca9b6842541a434854Steve Naroff  }
3420a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const ObjCInterfaceType *) { return true; }
3421c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3422c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  // Nonsense to "hide" certain members of ObjCObjectType within this
3423c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  // class.  People asking for protocols on an ObjCInterfaceType are
3424c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  // not going to get what they want: ObjCInterfaceTypes are
3425c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  // guaranteed to have no protocols.
3426c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  enum {
3427c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    qual_iterator,
3428c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    qual_begin,
3429c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    qual_end,
3430c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    getNumProtocols,
3431c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    getProtocol
3432c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  };
34333536b443bc50d58a79f14fca9b6842541a434854Steve Naroff};
34343536b443bc50d58a79f14fca9b6842541a434854Steve Naroff
3435c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallinline ObjCInterfaceDecl *ObjCObjectType::getInterface() const {
3436c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  if (const ObjCInterfaceType *T =
3437c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall        getBaseType()->getAs<ObjCInterfaceType>())
3438c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return T->getDecl();
3439c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  return 0;
3440c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall}
3441c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3442e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// ObjCObjectPointerType - Used to represent a pointer to an
3443e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// Objective C object.  These are constructed from pointer
3444e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// declarators when the pointee type is an ObjCObjectType (or sugar
3445e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// for one).  In addition, the 'id' and 'Class' types are typedefs
3446e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// for these, and the protocol-qualified types 'id<P>' and 'Class<P>'
3447e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// are translated into these.
344814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff///
3449e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// Pointers to pointers to Objective C objects are still PointerTypes;
3450e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// only the first level of pointer gets it own type implementation.
345114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroffclass ObjCObjectPointerType : public Type, public llvm::FoldingSetNode {
3452e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  QualType PointeeType;
34531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3454c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  ObjCObjectPointerType(QualType Canonical, QualType Pointee)
3455d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    : Type(ObjCObjectPointer, Canonical, false, false, false),
3456c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall      PointeeType(Pointee) {}
345714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  friend class ASTContext;  // ASTContext creates these.
34581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
345914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroffpublic:
3460e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// getPointeeType - Gets the type pointed to by this ObjC pointer.
3461e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// The result will always be an ObjCObjectType or sugar thereof.
346214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  QualType getPointeeType() const { return PointeeType; }
346314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff
3464e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// getObjCObjectType - Gets the type pointed to by this ObjC
3465e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// pointer.  This method always returns non-null.
3466e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///
3467e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// This method is equivalent to getPointeeType() except that
3468e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// it discards any typedefs (or other sugar) between this
3469e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// type and the "outermost" object type.  So for:
3470e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///   @class A; @protocol P; @protocol Q;
3471e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///   typedef A<P> AP;
3472e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///   typedef A A1;
3473e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///   typedef A1<P> A1P;
3474e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///   typedef A1P<Q> A1PQ;
3475e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// For 'A*', getObjectType() will return 'A'.
3476e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// For 'A<P>*', getObjectType() will return 'A<P>'.
3477e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// For 'AP*', getObjectType() will return 'A<P>'.
3478e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// For 'A1*', getObjectType() will return 'A'.
3479e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// For 'A1<P>*', getObjectType() will return 'A1<P>'.
3480e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// For 'A1P*', getObjectType() will return 'A1<P>'.
3481e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// For 'A1PQ*', getObjectType() will return 'A1<Q>', because
3482e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///   adding protocols to a protocol-qualified base discards the
3483e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///   old qualifiers (for now).  But if it didn't, getObjectType()
3484e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///   would return 'A1P<Q>' (and we'd have to make iterating over
3485e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///   qualifiers more complicated).
3486c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  const ObjCObjectType *getObjectType() const {
3487c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return PointeeType->getAs<ObjCObjectType>();
3488c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  }
3489c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3490e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// getInterfaceType - If this pointer points to an Objective C
3491e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// @interface type, gets the type for that interface.  Any protocol
3492e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// qualifiers on the interface are ignored.
3493e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///
3494e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// \return null if the base type for this pointer is 'id' or 'Class'
34951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  const ObjCInterfaceType *getInterfaceType() const {
3496c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getObjectType()->getBaseType()->getAs<ObjCInterfaceType>();
349714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  }
3498e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall
3499e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// getInterfaceDecl - If this pointer points to an Objective @interface
3500e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// type, gets the declaration for that interface.
3501e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///
3502e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// \return null if the base type for this pointer is 'id' or 'Class'
350314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  ObjCInterfaceDecl *getInterfaceDecl() const {
3504e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall    return getObjectType()->getInterface();
350514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  }
3506e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall
3507e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// isObjCIdType - True if this is equivalent to the 'id' type, i.e. if
3508e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// its object type is the primitive 'id' type with no protocols.
350914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  bool isObjCIdType() const {
3510c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getObjectType()->isObjCUnqualifiedId();
351114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  }
3512e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall
3513e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// isObjCClassType - True if this is equivalent to the 'Class' type,
3514e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// i.e. if its object tive is the primitive 'Class' type with no protocols.
351514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  bool isObjCClassType() const {
3516c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getObjectType()->isObjCUnqualifiedClass();
3517de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff  }
35188d2c0a9814e56c2b22e22d1045181c735aef62fdFariborz Jahanian
3519e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// isObjCQualifiedIdType - True if this is equivalent to 'id<P>' for some
3520e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// non-empty set of protocols.
35211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  bool isObjCQualifiedIdType() const {
3522c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getObjectType()->isObjCQualifiedId();
3523de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff  }
3524e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall
3525e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// isObjCQualifiedClassType - True if this is equivalent to 'Class<P>' for
3526e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// some non-empty set of protocols.
3527470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroff  bool isObjCQualifiedClassType() const {
3528c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getObjectType()->isObjCQualifiedClass();
352914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  }
3530e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall
3531e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// An iterator over the qualifiers on the object type.  Provided
3532e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// for convenience.  This will always iterate over the full set of
3533e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// protocols on a type, not just those provided directly.
3534c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  typedef ObjCObjectType::qual_iterator qual_iterator;
353514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff
353671842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek  qual_iterator qual_begin() const {
3537c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getObjectType()->qual_begin();
353871842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek  }
3539c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  qual_iterator qual_end() const {
3540c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getObjectType()->qual_end();
354171842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek  }
3542c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool qual_empty() const { return getObjectType()->qual_empty(); }
354314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff
3544e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// getNumProtocols - Return the number of qualifying protocols on
3545e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// the object type.
3546c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  unsigned getNumProtocols() const {
3547c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getObjectType()->getNumProtocols();
3548c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  }
354914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff
3550e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// \brief Retrieve a qualifying protocol by index on the object
3551e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// type.
355273dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor  ObjCProtocolDecl *getProtocol(unsigned I) const {
3553c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getObjectType()->getProtocol(I);
355473dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor  }
355573dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor
3556bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
3557bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
3558bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
3559e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  void Profile(llvm::FoldingSetNodeID &ID) {
3560e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall    Profile(ID, getPointeeType());
3561e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  }
3562c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  static void Profile(llvm::FoldingSetNodeID &ID, QualType T) {
3563c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    ID.AddPointer(T.getAsOpaquePtr());
3564c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  }
35651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
35661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == ObjCObjectPointer;
356714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  }
356814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  static bool classof(const ObjCObjectPointerType *) { return true; }
356914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff};
35701bb8a45f7386a23871598d05141a07af03067925Argyrios Kyrtzidis
35710953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// A qualifier set is used to build a set of qualifiers.
35720953e767ff7817f97b3ab20896b229891eeff45bJohn McCallclass QualifierCollector : public Qualifiers {
35730953e767ff7817f97b3ab20896b229891eeff45bJohn McCallpublic:
357449f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  QualifierCollector(Qualifiers Qs = Qualifiers()) : Qualifiers(Qs) {}
35750953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
35760953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// Collect any qualifiers on the given type and return an
35770953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// unqualified type.
35780953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  const Type *strip(QualType QT) {
3579a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor    addFastQualifiers(QT.getLocalFastQualifiers());
3580a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor    if (QT.hasLocalNonFastQualifiers()) {
35810953e767ff7817f97b3ab20896b229891eeff45bJohn McCall      const ExtQuals *EQ = QT.getExtQualsUnsafe();
35820953e767ff7817f97b3ab20896b229891eeff45bJohn McCall      addQualifiers(EQ->getQualifiers());
35830953e767ff7817f97b3ab20896b229891eeff45bJohn McCall      return EQ->getBaseType();
35840953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    }
35850953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return QT.getTypePtrUnsafe();
35860953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
35870953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
35880953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// Apply the collected qualifiers to the given type.
358949f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  QualType apply(ASTContext &Context, QualType QT) const;
35900953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
35910953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// Apply the collected qualifiers to the given type.
359249f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  QualType apply(ASTContext &Context, const Type* T) const;
35930953e767ff7817f97b3ab20896b229891eeff45bJohn McCall};
35940953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
35950953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3596611c1fff195d32df97706e0920c92468b2509900Chris Lattner// Inline function definitions.
35975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3598467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCallinline bool QualType::isCanonical() const {
3599467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall  const Type *T = getTypePtr();
3600a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  if (hasLocalQualifiers())
3601467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall    return T->isCanonicalUnqualified() && !isa<ArrayType>(T);
3602467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall  return T->isCanonicalUnqualified();
3603467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall}
3604467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall
360554e14c4db764c0636160d26c5bbf491637c83a76John McCallinline bool QualType::isCanonicalAsParam() const {
3606a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  if (hasLocalQualifiers()) return false;
3607745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian
360854e14c4db764c0636160d26c5bbf491637c83a76John McCall  const Type *T = getTypePtr();
3609745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian  if ((*this)->isPointerType()) {
3610745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian    QualType BaseType = (*this)->getAs<PointerType>()->getPointeeType();
3611745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian    if (isa<VariableArrayType>(BaseType)) {
3612745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian      ArrayType *AT = dyn_cast<ArrayType>(BaseType);
3613745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian      VariableArrayType *VAT = cast<VariableArrayType>(AT);
3614745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian      if (VAT->getSizeExpr())
3615745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian        T = BaseType.getTypePtr();
3616745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian    }
3617745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian  }
361854e14c4db764c0636160d26c5bbf491637c83a76John McCall  return T->isCanonicalUnqualified() &&
361954e14c4db764c0636160d26c5bbf491637c83a76John McCall           !isa<FunctionType>(T) && !isa<ArrayType>(T);
362054e14c4db764c0636160d26c5bbf491637c83a76John McCall}
362154e14c4db764c0636160d26c5bbf491637c83a76John McCall
3622fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregorinline bool QualType::isConstQualified() const {
3623fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  return isLocalConstQualified() ||
3624fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor              getTypePtr()->getCanonicalTypeInternal().isLocalConstQualified();
3625fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor}
3626fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor
3627fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregorinline bool QualType::isRestrictQualified() const {
3628fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  return isLocalRestrictQualified() ||
3629fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor            getTypePtr()->getCanonicalTypeInternal().isLocalRestrictQualified();
3630fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor}
3631fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor
3632fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor
3633fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregorinline bool QualType::isVolatileQualified() const {
3634fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  return isLocalVolatileQualified() ||
3635fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  getTypePtr()->getCanonicalTypeInternal().isLocalVolatileQualified();
3636fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor}
3637fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor
3638fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregorinline bool QualType::hasQualifiers() const {
3639fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  return hasLocalQualifiers() ||
3640fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor                  getTypePtr()->getCanonicalTypeInternal().hasLocalQualifiers();
3641fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor}
3642fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor
3643fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregorinline Qualifiers QualType::getQualifiers() const {
3644fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  Qualifiers Quals = getLocalQualifiers();
3645fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  Quals.addQualifiers(
3646fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor                 getTypePtr()->getCanonicalTypeInternal().getLocalQualifiers());
3647fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  return Quals;
3648fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor}
3649fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor
3650fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregorinline unsigned QualType::getCVRQualifiers() const {
3651fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  return getLocalCVRQualifiers() |
3652fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor              getTypePtr()->getCanonicalTypeInternal().getLocalCVRQualifiers();
3653fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor}
3654e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth
3655e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth/// getCVRQualifiersThroughArrayTypes - If there are CVR qualifiers for this
3656e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth/// type, returns them. Otherwise, if this is an array type, recurses
3657e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth/// on the element type until some qualifiers have been found or a non-array
3658e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth/// type reached.
3659e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruthinline unsigned QualType::getCVRQualifiersThroughArrayTypes() const {
3660e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth  if (unsigned Quals = getCVRQualifiers())
3661e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth    return Quals;
3662e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth  QualType CT = getTypePtr()->getCanonicalTypeInternal();
3663e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth  if (const ArrayType *AT = dyn_cast<ArrayType>(CT))
3664e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth    return AT->getElementType().getCVRQualifiersThroughArrayTypes();
3665e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth  return 0;
3666e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth}
3667e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth
366849f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCallinline void QualType::removeLocalConst() {
366949f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  removeLocalFastQualifiers(Qualifiers::Const);
36700953e767ff7817f97b3ab20896b229891eeff45bJohn McCall}
36710953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
367249f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCallinline void QualType::removeLocalRestrict() {
367349f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  removeLocalFastQualifiers(Qualifiers::Restrict);
36740953e767ff7817f97b3ab20896b229891eeff45bJohn McCall}
36750953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
367649f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCallinline void QualType::removeLocalVolatile() {
367749f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  removeLocalFastQualifiers(Qualifiers::Volatile);
36780953e767ff7817f97b3ab20896b229891eeff45bJohn McCall}
36790953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
368049f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCallinline void QualType::removeLocalCVRQualifiers(unsigned Mask) {
36816b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall  assert(!(Mask & ~Qualifiers::CVRMask) && "mask has non-CVR bits");
3682c3c0af36bac3d71f61dd758585ab307892545de4Douglas Gregor  assert((int)Qualifiers::CVRMask == (int)Qualifiers::FastMask);
36830953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
36840953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Fast path: we don't need to touch the slow qualifiers.
368549f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  removeLocalFastQualifiers(Mask);
3686ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb}
3687ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb
3688ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb/// getAddressSpace - Return the address space of this type.
3689ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lambinline unsigned QualType::getAddressSpace() const {
3690a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  if (hasLocalNonFastQualifiers()) {
36910953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    const ExtQuals *EQ = getExtQualsUnsafe();
36920953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    if (EQ->hasAddressSpace())
36930953e767ff7817f97b3ab20896b229891eeff45bJohn McCall      return EQ->getAddressSpace();
36940953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
36950953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
36964243a94b43ef6207938f3023dfcfb804dd545363Chris Lattner  QualType CT = getTypePtr()->getCanonicalTypeInternal();
3697a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  if (CT.hasLocalNonFastQualifiers()) {
36980953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    const ExtQuals *EQ = CT.getExtQualsUnsafe();
36990953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    if (EQ->hasAddressSpace())
37000953e767ff7817f97b3ab20896b229891eeff45bJohn McCall      return EQ->getAddressSpace();
37010953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
37020953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
37034243a94b43ef6207938f3023dfcfb804dd545363Chris Lattner  if (const ArrayType *AT = dyn_cast<ArrayType>(CT))
3704c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner    return AT->getElementType().getAddressSpace();
37054243a94b43ef6207938f3023dfcfb804dd545363Chris Lattner  if (const RecordType *RT = dyn_cast<RecordType>(CT))
37068e7dafec4b70303dfaff95151cd06bfc5532720cNate Begeman    return RT->getAddressSpace();
3707ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb  return 0;
3708ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb}
3709611c1fff195d32df97706e0920c92468b2509900Chris Lattner
3710d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian/// getObjCGCAttr - Return the gc attribute of this type.
37110953e767ff7817f97b3ab20896b229891eeff45bJohn McCallinline Qualifiers::GC QualType::getObjCGCAttr() const {
3712a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  if (hasLocalNonFastQualifiers()) {
37130953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    const ExtQuals *EQ = getExtQualsUnsafe();
37140953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    if (EQ->hasObjCGCAttr())
37150953e767ff7817f97b3ab20896b229891eeff45bJohn McCall      return EQ->getObjCGCAttr();
37160953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
37170953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3718d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian  QualType CT = getTypePtr()->getCanonicalTypeInternal();
3719a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  if (CT.hasLocalNonFastQualifiers()) {
37200953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    const ExtQuals *EQ = CT.getExtQualsUnsafe();
37210953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    if (EQ->hasObjCGCAttr())
37220953e767ff7817f97b3ab20896b229891eeff45bJohn McCall      return EQ->getObjCGCAttr();
37230953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
37240953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3725d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian  if (const ArrayType *AT = dyn_cast<ArrayType>(CT))
3726d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian      return AT->getElementType().getObjCGCAttr();
3727183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  if (const ObjCObjectPointerType *PT = CT->getAs<ObjCObjectPointerType>())
37281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return PT->getPointeeType().getObjCGCAttr();
3729ac423ba85bb59cc7cc1d43081b20d7e8d40355ffFariborz Jahanian  // We most look at all pointer types, not just pointer to interface types.
3730ac423ba85bb59cc7cc1d43081b20d7e8d40355ffFariborz Jahanian  if (const PointerType *PT = CT->getAs<PointerType>())
37311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return PT->getPointeeType().getObjCGCAttr();
37320953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  return Qualifiers::GCNone;
3733d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian}
37342455636163fdd18581d7fdae816433f886d88213Mike Stump
3735264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindolainline FunctionType::ExtInfo getFunctionExtInfo(const Type &t) {
3736264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola  if (const PointerType *PT = t.getAs<PointerType>()) {
3737183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall    if (const FunctionType *FT = PT->getPointeeType()->getAs<FunctionType>())
3738264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola      return FT->getExtInfo();
3739264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola  } else if (const FunctionType *FT = t.getAs<FunctionType>())
3740264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    return FT->getExtInfo();
37412455636163fdd18581d7fdae816433f886d88213Mike Stump
3742264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola  return FunctionType::ExtInfo();
37432455636163fdd18581d7fdae816433f886d88213Mike Stump}
37441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3745264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindolainline FunctionType::ExtInfo getFunctionExtInfo(QualType t) {
3746264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola  return getFunctionExtInfo(*t);
3747ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor}
3748ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor
3749b87786f045d798b070980c108c922e1475d27b15Douglas Gregor/// \brief Determine whether this set of qualifiers is a superset of the given
3750b87786f045d798b070980c108c922e1475d27b15Douglas Gregor/// set of qualifiers.
3751b87786f045d798b070980c108c922e1475d27b15Douglas Gregorinline bool Qualifiers::isSupersetOf(Qualifiers Other) const {
3752b87786f045d798b070980c108c922e1475d27b15Douglas Gregor  return Mask != Other.Mask && (Mask | Other.Mask) == Mask;
3753b87786f045d798b070980c108c922e1475d27b15Douglas Gregor}
3754b87786f045d798b070980c108c922e1475d27b15Douglas Gregor
3755e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// isMoreQualifiedThan - Determine whether this type is more
3756e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// qualified than the Other type. For example, "const volatile int"
3757e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// is more qualified than "const int", "volatile int", and
3758e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// "int". However, it is not more qualified than "const volatile
3759e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// int".
3760e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregorinline bool QualType::isMoreQualifiedThan(QualType Other) const {
37610953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // FIXME: work on arbitrary qualifiers
3762e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth  unsigned MyQuals = this->getCVRQualifiersThroughArrayTypes();
3763e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth  unsigned OtherQuals = Other.getCVRQualifiersThroughArrayTypes();
3764ecca7536488e425417dcb005c39cc15ae1947aabChris Lattner  if (getAddressSpace() != Other.getAddressSpace())
3765ecca7536488e425417dcb005c39cc15ae1947aabChris Lattner    return false;
3766e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor  return MyQuals != OtherQuals && (MyQuals | OtherQuals) == MyQuals;
3767e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor}
3768e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor
3769e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// isAtLeastAsQualifiedAs - Determine whether this type is at last
3770e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// as qualified as the Other type. For example, "const volatile
3771e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// int" is at least as qualified as "const int", "volatile int",
3772e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// "int", and "const volatile int".
3773e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregorinline bool QualType::isAtLeastAsQualifiedAs(QualType Other) const {
37740953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // FIXME: work on arbitrary qualifiers
3775e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth  unsigned MyQuals = this->getCVRQualifiersThroughArrayTypes();
3776e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth  unsigned OtherQuals = Other.getCVRQualifiersThroughArrayTypes();
3777ecca7536488e425417dcb005c39cc15ae1947aabChris Lattner  if (getAddressSpace() != Other.getAddressSpace())
3778ecca7536488e425417dcb005c39cc15ae1947aabChris Lattner    return false;
3779e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor  return (MyQuals | OtherQuals) == MyQuals;
3780e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor}
3781e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor
3782e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// getNonReferenceType - If Type is a reference type (e.g., const
3783e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// int&), returns the type that the reference refers to ("const
3784e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// int"). Otherwise, returns the type itself. This routine is used
3785e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// throughout Sema to implement C++ 5p6:
3786e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor///
3787e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor///   If an expression initially has the type "reference to T" (8.3.2,
3788e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor///   8.5.3), the type is adjusted to "T" prior to any further
3789e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor///   analysis, the expression designates the object or function
3790e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor///   denoted by the reference, and the expression is an lvalue.
3791e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregorinline QualType QualType::getNonReferenceType() const {
37926217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek  if (const ReferenceType *RefType = (*this)->getAs<ReferenceType>())
3793e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor    return RefType->getPointeeType();
3794e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor  else
3795e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor    return *this;
3796e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor}
3797e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor
3798611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isFunctionType() const {
3799a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<FunctionType>(CanonicalType);
3800611c1fff195d32df97706e0920c92468b2509900Chris Lattner}
3801611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isPointerType() const {
3802a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<PointerType>(CanonicalType);
3803611c1fff195d32df97706e0920c92468b2509900Chris Lattner}
380458f9f2c884af6b72d036b746a016d8031d31cb7aSteve Naroffinline bool Type::isAnyPointerType() const {
380558f9f2c884af6b72d036b746a016d8031d31cb7aSteve Naroff  return isPointerType() || isObjCObjectPointerType();
380658f9f2c884af6b72d036b746a016d8031d31cb7aSteve Naroff}
38075618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroffinline bool Type::isBlockPointerType() const {
3808a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<BlockPointerType>(CanonicalType);
38095618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff}
3810bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattnerinline bool Type::isReferenceType() const {
3811a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<ReferenceType>(CanonicalType);
3812bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner}
38137c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlinline bool Type::isLValueReferenceType() const {
3814a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<LValueReferenceType>(CanonicalType);
38157c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl}
38167c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlinline bool Type::isRValueReferenceType() const {
3817a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<RValueReferenceType>(CanonicalType);
38187c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl}
3819498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenekinline bool Type::isFunctionPointerType() const {
38206217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek  if (const PointerType* T = getAs<PointerType>())
3821498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek    return T->getPointeeType()->isFunctionType();
3822498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek  else
3823498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek    return false;
3824498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek}
3825f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlinline bool Type::isMemberPointerType() const {
3826a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<MemberPointerType>(CanonicalType);
3827f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl}
3828f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlinline bool Type::isMemberFunctionPointerType() const {
38296217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek  if (const MemberPointerType* T = getAs<MemberPointerType>())
38300bab0cdab751248ca389a5592bcb70eac5d39260John McCall    return T->isMemberFunctionPointer();
3831f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  else
3832f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    return false;
3833f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl}
3834db68e28c05a67735211e688009890cf834c22e75Douglas Gregorinline bool Type::isMemberDataPointerType() const {
3835db68e28c05a67735211e688009890cf834c22e75Douglas Gregor  if (const MemberPointerType* T = getAs<MemberPointerType>())
38360bab0cdab751248ca389a5592bcb70eac5d39260John McCall    return T->isMemberDataPointer();
3837db68e28c05a67735211e688009890cf834c22e75Douglas Gregor  else
3838db68e28c05a67735211e688009890cf834c22e75Douglas Gregor    return false;
3839db68e28c05a67735211e688009890cf834c22e75Douglas Gregor}
3840611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isArrayType() const {
3841a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<ArrayType>(CanonicalType);
3842611c1fff195d32df97706e0920c92468b2509900Chris Lattner}
3843c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattnerinline bool Type::isConstantArrayType() const {
3844a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<ConstantArrayType>(CanonicalType);
3845c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner}
3846c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattnerinline bool Type::isIncompleteArrayType() const {
3847a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<IncompleteArrayType>(CanonicalType);
3848c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner}
3849c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattnerinline bool Type::isVariableArrayType() const {
3850a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<VariableArrayType>(CanonicalType);
3851c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner}
3852898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorinline bool Type::isDependentSizedArrayType() const {
3853a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<DependentSizedArrayType>(CanonicalType);
3854898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor}
38553ff83dd534ccc828203670ce3f5125a4eb4199f8John McCallinline bool Type::isBuiltinType() const {
38563ff83dd534ccc828203670ce3f5125a4eb4199f8John McCall  return isa<BuiltinType>(CanonicalType);
38573ff83dd534ccc828203670ce3f5125a4eb4199f8John McCall}
3858611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isRecordType() const {
3859a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<RecordType>(CanonicalType);
3860611c1fff195d32df97706e0920c92468b2509900Chris Lattner}
38613ff83dd534ccc828203670ce3f5125a4eb4199f8John McCallinline bool Type::isEnumeralType() const {
38623ff83dd534ccc828203670ce3f5125a4eb4199f8John McCall  return isa<EnumType>(CanonicalType);
38633ff83dd534ccc828203670ce3f5125a4eb4199f8John McCall}
3864f23d364084d1aabea688222780d6fc1dd8c7f78cChris Lattnerinline bool Type::isAnyComplexType() const {
3865a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<ComplexType>(CanonicalType);
3866f23d364084d1aabea688222780d6fc1dd8c7f78cChris Lattner}
3867611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isVectorType() const {
3868a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<VectorType>(CanonicalType);
3869611c1fff195d32df97706e0920c92468b2509900Chris Lattner}
3870213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begemaninline bool Type::isExtVectorType() const {
3871a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<ExtVectorType>(CanonicalType);
3872611c1fff195d32df97706e0920c92468b2509900Chris Lattner}
3873d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroffinline bool Type::isObjCObjectPointerType() const {
3874a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<ObjCObjectPointerType>(CanonicalType);
3875d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff}
3876c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallinline bool Type::isObjCObjectType() const {
3877c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  return isa<ObjCObjectType>(CanonicalType);
3878368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner}
3879569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregorinline bool Type::isObjCObjectOrInterfaceType() const {
3880569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor  return isa<ObjCInterfaceType>(CanonicalType) ||
3881569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor    isa<ObjCObjectType>(CanonicalType);
3882569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor}
3883569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor
3884a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekinline bool Type::isObjCQualifiedIdType() const {
3885183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>())
3886d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff    return OPT->isObjCQualifiedIdType();
3887d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff  return false;
3888d58fabf7ed279be18a5e82617f809c9deff9be67Fariborz Jahanian}
3889470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroffinline bool Type::isObjCQualifiedClassType() const {
3890183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>())
3891470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroff    return OPT->isObjCQualifiedClassType();
3892470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroff  return false;
3893470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroff}
389414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroffinline bool Type::isObjCIdType() const {
3895183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>())
389614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff    return OPT->isObjCIdType();
389714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  return false;
389814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff}
389914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroffinline bool Type::isObjCClassType() const {
3900183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>())
390114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff    return OPT->isObjCClassType();
390214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  return false;
390314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff}
390413dcd00615de5c4279d97bdf63cd5f0a14fd9dccFariborz Jahanianinline bool Type::isObjCSelType() const {
39058d2c0a9814e56c2b22e22d1045181c735aef62fdFariborz Jahanian  if (const PointerType *OPT = getAs<PointerType>())
39068d2c0a9814e56c2b22e22d1045181c735aef62fdFariborz Jahanian    return OPT->getPointeeType()->isSpecificBuiltinType(BuiltinType::ObjCSel);
390713dcd00615de5c4279d97bdf63cd5f0a14fd9dccFariborz Jahanian  return false;
390813dcd00615de5c4279d97bdf63cd5f0a14fd9dccFariborz Jahanian}
3909de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroffinline bool Type::isObjCBuiltinType() const {
391013dcd00615de5c4279d97bdf63cd5f0a14fd9dccFariborz Jahanian  return isObjCIdType() || isObjCClassType() || isObjCSelType();
3911de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff}
391272c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregorinline bool Type::isTemplateTypeParmType() const {
3913a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<TemplateTypeParmType>(CanonicalType);
391472c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor}
391572c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor
3916e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbarinline bool Type::isSpecificBuiltinType(unsigned K) const {
3917183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  if (const BuiltinType *BT = getAs<BuiltinType>())
3918e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar    if (BT->getKind() == (BuiltinType::Kind) K)
3919e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar      return true;
3920e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar  return false;
3921e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar}
3922e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar
39232a984cad5ac3fdceeff2bd99daa7b90979313475John McCallinline bool Type::isPlaceholderType() const {
39242a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  if (const BuiltinType *BT = getAs<BuiltinType>())
39252a984cad5ac3fdceeff2bd99daa7b90979313475John McCall    return BT->isPlaceholderType();
39262a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  return false;
39272a984cad5ac3fdceeff2bd99daa7b90979313475John McCall}
39282a984cad5ac3fdceeff2bd99daa7b90979313475John McCall
3929063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor/// \brief Determines whether this is a type for which one can define
3930063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor/// an overloaded operator.
3931063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregorinline bool Type::isOverloadableType() const {
3932063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  return isDependentType() || isRecordType() || isEnumeralType();
3933904eed3f6148758d39a2d3c88f3133274460d645Douglas Gregor}
3934904eed3f6148758d39a2d3c88f3133274460d645Douglas Gregor
39358958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbarinline bool Type::hasPointerRepresentation() const {
39368958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar  return (isPointerType() || isReferenceType() || isBlockPointerType() ||
3937c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall          isObjCObjectPointerType() || isNullPtrType());
39388958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar}
39398958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar
3940820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanianinline bool Type::hasObjCPointerRepresentation() const {
3941c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  return isObjCObjectPointerType();
3942820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian}
3943820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian
394422caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner/// Insertion operator for diagnostics.  This allows sending QualType's into a
394522caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner/// diagnostic with <<.
394622caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattnerinline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
394722caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner                                           QualType T) {
394822caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner  DB.AddTaggedVal(reinterpret_cast<intptr_t>(T.getAsOpaquePtr()),
394922caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner                  Diagnostic::ak_qualtype);
395022caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner  return DB;
395122caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner}
39521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
395347c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth/// Insertion operator for partial diagnostics.  This allows sending QualType's
395447c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth/// into a diagnostic with <<.
395547c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruthinline const PartialDiagnostic &operator<<(const PartialDiagnostic &PD,
395647c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth                                           QualType T) {
395747c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth  PD.AddTaggedVal(reinterpret_cast<intptr_t>(T.getAsOpaquePtr()),
395847c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth                  Diagnostic::ak_qualtype);
395947c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth  return PD;
396047c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth}
396147c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth
396289c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor// Helper class template that is used by Type::getAs to ensure that one does
396389c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor// not try to look through a qualified type to get to an array type.
396489c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregortemplate<typename T,
396589c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor         bool isArrayType = (llvm::is_same<T, ArrayType>::value ||
396689c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor                             llvm::is_base_of<ArrayType, T>::value)>
396789c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregorstruct ArrayType_cannot_be_used_with_getAs { };
396889c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor
396989c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregortemplate<typename T>
397089c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregorstruct ArrayType_cannot_be_used_with_getAs<T, true>;
397189c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor
39721a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek/// Member-template getAs<specific type>'.
39731a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenektemplate <typename T> const T *Type::getAs() const {
397489c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor  ArrayType_cannot_be_used_with_getAs<T> at;
397589c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor  (void)at;
397689c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor
39771a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek  // If this is directly a T type, return it.
39781a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek  if (const T *Ty = dyn_cast<T>(this))
39791a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek    return Ty;
39801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
39811a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek  // If the canonical form of this type isn't the right kind, reject it.
39820953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  if (!isa<T>(CanonicalType))
39831a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek    return 0;
39841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
39850953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // If this is a typedef for the type, strip the typedef off without
39861a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek  // losing all typedef information.
3987bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  return cast<T>(getUnqualifiedDesugaredType());
39881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump}
398922caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner
39905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}  // end namespace clang
39915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
39925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif
3993