Type.h revision 3e4c6c4c79a03f5cb0c4671d7c282d623c6dc35e
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"
188b5b4099c61a136e9a1714c4d8a593febe942268Sebastian Redl#include "clang/Basic/ExceptionSpecificationType.h"
191734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor#include "clang/Basic/IdentifierTable.h"
200b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor#include "clang/Basic/Linkage.h"
2147c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth#include "clang/Basic/PartialDiagnostic.h"
221fb0caaa7bef765b85972274e3b434af2572c141John McCall#include "clang/Basic/Visibility.h"
23e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor#include "clang/AST/NestedNameSpecifier.h"
247532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor#include "clang/AST/TemplateName.h"
255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "llvm/Support/Casting.h"
2650d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor#include "llvm/Support/type_traits.h"
27fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff#include "llvm/ADT/APSInt.h"
285cf243a883872441d73ca49cea7e20de5802629bChris Lattner#include "llvm/ADT/FoldingSet.h"
29cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor#include "llvm/ADT/Optional.h"
305cf243a883872441d73ca49cea7e20de5802629bChris Lattner#include "llvm/ADT/PointerIntPair.h"
311734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor#include "llvm/ADT/PointerUnion.h"
327532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor
335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing llvm::isa;
345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing llvm::cast;
355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing llvm::cast_or_null;
365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing llvm::dyn_cast;
375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing llvm::dyn_cast_or_null;
386b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCallnamespace clang {
396b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall  enum {
40f7616b9067790757f4e12e834b216c53c8c04ebeDouglas Gregor    TypeAlignmentInBits = 4,
416b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall    TypeAlignment = 1 << TypeAlignmentInBits
426b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall  };
43aed1df80bf64228e1429c1edc408397f9174847cChris Lattner  class Type;
44aed1df80bf64228e1429c1edc408397f9174847cChris Lattner  class ExtQuals;
45aed1df80bf64228e1429c1edc408397f9174847cChris Lattner  class QualType;
466b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall}
475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
484e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattnernamespace llvm {
494e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner  template <typename T>
50daae940507f2e93c6fa12e8062fa958e34cc2d1cChris Lattner  class PointerLikeTypeTraits;
51bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner  template<>
52bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner  class PointerLikeTypeTraits< ::clang::Type*> {
53bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner  public:
54bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner    static inline void *getAsVoidPointer(::clang::Type *P) { return P; }
55bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner    static inline ::clang::Type *getFromVoidPointer(void *P) {
56bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner      return static_cast< ::clang::Type*>(P);
57bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner    }
586b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall    enum { NumLowBitsAvailable = clang::TypeAlignmentInBits };
59bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner  };
600953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  template<>
610953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  class PointerLikeTypeTraits< ::clang::ExtQuals*> {
620953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  public:
630953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    static inline void *getAsVoidPointer(::clang::ExtQuals *P) { return P; }
640953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    static inline ::clang::ExtQuals *getFromVoidPointer(void *P) {
650953e767ff7817f97b3ab20896b229891eeff45bJohn McCall      return static_cast< ::clang::ExtQuals*>(P);
660953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    }
676b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall    enum { NumLowBitsAvailable = clang::TypeAlignmentInBits };
680953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  };
69aed1df80bf64228e1429c1edc408397f9174847cChris Lattner
70aed1df80bf64228e1429c1edc408397f9174847cChris Lattner  template <>
71aed1df80bf64228e1429c1edc408397f9174847cChris Lattner  struct isPodLike<clang::QualType> { static const bool value = true; };
724e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner}
734e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner
745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang {
755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class ASTContext;
76162e1c1b487352434552147967c3dd296ebee2f7Richard Smith  class TypedefNameDecl;
7755f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  class TemplateDecl;
7872c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor  class TemplateTypeParmDecl;
79aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor  class NonTypeTemplateParmDecl;
807532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor  class TemplateTemplateParmDecl;
815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class TagDecl;
825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class RecordDecl;
8349aa7ff1245abd03e6e998e01302df31e4c6f8f6Argyrios Kyrtzidis  class CXXRecordDecl;
845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class EnumDecl;
8521d50e12c3c412d8457071dc419363b7a7e8b855Ted Kremenek  class FieldDecl;
86a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  class ObjCInterfaceDecl;
87a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  class ObjCProtocolDecl;
88a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  class ObjCMethodDecl;
89ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  class UnresolvedUsingTypenameDecl;
905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class Expr;
91b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek  class Stmt;
925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class SourceLocation;
9392866e2e90f6d93fb95e25a7ac4438e239d89ce6Ted Kremenek  class StmtIteratorBase;
9440808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  class TemplateArgument;
95833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  class TemplateArgumentLoc;
96d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  class TemplateArgumentListInfo;
97465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  class ElaboratedType;
983b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  class ExtQuals;
993b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  class ExtQualsTypeCommonBase;
1003b4ea54acf01f72f6eb74d96689dda86d950228fDaniel Dunbar  struct PrintingPolicy;
10172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor
102ead608af31b6c9abeae1ca6d0b75094dac4641c0John McCall  template <typename> class CanQual;
103ead608af31b6c9abeae1ca6d0b75094dac4641c0John McCall  typedef CanQual<Type> CanQualType;
104ead608af31b6c9abeae1ca6d0b75094dac4641c0John McCall
10572564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  // Provide forward declarations for all of the *Type classes
10672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#define TYPE(Class, Base) class Class##Type;
10772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#include "clang/AST/TypeNodes.def"
108f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl
1090953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// Qualifiers - The collection of all-type qualifiers we support.
1100953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// Clang supports five independent qualifiers:
1110953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// * C99: const, volatile, and restrict
1120953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// * Embedded C (TR18037): address spaces
1130953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// * Objective C: the GC attributes (none, weak, or strong)
1140953e767ff7817f97b3ab20896b229891eeff45bJohn McCallclass Qualifiers {
1155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
1160953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  enum TQ { // NOTE: These flags must be kept in sync with DeclSpec::TQ.
1175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Const    = 0x1,
1185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Restrict = 0x2,
1195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Volatile = 0x4,
1200953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    CVRMask = Const | Volatile | Restrict
1215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
1221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1230953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  enum GC {
124d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian    GCNone = 0,
125d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian    Weak,
126d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian    Strong
127d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian  };
128efadb7768e7c7418185f5a4010ecd8b21ca9731bJohn McCall
1290953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  enum {
1300953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    /// The maximum supported address space number.
1310953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    /// 24 bits should be enough for anyone.
1320953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    MaxAddressSpace = 0xffffffu,
1330953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
1340953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    /// The width of the "fast" qualifier mask.
135f7616b9067790757f4e12e834b216c53c8c04ebeDouglas Gregor    FastWidth = 3,
1360953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
1370953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    /// The fast qualifier mask.
1380953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    FastMask = (1 << FastWidth) - 1
1390953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  };
1400953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
1410953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  Qualifiers() : Mask(0) {}
1420953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
1430953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  static Qualifiers fromFastMask(unsigned Mask) {
1440953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Qualifiers Qs;
1450953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Qs.addFastQualifiers(Mask);
1460953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return Qs;
1470953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
1480953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
1490953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  static Qualifiers fromCVRMask(unsigned CVR) {
1500953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Qualifiers Qs;
1510953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Qs.addCVRQualifiers(CVR);
1520953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return Qs;
1530953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
1540953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
1550953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Deserialize qualifiers from an opaque representation.
1560953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  static Qualifiers fromOpaqueValue(unsigned opaque) {
1570953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Qualifiers Qs;
1580953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Qs.Mask = opaque;
1590953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return Qs;
1600953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
1610953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
1620953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Serialize these qualifiers into an opaque representation.
1630953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  unsigned getAsOpaqueValue() const {
1640953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return Mask;
1650953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
1660953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
1670953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool hasConst() const { return Mask & Const; }
1680953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void setConst(bool flag) {
1690953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask = (Mask & ~Const) | (flag ? Const : 0);
1700953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
1710953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void removeConst() { Mask &= ~Const; }
1720953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void addConst() { Mask |= Const; }
1730953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
1740953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool hasVolatile() const { return Mask & Volatile; }
1750953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void setVolatile(bool flag) {
1760953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask = (Mask & ~Volatile) | (flag ? Volatile : 0);
1770953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
1780953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void removeVolatile() { Mask &= ~Volatile; }
1790953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void addVolatile() { Mask |= Volatile; }
1800953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
1810953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool hasRestrict() const { return Mask & Restrict; }
1820953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void setRestrict(bool flag) {
1830953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask = (Mask & ~Restrict) | (flag ? Restrict : 0);
1840953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
1850953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void removeRestrict() { Mask &= ~Restrict; }
1860953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void addRestrict() { Mask |= Restrict; }
1870953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
1880953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool hasCVRQualifiers() const { return getCVRQualifiers(); }
1890953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  unsigned getCVRQualifiers() const { return Mask & CVRMask; }
1900953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void setCVRQualifiers(unsigned mask) {
1910953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(!(mask & ~CVRMask) && "bitmask contains non-CVR bits");
1920953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask = (Mask & ~CVRMask) | mask;
1930953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
1940953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void removeCVRQualifiers(unsigned mask) {
1950953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(!(mask & ~CVRMask) && "bitmask contains non-CVR bits");
1960953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask &= ~mask;
1970953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
1980953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void removeCVRQualifiers() {
1990953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    removeCVRQualifiers(CVRMask);
2000953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2010953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void addCVRQualifiers(unsigned mask) {
2020953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(!(mask & ~CVRMask) && "bitmask contains non-CVR bits");
2030953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask |= mask;
2040953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2050953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
2060953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool hasObjCGCAttr() const { return Mask & GCAttrMask; }
2070953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  GC getObjCGCAttr() const { return GC((Mask & GCAttrMask) >> GCAttrShift); }
2080953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void setObjCGCAttr(GC type) {
2090953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask = (Mask & ~GCAttrMask) | (type << GCAttrShift);
2100953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2110953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void removeObjCGCAttr() { setObjCGCAttr(GCNone); }
2120953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void addObjCGCAttr(GC type) {
2130953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(type);
2140953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    setObjCGCAttr(type);
2150953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2162234873111009eb8655d63362cedc422eb9fc517John McCall  Qualifiers withoutObjCGCAttr() const {
2172234873111009eb8655d63362cedc422eb9fc517John McCall    Qualifiers qs = *this;
2182234873111009eb8655d63362cedc422eb9fc517John McCall    qs.removeObjCGCAttr();
2192234873111009eb8655d63362cedc422eb9fc517John McCall    return qs;
2202234873111009eb8655d63362cedc422eb9fc517John McCall  }
2210953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
2220953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool hasAddressSpace() const { return Mask & AddressSpaceMask; }
2230953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  unsigned getAddressSpace() const { return Mask >> AddressSpaceShift; }
2240953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void setAddressSpace(unsigned space) {
2250953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(space <= MaxAddressSpace);
2260953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask = (Mask & ~AddressSpaceMask)
2270953e767ff7817f97b3ab20896b229891eeff45bJohn McCall         | (((uint32_t) space) << AddressSpaceShift);
2280953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2290953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void removeAddressSpace() { setAddressSpace(0); }
2300953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void addAddressSpace(unsigned space) {
2310953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(space);
2320953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    setAddressSpace(space);
2330953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2340953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
2350953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Fast qualifiers are those that can be allocated directly
2360953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // on a QualType object.
2370953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool hasFastQualifiers() const { return getFastQualifiers(); }
2380953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  unsigned getFastQualifiers() const { return Mask & FastMask; }
2390953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void setFastQualifiers(unsigned mask) {
2400953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(!(mask & ~FastMask) && "bitmask contains non-fast qualifier bits");
2410953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask = (Mask & ~FastMask) | mask;
2420953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2430953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void removeFastQualifiers(unsigned mask) {
2440953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(!(mask & ~FastMask) && "bitmask contains non-fast qualifier bits");
2450953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask &= ~mask;
2460953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2470953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void removeFastQualifiers() {
2480953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    removeFastQualifiers(FastMask);
2490953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2500953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void addFastQualifiers(unsigned mask) {
2510953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(!(mask & ~FastMask) && "bitmask contains non-fast qualifier bits");
2520953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask |= mask;
2530953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2540953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
2550953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// hasNonFastQualifiers - Return true if the set contains any
2560953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// qualifiers which require an ExtQuals node to be allocated.
2570953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool hasNonFastQualifiers() const { return Mask & ~FastMask; }
2580953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  Qualifiers getNonFastQualifiers() const {
2590953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Qualifiers Quals = *this;
2600953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Quals.setFastQualifiers(0);
2610953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return Quals;
2620953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2630953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
2640953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// hasQualifiers - Return true if the set contains any qualifiers.
2650953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool hasQualifiers() const { return Mask; }
2660953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool empty() const { return !Mask; }
2670953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
2680953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// \brief Add the qualifiers from the given set to this set.
2690953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void addQualifiers(Qualifiers Q) {
2700953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    // If the other set doesn't have any non-boolean qualifiers, just
2710953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    // bit-or it in.
2720953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    if (!(Q.Mask & ~CVRMask))
2730953e767ff7817f97b3ab20896b229891eeff45bJohn McCall      Mask |= Q.Mask;
2740953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    else {
2750953e767ff7817f97b3ab20896b229891eeff45bJohn McCall      Mask |= (Q.Mask & CVRMask);
2760953e767ff7817f97b3ab20896b229891eeff45bJohn McCall      if (Q.hasAddressSpace())
2770953e767ff7817f97b3ab20896b229891eeff45bJohn McCall        addAddressSpace(Q.getAddressSpace());
2780953e767ff7817f97b3ab20896b229891eeff45bJohn McCall      if (Q.hasObjCGCAttr())
2790953e767ff7817f97b3ab20896b229891eeff45bJohn McCall        addObjCGCAttr(Q.getObjCGCAttr());
2800953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    }
2810953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2820953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
28362c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// \brief Add the qualifiers from the given set to this set, given that
28462c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// they don't conflict.
28562c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  void addConsistentQualifiers(Qualifiers qs) {
28662c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall    assert(getAddressSpace() == qs.getAddressSpace() ||
28762c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall           !hasAddressSpace() || !qs.hasAddressSpace());
28862c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall    assert(getObjCGCAttr() == qs.getObjCGCAttr() ||
28962c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall           !hasObjCGCAttr() || !qs.hasObjCGCAttr());
29062c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall    Mask |= qs.Mask;
29162c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  }
29262c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall
29362c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// \brief Determines if these qualifiers compatibly include another set.
29462c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// Generally this answers the question of whether an object with the other
29562c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// qualifiers can be safely used as an object with these qualifiers.
29662c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  bool compatiblyIncludes(Qualifiers other) const {
29762c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall    // Non-CVR qualifiers must match exactly.  CVR qualifiers may subset.
29862c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall    return ((Mask & ~CVRMask) == (other.Mask & ~CVRMask)) &&
29962c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall           (((Mask & CVRMask) | (other.Mask & CVRMask)) == (Mask & CVRMask));
30062c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  }
30162c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall
302769d0cc72b1831785596d0e76f327bdb887823beDouglas Gregor  /// \brief Determine whether this set of qualifiers is a strict superset of
303769d0cc72b1831785596d0e76f327bdb887823beDouglas Gregor  /// another set of qualifiers, not considering qualifier compatibility.
304769d0cc72b1831785596d0e76f327bdb887823beDouglas Gregor  bool isStrictSupersetOf(Qualifiers Other) const;
305769d0cc72b1831785596d0e76f327bdb887823beDouglas Gregor
3060953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool operator==(Qualifiers Other) const { return Mask == Other.Mask; }
3070953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool operator!=(Qualifiers Other) const { return Mask != Other.Mask; }
3080953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3090953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  operator bool() const { return hasQualifiers(); }
3100953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3110953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  Qualifiers &operator+=(Qualifiers R) {
3120953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    addQualifiers(R);
3130953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return *this;
3140953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
3150953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3160953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Union two qualifier sets.  If an enumerated qualifier appears
3170953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // in both sets, use the one from the right.
3180953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  friend Qualifiers operator+(Qualifiers L, Qualifiers R) {
3190953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    L += R;
3200953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return L;
3210953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
3223cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor
3233cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor  Qualifiers &operator-=(Qualifiers R) {
3243cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor    Mask = Mask & ~(R.Mask);
3253cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor    return *this;
3263cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor  }
3270953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3283cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor  /// \brief Compute the difference between two qualifier sets.
3293cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor  friend Qualifiers operator-(Qualifiers L, Qualifiers R) {
3303cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor    L -= R;
3313cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor    return L;
3323cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor  }
3333cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor
3340953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  std::string getAsString() const;
3350953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  std::string getAsString(const PrintingPolicy &Policy) const {
3360953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    std::string Buffer;
3370953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    getAsStringInternal(Buffer, Policy);
3380953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return Buffer;
3390953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
3400953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void getAsStringInternal(std::string &S, const PrintingPolicy &Policy) const;
3410953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3420953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void Profile(llvm::FoldingSetNodeID &ID) const {
3430953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    ID.AddInteger(Mask);
3440953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
3450953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3460953e767ff7817f97b3ab20896b229891eeff45bJohn McCallprivate:
3470953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3480953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // bits:     |0 1 2|3 .. 4|5  ..  31|
3490953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  //           |C R V|GCAttr|AddrSpace|
3500953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  uint32_t Mask;
3510953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3520953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  static const uint32_t GCAttrMask = 0x18;
3530953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  static const uint32_t GCAttrShift = 3;
3540953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  static const uint32_t AddressSpaceMask = ~(CVRMask | GCAttrMask);
3550953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  static const uint32_t AddressSpaceShift = 5;
3560953e767ff7817f97b3ab20896b229891eeff45bJohn McCall};
3570953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
358ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor/// CallingConv - Specifies the calling convention that a function uses.
359ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregorenum CallingConv {
360ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor  CC_Default,
361ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor  CC_C,           // __attribute__((cdecl))
362ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor  CC_X86StdCall,  // __attribute__((stdcall))
363f813a2c03fcb05381b3252010435f557eb6b3cdeDouglas Gregor  CC_X86FastCall, // __attribute__((fastcall))
36452fc314e1b5e1baee6305067cf831763d02bd243Dawn Perchik  CC_X86ThisCall, // __attribute__((thiscall))
365414d8967e1d760ea1e19a4aca96b13777a8cf8c5Anton Korobeynikov  CC_X86Pascal,   // __attribute__((pascal))
366414d8967e1d760ea1e19a4aca96b13777a8cf8c5Anton Korobeynikov  CC_AAPCS,       // __attribute__((pcs("aapcs")))
367414d8967e1d760ea1e19a4aca96b13777a8cf8c5Anton Korobeynikov  CC_AAPCS_VFP    // __attribute__((pcs("aapcs-vfp")))
368ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor};
369ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor
37049f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCalltypedef std::pair<const Type*, Qualifiers> SplitQualType;
3710953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3720953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// QualType - For efficiency, we don't store CV-qualified types as nodes on
3730953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// their own: instead each reference to a type stores the qualifiers.  This
3740953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// greatly reduces the number of nodes we need to allocate for types (for
3750953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// example we only need one for 'int', 'const int', 'volatile int',
3760953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// 'const volatile int', etc).
3770953e767ff7817f97b3ab20896b229891eeff45bJohn McCall///
3780953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// As an added efficiency bonus, instead of making this a pair, we
3790953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// just store the two bits we care about in the low bits of the
3800953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// pointer.  To handle the packing/unpacking, we make QualType be a
3810953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// simple wrapper class that acts like a smart pointer.  A third bit
3820953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// indicates whether there are extended qualifiers present, in which
3830953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// case the pointer points to a special structure.
3840953e767ff7817f97b3ab20896b229891eeff45bJohn McCallclass QualType {
3850953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Thankfully, these are efficiently composable.
3860953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  llvm::PointerIntPair<llvm::PointerUnion<const Type*,const ExtQuals*>,
3870953e767ff7817f97b3ab20896b229891eeff45bJohn McCall                       Qualifiers::FastWidth> Value;
3880953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3890953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  const ExtQuals *getExtQualsUnsafe() const {
3900953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return Value.getPointer().get<const ExtQuals*>();
3910953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
3920953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3930953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  const Type *getTypePtrUnsafe() const {
3940953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return Value.getPointer().get<const Type*>();
3950953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
3960953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3973b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  const ExtQualsTypeCommonBase *getCommonPtr() const {
3983b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    assert(!isNull() && "Cannot retrieve a NULL type pointer");
3993b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    uintptr_t CommonPtrVal
4003b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall      = reinterpret_cast<uintptr_t>(Value.getOpaqueValue());
4013b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    CommonPtrVal &= ~(uintptr_t)((1 << TypeAlignmentInBits) - 1);
4023b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    return reinterpret_cast<ExtQualsTypeCommonBase*>(CommonPtrVal);
4033b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  }
4043b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
4050953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  friend class QualifierCollector;
4060953e767ff7817f97b3ab20896b229891eeff45bJohn McCallpublic:
4075cf243a883872441d73ca49cea7e20de5802629bChris Lattner  QualType() {}
4081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4095cf243a883872441d73ca49cea7e20de5802629bChris Lattner  QualType(const Type *Ptr, unsigned Quals)
4100953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    : Value(Ptr, Quals) {}
4110953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  QualType(const ExtQuals *Ptr, unsigned Quals)
4120953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    : Value(Ptr, Quals) {}
4130953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
414a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  unsigned getLocalFastQualifiers() const { return Value.getInt(); }
415a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  void setLocalFastQualifiers(unsigned Quals) { Value.setInt(Quals); }
4165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4170953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// Retrieves a pointer to the underlying (unqualified) type.
4180953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// This should really return a const Type, but it's not worth
4190953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// changing all the users right now.
4201ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor  ///
4211ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor  /// This function requires that the type not be NULL. If the type might be
4221ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor  /// NULL, use the (slightly less efficient) \c getTypePtrOrNull().
4233b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  const Type *getTypePtr() const;
4241ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor
4253b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  const Type *getTypePtrOrNull() const;
4261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
42749f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  /// Divides a QualType into its unqualified type and a set of local
42849f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  /// qualifiers.
4293b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  SplitQualType split() const;
43049f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall
4315cf243a883872441d73ca49cea7e20de5802629bChris Lattner  void *getAsOpaquePtr() const { return Value.getOpaqueValue(); }
432f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  static QualType getFromOpaquePtr(const void *Ptr) {
4335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    QualType T;
434f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall    T.Value.setFromOpaqueValue(const_cast<void*>(Ptr));
4355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T;
4365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
4371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
438f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const Type &operator*() const {
4395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return *getTypePtr();
4405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
4415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
442f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const Type *operator->() const {
4435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return getTypePtr();
4445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
4451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
446467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall  bool isCanonical() const;
44754e14c4db764c0636160d26c5bbf491637c83a76John McCall  bool isCanonicalAsParam() const;
448467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall
4495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isNull - Return true if this QualType doesn't point to a type yet.
4505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isNull() const {
4510953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return Value.getPointer().isNull();
4525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
4535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
454a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Determine whether this particular QualType instance has the
455a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// "const" qualifier set, without looking through typedefs that may have
456a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// added "const" at a different level.
457a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  bool isLocalConstQualified() const {
458a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor    return (getLocalFastQualifiers() & Qualifiers::Const);
4590953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
460a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor
461a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Determine whether this type is const-qualified.
462fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  bool isConstQualified() const;
463a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor
464a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Determine whether this particular QualType instance has the
465a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// "restrict" qualifier set, without looking through typedefs that may have
466a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// added "restrict" at a different level.
467a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  bool isLocalRestrictQualified() const {
468a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor    return (getLocalFastQualifiers() & Qualifiers::Restrict);
469a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  }
470a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor
471a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Determine whether this type is restrict-qualified.
472fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  bool isRestrictQualified() const;
473a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor
474a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Determine whether this particular QualType instance has the
475a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// "volatile" qualifier set, without looking through typedefs that may have
476a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// added "volatile" at a different level.
477a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  bool isLocalVolatileQualified() const {
478f7616b9067790757f4e12e834b216c53c8c04ebeDouglas Gregor    return (getLocalFastQualifiers() & Qualifiers::Volatile);
4795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
4800953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
481a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Determine whether this type is volatile-qualified.
482fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  bool isVolatileQualified() const;
483a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor
484a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Determine whether this particular QualType instance has any
485a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// qualifiers, without looking through any typedefs that might add
486a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// qualifiers at a different level.
487a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  bool hasLocalQualifiers() const {
488a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor    return getLocalFastQualifiers() || hasLocalNonFastQualifiers();
4890953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
4900953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
491a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Determine whether this type has any qualifiers.
492fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  bool hasQualifiers() const;
493a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor
494a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Determine whether this particular QualType instance has any
495a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// "non-fast" qualifiers, e.g., those that are stored in an ExtQualType
496a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// instance.
497a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  bool hasLocalNonFastQualifiers() const {
498a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor    return Value.getPointer().is<const ExtQuals*>();
4990953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
5000953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
501a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Retrieve the set of qualifiers local to this particular QualType
502a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// instance, not including any qualifiers acquired through typedefs or
503a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// other sugar.
5043b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  Qualifiers getLocalQualifiers() const;
5050953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
506a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Retrieve the set of qualifiers applied to this type.
507fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  Qualifiers getQualifiers() const;
508a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor
509a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Retrieve the set of CVR (const-volatile-restrict) qualifiers
510a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// local to this particular QualType instance, not including any qualifiers
511a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// acquired through typedefs or other sugar.
512a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  unsigned getLocalCVRQualifiers() const {
513f7616b9067790757f4e12e834b216c53c8c04ebeDouglas Gregor    return getLocalFastQualifiers();
5145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
515b381aac9bae6d608c72267dd0ed08ec6369e94e4Nuno Lopes
516a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Retrieve the set of CVR (const-volatile-restrict) qualifiers
517a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// applied to this type.
518fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  unsigned getCVRQualifiers() const;
519e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth
520bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isConstant(ASTContext& Ctx) const {
521bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall    return QualType::isConstant(*this, Ctx);
522bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  }
5231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5240953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Don't promise in the API that anything besides 'const' can be
5250953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // easily added.
5260953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
5270953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// addConst - add the specified type qualifier to this QualType.
5280953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void addConst() {
5290953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    addFastQualifiers(Qualifiers::Const);
5300953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
5310953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  QualType withConst() const {
5320953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return withFastQualifiers(Qualifiers::Const);
5330953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
5340953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
5350953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void addFastQualifiers(unsigned TQs) {
5360953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(!(TQs & ~Qualifiers::FastMask)
5370953e767ff7817f97b3ab20896b229891eeff45bJohn McCall           && "non-fast qualifier bits set in mask!");
5380953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Value.setInt(Value.getInt() | TQs);
5390953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
5400953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
54149f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  void removeLocalConst();
54249f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  void removeLocalVolatile();
54349f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  void removeLocalRestrict();
54449f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  void removeLocalCVRQualifiers(unsigned Mask);
5450953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
54649f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  void removeLocalFastQualifiers() { Value.setInt(0); }
54749f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  void removeLocalFastQualifiers(unsigned Mask) {
5480953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(!(Mask & ~Qualifiers::FastMask) && "mask has non-fast qualifiers");
5490953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Value.setInt(Value.getInt() & ~Mask);
5500953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
5515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
5520953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Creates a type with the given qualifiers in addition to any
5530953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // qualifiers already on this type.
5540953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  QualType withFastQualifiers(unsigned TQs) const {
5550953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    QualType T = *this;
5560953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    T.addFastQualifiers(TQs);
5570953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return T;
5580953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
5591c6a38bcea17801e9a4738753aee845381af2b6cSanjiv Gupta
5600953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Creates a type with exactly the given fast qualifiers, removing
5610953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // any existing fast qualifiers.
56249f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  QualType withExactLocalFastQualifiers(unsigned TQs) const {
56349f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall    return withoutLocalFastQualifiers().withFastQualifiers(TQs);
5645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
5650953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
5660953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Removes fast qualifiers, but leaves any extended qualifiers in place.
56749f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  QualType withoutLocalFastQualifiers() const {
5680953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    QualType T = *this;
56949f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall    T.removeLocalFastQualifiers();
5700953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return T;
571c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  }
572971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis
5733b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  QualType getCanonicalType() const;
5743b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
575a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Return this type with all of the instance-specific qualifiers
576a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// removed, but without removing any qualifiers that may have been applied
577a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// through typedefs.
578a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  QualType getLocalUnqualifiedType() const { return QualType(getTypePtr(), 0); }
5791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
58062c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// \brief Retrieve the unqualified variant of the given type,
58162c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// removing as little sugar as possible.
58262c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  ///
58362c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// This routine looks through various kinds of sugar to find the
58462c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// least-desugared type that is unqualified. For example, given:
58562c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  ///
58662c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// \code
58762c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// typedef int Integer;
58862c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// typedef const Integer CInteger;
58962c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// typedef CInteger DifferenceType;
59062c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// \endcode
59162c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  ///
59262c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// Executing \c getUnqualifiedType() on the type \c DifferenceType will
59362c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// desugar until we hit the type \c Integer, which has no qualifiers on it.
59462c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  ///
59562c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// The resulting type might still be qualified if it's an array
59662c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// type.  To strip qualifiers even from within an array type, use
59762c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// ASTContext::getUnqualifiedArrayType.
59862c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  inline QualType getUnqualifiedType() const;
59962c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall
60062c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// getSplitUnqualifiedType - Retrieve the unqualified variant of the
60162c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// given type, removing as little sugar as possible.
60262c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  ///
60362c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// Like getUnqualifiedType(), but also returns the set of
60462c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// qualifiers that were built up.
60562c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  ///
60662c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// The resulting type might still be qualified if it's an array
60762c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// type.  To strip qualifiers even from within an array type, use
60862c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// ASTContext::getUnqualifiedArrayType.
60962c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  inline SplitQualType getSplitUnqualifiedType() const;
610a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor
61161d0b6baf47cf411f6c0f6ddb4acffcfeec724f1Douglas Gregor  /// \brief Determine whether this type is more qualified than the other
61261d0b6baf47cf411f6c0f6ddb4acffcfeec724f1Douglas Gregor  /// given type, requiring exact equality for non-CVR qualifiers.
613e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor  bool isMoreQualifiedThan(QualType Other) const;
61461d0b6baf47cf411f6c0f6ddb4acffcfeec724f1Douglas Gregor
61561d0b6baf47cf411f6c0f6ddb4acffcfeec724f1Douglas Gregor  /// \brief Determine whether this type is at least as qualified as the other
61661d0b6baf47cf411f6c0f6ddb4acffcfeec724f1Douglas Gregor  /// given type, requiring exact equality for non-CVR qualifiers.
617e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor  bool isAtLeastAsQualifiedAs(QualType Other) const;
61861d0b6baf47cf411f6c0f6ddb4acffcfeec724f1Douglas Gregor
619e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor  QualType getNonReferenceType() const;
6201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6216398235d7890a81b785ea5af3b6e66d86bf184ccDouglas Gregor  /// \brief Determine the type of a (typically non-lvalue) expression with the
6226398235d7890a81b785ea5af3b6e66d86bf184ccDouglas Gregor  /// specified result type.
6235291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor  ///
6246398235d7890a81b785ea5af3b6e66d86bf184ccDouglas Gregor  /// This routine should be used for expressions for which the return type is
6256398235d7890a81b785ea5af3b6e66d86bf184ccDouglas Gregor  /// explicitly specified (e.g., in a cast or call) and isn't necessarily
6266398235d7890a81b785ea5af3b6e66d86bf184ccDouglas Gregor  /// an lvalue. It removes a top-level reference (since there are no
6275291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor  /// expressions of reference type) and deletes top-level cvr-qualifiers
6285291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor  /// from non-class types (in C++) or all types (in C).
6296398235d7890a81b785ea5af3b6e66d86bf184ccDouglas Gregor  QualType getNonLValueExprType(ASTContext &Context) const;
6305291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor
6312fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner  /// getDesugaredType - Return the specified type with any "sugar" removed from
6322fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner  /// the type.  This takes off typedefs, typeof's etc.  If the outer level of
6332fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner  /// the type is already concrete, it returns it unmodified.  This is similar
6342fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner  /// to getting the canonical type, but it doesn't remove *all* typedefs.  For
6352fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner  /// example, it returns "T*" as "T*", (not as "int*"), because the pointer is
6362fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner  /// concrete.
6370953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  ///
6380953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// Qualifiers are left in place.
6394ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  QualType getDesugaredType(const ASTContext &Context) const {
64049f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall    return getDesugaredType(*this, Context);
64149f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  }
64249f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall
64349f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  SplitQualType getSplitDesugaredType() const {
64449f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall    return getSplitDesugaredType(*this);
645bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  }
64698cd599ee8a9b259ed7388ee2921a20d97658864Douglas Gregor
647075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  /// IgnoreParens - Returns the specified type after dropping any
648075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  /// outer-level parentheses.
649075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  QualType IgnoreParens() const {
650723df245307a530da5433dfb43accf187dc3e243Abramo Bagnara    if (isa<ParenType>(*this))
651723df245307a530da5433dfb43accf187dc3e243Abramo Bagnara      return QualType::IgnoreParens(*this);
652723df245307a530da5433dfb43accf187dc3e243Abramo Bagnara    return *this;
653075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  }
654075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
6555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// operator==/!= - Indicate whether the specified types and qualifiers are
6565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// identical.
65750d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor  friend bool operator==(const QualType &LHS, const QualType &RHS) {
65850d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor    return LHS.Value == RHS.Value;
6595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
66050d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor  friend bool operator!=(const QualType &LHS, const QualType &RHS) {
66150d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor    return LHS.Value != RHS.Value;
6625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
66349f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  std::string getAsString() const {
66449f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall    return getAsString(split());
66549f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  }
66649f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  static std::string getAsString(SplitQualType split) {
66749f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall    return getAsString(split.first, split.second);
66849f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  }
66949f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  static std::string getAsString(const Type *ty, Qualifiers qs);
670d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor
671d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor  std::string getAsString(const PrintingPolicy &Policy) const {
6725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    std::string S;
673d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor    getAsStringInternal(S, Policy);
6745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return S;
6755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
676e4f2142d00fa5fdb580c4e2413da91882d955381Chris Lattner  void getAsStringInternal(std::string &Str,
67749f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall                           const PrintingPolicy &Policy) const {
67849f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall    return getAsStringInternal(split(), Str, Policy);
67949f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  }
68049f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  static void getAsStringInternal(SplitQualType split, std::string &out,
68149f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall                                  const PrintingPolicy &policy) {
68249f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall    return getAsStringInternal(split.first, split.second, out, policy);
68349f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  }
68449f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  static void getAsStringInternal(const Type *ty, Qualifiers qs,
68549f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall                                  std::string &out,
68649f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall                                  const PrintingPolicy &policy);
6871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
688c36d405a02fab41f6c45cb2bc750d64949742903Chris Lattner  void dump(const char *s) const;
689c36d405a02fab41f6c45cb2bc750d64949742903Chris Lattner  void dump() const;
6901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6913f2dcb1ca8bd2d5d3ccc5c80f4ab06f949d88a89Ted Kremenek  void Profile(llvm::FoldingSetNodeID &ID) const {
6923f2dcb1ca8bd2d5d3ccc5c80f4ab06f949d88a89Ted Kremenek    ID.AddPointer(getAsOpaquePtr());
6933f2dcb1ca8bd2d5d3ccc5c80f4ab06f949d88a89Ted Kremenek  }
6945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
695ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb  /// getAddressSpace - Return the address space of this type.
696ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb  inline unsigned getAddressSpace() const;
6971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
698d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian  /// GCAttrTypesAttr - Returns gc attribute of this type.
6990953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  inline Qualifiers::GC getObjCGCAttr() const;
700f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian
701f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian  /// isObjCGCWeak true when Type is objc's weak.
702f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian  bool isObjCGCWeak() const {
7030953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return getObjCGCAttr() == Qualifiers::Weak;
704f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian  }
705f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian
706f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian  /// isObjCGCStrong true when Type is objc's strong.
707f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian  bool isObjCGCStrong() const {
7080953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return getObjCGCAttr() == Qualifiers::Strong;
709f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian  }
7102455636163fdd18581d7fdae816433f886d88213Mike Stump
7110d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall  enum DestructionKind {
7120d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall    DK_none,
7130d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall    DK_cxx_destructor
7140d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall  };
7150d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall
7160d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall  /// isDestructedType - nonzero if objects of this type require
7170d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall  /// non-trivial work to clean up after.  Non-zero because it's
7180d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall  /// conceivable that qualifiers (objc_gc(weak)?) could make
7190d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall  /// something require destruction.
7200d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall  DestructionKind isDestructedType() const {
7210d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall    return isDestructedTypeImpl(*this);
7220d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall  }
7230d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall
724bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCallprivate:
725bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  // These methods are implemented in a separate translation unit;
726bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  // "static"-ize them to avoid creating temporary QualTypes in the
727bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  // caller.
728bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  static bool isConstant(QualType T, ASTContext& Ctx);
7294ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  static QualType getDesugaredType(QualType T, const ASTContext &Context);
73049f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  static SplitQualType getSplitDesugaredType(QualType T);
73162c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  static SplitQualType getSplitUnqualifiedTypeImpl(QualType type);
732075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  static QualType IgnoreParens(QualType T);
7330d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall  static DestructionKind isDestructedTypeImpl(QualType type);
7345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
7355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end clang.
7375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace llvm {
7395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Implement simplify_type for QualType, so that we can dyn_cast from QualType
7405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// to a specific Type class.
7415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencertemplate<> struct simplify_type<const ::clang::QualType> {
742f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  typedef const ::clang::Type *SimpleType;
7435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static SimpleType getSimplifiedValue(const ::clang::QualType &Val) {
7444472fc641ea3069463798fb56a04043c28ea2910Douglas Gregor    return Val.getTypePtr();
7455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
7465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
7475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencertemplate<> struct simplify_type< ::clang::QualType>
7485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  : public simplify_type<const ::clang::QualType> {};
7491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7504e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner// Teach SmallPtrSet that QualType is "basically a pointer".
7514e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattnertemplate<>
752daae940507f2e93c6fa12e8062fa958e34cc2d1cChris Lattnerclass PointerLikeTypeTraits<clang::QualType> {
7534e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattnerpublic:
7544e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner  static inline void *getAsVoidPointer(clang::QualType P) {
7554e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner    return P.getAsOpaquePtr();
7564e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner  }
7574e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner  static inline clang::QualType getFromVoidPointer(void *P) {
7584e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner    return clang::QualType::getFromOpaquePtr(P);
7594e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner  }
7600953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Various qualifiers go in low bits.
7610eda3b31a672ea486fa92b9bc49a2c91be856b53Chris Lattner  enum { NumLowBitsAvailable = 0 };
7624e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner};
7631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
76473af669633e13c813f80cd15ecf3e6414778aee4Ted Kremenek} // end namespace llvm
7655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang {
7675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7683b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// \brief Base class that is common to both the \c ExtQuals and \c Type
7693b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// classes, which allows \c QualType to access the common fields between the
7703b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// two.
7713b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall///
7723b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallclass ExtQualsTypeCommonBase {
7733b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  ExtQualsTypeCommonBase(const Type *baseType, QualType canon)
7743b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    : BaseType(baseType), CanonicalType(canon) {}
7753b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
7763b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  /// \brief The "base" type of an extended qualifiers type (\c ExtQuals) or
7773b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  /// a self-referential pointer (for \c Type).
7783b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  ///
7793b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  /// This pointer allows an efficient mapping from a QualType to its
7803b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  /// underlying type pointer.
7813b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  const Type *const BaseType;
7823b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
7833b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  /// \brief The canonical type of this type.  A QualType.
7843b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  QualType CanonicalType;
7853b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
7863b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  friend class QualType;
7873b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  friend class Type;
7883b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  friend class ExtQuals;
7893b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall};
7903b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
7913b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// ExtQuals - We can encode up to four bits in the low bits of a
7923b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// type pointer, but there are many more type qualifiers that we want
7933b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// to be able to apply to an arbitrary type.  Therefore we have this
7943b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// struct, intended to be heap-allocated and used by QualType to
7953b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// store qualifiers.
7963b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall///
7973b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// The current design tags the 'const', 'restrict', and 'volatile' qualifiers
7983b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// in three low bits on the QualType pointer; a fourth bit records whether
7993b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// the pointer is an ExtQuals node. The extended qualifiers (address spaces,
8003b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// Objective-C GC attributes) are much more rare.
8013b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallclass ExtQuals : public ExtQualsTypeCommonBase, public llvm::FoldingSetNode {
8023b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  // NOTE: changing the fast qualifiers should be straightforward as
8033b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  // long as you don't make 'const' non-fast.
8043b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  // 1. Qualifiers:
8053b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  //    a) Modify the bitmasks (Qualifiers::TQ and DeclSpec::TQ).
8063b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  //       Fast qualifiers must occupy the low-order bits.
8073b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  //    b) Update Qualifiers::FastWidth and FastMask.
8083b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  // 2. QualType:
8093b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  //    a) Update is{Volatile,Restrict}Qualified(), defined inline.
8103b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  //    b) Update remove{Volatile,Restrict}, defined near the end of
8113b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  //       this header.
8123b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  // 3. ASTContext:
8133b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  //    a) Update get{Volatile,Restrict}Type.
8143b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
8153b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  /// Quals - the immutable set of qualifiers applied by this
8163b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  /// node;  always contains extended qualifiers.
8173b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  Qualifiers Quals;
8183b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
8193b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  ExtQuals *this_() { return this; }
8203b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
8213b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallpublic:
8223b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  ExtQuals(const Type *baseType, QualType canon, Qualifiers quals)
8233b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    : ExtQualsTypeCommonBase(baseType,
8243b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall                             canon.isNull() ? QualType(this_(), 0) : canon),
8253b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall      Quals(quals)
8263b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  {
8273b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    assert(Quals.hasNonFastQualifiers()
8283b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall           && "ExtQuals created with no fast qualifiers");
8293b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    assert(!Quals.hasFastQualifiers()
8303b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall           && "ExtQuals created with fast qualifiers");
8313b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  }
8323b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
8333b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  Qualifiers getQualifiers() const { return Quals; }
8343b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
8353b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  bool hasObjCGCAttr() const { return Quals.hasObjCGCAttr(); }
8363b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  Qualifiers::GC getObjCGCAttr() const { return Quals.getObjCGCAttr(); }
8373b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
8383b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  bool hasAddressSpace() const { return Quals.hasAddressSpace(); }
8393b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  unsigned getAddressSpace() const { return Quals.getAddressSpace(); }
8403b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
8413b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  const Type *getBaseType() const { return BaseType; }
8423b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
8433b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallpublic:
8443b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  void Profile(llvm::FoldingSetNodeID &ID) const {
8453b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    Profile(ID, getBaseType(), Quals);
8463b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  }
8473b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  static void Profile(llvm::FoldingSetNodeID &ID,
8483b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall                      const Type *BaseType,
8493b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall                      Qualifiers Quals) {
8503b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    assert(!Quals.hasFastQualifiers() && "fast qualifiers in ExtQuals hash!");
8513b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    ID.AddPointer(BaseType);
8523b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    Quals.Profile(ID);
8533b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  }
8543b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall};
8553b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
856c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor/// \brief The kind of C++0x ref-qualifier associated with a function type,
857c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor/// which determines whether a member function's "this" object can be an
858c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor/// lvalue, rvalue, or neither.
859c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregorenum RefQualifierKind {
860c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor  /// \brief No ref-qualifier was provided.
861c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor  RQ_None = 0,
862c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor  /// \brief An lvalue ref-qualifier was provided (\c &).
863c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor  RQ_LValue,
864c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor  /// \brief An rvalue ref-qualifier was provided (\c &&).
865c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor  RQ_RValue
866c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor};
867c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor
8685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Type - This is the base class of the type hierarchy.  A central concept
8695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// with types is that each type always has a canonical type.  A canonical type
8705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// is the type with any typedef names stripped out of it or the types it
8715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// references.  For example, consider:
8725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
8735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///  typedef int  foo;
8745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///  typedef foo* bar;
8755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///    'int *'    'foo *'    'bar'
8765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
8775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// There will be a Type object created for 'int'.  Since int is canonical, its
8785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// canonicaltype pointer points to itself.  There is also a Type for 'foo' (a
87972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// TypedefType).  Its CanonicalType pointer points to the 'int' Type.  Next
8805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// there is a PointerType that represents 'int*', which, like 'int', is
8815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// canonical.  Finally, there is a PointerType type for 'foo*' whose canonical
88272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// type is 'int*', and there is a TypedefType for 'bar', whose canonical type
8835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// is also 'int*'.
8845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
8855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Non-canonical types are useful for emitting diagnostics, without losing
8865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// information about typedefs being used.  Canonical types are useful for type
8875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// comparisons (they allow by-pointer equality tests) and useful for reasoning
8885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// about whether something has a particular form (e.g. is a function type),
8895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// because they implicitly, recursively, strip all typedefs out of a type.
8905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
8915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Types, once created, are immutable.
8925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
8931ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregorclass Type : public ExtQualsTypeCommonBase {
8945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
8955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  enum TypeClass {
89672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#define TYPE(Class, Base) Class,
89727935ee59c30b0d8b610ab676aab8e65350af932John McCall#define LAST_TYPE(Class) TypeLast = Class,
89872564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#define ABSTRACT_TYPE(Class, Base)
89972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#include "clang/AST/TypeNodes.def"
90072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor    TagFirst = Record, TagLast = Enum
9015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
9021bb8a45f7386a23871598d05141a07af03067925Argyrios Kyrtzidis
9035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate:
904c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  Type(const Type&);           // DO NOT IMPLEMENT.
905c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  void operator=(const Type&); // DO NOT IMPLEMENT.
906c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
907b870b88df784c2940efce448ebfaf54dece14666John McCall  /// Bitfields required by the Type class.
908b870b88df784c2940efce448ebfaf54dece14666John McCall  class TypeBitfields {
909b870b88df784c2940efce448ebfaf54dece14666John McCall    friend class Type;
910b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall    template <class T> friend class TypePropertyCache;
91127935ee59c30b0d8b610ab676aab8e65350af932John McCall
912b870b88df784c2940efce448ebfaf54dece14666John McCall    /// TypeClass bitfield - Enum that specifies what subclass this belongs to.
913b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned TC : 8;
914b870b88df784c2940efce448ebfaf54dece14666John McCall
915b870b88df784c2940efce448ebfaf54dece14666John McCall    /// Dependent - Whether this type is a dependent type (C++ [temp.dep.type]).
916b870b88df784c2940efce448ebfaf54dece14666John McCall    /// Note that this should stay at the end of the ivars for Type so that
917b870b88df784c2940efce448ebfaf54dece14666John McCall    /// subclasses can pack their bitfields into the same word.
918bdb5b0e8ad8ed297ad01eb2ccd0d6d5ed6058033Francois Pichet    unsigned Dependent : 1;
91960e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
920b870b88df784c2940efce448ebfaf54dece14666John McCall    /// \brief Whether this type is a variably-modified type (C99 6.7.5).
921bdb5b0e8ad8ed297ad01eb2ccd0d6d5ed6058033Francois Pichet    unsigned VariablyModified : 1;
922d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor
923d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    /// \brief Whether this type contains an unexpanded parameter pack
924d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    /// (for C++0x variadic templates).
925d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    unsigned ContainsUnexpandedParameterPack : 1;
92635495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor
9271fb0caaa7bef765b85972274e3b434af2572c141John McCall    /// \brief Nonzero if the cache (i.e. the bitfields here starting
9281fb0caaa7bef765b85972274e3b434af2572c141John McCall    /// with 'Cache') is valid.  If so, then this is a
9291fb0caaa7bef765b85972274e3b434af2572c141John McCall    /// LangOptions::VisibilityMode+1.
9301fb0caaa7bef765b85972274e3b434af2572c141John McCall    mutable unsigned CacheValidAndVisibility : 2;
93160e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
932b870b88df784c2940efce448ebfaf54dece14666John McCall    /// \brief Linkage of this type.
933b870b88df784c2940efce448ebfaf54dece14666John McCall    mutable unsigned CachedLinkage : 2;
93407a353c2af3a3c557205466d4f4ed2513462ebfeSebastian Redl
935b870b88df784c2940efce448ebfaf54dece14666John McCall    /// \brief Whether this type involves and local or unnamed types.
936bdb5b0e8ad8ed297ad01eb2ccd0d6d5ed6058033Francois Pichet    mutable unsigned CachedLocalOrUnnamed : 1;
937db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor
938b870b88df784c2940efce448ebfaf54dece14666John McCall    /// \brief FromAST - Whether this type comes from an AST file.
939bdb5b0e8ad8ed297ad01eb2ccd0d6d5ed6058033Francois Pichet    mutable unsigned FromAST : 1;
940b870b88df784c2940efce448ebfaf54dece14666John McCall
9411fb0caaa7bef765b85972274e3b434af2572c141John McCall    bool isCacheValid() const {
9421fb0caaa7bef765b85972274e3b434af2572c141John McCall      return (CacheValidAndVisibility != 0);
9431fb0caaa7bef765b85972274e3b434af2572c141John McCall    }
9441fb0caaa7bef765b85972274e3b434af2572c141John McCall    Visibility getVisibility() const {
9451fb0caaa7bef765b85972274e3b434af2572c141John McCall      assert(isCacheValid() && "getting linkage from invalid cache");
9461fb0caaa7bef765b85972274e3b434af2572c141John McCall      return static_cast<Visibility>(CacheValidAndVisibility-1);
9471fb0caaa7bef765b85972274e3b434af2572c141John McCall    }
9481fb0caaa7bef765b85972274e3b434af2572c141John McCall    Linkage getLinkage() const {
9491fb0caaa7bef765b85972274e3b434af2572c141John McCall      assert(isCacheValid() && "getting linkage from invalid cache");
9501fb0caaa7bef765b85972274e3b434af2572c141John McCall      return static_cast<Linkage>(CachedLinkage);
9511fb0caaa7bef765b85972274e3b434af2572c141John McCall    }
9521fb0caaa7bef765b85972274e3b434af2572c141John McCall    bool hasLocalOrUnnamedType() const {
9531fb0caaa7bef765b85972274e3b434af2572c141John McCall      assert(isCacheValid() && "getting linkage from invalid cache");
9541fb0caaa7bef765b85972274e3b434af2572c141John McCall      return CachedLocalOrUnnamed;
9551fb0caaa7bef765b85972274e3b434af2572c141John McCall    }
956b870b88df784c2940efce448ebfaf54dece14666John McCall  };
957d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  enum { NumTypeBits = 17 };
958b870b88df784c2940efce448ebfaf54dece14666John McCall
959b870b88df784c2940efce448ebfaf54dece14666John McCallprotected:
960b870b88df784c2940efce448ebfaf54dece14666John McCall  // These classes allow subclasses to somewhat cleanly pack bitfields
961b870b88df784c2940efce448ebfaf54dece14666John McCall  // into Type.
962b870b88df784c2940efce448ebfaf54dece14666John McCall
963b870b88df784c2940efce448ebfaf54dece14666John McCall  class ArrayTypeBitfields {
964b870b88df784c2940efce448ebfaf54dece14666John McCall    friend class ArrayType;
965b870b88df784c2940efce448ebfaf54dece14666John McCall
966b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned : NumTypeBits;
967b870b88df784c2940efce448ebfaf54dece14666John McCall
968b870b88df784c2940efce448ebfaf54dece14666John McCall    /// IndexTypeQuals - CVR qualifiers from declarations like
969b870b88df784c2940efce448ebfaf54dece14666John McCall    /// 'int X[static restrict 4]'. For function parameters only.
970b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned IndexTypeQuals : 3;
971b870b88df784c2940efce448ebfaf54dece14666John McCall
972b870b88df784c2940efce448ebfaf54dece14666John McCall    /// SizeModifier - storage class qualifiers from declarations like
973b870b88df784c2940efce448ebfaf54dece14666John McCall    /// 'int X[static restrict 4]'. For function parameters only.
974b870b88df784c2940efce448ebfaf54dece14666John McCall    /// Actually an ArrayType::ArraySizeModifier.
975b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned SizeModifier : 3;
976b870b88df784c2940efce448ebfaf54dece14666John McCall  };
977b870b88df784c2940efce448ebfaf54dece14666John McCall
978b870b88df784c2940efce448ebfaf54dece14666John McCall  class BuiltinTypeBitfields {
979b870b88df784c2940efce448ebfaf54dece14666John McCall    friend class BuiltinType;
980b870b88df784c2940efce448ebfaf54dece14666John McCall
981b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned : NumTypeBits;
982b870b88df784c2940efce448ebfaf54dece14666John McCall
983b870b88df784c2940efce448ebfaf54dece14666John McCall    /// The kind (BuiltinType::Kind) of builtin type this is.
984b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned Kind : 8;
985b870b88df784c2940efce448ebfaf54dece14666John McCall  };
986b870b88df784c2940efce448ebfaf54dece14666John McCall
987b870b88df784c2940efce448ebfaf54dece14666John McCall  class FunctionTypeBitfields {
988b870b88df784c2940efce448ebfaf54dece14666John McCall    friend class FunctionType;
989b870b88df784c2940efce448ebfaf54dece14666John McCall
990b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned : NumTypeBits;
991b870b88df784c2940efce448ebfaf54dece14666John McCall
992b870b88df784c2940efce448ebfaf54dece14666John McCall    /// Extra information which affects how the function is called, like
993b870b88df784c2940efce448ebfaf54dece14666John McCall    /// regparm and the calling convention.
994b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned ExtInfo : 8;
995b870b88df784c2940efce448ebfaf54dece14666John McCall
996e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall    /// Whether the function is variadic.  Only used by FunctionProtoType.
997e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall    unsigned Variadic : 1;
998b870b88df784c2940efce448ebfaf54dece14666John McCall
999b870b88df784c2940efce448ebfaf54dece14666John McCall    /// TypeQuals - Used only by FunctionProtoType, put here to pack with the
1000b870b88df784c2940efce448ebfaf54dece14666John McCall    /// other bitfields.
1001b870b88df784c2940efce448ebfaf54dece14666John McCall    /// The qualifiers are part of FunctionProtoType because...
1002b870b88df784c2940efce448ebfaf54dece14666John McCall    ///
1003b870b88df784c2940efce448ebfaf54dece14666John McCall    /// C++ 8.3.5p4: The return type, the parameter type list and the
1004b870b88df784c2940efce448ebfaf54dece14666John McCall    /// cv-qualifier-seq, [...], are part of the function type.
1005b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned TypeQuals : 3;
1006c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor
1007c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor    /// \brief The ref-qualifier associated with a \c FunctionProtoType.
1008c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor    ///
1009c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor    /// This is a value of type \c RefQualifierKind.
1010c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor    unsigned RefQualifier : 2;
1011b870b88df784c2940efce448ebfaf54dece14666John McCall  };
1012b870b88df784c2940efce448ebfaf54dece14666John McCall
1013b870b88df784c2940efce448ebfaf54dece14666John McCall  class ObjCObjectTypeBitfields {
1014b870b88df784c2940efce448ebfaf54dece14666John McCall    friend class ObjCObjectType;
1015b870b88df784c2940efce448ebfaf54dece14666John McCall
1016b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned : NumTypeBits;
1017b870b88df784c2940efce448ebfaf54dece14666John McCall
1018b870b88df784c2940efce448ebfaf54dece14666John McCall    /// NumProtocols - The number of protocols stored directly on this
1019b870b88df784c2940efce448ebfaf54dece14666John McCall    /// object type.
1020b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned NumProtocols : 32 - NumTypeBits;
1021b870b88df784c2940efce448ebfaf54dece14666John McCall  };
1022b870b88df784c2940efce448ebfaf54dece14666John McCall
1023b870b88df784c2940efce448ebfaf54dece14666John McCall  class ReferenceTypeBitfields {
1024b870b88df784c2940efce448ebfaf54dece14666John McCall    friend class ReferenceType;
1025b870b88df784c2940efce448ebfaf54dece14666John McCall
1026b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned : NumTypeBits;
1027b870b88df784c2940efce448ebfaf54dece14666John McCall
1028b870b88df784c2940efce448ebfaf54dece14666John McCall    /// True if the type was originally spelled with an lvalue sigil.
1029b870b88df784c2940efce448ebfaf54dece14666John McCall    /// This is never true of rvalue references but can also be false
1030b870b88df784c2940efce448ebfaf54dece14666John McCall    /// on lvalue references because of C++0x [dcl.typedef]p9,
1031b870b88df784c2940efce448ebfaf54dece14666John McCall    /// as follows:
1032b870b88df784c2940efce448ebfaf54dece14666John McCall    ///
1033b870b88df784c2940efce448ebfaf54dece14666John McCall    ///   typedef int &ref;    // lvalue, spelled lvalue
1034b870b88df784c2940efce448ebfaf54dece14666John McCall    ///   typedef int &&rvref; // rvalue
1035b870b88df784c2940efce448ebfaf54dece14666John McCall    ///   ref &a;              // lvalue, inner ref, spelled lvalue
1036b870b88df784c2940efce448ebfaf54dece14666John McCall    ///   ref &&a;             // lvalue, inner ref
1037b870b88df784c2940efce448ebfaf54dece14666John McCall    ///   rvref &a;            // lvalue, inner ref, spelled lvalue
1038b870b88df784c2940efce448ebfaf54dece14666John McCall    ///   rvref &&a;           // rvalue, inner ref
1039bdb5b0e8ad8ed297ad01eb2ccd0d6d5ed6058033Francois Pichet    unsigned SpelledAsLValue : 1;
1040b870b88df784c2940efce448ebfaf54dece14666John McCall
1041b870b88df784c2940efce448ebfaf54dece14666John McCall    /// True if the inner type is a reference type.  This only happens
1042b870b88df784c2940efce448ebfaf54dece14666John McCall    /// in non-canonical forms.
1043bdb5b0e8ad8ed297ad01eb2ccd0d6d5ed6058033Francois Pichet    unsigned InnerRef : 1;
1044b870b88df784c2940efce448ebfaf54dece14666John McCall  };
1045b870b88df784c2940efce448ebfaf54dece14666John McCall
104677be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall  class TypeWithKeywordBitfields {
104777be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall    friend class TypeWithKeyword;
104877be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall
104977be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall    unsigned : NumTypeBits;
105077be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall
105177be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall    /// An ElaboratedTypeKeyword.  8 bits for efficient access.
105277be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall    unsigned Keyword : 8;
105377be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall  };
105477be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall
1055b870b88df784c2940efce448ebfaf54dece14666John McCall  class VectorTypeBitfields {
1056b870b88df784c2940efce448ebfaf54dece14666John McCall    friend class VectorType;
105707a353c2af3a3c557205466d4f4ed2513462ebfeSebastian Redl
1058b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned : NumTypeBits;
105971c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall
1060e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson    /// VecKind - The kind of vector, either a generic vector type or some
1061e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson    /// target-specific vector type such as for AltiVec or Neon.
1062cc3b946c35c4372272034e6f0663089477a9a5bdBob Wilson    unsigned VecKind : 3;
1063b870b88df784c2940efce448ebfaf54dece14666John McCall
1064b870b88df784c2940efce448ebfaf54dece14666John McCall    /// NumElements - The number of elements in the vector.
1065cc3b946c35c4372272034e6f0663089477a9a5bdBob Wilson    unsigned NumElements : 29 - NumTypeBits;
1066b870b88df784c2940efce448ebfaf54dece14666John McCall  };
1067b870b88df784c2940efce448ebfaf54dece14666John McCall
10689d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  class AttributedTypeBitfields {
10699d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    friend class AttributedType;
10709d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
10719d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    unsigned : NumTypeBits;
10729d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
10739d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    /// AttrKind - an AttributedType::Kind
10749d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    unsigned AttrKind : 32 - NumTypeBits;
10759d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  };
10769d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
1077b870b88df784c2940efce448ebfaf54dece14666John McCall  union {
1078b870b88df784c2940efce448ebfaf54dece14666John McCall    TypeBitfields TypeBits;
1079b870b88df784c2940efce448ebfaf54dece14666John McCall    ArrayTypeBitfields ArrayTypeBits;
10809d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    AttributedTypeBitfields AttributedTypeBits;
1081b870b88df784c2940efce448ebfaf54dece14666John McCall    BuiltinTypeBitfields BuiltinTypeBits;
1082b870b88df784c2940efce448ebfaf54dece14666John McCall    FunctionTypeBitfields FunctionTypeBits;
1083b870b88df784c2940efce448ebfaf54dece14666John McCall    ObjCObjectTypeBitfields ObjCObjectTypeBits;
1084b870b88df784c2940efce448ebfaf54dece14666John McCall    ReferenceTypeBitfields ReferenceTypeBits;
108577be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall    TypeWithKeywordBitfields TypeWithKeywordBits;
1086b870b88df784c2940efce448ebfaf54dece14666John McCall    VectorTypeBitfields VectorTypeBits;
1087b870b88df784c2940efce448ebfaf54dece14666John McCall  };
1088b870b88df784c2940efce448ebfaf54dece14666John McCall
1089b870b88df784c2940efce448ebfaf54dece14666John McCallprivate:
10903c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief Set whether this type comes from an AST file.
10913c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  void setFromAST(bool V = true) const {
1092b870b88df784c2940efce448ebfaf54dece14666John McCall    TypeBits.FromAST = V;
109307a353c2af3a3c557205466d4f4ed2513462ebfeSebastian Redl  }
109407a353c2af3a3c557205466d4f4ed2513462ebfeSebastian Redl
1095b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall  template <class T> friend class TypePropertyCache;
10961fb0caaa7bef765b85972274e3b434af2572c141John McCall
10975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprotected:
1098124dd7b5777e29ecac006822bd4d4623f0dc4264Hartmut Kaiser  // silence VC++ warning C4355: 'this' : used in base member initializer list
1099124dd7b5777e29ecac006822bd4d4623f0dc4264Hartmut Kaiser  Type *this_() { return this; }
11003b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  Type(TypeClass tc, QualType canon, bool Dependent, bool VariablyModified,
1101d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor       bool ContainsUnexpandedParameterPack)
11023b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    : ExtQualsTypeCommonBase(this,
11033b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall                             canon.isNull() ? QualType(this_(), 0) : canon) {
1104b870b88df784c2940efce448ebfaf54dece14666John McCall    TypeBits.TC = tc;
1105b870b88df784c2940efce448ebfaf54dece14666John McCall    TypeBits.Dependent = Dependent;
1106b870b88df784c2940efce448ebfaf54dece14666John McCall    TypeBits.VariablyModified = VariablyModified;
1107d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    TypeBits.ContainsUnexpandedParameterPack = ContainsUnexpandedParameterPack;
11081fb0caaa7bef765b85972274e3b434af2572c141John McCall    TypeBits.CacheValidAndVisibility = 0;
1109b870b88df784c2940efce448ebfaf54dece14666John McCall    TypeBits.CachedLocalOrUnnamed = false;
1110b870b88df784c2940efce448ebfaf54dece14666John McCall    TypeBits.CachedLinkage = NoLinkage;
1111b870b88df784c2940efce448ebfaf54dece14666John McCall    TypeBits.FromAST = false;
1112b870b88df784c2940efce448ebfaf54dece14666John McCall  }
11135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;
11141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1115b870b88df784c2940efce448ebfaf54dece14666John McCall  void setDependent(bool D = true) { TypeBits.Dependent = D; }
1116b870b88df784c2940efce448ebfaf54dece14666John McCall  void setVariablyModified(bool VM = true) { TypeBits.VariablyModified = VM; }
1117d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  void setContainsUnexpandedParameterPack(bool PP = true) {
1118d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    TypeBits.ContainsUnexpandedParameterPack = PP;
1119d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  }
1120d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor
11218b9023ba35a86838789e2c9034a6128728c547aaChris Lattnerpublic:
1122b870b88df784c2940efce448ebfaf54dece14666John McCall  TypeClass getTypeClass() const { return static_cast<TypeClass>(TypeBits.TC); }
11231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
11243c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief Whether this type comes from an AST file.
1125b870b88df784c2940efce448ebfaf54dece14666John McCall  bool isFromAST() const { return TypeBits.FromAST; }
112607a353c2af3a3c557205466d4f4ed2513462ebfeSebastian Redl
1127d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// \brief Whether this type is or contains an unexpanded parameter
1128d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// pack, used to support C++0x variadic templates.
1129d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  ///
1130d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// A type that contains a parameter pack shall be expanded by the
1131d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// ellipsis operator at some point. For example, the typedef in the
1132d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// following example contains an unexpanded parameter pack 'T':
1133d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  ///
1134d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// \code
1135d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// template<typename ...T>
1136d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// struct X {
1137d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  ///   typedef T* pointer_types; // ill-formed; T is a parameter pack.
1138d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// };
1139d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// \endcode
1140d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  ///
1141d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// Note that this routine does not specify which
1142d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  bool containsUnexpandedParameterPack() const {
1143d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    return TypeBits.ContainsUnexpandedParameterPack;
1144d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  }
1145d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor
11463b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  /// Determines if this type would be canonical if it had no further
11473b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  /// qualification.
1148467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall  bool isCanonicalUnqualified() const {
11493b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    return CanonicalType == QualType(this, 0);
1150467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall  }
11515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
11521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// Types are partitioned into 3 broad categories (C99 6.2.5p1):
11535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// object types, function types, and incomplete types.
11541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
11555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isIncompleteType - Return true if this is an incomplete type.
11565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// A type that can describe objects, but which lacks information needed to
11575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// determine its size (e.g. void, or a fwd declared struct). Clients of this
11581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// routine will need to determine if the size is actually required.
11595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isIncompleteType() const;
1160d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner
1161d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner  /// isIncompleteOrObjectType - Return true if this is an incomplete or object
1162d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner  /// type, in other words, not a function type.
1163d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner  bool isIncompleteOrObjectType() const {
1164d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner    return !isFunctionType();
1165d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner  }
11662fdc5e8199e1e239620f2faae88997153703e16fDouglas Gregor
11672fdc5e8199e1e239620f2faae88997153703e16fDouglas Gregor  /// \brief Determine whether this type is an object type.
11682fdc5e8199e1e239620f2faae88997153703e16fDouglas Gregor  bool isObjectType() const {
11692fdc5e8199e1e239620f2faae88997153703e16fDouglas Gregor    // C++ [basic.types]p8:
11702fdc5e8199e1e239620f2faae88997153703e16fDouglas Gregor    //   An object type is a (possibly cv-qualified) type that is not a
11712fdc5e8199e1e239620f2faae88997153703e16fDouglas Gregor    //   function type, not a reference type, and not a void type.
11722fdc5e8199e1e239620f2faae88997153703e16fDouglas Gregor    return !isReferenceType() && !isFunctionType() && !isVoidType();
11732fdc5e8199e1e239620f2faae88997153703e16fDouglas Gregor  }
117464b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
117564b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  /// isPODType - Return true if this is a plain-old-data type (C++ 3.9p10).
117664b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  bool isPODType() const;
117764b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
1178ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl  /// isLiteralType - Return true if this is a literal type
1179ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl  /// (C++0x [basic.types]p10)
1180ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl  bool isLiteralType() const;
1181ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl
118220c0da7787c9a7d2529e42a4a91d777778595d74John Wiegley  /// isTrivialType - Return true if this is a trivial type
1183b7e9589bce9852b4db9575f55ac9137572147eb5Chandler Carruth  /// (C++0x [basic.types]p9)
1184b7e9589bce9852b4db9575f55ac9137572147eb5Chandler Carruth  bool isTrivialType() const;
1185b7e9589bce9852b4db9575f55ac9137572147eb5Chandler Carruth
1186636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth  /// \brief Test if this type is a standard-layout type.
1187636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth  /// (C++0x [basic.type]p9)
1188636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth  bool isStandardLayoutType() const;
1189636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth
119043fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth  /// isCXX11PODType() - Return true if this is a POD type according to the
119143fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth  /// more relaxed rules of the C++11 standard, regardless of the current
119243fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth  /// compilation's language.
119343fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth  /// (C++0x [basic.types]p9)
119443fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth  bool isCXX11PODType() const;
119543fa33b4bedc28d2faa17d678ad1f40eb42817a1Chandler Carruth
11965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// Helper methods to distinguish type categories. All type predicates
1197ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb  /// operate on the canonical type, ignoring typedefs and qualifiers.
1198e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar
11999b065ddabf572772991a4aadad5bf4921fac5069Tom Care  /// isBuiltinType - returns true if the type is a builtin type.
12009b065ddabf572772991a4aadad5bf4921fac5069Tom Care  bool isBuiltinType() const;
12019b065ddabf572772991a4aadad5bf4921fac5069Tom Care
1202e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar  /// isSpecificBuiltinType - Test for a particular builtin type.
1203e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar  bool isSpecificBuiltinType(unsigned K) const;
12041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12052a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  /// isPlaceholderType - Test for a type which does not represent an
12062a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  /// actual type-system type but is instead used as a placeholder for
12072a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  /// various convenient purposes within Clang.  All such types are
12082a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  /// BuiltinTypes.
12092a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  bool isPlaceholderType() const;
12102a984cad5ac3fdceeff2bd99daa7b90979313475John McCall
1211864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall  /// isSpecificPlaceholderType - Test for a specific placeholder type.
1212864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall  bool isSpecificPlaceholderType(unsigned K) const;
1213864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall
121496d2c438f5c9ada8229f7f2ac049d2e9957bc954Steve Naroff  /// isIntegerType() does *not* include complex integers (a GCC extension).
121596d2c438f5c9ada8229f7f2ac049d2e9957bc954Steve Naroff  /// isComplexIntegerType() can be used to test for complex integers.
12165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isIntegerType() const;     // C99 6.2.5p17 (int, char, bool, enum)
121713b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff  bool isEnumeralType() const;
121813b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff  bool isBooleanType() const;
121913b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff  bool isCharType() const;
122077a52233f7c0f162672652051bfe78b65ad4f789Douglas Gregor  bool isWideCharType() const;
122120093b4bf698f292c664676987541d5103b65b15Douglas Gregor  bool isAnyCharacterType() const;
12229d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor  bool isIntegralType(ASTContext &Ctx) const;
122320093b4bf698f292c664676987541d5103b65b15Douglas Gregor
12242ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor  /// \brief Determine whether this type is an integral or enumeration type.
12252ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor  bool isIntegralOrEnumerationType() const;
12261274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor  /// \brief Determine whether this type is an integral or unscoped enumeration
12271274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor  /// type.
12281274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor  bool isIntegralOrUnscopedEnumerationType() const;
12292ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor
12305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// Floating point categories.
12315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isRealFloatingType() const; // C99 6.2.5p10 (float, double, long double)
123202f62a9fedbc370fba081303399410a3afdde29fSteve Naroff  /// isComplexType() does *not* include complex integers (a GCC extension).
123302f62a9fedbc370fba081303399410a3afdde29fSteve Naroff  /// isComplexIntegerType() can be used to test for complex integers.
12345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isComplexType() const;      // C99 6.2.5p11 (complex)
1235f23d364084d1aabea688222780d6fc1dd8c7f78cChris Lattner  bool isAnyComplexType() const;   // C99 6.2.5p11 (complex) + Complex Int.
12365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isFloatingType() const;     // C99 6.2.5p11 (real floating + complex)
12375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isRealType() const;         // C99 6.2.5p17 (real floating + integer)
12385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isArithmeticType() const;   // C99 6.2.5p18 (integer + floating)
1239c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  bool isVoidType() const;         // C99 6.2.5p19
1240c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  bool isDerivedType() const;      // C99 6.2.5p20
1241c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  bool isScalarType() const;       // C99 6.2.5p21 (arithmetic + pointers)
1242d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor  bool isAggregateType() const;
1243aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth  bool isFundamentalType() const;
1244aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth  bool isCompoundType() const;
12451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1246c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  // Type Predicates: Check to see if this type is structurally the specified
1247ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb  // type, ignoring typedefs and qualifiers.
1248c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  bool isFunctionType() const;
1249183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  bool isFunctionNoProtoType() const { return getAs<FunctionNoProtoType>(); }
1250183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  bool isFunctionProtoType() const { return getAs<FunctionProtoType>(); }
1251befee48ff2a1dab236c5700f00ecca1cfdcd5837Chris Lattner  bool isPointerType() const;
125258f9f2c884af6b72d036b746a016d8031d31cb7aSteve Naroff  bool isAnyPointerType() const;   // Any C pointer or ObjC object pointer
12535618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  bool isBlockPointerType() const;
12547154a77e7c1f23418342d3b72836ab504aa7821eSteve Naroff  bool isVoidPointerType() const;
1255a1d9fdea79ba7bbd71862b9f9f78f5f117331fc7Chris Lattner  bool isReferenceType() const;
12567c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  bool isLValueReferenceType() const;
12577c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  bool isRValueReferenceType() const;
1258bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner  bool isFunctionPointerType() const;
1259f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  bool isMemberPointerType() const;
1260f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  bool isMemberFunctionPointerType() const;
1261db68e28c05a67735211e688009890cf834c22e75Douglas Gregor  bool isMemberDataPointerType() const;
1262c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  bool isArrayType() const;
1263c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  bool isConstantArrayType() const;
1264c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  bool isIncompleteArrayType() const;
1265c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  bool isVariableArrayType() const;
1266898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  bool isDependentSizedArrayType() const;
1267c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  bool isRecordType() const;
12681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  bool isClassType() const;
12691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  bool isStructureType() const;
1270fb87b89fc9eb103e19fb8e4b925c23f0bd091b99Douglas Gregor  bool isStructureOrClassType() const;
12714cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroff  bool isUnionType() const;
1272368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner  bool isComplexIntegerType() const;            // GCC _Complex integer type.
1273368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner  bool isVectorType() const;                    // GCC vector type.
1274213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman  bool isExtVectorType() const;                 // Extended vector type.
1275d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff  bool isObjCObjectPointerType() const;         // Pointer to *any* ObjC object.
127614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  // FIXME: change this to 'raw' interface type, so we can used 'interface' type
127714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  // for the common case.
1278c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool isObjCObjectType() const;                // NSString or typeof(*(id)0)
1279368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner  bool isObjCQualifiedInterfaceType() const;    // NSString<foo>
1280368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner  bool isObjCQualifiedIdType() const;           // id<foo>
1281470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroff  bool isObjCQualifiedClassType() const;        // Class<foo>
1282569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor  bool isObjCObjectOrInterfaceType() const;
128314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  bool isObjCIdType() const;                    // id
128414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  bool isObjCClassType() const;                 // Class
128513dcd00615de5c4279d97bdf63cd5f0a14fd9dccFariborz Jahanian  bool isObjCSelType() const;                 // Class
1286de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff  bool isObjCBuiltinType() const;               // 'id' or 'Class'
128772c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor  bool isTemplateTypeParmType() const;          // C++ template type parameter
12886e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl  bool isNullPtrType() const;                   // C++0x nullptr_t
1289898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
1290daa8e4e888758d55a7a759dd4a91b83921cef222John McCall  enum ScalarTypeKind {
1291daa8e4e888758d55a7a759dd4a91b83921cef222John McCall    STK_Pointer,
1292daa8e4e888758d55a7a759dd4a91b83921cef222John McCall    STK_MemberPointer,
1293daa8e4e888758d55a7a759dd4a91b83921cef222John McCall    STK_Bool,
1294daa8e4e888758d55a7a759dd4a91b83921cef222John McCall    STK_Integral,
1295daa8e4e888758d55a7a759dd4a91b83921cef222John McCall    STK_Floating,
1296daa8e4e888758d55a7a759dd4a91b83921cef222John McCall    STK_IntegralComplex,
1297daa8e4e888758d55a7a759dd4a91b83921cef222John McCall    STK_FloatingComplex
1298daa8e4e888758d55a7a759dd4a91b83921cef222John McCall  };
1299daa8e4e888758d55a7a759dd4a91b83921cef222John McCall  /// getScalarTypeKind - Given that this is a scalar type, classify it.
1300daa8e4e888758d55a7a759dd4a91b83921cef222John McCall  ScalarTypeKind getScalarTypeKind() const;
1301daa8e4e888758d55a7a759dd4a91b83921cef222John McCall
1302898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// isDependentType - Whether this type is a dependent type, meaning
13031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// that its definition somehow depends on a template parameter
1304898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// (C++ [temp.dep.type]).
1305b870b88df784c2940efce448ebfaf54dece14666John McCall  bool isDependentType() const { return TypeBits.Dependent; }
130635495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor
130735495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor  /// \brief Whether this type is a variably-modified type (C99 6.7.5).
1308b870b88df784c2940efce448ebfaf54dece14666John McCall  bool isVariablyModifiedType() const { return TypeBits.VariablyModified; }
13093b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
13103b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  /// \brief Whether this type involves a variable-length array type
13113b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  /// with a definite size.
13123b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  bool hasSizedVLAType() const;
131335495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor
1314db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor  /// \brief Whether this type is or contains a local or unnamed type.
1315db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor  bool hasUnnamedOrLocalType() const;
1316db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor
1317063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  bool isOverloadableType() const;
131872c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor
13194033642464e8ba0982f88f34cffad808d247b393Douglas Gregor  /// \brief Determine wither this type is a C++ elaborated-type-specifier.
13204033642464e8ba0982f88f34cffad808d247b393Douglas Gregor  bool isElaboratedTypeSpecifier() const;
13214033642464e8ba0982f88f34cffad808d247b393Douglas Gregor
13228958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar  /// hasPointerRepresentation - Whether this type is represented
13238958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar  /// natively as a pointer; this includes pointers, references, block
13248958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar  /// pointers, and Objective-C interface, qualified id, and qualified
13256e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl  /// interface types, as well as nullptr_t.
13268958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar  bool hasPointerRepresentation() const;
13278958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar
1328820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian  /// hasObjCPointerRepresentation - Whether this type can represent
1329820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian  /// an objective pointer type for the purpose of GC'ability
13301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  bool hasObjCPointerRepresentation() const;
1331820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian
1332f60946222721d9ba3c059563935c17b84703187aDouglas Gregor  /// \brief Determine whether this type has an integer representation
1333f60946222721d9ba3c059563935c17b84703187aDouglas Gregor  /// of some sort, e.g., it is an integer type or a vector.
1334f60946222721d9ba3c059563935c17b84703187aDouglas Gregor  bool hasIntegerRepresentation() const;
1335f60946222721d9ba3c059563935c17b84703187aDouglas Gregor
1336f60946222721d9ba3c059563935c17b84703187aDouglas Gregor  /// \brief Determine whether this type has an signed integer representation
1337f60946222721d9ba3c059563935c17b84703187aDouglas Gregor  /// of some sort, e.g., it is an signed integer type or a vector.
1338f60946222721d9ba3c059563935c17b84703187aDouglas Gregor  bool hasSignedIntegerRepresentation() const;
1339f60946222721d9ba3c059563935c17b84703187aDouglas Gregor
1340f60946222721d9ba3c059563935c17b84703187aDouglas Gregor  /// \brief Determine whether this type has an unsigned integer representation
1341f60946222721d9ba3c059563935c17b84703187aDouglas Gregor  /// of some sort, e.g., it is an unsigned integer type or a vector.
1342f60946222721d9ba3c059563935c17b84703187aDouglas Gregor  bool hasUnsignedIntegerRepresentation() const;
1343f60946222721d9ba3c059563935c17b84703187aDouglas Gregor
13448eee119bf4f1693dde17b8552c1f9f81bf2b681eDouglas Gregor  /// \brief Determine whether this type has a floating-point representation
13458eee119bf4f1693dde17b8552c1f9f81bf2b681eDouglas Gregor  /// of some sort, e.g., it is a floating-point type or a vector thereof.
13468eee119bf4f1693dde17b8552c1f9f81bf2b681eDouglas Gregor  bool hasFloatingRepresentation() const;
1347f60946222721d9ba3c059563935c17b84703187aDouglas Gregor
1348c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  // Type Checking Functions: Check to see if this type is structurally the
1349f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner  // specified type, ignoring typedefs and qualifiers, and return a pointer to
1350f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner  // the best type we can.
1351769c9cfc6e06bd9d8ffe7a4397b939f19b0e4dc3Ted Kremenek  const RecordType *getAsStructureType() const;
1352898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// NOTE: getAs*ArrayType are methods on ASTContext.
1353c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  const RecordType *getAsUnionType() const;
13544cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroff  const ComplexType *getAsComplexIntegerType() const; // GCC complex int type.
135514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  // The following is a convenience method that returns an ObjCObjectPointerType
135614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  // for object declared using an interface.
135714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  const ObjCObjectPointerType *getAsObjCInterfacePointerType() const;
135814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  const ObjCObjectPointerType *getAsObjCQualifiedIdType() const;
1359759abb4d9ec14ae32104a9677b60f0542b60d1d8Fariborz Jahanian  const ObjCObjectPointerType *getAsObjCQualifiedClassType() const;
1360c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  const ObjCObjectType *getAsObjCQualifiedInterfaceType() const;
1361a91d6a6619a91d0ca7102d8ab5678d855f04d850Fariborz Jahanian  const CXXRecordDecl *getCXXRecordDeclForPointerType() const;
13621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1363c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor  /// \brief Retrieves the CXXRecordDecl that this type refers to, either
1364c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor  /// because the type is a RecordType or because it is the injected-class-name
1365c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor  /// type of a class template or class template partial specialization.
1366c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor  CXXRecordDecl *getAsCXXRecordDecl() const;
136734b41d939a1328f484511c6002ba2456db879a29Richard Smith
136834b41d939a1328f484511c6002ba2456db879a29Richard Smith  /// \brief Get the AutoType whose type will be deduced for a variable with
136934b41d939a1328f484511c6002ba2456db879a29Richard Smith  /// an initializer of this type. This looks through declarators like pointer
137034b41d939a1328f484511c6002ba2456db879a29Richard Smith  /// types, but not through decltype or typedefs.
137134b41d939a1328f484511c6002ba2456db879a29Richard Smith  AutoType *getContainedAutoType() const;
1372c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor
1373d0370f59e79702ac908c81bf556519f91e9ca297John McCall  /// Member-template getAs<specific type>'.  Look through sugar for
1374d0370f59e79702ac908c81bf556519f91e9ca297John McCall  /// an instance of <specific type>.   This scheme will eventually
1375d0370f59e79702ac908c81bf556519f91e9ca297John McCall  /// replace the specific getAsXXXX methods above.
1376d0370f59e79702ac908c81bf556519f91e9ca297John McCall  ///
1377d0370f59e79702ac908c81bf556519f91e9ca297John McCall  /// There are some specializations of this member template listed
1378d0370f59e79702ac908c81bf556519f91e9ca297John McCall  /// immediately following this class.
13791a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek  template <typename T> const T *getAs() const;
13801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
13813b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  /// A variant of getAs<> for array types which silently discards
13823b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  /// qualifiers from the outermost type.
13833b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  const ArrayType *getAsArrayTypeUnsafe() const;
13843b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
1385d0370f59e79702ac908c81bf556519f91e9ca297John McCall  /// Member-template castAs<specific type>.  Look through sugar for
1386d0370f59e79702ac908c81bf556519f91e9ca297John McCall  /// the underlying instance of <specific type>.
1387d0370f59e79702ac908c81bf556519f91e9ca297John McCall  ///
1388d0370f59e79702ac908c81bf556519f91e9ca297John McCall  /// This method has the same relationship to getAs<T> as cast<T> has
1389d0370f59e79702ac908c81bf556519f91e9ca297John McCall  /// to dyn_cast<T>; which is to say, the underlying type *must*
1390d0370f59e79702ac908c81bf556519f91e9ca297John McCall  /// have the intended type, and this method will never return null.
1391d0370f59e79702ac908c81bf556519f91e9ca297John McCall  template <typename T> const T *castAs() const;
1392d0370f59e79702ac908c81bf556519f91e9ca297John McCall
1393d0370f59e79702ac908c81bf556519f91e9ca297John McCall  /// A variant of castAs<> for array type which silently discards
1394d0370f59e79702ac908c81bf556519f91e9ca297John McCall  /// qualifiers from the outermost type.
1395d0370f59e79702ac908c81bf556519f91e9ca297John McCall  const ArrayType *castAsArrayTypeUnsafe() const;
1396d0370f59e79702ac908c81bf556519f91e9ca297John McCall
1397d0370f59e79702ac908c81bf556519f91e9ca297John McCall  /// getBaseElementTypeUnsafe - Get the base element type of this
1398d0370f59e79702ac908c81bf556519f91e9ca297John McCall  /// type, potentially discarding type qualifiers.  This method
1399d0370f59e79702ac908c81bf556519f91e9ca297John McCall  /// should never be used when type qualifiers are meaningful.
1400d0370f59e79702ac908c81bf556519f91e9ca297John McCall  const Type *getBaseElementTypeUnsafe() const;
1401d0370f59e79702ac908c81bf556519f91e9ca297John McCall
1402c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  /// getArrayElementTypeNoTypeQual - If this is an array type, return the
1403c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  /// element type of the array, potentially with type qualifiers missing.
1404c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  /// This method should never be used when type qualifiers are meaningful.
1405c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  const Type *getArrayElementTypeNoTypeQual() const;
14061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1407f8910df57799256c1897a8610dc52685729ae90eSteve Naroff  /// getPointeeType - If this is a pointer, ObjC object pointer, or block
1408f8910df57799256c1897a8610dc52685729ae90eSteve Naroff  /// pointer, this returns the respective pointee.
140914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  QualType getPointeeType() const;
14101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1411bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// getUnqualifiedDesugaredType() - Return the specified type with
1412bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// any "sugar" removed from the type, removing any typedefs,
1413bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// typeofs, etc., as well as any qualifiers.
1414bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  const Type *getUnqualifiedDesugaredType() const;
14151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
14165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// More type predicates useful for type checking/promotion
14175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isPromotableIntegerType() const; // C99 6.3.1.1p2
14185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
14195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isSignedIntegerType - Return true if this is an integer type that is
1420d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner  /// signed, according to C99 6.2.5p4 [char, signed char, short, int, long..],
1421d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner  /// an enum decl which has a signed representation, or a vector of signed
1422d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner  /// integer element type.
14235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isSignedIntegerType() const;
14245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
14255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isUnsignedIntegerType - Return true if this is an integer type that is
1426d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner  /// unsigned, according to C99 6.2.5p6 [which returns true for _Bool], an enum
1427d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner  /// decl which has an unsigned representation, or a vector of unsigned integer
1428d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner  /// element type.
14295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isUnsignedIntegerType() const;
1430d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner
14315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isConstantSizeType - Return true if this is not a variable sized type,
14329bfa73c5ab7bf4b0e749d04f29da6884e8d5bd9fChris Lattner  /// according to the rules of C99 6.7.5p3.  It is not legal to call this on
14339bfa73c5ab7bf4b0e749d04f29da6884e8d5bd9fChris Lattner  /// incomplete types.
14343c2b3170041f69a92904e3bab9b6d654eaf260acEli Friedman  bool isConstantSizeType() const;
1435c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner
143622b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman  /// isSpecifierType - Returns true if this type can be represented by some
143722b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman  /// set of type specifiers.
143822b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman  bool isSpecifierType() const;
143922b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman
14400b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor  /// \brief Determine the linkage of this type.
144160e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor  Linkage getLinkage() const;
14421fb0caaa7bef765b85972274e3b434af2572c141John McCall
14431fb0caaa7bef765b85972274e3b434af2572c141John McCall  /// \brief Determine the visibility of this type.
14441fb0caaa7bef765b85972274e3b434af2572c141John McCall  Visibility getVisibility() const;
14451fb0caaa7bef765b85972274e3b434af2572c141John McCall
14461fb0caaa7bef765b85972274e3b434af2572c141John McCall  /// \brief Determine the linkage and visibility of this type.
14471fb0caaa7bef765b85972274e3b434af2572c141John McCall  std::pair<Linkage,Visibility> getLinkageAndVisibility() const;
144860e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
144960e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor  /// \brief Note that the linkage is no longer known.
145060e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor  void ClearLinkageCache();
145160e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
145260e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor  const char *getTypeClassName() const;
14530b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor
1454ead608af31b6c9abeae1ca6d0b75094dac4641c0John McCall  QualType getCanonicalTypeInternal() const {
1455ead608af31b6c9abeae1ca6d0b75094dac4641c0John McCall    return CanonicalType;
1456ead608af31b6c9abeae1ca6d0b75094dac4641c0John McCall  }
1457ead608af31b6c9abeae1ca6d0b75094dac4641c0John McCall  CanQualType getCanonicalTypeUnqualified() const; // in CanonicalType.h
1458c36d405a02fab41f6c45cb2bc750d64949742903Chris Lattner  void dump() const;
14595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *) { return true; }
1460be191100e034b23a3e13053757a57b7f5068c24aArgyrios Kyrtzidis
1461c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl  friend class ASTReader;
1462a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian Redl  friend class ASTWriter;
14635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
14645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1465183700f494ec9b6701b6efe82bcb25f4c79ba561John McCalltemplate <> inline const TypedefType *Type::getAs() const {
1466183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  return dyn_cast<TypedefType>(this);
1467183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall}
1468183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall
1469183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall// We can do canonical leaf types faster, because we don't have to
1470183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall// worry about preserving child type decoration.
1471183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall#define TYPE(Class, Base)
1472183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall#define LEAF_TYPE(Class) \
1473183700f494ec9b6701b6efe82bcb25f4c79ba561John McCalltemplate <> inline const Class##Type *Type::getAs() const { \
14740953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  return dyn_cast<Class##Type>(CanonicalType); \
1475d0370f59e79702ac908c81bf556519f91e9ca297John McCall} \
1476d0370f59e79702ac908c81bf556519f91e9ca297John McCalltemplate <> inline const Class##Type *Type::castAs() const { \
1477d0370f59e79702ac908c81bf556519f91e9ca297John McCall  return cast<Class##Type>(CanonicalType); \
1478183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall}
1479183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall#include "clang/AST/TypeNodes.def"
1480183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall
1481183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall
14825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// BuiltinType - This class is used for builtin types like 'int'.  Builtin
14835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// types are always canonical and have a literal name field.
14845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass BuiltinType : public Type {
14855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
14865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  enum Kind {
14875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Void,
14881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
14895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Bool,     // This is bool and/or _Bool.
14905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Char_U,   // This is 'char' for targets where char is unsigned.
14915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    UChar,    // This is explicitly qualified unsigned char.
14923f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner    WChar_U,  // This is 'wchar_t' for C++, when unsigned.
1493f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith    Char16,   // This is 'char16_t' for C++.
1494f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith    Char32,   // This is 'char32_t' for C++.
14955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    UShort,
14965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    UInt,
14975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ULong,
14985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ULongLong,
14992df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner    UInt128,  // __uint128_t
15001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
15015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Char_S,   // This is 'char' for targets where char is signed.
15025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    SChar,    // This is explicitly qualified signed char.
15033f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner    WChar_S,  // This is 'wchar_t' for C++, when signed.
15045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Short,
15055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Int,
15065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Long,
15075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    LongLong,
15082df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner    Int128,   // __int128_t
15091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
15108e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor    Float, Double, LongDouble,
15118e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor
15126e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl    NullPtr,  // This is the type of C++0x 'nullptr'.
15136e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl
1514864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall    /// The primitive Objective C 'id' type.  The user-visible 'id'
1515864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall    /// type is a typedef of an ObjCObjectPointerType to an
1516864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall    /// ObjCObjectType with this as its base.  In fact, this only ever
1517864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall    /// shows up in an AST as the base type of an ObjCObjectType.
1518864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall    ObjCId,
1519864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall
1520864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall    /// The primitive Objective C 'Class' type.  The user-visible
1521864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall    /// 'Class' type is a typedef of an ObjCObjectPointerType to an
1522864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall    /// ObjCObjectType with this as its base.  In fact, this only ever
1523864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall    /// shows up in an AST as the base type of an ObjCObjectType.
1524864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall    ObjCClass,
1525864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall
1526864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall    /// The primitive Objective C 'SEL' type.  The user-visible 'SEL'
1527864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall    /// type is a typedef of a PointerType to this.
1528864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall    ObjCSel,
1529864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall
15302a984cad5ac3fdceeff2bd99daa7b90979313475John McCall    /// This represents the type of an expression whose type is
15312a984cad5ac3fdceeff2bd99daa7b90979313475John McCall    /// totally unknown, e.g. 'T::foo'.  It is permitted for this to
15322a984cad5ac3fdceeff2bd99daa7b90979313475John McCall    /// appear in situations where the structure of the type is
15332a984cad5ac3fdceeff2bd99daa7b90979313475John McCall    /// theoretically deducible.
15342a984cad5ac3fdceeff2bd99daa7b90979313475John McCall    Dependent,
15352a984cad5ac3fdceeff2bd99daa7b90979313475John McCall
1536864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall    /// The type of an unresolved overload set.  A placeholder type.
1537864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall    /// Expressions with this type have one of the following basic
1538864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall    /// forms, with parentheses generally permitted:
1539864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall    ///   foo          # possibly qualified, not if an implicit access
1540864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall    ///   foo          # possibly qualified, not if an implicit access
1541864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall    ///   &foo         # possibly qualified, not if an implicit access
1542864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall    ///   x->foo       # only if might be a static member function
1543864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall    ///   &x->foo      # only if might be a static member function
1544864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall    ///   &Class::foo  # when a pointer-to-member; sub-expr also has this type
1545864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall    /// OverloadExpr::find can be used to analyze the expression.
15461de4d4e8cb2e9c88809fea8092bc6e835a5473d2John McCall    Overload,
15471de4d4e8cb2e9c88809fea8092bc6e835a5473d2John McCall
1548864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall    /// The type of a bound C++ non-static member function.
1549864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall    /// A placeholder type.  Expressions with this type have one of the
1550864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall    /// following basic forms:
1551864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall    ///   foo          # if an implicit access
1552864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall    ///   x->foo       # if only contains non-static members
1553864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall    BoundMember,
1554864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall
1555864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall    /// __builtin_any_type.  A placeholder type.  Useful for clients
1556864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall    /// like debuggers that don't know what type to give something.
1557864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall    /// Only a small number of operations are valid on expressions of
1558864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall    /// unknown type, most notably explicit casts.
1559864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall    UnknownAny
15605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
156171c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall
15625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
15631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  BuiltinType(Kind K)
156435495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    : Type(Builtin, QualType(), /*Dependent=*/(K == Dependent),
1565d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor           /*VariablyModified=*/false,
1566d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor           /*Unexpanded paramter pack=*/false) {
1567b870b88df784c2940efce448ebfaf54dece14666John McCall    BuiltinTypeBits.Kind = K;
156871c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  }
15691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1570b870b88df784c2940efce448ebfaf54dece14666John McCall  Kind getKind() const { return static_cast<Kind>(BuiltinTypeBits.Kind); }
1571e4f2142d00fa5fdb580c4e2413da91882d955381Chris Lattner  const char *getName(const LangOptions &LO) const;
15721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1573bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1574bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1575bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
1576680523a91dd3351389667c8de17121ba7ae82673John McCall  bool isInteger() const {
157771c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    return getKind() >= Bool && getKind() <= Int128;
1578680523a91dd3351389667c8de17121ba7ae82673John McCall  }
1579680523a91dd3351389667c8de17121ba7ae82673John McCall
1580680523a91dd3351389667c8de17121ba7ae82673John McCall  bool isSignedInteger() const {
158171c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    return getKind() >= Char_S && getKind() <= Int128;
1582680523a91dd3351389667c8de17121ba7ae82673John McCall  }
1583680523a91dd3351389667c8de17121ba7ae82673John McCall
1584680523a91dd3351389667c8de17121ba7ae82673John McCall  bool isUnsignedInteger() const {
158571c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    return getKind() >= Bool && getKind() <= UInt128;
1586680523a91dd3351389667c8de17121ba7ae82673John McCall  }
1587680523a91dd3351389667c8de17121ba7ae82673John McCall
1588680523a91dd3351389667c8de17121ba7ae82673John McCall  bool isFloatingPoint() const {
158971c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    return getKind() >= Float && getKind() <= LongDouble;
1590680523a91dd3351389667c8de17121ba7ae82673John McCall  }
1591680523a91dd3351389667c8de17121ba7ae82673John McCall
1592864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall  /// Determines whether this type is a placeholder type, i.e. a type
1593864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall  /// which cannot appear in arbitrary positions in a fully-formed
1594864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall  /// expression.
15952a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  bool isPlaceholderType() const {
1596864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall    return getKind() >= Overload;
15972a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  }
15982a984cad5ac3fdceeff2bd99daa7b90979313475John McCall
15995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T) { return T->getTypeClass() == Builtin; }
16005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const BuiltinType *) { return true; }
16015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
16025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
16035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ComplexType - C99 6.2.5p11 - Complex values.  This supports the C99 complex
16045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// types (_Complex float etc) as well as the GCC integer complex extensions.
16055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
16065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ComplexType : public Type, public llvm::FoldingSetNode {
16075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType ElementType;
16085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ComplexType(QualType Element, QualType CanonicalPtr) :
160935495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    Type(Complex, CanonicalPtr, Element->isDependentType(),
1610d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor         Element->isVariablyModifiedType(),
1611d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor         Element->containsUnexpandedParameterPack()),
1612898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    ElementType(Element) {
16135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
16145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
161560e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
16165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
16175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType getElementType() const { return ElementType; }
16181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1619bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1620bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1621bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
16225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void Profile(llvm::FoldingSetNodeID &ID) {
16235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Profile(ID, getElementType());
16245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
16255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static void Profile(llvm::FoldingSetNodeID &ID, QualType Element) {
16265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ID.AddPointer(Element.getAsOpaquePtr());
16275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
16281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
16295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T) { return T->getTypeClass() == Complex; }
16305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const ComplexType *) { return true; }
16315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
16325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1633075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara/// ParenType - Sugar for parentheses used when specifying types.
1634075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara///
1635075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnaraclass ParenType : public Type, public llvm::FoldingSetNode {
1636075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  QualType Inner;
1637075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
1638075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  ParenType(QualType InnerType, QualType CanonType) :
1639075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara    Type(Paren, CanonType, InnerType->isDependentType(),
1640d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor         InnerType->isVariablyModifiedType(),
1641d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor         InnerType->containsUnexpandedParameterPack()),
1642075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara    Inner(InnerType) {
1643075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  }
1644075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  friend class ASTContext;  // ASTContext creates these.
1645075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
1646075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnarapublic:
1647075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
1648075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  QualType getInnerType() const { return Inner; }
1649075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
1650075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  bool isSugared() const { return true; }
1651075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  QualType desugar() const { return getInnerType(); }
1652075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
1653075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  void Profile(llvm::FoldingSetNodeID &ID) {
1654075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara    Profile(ID, getInnerType());
1655075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  }
1656075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  static void Profile(llvm::FoldingSetNodeID &ID, QualType Inner) {
1657075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara    Inner.Profile(ID);
1658075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  }
1659075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
1660075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  static bool classof(const Type *T) { return T->getTypeClass() == Paren; }
1661075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  static bool classof(const ParenType *) { return true; }
1662075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara};
1663075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
166468694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar/// PointerType - C99 6.7.5.1 - Pointer Declarators.
1665bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner///
166668694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbarclass PointerType : public Type, public llvm::FoldingSetNode {
1667bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner  QualType PointeeType;
16685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
16695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  PointerType(QualType Pointee, QualType CanonicalPtr) :
167035495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    Type(Pointer, CanonicalPtr, Pointee->isDependentType(),
1671d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor         Pointee->isVariablyModifiedType(),
1672d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor         Pointee->containsUnexpandedParameterPack()),
167335495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    PointeeType(Pointee) {
16745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
16755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
167660e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
16775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
16781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
167968694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar  QualType getPointeeType() const { return PointeeType; }
168068694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar
1681bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1682bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1683bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
16845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void Profile(llvm::FoldingSetNodeID &ID) {
16855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Profile(ID, getPointeeType());
16865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
16875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) {
16885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ID.AddPointer(Pointee.getAsOpaquePtr());
16895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
16901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
16915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T) { return T->getTypeClass() == Pointer; }
16925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const PointerType *) { return true; }
16935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
16945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
16955618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff/// BlockPointerType - pointer to a block type.
16965618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff/// This type is to represent types syntactically represented as
16975618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff/// "void (^)(int)", etc. Pointee is required to always be a function type.
16985618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff///
16995618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroffclass BlockPointerType : public Type, public llvm::FoldingSetNode {
17005618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  QualType PointeeType;  // Block is some kind of pointer type
17015618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  BlockPointerType(QualType Pointee, QualType CanonicalCls) :
170235495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    Type(BlockPointer, CanonicalCls, Pointee->isDependentType(),
1703d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor         Pointee->isVariablyModifiedType(),
1704d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor         Pointee->containsUnexpandedParameterPack()),
1705898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    PointeeType(Pointee) {
17065618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  }
17075618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  friend class ASTContext;  // ASTContext creates these.
170860e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
17095618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroffpublic:
17101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
17115618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  // Get the pointee type. Pointee is required to always be a function type.
17125618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  QualType getPointeeType() const { return PointeeType; }
17135618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff
1714bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1715bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1716bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
17175618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  void Profile(llvm::FoldingSetNodeID &ID) {
17185618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff      Profile(ID, getPointeeType());
17195618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  }
17205618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) {
17215618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff      ID.AddPointer(Pointee.getAsOpaquePtr());
17225618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  }
17231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
17241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
17251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == BlockPointer;
17265618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  }
17275618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  static bool classof(const BlockPointerType *) { return true; }
17285618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff};
17295618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff
17307c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// ReferenceType - Base for LValueReferenceType and RValueReferenceType
17315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
173268694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbarclass ReferenceType : public Type, public llvm::FoldingSetNode {
173368694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar  QualType PointeeType;
173468694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar
17357c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlprotected:
173654e14c4db764c0636160d26c5bbf491637c83a76John McCall  ReferenceType(TypeClass tc, QualType Referencee, QualType CanonicalRef,
173754e14c4db764c0636160d26c5bbf491637c83a76John McCall                bool SpelledAsLValue) :
173835495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    Type(tc, CanonicalRef, Referencee->isDependentType(),
1739d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor         Referencee->isVariablyModifiedType(),
1740d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor         Referencee->containsUnexpandedParameterPack()),
1741d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    PointeeType(Referencee)
1742d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  {
1743b870b88df784c2940efce448ebfaf54dece14666John McCall    ReferenceTypeBits.SpelledAsLValue = SpelledAsLValue;
1744b870b88df784c2940efce448ebfaf54dece14666John McCall    ReferenceTypeBits.InnerRef = Referencee->isReferenceType();
17455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
174660e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
17475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
1748b870b88df784c2940efce448ebfaf54dece14666John McCall  bool isSpelledAsLValue() const { return ReferenceTypeBits.SpelledAsLValue; }
1749b870b88df784c2940efce448ebfaf54dece14666John McCall  bool isInnerRef() const { return ReferenceTypeBits.InnerRef; }
175073dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor
175154e14c4db764c0636160d26c5bbf491637c83a76John McCall  QualType getPointeeTypeAsWritten() const { return PointeeType; }
175254e14c4db764c0636160d26c5bbf491637c83a76John McCall  QualType getPointeeType() const {
175354e14c4db764c0636160d26c5bbf491637c83a76John McCall    // FIXME: this might strip inner qualifiers; okay?
175454e14c4db764c0636160d26c5bbf491637c83a76John McCall    const ReferenceType *T = this;
175571c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    while (T->isInnerRef())
1756d0370f59e79702ac908c81bf556519f91e9ca297John McCall      T = T->PointeeType->castAs<ReferenceType>();
175754e14c4db764c0636160d26c5bbf491637c83a76John McCall    return T->PointeeType;
175854e14c4db764c0636160d26c5bbf491637c83a76John McCall  }
175968694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar
17605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void Profile(llvm::FoldingSetNodeID &ID) {
176171c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    Profile(ID, PointeeType, isSpelledAsLValue());
17625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
176354e14c4db764c0636160d26c5bbf491637c83a76John McCall  static void Profile(llvm::FoldingSetNodeID &ID,
176454e14c4db764c0636160d26c5bbf491637c83a76John McCall                      QualType Referencee,
176554e14c4db764c0636160d26c5bbf491637c83a76John McCall                      bool SpelledAsLValue) {
17665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ID.AddPointer(Referencee.getAsOpaquePtr());
176754e14c4db764c0636160d26c5bbf491637c83a76John McCall    ID.AddBoolean(SpelledAsLValue);
17685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
17695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
17707c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  static bool classof(const Type *T) {
17717c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl    return T->getTypeClass() == LValueReference ||
17727c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl           T->getTypeClass() == RValueReference;
17737c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  }
17745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const ReferenceType *) { return true; }
17757c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl};
17767c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl
17777c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// LValueReferenceType - C++ [dcl.ref] - Lvalue reference
17787c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl///
17797c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlclass LValueReferenceType : public ReferenceType {
178054e14c4db764c0636160d26c5bbf491637c83a76John McCall  LValueReferenceType(QualType Referencee, QualType CanonicalRef,
178154e14c4db764c0636160d26c5bbf491637c83a76John McCall                      bool SpelledAsLValue) :
178254e14c4db764c0636160d26c5bbf491637c83a76John McCall    ReferenceType(LValueReference, Referencee, CanonicalRef, SpelledAsLValue)
178354e14c4db764c0636160d26c5bbf491637c83a76John McCall  {}
17847c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  friend class ASTContext; // ASTContext creates these
17857c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlpublic:
1786bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1787bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1788bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
17897c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  static bool classof(const Type *T) {
17907c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl    return T->getTypeClass() == LValueReference;
17917c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  }
17927c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  static bool classof(const LValueReferenceType *) { return true; }
17937c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl};
17947c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl
17957c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// RValueReferenceType - C++0x [dcl.ref] - Rvalue reference
17967c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl///
17977c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlclass RValueReferenceType : public ReferenceType {
17987c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  RValueReferenceType(QualType Referencee, QualType CanonicalRef) :
179954e14c4db764c0636160d26c5bbf491637c83a76John McCall    ReferenceType(RValueReference, Referencee, CanonicalRef, false) {
18007c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  }
18017c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  friend class ASTContext; // ASTContext creates these
18027c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlpublic:
1803bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1804bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1805bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
18067c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  static bool classof(const Type *T) {
18077c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl    return T->getTypeClass() == RValueReference;
18087c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  }
18097c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  static bool classof(const RValueReferenceType *) { return true; }
1810f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl};
1811f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl
1812f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl/// MemberPointerType - C++ 8.3.3 - Pointers to members
1813f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl///
1814f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlclass MemberPointerType : public Type, public llvm::FoldingSetNode {
1815f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  QualType PointeeType;
1816f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  /// The class of which the pointee is a member. Must ultimately be a
1817f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  /// RecordType, but could be a typedef or a template parameter too.
1818f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  const Type *Class;
1819f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl
1820f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  MemberPointerType(QualType Pointee, const Type *Cls, QualType CanonicalPtr) :
1821f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    Type(MemberPointer, CanonicalPtr,
182235495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor         Cls->isDependentType() || Pointee->isDependentType(),
1823d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor         Pointee->isVariablyModifiedType(),
1824d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor         (Cls->containsUnexpandedParameterPack() ||
1825d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor          Pointee->containsUnexpandedParameterPack())),
1826f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    PointeeType(Pointee), Class(Cls) {
1827f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  }
1828f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  friend class ASTContext; // ASTContext creates these.
182960e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
1830f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlpublic:
1831f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  QualType getPointeeType() const { return PointeeType; }
1832f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl
18330bab0cdab751248ca389a5592bcb70eac5d39260John McCall  /// Returns true if the member type (i.e. the pointee type) is a
18340bab0cdab751248ca389a5592bcb70eac5d39260John McCall  /// function type rather than a data-member type.
18350bab0cdab751248ca389a5592bcb70eac5d39260John McCall  bool isMemberFunctionPointer() const {
18360bab0cdab751248ca389a5592bcb70eac5d39260John McCall    return PointeeType->isFunctionProtoType();
18370bab0cdab751248ca389a5592bcb70eac5d39260John McCall  }
18380bab0cdab751248ca389a5592bcb70eac5d39260John McCall
18390bab0cdab751248ca389a5592bcb70eac5d39260John McCall  /// Returns true if the member type (i.e. the pointee type) is a
18400bab0cdab751248ca389a5592bcb70eac5d39260John McCall  /// data type rather than a function type.
18410bab0cdab751248ca389a5592bcb70eac5d39260John McCall  bool isMemberDataPointer() const {
18420bab0cdab751248ca389a5592bcb70eac5d39260John McCall    return !PointeeType->isFunctionProtoType();
18430bab0cdab751248ca389a5592bcb70eac5d39260John McCall  }
18440bab0cdab751248ca389a5592bcb70eac5d39260John McCall
1845f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  const Type *getClass() const { return Class; }
1846f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl
1847bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1848bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1849bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
1850f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  void Profile(llvm::FoldingSetNodeID &ID) {
1851f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    Profile(ID, getPointeeType(), getClass());
1852f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  }
1853f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee,
1854f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl                      const Type *Class) {
1855f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    ID.AddPointer(Pointee.getAsOpaquePtr());
1856f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    ID.AddPointer(Class);
1857f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  }
1858f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl
1859f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  static bool classof(const Type *T) {
1860f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    return T->getTypeClass() == MemberPointer;
1861f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  }
1862f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  static bool classof(const MemberPointerType *) { return true; }
18635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
18645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
18655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ArrayType - C99 6.7.5.2 - Array Declarators.
18665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
18672e7d352dbec06755105237afba183492d31d03cbTed Kremenekclass ArrayType : public Type, public llvm::FoldingSetNode {
18685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
18695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// ArraySizeModifier - Capture whether this is a normal array (e.g. int X[4])
1870898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// an array with a static size (e.g. int X[static 4]), or an array
1871898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// with a star size (e.g. int X[*]).
1872898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// 'static' is only allowed on function parameters.
18735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  enum ArraySizeModifier {
18745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Normal, Static, Star
18755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
18765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate:
1877fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  /// ElementType - The element type of the array.
1878fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  QualType ElementType;
18791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1880fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroffprotected:
1881898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  // C++ [temp.dep.type]p1:
1882898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  //   A type is dependent if it is...
1883898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  //     - an array type constructed from any dependent type or whose
1884898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  //       size is specified by a constant expression that is
1885898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  //       value-dependent,
1886c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff  ArrayType(TypeClass tc, QualType et, QualType can,
1887d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor            ArraySizeModifier sm, unsigned tq,
1888d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor            bool ContainsUnexpandedParameterPack)
188935495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    : Type(tc, can, et->isDependentType() || tc == DependentSizedArray,
1890d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor           (tc == VariableArray || et->isVariablyModifiedType()),
1891d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor           ContainsUnexpandedParameterPack),
189271c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall      ElementType(et) {
1893b870b88df784c2940efce448ebfaf54dece14666John McCall    ArrayTypeBits.IndexTypeQuals = tq;
1894b870b88df784c2940efce448ebfaf54dece14666John McCall    ArrayTypeBits.SizeModifier = sm;
189571c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  }
1896898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
1897fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  friend class ASTContext;  // ASTContext creates these.
189860e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
1899fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroffpublic:
1900fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  QualType getElementType() const { return ElementType; }
1901ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek  ArraySizeModifier getSizeModifier() const {
1902b870b88df784c2940efce448ebfaf54dece14666John McCall    return ArraySizeModifier(ArrayTypeBits.SizeModifier);
1903ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek  }
19040953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  Qualifiers getIndexTypeQualifiers() const {
190571c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    return Qualifiers::fromCVRMask(getIndexTypeCVRQualifiers());
190671c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  }
190771c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  unsigned getIndexTypeCVRQualifiers() const {
1908b870b88df784c2940efce448ebfaf54dece14666John McCall    return ArrayTypeBits.IndexTypeQuals;
19090953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
19101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1911fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  static bool classof(const Type *T) {
1912fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff    return T->getTypeClass() == ConstantArray ||
1913c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman           T->getTypeClass() == VariableArray ||
1914898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor           T->getTypeClass() == IncompleteArray ||
1915898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor           T->getTypeClass() == DependentSizedArray;
1916fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  }
1917fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  static bool classof(const ArrayType *) { return true; }
1918fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff};
1919fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff
19207e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// ConstantArrayType - This class represents the canonical version of
19217e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// C arrays with a specified constant size.  For example, the canonical
19227e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// type for 'int A[4 + 4*100]' is a ConstantArrayType where the element
19237e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// type is 'int' and the size is 404.
19242e7d352dbec06755105237afba183492d31d03cbTed Kremenekclass ConstantArrayType : public ArrayType {
1925fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  llvm::APInt Size; // Allows us to unique the type.
19261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
19270be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner  ConstantArrayType(QualType et, QualType can, const llvm::APInt &size,
1928c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff                    ArraySizeModifier sm, unsigned tq)
1929d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    : ArrayType(ConstantArray, et, can, sm, tq,
1930d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor                et->containsUnexpandedParameterPack()),
19317e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor      Size(size) {}
19327e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregorprotected:
19337e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  ConstantArrayType(TypeClass tc, QualType et, QualType can,
19347e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor                    const llvm::APInt &size, ArraySizeModifier sm, unsigned tq)
1935d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    : ArrayType(tc, et, can, sm, tq, et->containsUnexpandedParameterPack()),
1936d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor      Size(size) {}
1937fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  friend class ASTContext;  // ASTContext creates these.
1938fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroffpublic:
1939c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  const llvm::APInt &getSize() const { return Size; }
1940bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1941bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1942bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
19432767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor
19442767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor  /// \brief Determine the number of bits required to address a member of
19452767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor  // an array with the given element type and number of elements.
19462767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor  static unsigned getNumAddressingBits(ASTContext &Context,
19472767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor                                       QualType ElementType,
19482767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor                                       const llvm::APInt &NumElements);
19492767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor
19502767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor  /// \brief Determine the maximum number of active bits that an array's size
19512767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor  /// can require, which limits the maximum size of the array.
19522767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor  static unsigned getMaxSizeBits(ASTContext &Context);
19532767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor
1954fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  void Profile(llvm::FoldingSetNodeID &ID) {
19551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    Profile(ID, getElementType(), getSize(),
19560953e767ff7817f97b3ab20896b229891eeff45bJohn McCall            getSizeModifier(), getIndexTypeCVRQualifiers());
1957fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  }
1958fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  static void Profile(llvm::FoldingSetNodeID &ID, QualType ET,
19590be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner                      const llvm::APInt &ArraySize, ArraySizeModifier SizeMod,
19600be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner                      unsigned TypeQuals) {
1961fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff    ID.AddPointer(ET.getAsOpaquePtr());
1962fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff    ID.AddInteger(ArraySize.getZExtValue());
19630be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner    ID.AddInteger(SizeMod);
19640be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner    ID.AddInteger(TypeQuals);
1965fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  }
19667e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  static bool classof(const Type *T) {
196746a617a792bfab0d9b1e057371ea3b9540802226John McCall    return T->getTypeClass() == ConstantArray;
1968fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  }
1969fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  static bool classof(const ConstantArrayType *) { return true; }
1970fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff};
1971fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff
1972da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// IncompleteArrayType - This class represents C arrays with an unspecified
1973da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// size.  For example 'int A[]' has an IncompleteArrayType where the element
1974da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// type is 'int' and the size is unspecified.
1975c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedmanclass IncompleteArrayType : public ArrayType {
19767e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor
1977c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman  IncompleteArrayType(QualType et, QualType can,
19787e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor                      ArraySizeModifier sm, unsigned tq)
1979d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    : ArrayType(IncompleteArray, et, can, sm, tq,
1980d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor                et->containsUnexpandedParameterPack()) {}
1981c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman  friend class ASTContext;  // ASTContext creates these.
1982c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedmanpublic:
1983bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1984bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1985bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
19861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
19871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == IncompleteArray;
1988c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman  }
1989c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman  static bool classof(const IncompleteArrayType *) { return true; }
19901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1991c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman  friend class StmtIteratorBase;
19921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1993c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman  void Profile(llvm::FoldingSetNodeID &ID) {
19940953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Profile(ID, getElementType(), getSizeModifier(),
19950953e767ff7817f97b3ab20896b229891eeff45bJohn McCall            getIndexTypeCVRQualifiers());
1996c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman  }
19971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
19980be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner  static void Profile(llvm::FoldingSetNodeID &ID, QualType ET,
19990be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner                      ArraySizeModifier SizeMod, unsigned TypeQuals) {
2000c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman    ID.AddPointer(ET.getAsOpaquePtr());
20010be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner    ID.AddInteger(SizeMod);
20020be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner    ID.AddInteger(TypeQuals);
2003c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman  }
2004c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman};
2005c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman
2006da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// VariableArrayType - This class represents C arrays with a specified size
2007da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// which is not an integer-constant-expression.  For example, 'int s[x+foo()]'.
2008da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// Since the size expression is an arbitrary expression, we store it as such.
2009da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner///
2010da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// Note: VariableArrayType's aren't uniqued (since the expressions aren't) and
2011da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// should not be: two lexically equivalent variable array types could mean
2012da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// different things, for example, these variables do not have the same type
2013da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// dynamically:
2014da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner///
2015da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// void foo(int x) {
2016da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner///   int Y[x];
2017da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner///   ++x;
2018da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner///   int Z[x];
2019da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// }
2020da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner///
20212e7d352dbec06755105237afba183492d31d03cbTed Kremenekclass VariableArrayType : public ArrayType {
20221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// SizeExpr - An assignment expression. VLA's are only permitted within
20231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// a function block.
2024b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek  Stmt *SizeExpr;
20257e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  /// Brackets - The left and right array brackets.
20267e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  SourceRange Brackets;
20277e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor
2028c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff  VariableArrayType(QualType et, QualType can, Expr *e,
20297e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor                    ArraySizeModifier sm, unsigned tq,
20307e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor                    SourceRange brackets)
2031d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    : ArrayType(VariableArray, et, can, sm, tq,
2032d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor                et->containsUnexpandedParameterPack()),
20337e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor      SizeExpr((Stmt*) e), Brackets(brackets) {}
20345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
20354b05b1dee6cc65ae61d93dab7edff72710f24589Ted Kremenek
20365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
20371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Expr *getSizeExpr() const {
2038b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek    // We use C-style casts instead of cast<> here because we do not wish
2039b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek    // to have a dependency of Type.h on Stmt.h/Expr.h.
2040b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek    return (Expr*) SizeExpr;
2041b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek  }
20427e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  SourceRange getBracketsRange() const { return Brackets; }
20437e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  SourceLocation getLBracketLoc() const { return Brackets.getBegin(); }
20447e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  SourceLocation getRBracketLoc() const { return Brackets.getEnd(); }
20451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2046bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2047bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2048bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
20491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
20501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == VariableArray;
20515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
2052fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  static bool classof(const VariableArrayType *) { return true; }
20531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
205492866e2e90f6d93fb95e25a7ac4438e239d89ce6Ted Kremenek  friend class StmtIteratorBase;
20551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
20562bd24ba6d10f8c811c8e2a57c8397e07082ba497Ted Kremenek  void Profile(llvm::FoldingSetNodeID &ID) {
2057fc8f0e14ad142ed811e90fbd9a30e419e301c717Chris Lattner    assert(0 && "Cannot unique VariableArrayTypes.");
20582bd24ba6d10f8c811c8e2a57c8397e07082ba497Ted Kremenek  }
20595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
20605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2061898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// DependentSizedArrayType - This type represents an array type in
2062898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// C++ whose size is a value-dependent expression. For example:
2063cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor///
2064cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor/// \code
20651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// template<typename T, int Size>
2066898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// class array {
2067898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor///   T data[Size];
2068898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// };
2069cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor/// \endcode
2070cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor///
2071898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// For these types, we won't actually know what the array bound is
2072898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// until template instantiation occurs, at which point this will
2073898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// become either a ConstantArrayType or a VariableArrayType.
2074898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorclass DependentSizedArrayType : public ArrayType {
20754ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  const ASTContext &Context;
20761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2077cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor  /// \brief An assignment expression that will instantiate to the
2078898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// size of the array.
2079cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor  ///
2080cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor  /// The expression itself might be NULL, in which case the array
2081cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor  /// type will have its size deduced from an initializer.
2082898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  Stmt *SizeExpr;
2083cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor
20847e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  /// Brackets - The left and right array brackets.
20857e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  SourceRange Brackets;
20861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
20874ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  DependentSizedArrayType(const ASTContext &Context, QualType et, QualType can,
208804d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor                          Expr *e, ArraySizeModifier sm, unsigned tq,
2089d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor                          SourceRange brackets);
2090d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor
2091898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  friend class ASTContext;  // ASTContext creates these.
2092898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
2093898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorpublic:
20941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Expr *getSizeExpr() const {
2095898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    // We use C-style casts instead of cast<> here because we do not wish
2096898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    // to have a dependency of Type.h on Stmt.h/Expr.h.
2097898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    return (Expr*) SizeExpr;
2098898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  }
20997e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  SourceRange getBracketsRange() const { return Brackets; }
21007e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  SourceLocation getLBracketLoc() const { return Brackets.getBegin(); }
21017e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  SourceLocation getRBracketLoc() const { return Brackets.getEnd(); }
21021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2103bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2104bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2105bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
21061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
21071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == DependentSizedArray;
2108898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  }
2109898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  static bool classof(const DependentSizedArrayType *) { return true; }
21101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2111898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  friend class StmtIteratorBase;
21121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
21131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2114898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  void Profile(llvm::FoldingSetNodeID &ID) {
21151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    Profile(ID, Context, getElementType(),
21160953e767ff7817f97b3ab20896b229891eeff45bJohn McCall            getSizeModifier(), getIndexTypeCVRQualifiers(), getSizeExpr());
2117898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  }
21181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
21194ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
21201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                      QualType ET, ArraySizeModifier SizeMod,
212104d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor                      unsigned TypeQuals, Expr *E);
2122898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor};
2123898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
2124f6ddb737cb882ffbf0b75a9abd50b930cc2b9068Douglas Gregor/// DependentSizedExtVectorType - This type represent an extended vector type
21259cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// where either the type or size is dependent. For example:
21269cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// @code
21279cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// template<typename T, int Size>
21289cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// class vector {
21299cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor///   typedef T __attribute__((ext_vector_type(Size))) type;
21309cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// }
21319cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// @endcode
21322ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregorclass DependentSizedExtVectorType : public Type, public llvm::FoldingSetNode {
21334ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  const ASTContext &Context;
21349cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor  Expr *SizeExpr;
21359cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor  /// ElementType - The element type of the array.
21369cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor  QualType ElementType;
21379cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor  SourceLocation loc;
21381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
21394ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  DependentSizedExtVectorType(const ASTContext &Context, QualType ElementType,
2140d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor                              QualType can, Expr *SizeExpr, SourceLocation loc);
2141d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor
21429cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor  friend class ASTContext;
21439cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor
21449cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregorpublic:
21452ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor  Expr *getSizeExpr() const { return SizeExpr; }
21469cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor  QualType getElementType() const { return ElementType; }
21479cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor  SourceLocation getAttributeLoc() const { return loc; }
21489cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor
2149bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2150bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2151bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
21521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
21531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == DependentSizedExtVector;
21549cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor  }
21551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const DependentSizedExtVectorType *) { return true; }
21562ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor
21572ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor  void Profile(llvm::FoldingSetNodeID &ID) {
21582ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor    Profile(ID, Context, getElementType(), getSizeExpr());
21592ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor  }
21601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
21614ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
21622ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor                      QualType ElementType, Expr *SizeExpr);
21639cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor};
21641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
21659cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor
216673322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// VectorType - GCC generic vector type. This type is created using
21671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// __attribute__((vector_size(n)), where "n" specifies the vector size in
216882287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson/// bytes; or from an Altivec __vector or vector declaration.
216982287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson/// Since the constructor takes the number of vector elements, the
217073322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// client is responsible for converting the size into the number of elements.
21715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass VectorType : public Type, public llvm::FoldingSetNode {
2172788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattnerpublic:
2173e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson  enum VectorKind {
2174e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson    GenericVector,  // not a target-specific vector type
2175e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson    AltiVecVector,  // is AltiVec vector
2176e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson    AltiVecPixel,   // is AltiVec 'vector Pixel'
2177e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson    AltiVecBool,    // is AltiVec 'vector bool ...'
2178491328c90c00ecad6ad27fa0ab3cdf9195a4a820Bob Wilson    NeonVector,     // is ARM Neon vector
2179491328c90c00ecad6ad27fa0ab3cdf9195a4a820Bob Wilson    NeonPolyVector  // is ARM Neon polynomial vector
2180788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner  };
218173322924127c873c13101b705dd823f5539ffa5fSteve Naroffprotected:
21825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// ElementType - The element type of the vector.
21835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType ElementType;
21841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
218582287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson  VectorType(QualType vecType, unsigned nElements, QualType canonType,
2186d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor             VectorKind vecKind);
218735495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor
21881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  VectorType(TypeClass tc, QualType vecType, unsigned nElements,
2189d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor             QualType canonType, VectorKind vecKind);
2190d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor
21915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
219260e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
21935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
21941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
21955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType getElementType() const { return ElementType; }
2196b870b88df784c2940efce448ebfaf54dece14666John McCall  unsigned getNumElements() const { return VectorTypeBits.NumElements; }
21975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2198bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2199bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2200bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
2201e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson  VectorKind getVectorKind() const {
2202e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson    return VectorKind(VectorTypeBits.VecKind);
220371c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  }
2204788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner
22055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void Profile(llvm::FoldingSetNodeID &ID) {
220671c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    Profile(ID, getElementType(), getNumElements(),
2207e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson            getTypeClass(), getVectorKind());
22085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
22091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static void Profile(llvm::FoldingSetNodeID &ID, QualType ElementType,
221082287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson                      unsigned NumElements, TypeClass TypeClass,
2211e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson                      VectorKind VecKind) {
22125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ID.AddPointer(ElementType.getAsOpaquePtr());
22135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ID.AddInteger(NumElements);
221473322924127c873c13101b705dd823f5539ffa5fSteve Naroff    ID.AddInteger(TypeClass);
2215e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson    ID.AddInteger(VecKind);
221673322924127c873c13101b705dd823f5539ffa5fSteve Naroff  }
22170b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor
22181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
22191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == Vector || T->getTypeClass() == ExtVector;
22205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
22215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const VectorType *) { return true; }
22225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
22235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2224213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman/// ExtVectorType - Extended vector type. This type is created using
2225213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman/// __attribute__((ext_vector_type(n)), where "n" is the number of elements.
2226213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman/// Unlike vector_size, ext_vector_type is only allowed on typedef's. This
2227fcac0fff877a461bc5d5a57e6c6727a4c819d95aSteve Naroff/// class enables syntactic extensions, like Vector Components for accessing
2228fcac0fff877a461bc5d5a57e6c6727a4c819d95aSteve Naroff/// points, colors, and textures (modeled after OpenGL Shading Language).
2229213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begemanclass ExtVectorType : public VectorType {
2230213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman  ExtVectorType(QualType vecType, unsigned nElements, QualType canonType) :
2231e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson    VectorType(ExtVector, vecType, nElements, canonType, GenericVector) {}
223273322924127c873c13101b705dd823f5539ffa5fSteve Naroff  friend class ASTContext;  // ASTContext creates these.
223373322924127c873c13101b705dd823f5539ffa5fSteve Naroffpublic:
223488dca0464804b8b26ae605f89784c927e8493dddChris Lattner  static int getPointAccessorIdx(char c) {
223588dca0464804b8b26ae605f89784c927e8493dddChris Lattner    switch (c) {
223688dca0464804b8b26ae605f89784c927e8493dddChris Lattner    default: return -1;
223788dca0464804b8b26ae605f89784c927e8493dddChris Lattner    case 'x': return 0;
223888dca0464804b8b26ae605f89784c927e8493dddChris Lattner    case 'y': return 1;
223988dca0464804b8b26ae605f89784c927e8493dddChris Lattner    case 'z': return 2;
224088dca0464804b8b26ae605f89784c927e8493dddChris Lattner    case 'w': return 3;
224188dca0464804b8b26ae605f89784c927e8493dddChris Lattner    }
2242e1b31fedbc006e6e4071bbb4f74c6116b56cfa9fSteve Naroff  }
2243353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman  static int getNumericAccessorIdx(char c) {
224488dca0464804b8b26ae605f89784c927e8493dddChris Lattner    switch (c) {
2245353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      default: return -1;
2246353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '0': return 0;
2247353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '1': return 1;
2248353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '2': return 2;
2249353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '3': return 3;
2250353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '4': return 4;
2251353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '5': return 5;
2252353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '6': return 6;
2253353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '7': return 7;
2254353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '8': return 8;
2255353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '9': return 9;
2256131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman      case 'A':
2257353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case 'a': return 10;
2258131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman      case 'B':
2259353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case 'b': return 11;
2260131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman      case 'C':
2261353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case 'c': return 12;
2262131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman      case 'D':
2263353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case 'd': return 13;
2264131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman      case 'E':
2265353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case 'e': return 14;
2266131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman      case 'F':
2267353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case 'f': return 15;
226888dca0464804b8b26ae605f89784c927e8493dddChris Lattner    }
2269e1b31fedbc006e6e4071bbb4f74c6116b56cfa9fSteve Naroff  }
22701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2271b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner  static int getAccessorIdx(char c) {
2272b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner    if (int idx = getPointAccessorIdx(c)+1) return idx-1;
2273353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman    return getNumericAccessorIdx(c);
2274b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner  }
22751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
227688dca0464804b8b26ae605f89784c927e8493dddChris Lattner  bool isAccessorWithinNumElements(char c) const {
2277b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner    if (int idx = getAccessorIdx(c)+1)
227871c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall      return unsigned(idx-1) < getNumElements();
227988dca0464804b8b26ae605f89784c927e8493dddChris Lattner    return false;
2280e1b31fedbc006e6e4071bbb4f74c6116b56cfa9fSteve Naroff  }
2281bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2282bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2283bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
22841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
22851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == ExtVector;
228673322924127c873c13101b705dd823f5539ffa5fSteve Naroff  }
2287213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman  static bool classof(const ExtVectorType *) { return true; }
228873322924127c873c13101b705dd823f5539ffa5fSteve Naroff};
228973322924127c873c13101b705dd823f5539ffa5fSteve Naroff
22905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// FunctionType - C99 6.7.5.3 - Function Declarators.  This is the common base
229172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// class of FunctionNoProtoType and FunctionProtoType.
22925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
22935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass FunctionType : public Type {
22945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // The type returned by the function.
22955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType ResultType;
2296264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola
2297264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola public:
2298373920bd733b1d28fe7bf209945a62eb9248d948John McCall  /// ExtInfo - A class which abstracts out some details necessary for
2299373920bd733b1d28fe7bf209945a62eb9248d948John McCall  /// making a call.
2300373920bd733b1d28fe7bf209945a62eb9248d948John McCall  ///
2301373920bd733b1d28fe7bf209945a62eb9248d948John McCall  /// It is not actually used directly for storing this information in
2302373920bd733b1d28fe7bf209945a62eb9248d948John McCall  /// a FunctionType, although FunctionType does currently use the
2303373920bd733b1d28fe7bf209945a62eb9248d948John McCall  /// same bit-pattern.
2304373920bd733b1d28fe7bf209945a62eb9248d948John McCall  ///
2305075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  // If you add a field (say Foo), other than the obvious places (both,
2306075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  // constructors, compile failures), what you need to update is
2307075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  // * Operator==
2308425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola  // * getFoo
2309425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola  // * withFoo
2310425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola  // * functionType. Add Foo, getFoo.
2311425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola  // * ASTContext::getFooType
2312425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola  // * ASTContext::mergeFunctionTypes
2313425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola  // * FunctionNoProtoType::Profile
2314425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola  // * FunctionProtoType::Profile
2315425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola  // * TypePrinter::PrintFunctionProto
23163c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  // * AST read and write
2317425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola  // * Codegen
2318264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola  class ExtInfo {
2319373920bd733b1d28fe7bf209945a62eb9248d948John McCall    // Feel free to rearrange or add bits, but if you go over 8,
2320373920bd733b1d28fe7bf209945a62eb9248d948John McCall    // you'll need to adjust both the Bits field below and
2321373920bd733b1d28fe7bf209945a62eb9248d948John McCall    // Type::FunctionTypeBitfields.
2322373920bd733b1d28fe7bf209945a62eb9248d948John McCall
2323a49218e17bcbb1acde0245773173e2c0c42f4f19Eli Friedman    //   |  CC  |noreturn|hasregparm|regparm
2324a49218e17bcbb1acde0245773173e2c0c42f4f19Eli Friedman    //   |0 .. 2|   3    |    4     |5 ..  7
2325b870b88df784c2940efce448ebfaf54dece14666John McCall    enum { CallConvMask = 0x7 };
2326b870b88df784c2940efce448ebfaf54dece14666John McCall    enum { NoReturnMask = 0x8 };
2327a49218e17bcbb1acde0245773173e2c0c42f4f19Eli Friedman    enum { HasRegParmMask = 0x10 };
2328b870b88df784c2940efce448ebfaf54dece14666John McCall    enum { RegParmMask = ~(CallConvMask | NoReturnMask),
2329a49218e17bcbb1acde0245773173e2c0c42f4f19Eli Friedman           RegParmOffset = 5 };
2330b870b88df784c2940efce448ebfaf54dece14666John McCall
2331373920bd733b1d28fe7bf209945a62eb9248d948John McCall    unsigned char Bits;
233271c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall
2333373920bd733b1d28fe7bf209945a62eb9248d948John McCall    ExtInfo(unsigned Bits) : Bits(static_cast<unsigned char>(Bits)) {}
233471c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall
233571c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    friend class FunctionType;
233671c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall
2337264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola   public:
2338264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    // Constructor with no defaults. Use this when you know that you
23393c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl    // have all the elements (when reading an AST file for example).
2340a49218e17bcbb1acde0245773173e2c0c42f4f19Eli Friedman    ExtInfo(bool noReturn, bool hasRegParm, unsigned regParm, CallingConv cc) {
2341b870b88df784c2940efce448ebfaf54dece14666John McCall      Bits = ((unsigned) cc) |
2342b870b88df784c2940efce448ebfaf54dece14666John McCall             (noReturn ? NoReturnMask : 0) |
2343a49218e17bcbb1acde0245773173e2c0c42f4f19Eli Friedman             (hasRegParm ? HasRegParmMask : 0) |
2344b870b88df784c2940efce448ebfaf54dece14666John McCall             (regParm << RegParmOffset);
234571c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    }
2346264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola
2347264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    // Constructor with all defaults. Use when for example creating a
2348264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    // function know to use defaults.
234971c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    ExtInfo() : Bits(0) {}
2350264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola
2351b870b88df784c2940efce448ebfaf54dece14666John McCall    bool getNoReturn() const { return Bits & NoReturnMask; }
2352a49218e17bcbb1acde0245773173e2c0c42f4f19Eli Friedman    bool getHasRegParm() const { return Bits & HasRegParmMask; }
2353b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned getRegParm() const { return Bits >> RegParmOffset; }
2354b870b88df784c2940efce448ebfaf54dece14666John McCall    CallingConv getCC() const { return CallingConv(Bits & CallConvMask); }
2355264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola
235671c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    bool operator==(ExtInfo Other) const {
235771c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall      return Bits == Other.Bits;
2358264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    }
235971c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    bool operator!=(ExtInfo Other) const {
236071c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall      return Bits != Other.Bits;
2361264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    }
2362264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola
2363264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    // Note that we don't have setters. That is by design, use
2364264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    // the following with methods instead of mutating these objects.
2365264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola
2366264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    ExtInfo withNoReturn(bool noReturn) const {
236771c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall      if (noReturn)
236871c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall        return ExtInfo(Bits | NoReturnMask);
236971c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall      else
237071c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall        return ExtInfo(Bits & ~NoReturnMask);
2371425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola    }
2372425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola
2373425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola    ExtInfo withRegParm(unsigned RegParm) const {
2374a49218e17bcbb1acde0245773173e2c0c42f4f19Eli Friedman      return ExtInfo(HasRegParmMask | (Bits & ~RegParmMask) | (RegParm << RegParmOffset));
2375264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    }
2376264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola
2377264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    ExtInfo withCallingConv(CallingConv cc) const {
2378b870b88df784c2940efce448ebfaf54dece14666John McCall      return ExtInfo((Bits & ~CallConvMask) | (unsigned) cc);
2379264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    }
2380264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola
2381e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall    void Profile(llvm::FoldingSetNodeID &ID) const {
238271c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall      ID.AddInteger(Bits);
238371c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    }
2384264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola  };
2385264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola
23865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprotected:
2387e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall  FunctionType(TypeClass tc, QualType res, bool variadic,
2388c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor               unsigned typeQuals, RefQualifierKind RefQualifier,
2389c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor               QualType Canonical, bool Dependent,
2390d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor               bool VariablyModified, bool ContainsUnexpandedParameterPack,
2391d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor               ExtInfo Info)
2392d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    : Type(tc, Canonical, Dependent, VariablyModified,
2393d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor           ContainsUnexpandedParameterPack),
2394d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor      ResultType(res) {
2395b870b88df784c2940efce448ebfaf54dece14666John McCall    FunctionTypeBits.ExtInfo = Info.Bits;
2396e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall    FunctionTypeBits.Variadic = variadic;
2397b870b88df784c2940efce448ebfaf54dece14666John McCall    FunctionTypeBits.TypeQuals = typeQuals;
2398c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor    FunctionTypeBits.RefQualifier = static_cast<unsigned>(RefQualifier);
239971c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  }
2400e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall  bool isVariadic() const { return FunctionTypeBits.Variadic; }
2401b870b88df784c2940efce448ebfaf54dece14666John McCall  unsigned getTypeQuals() const { return FunctionTypeBits.TypeQuals; }
2402c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor
2403c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor  RefQualifierKind getRefQualifier() const {
2404c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor    return static_cast<RefQualifierKind>(FunctionTypeBits.RefQualifier);
2405c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor  }
2406c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor
24075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
24081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
24095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType getResultType() const { return ResultType; }
2410a49218e17bcbb1acde0245773173e2c0c42f4f19Eli Friedman
2411a49218e17bcbb1acde0245773173e2c0c42f4f19Eli Friedman  bool getHasRegParm() const { return getExtInfo().getHasRegParm(); }
2412b870b88df784c2940efce448ebfaf54dece14666John McCall  unsigned getRegParmType() const { return getExtInfo().getRegParm(); }
2413b870b88df784c2940efce448ebfaf54dece14666John McCall  bool getNoReturnAttr() const { return getExtInfo().getNoReturn(); }
2414b870b88df784c2940efce448ebfaf54dece14666John McCall  CallingConv getCallConv() const { return getExtInfo().getCC(); }
2415b870b88df784c2940efce448ebfaf54dece14666John McCall  ExtInfo getExtInfo() const { return ExtInfo(FunctionTypeBits.ExtInfo); }
24165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
24175291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor  /// \brief Determine the type of an expression that calls a function of
24185291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor  /// this type.
24195291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor  QualType getCallResultType(ASTContext &Context) const {
24206398235d7890a81b785ea5af3b6e66d86bf184ccDouglas Gregor    return getResultType().getNonLValueExprType(Context);
24215291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor  }
24225291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor
242304a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall  static llvm::StringRef getNameForCallConv(CallingConv CC);
242404a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall
24255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T) {
24265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T->getTypeClass() == FunctionNoProto ||
24275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer           T->getTypeClass() == FunctionProto;
24285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
24295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const FunctionType *) { return true; }
24305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
24315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
243272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// FunctionNoProtoType - Represents a K&R-style 'int foo()' function, which has
24335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// no information available about its arguments.
243472564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregorclass FunctionNoProtoType : public FunctionType, public llvm::FoldingSetNode {
243571c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  FunctionNoProtoType(QualType Result, QualType Canonical, ExtInfo Info)
2436c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor    : FunctionType(FunctionNoProto, Result, false, 0, RQ_None, Canonical,
243735495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor                   /*Dependent=*/false, Result->isVariablyModifiedType(),
2438d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor                   /*ContainsUnexpandedParameterPack=*/false, Info) {}
2439d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor
24405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
244160e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
24425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
24435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // No additional state past what FunctionType provides.
24441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2445bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2446bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2447bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
24485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void Profile(llvm::FoldingSetNodeID &ID) {
2449264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    Profile(ID, getResultType(), getExtInfo());
24505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
24512455636163fdd18581d7fdae816433f886d88213Mike Stump  static void Profile(llvm::FoldingSetNodeID &ID, QualType ResultType,
245271c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall                      ExtInfo Info) {
245371c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    Info.Profile(ID);
24545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ID.AddPointer(ResultType.getAsOpaquePtr());
24555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
24561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
24575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T) {
24585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T->getTypeClass() == FunctionNoProto;
24595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
246072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  static bool classof(const FunctionNoProtoType *) { return true; }
24615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
24625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
246372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// FunctionProtoType - Represents a prototype with argument type info, e.g.
24645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 'int foo(int)' or 'int foo(void)'.  'void' is represented as having no
2465465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl/// arguments, not as having a single void argument. Such a type can have an
2466465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl/// exception specification, but this specification is not part of the canonical
2467465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl/// type.
246872564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregorclass FunctionProtoType : public FunctionType, public llvm::FoldingSetNode {
2469e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCallpublic:
2470e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall  /// ExtProtoInfo - Extra information about a function prototype.
2471e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall  struct ExtProtoInfo {
2472e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall    ExtProtoInfo() :
24738b5b4099c61a136e9a1714c4d8a593febe942268Sebastian Redl      Variadic(false), ExceptionSpecType(EST_None), TypeQuals(0),
24748b5b4099c61a136e9a1714c4d8a593febe942268Sebastian Redl      RefQualifier(RQ_None), NumExceptions(0), Exceptions(0), NoexceptExpr(0) {}
2475e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall
2476e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall    FunctionType::ExtInfo ExtInfo;
2477e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall    bool Variadic;
24788b5b4099c61a136e9a1714c4d8a593febe942268Sebastian Redl    ExceptionSpecificationType ExceptionSpecType;
2479e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall    unsigned char TypeQuals;
2480c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor    RefQualifierKind RefQualifier;
2481e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall    unsigned NumExceptions;
2482e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall    const QualType *Exceptions;
24838b5b4099c61a136e9a1714c4d8a593febe942268Sebastian Redl    Expr *NoexceptExpr;
2484e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall  };
2485e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall
2486e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCallprivate:
2487d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// \brief Determine whether there are any argument types that
2488d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// contain an unexpanded parameter pack.
2489d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  static bool containsAnyUnexpandedParameterPack(const QualType *ArgArray,
2490d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor                                                 unsigned numArgs) {
2491d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    for (unsigned Idx = 0; Idx < numArgs; ++Idx)
2492d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor      if (ArgArray[Idx]->containsUnexpandedParameterPack())
2493d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor        return true;
2494d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor
2495d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    return false;
2496d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  }
2497d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor
2498e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall  FunctionProtoType(QualType result, const QualType *args, unsigned numArgs,
24998026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redl                    QualType canonical, const ExtProtoInfo &epi);
2500465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
25015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// NumArgs - The number of arguments this function has, not counting '...'.
2502465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  unsigned NumArgs : 20;
2503465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
2504465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  /// NumExceptions - The number of types in the exception spec, if any.
250560618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  unsigned NumExceptions : 9;
2506465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
250760618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  /// ExceptionSpecType - The type of exception specification this function has.
250860618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  unsigned ExceptionSpecType : 3;
2509465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
2510942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner  /// ArgInfo - There is an variable size array after the class in memory that
2511942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner  /// holds the argument types.
2512465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
2513465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  /// Exceptions - There is another variable size array after ArgInfo that
2514465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  /// holds the exception types.
2515465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
251660618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  /// NoexceptExpr - Instead of Exceptions, there may be a single Expr* pointing
251760618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  /// to the expression in the noexcept() specifier.
251860618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl
25195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
25204b05b1dee6cc65ae61d93dab7edff72710f24589Ted Kremenek
25215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
25225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned getNumArgs() const { return NumArgs; }
25235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType getArgType(unsigned i) const {
25245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    assert(i < NumArgs && "Invalid argument number!");
2525942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner    return arg_type_begin()[i];
25265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
2527465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
2528e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall  ExtProtoInfo getExtProtoInfo() const {
2529e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall    ExtProtoInfo EPI;
2530e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall    EPI.ExtInfo = getExtInfo();
2531e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall    EPI.Variadic = isVariadic();
253260618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    EPI.ExceptionSpecType = getExceptionSpecType();
2533e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall    EPI.TypeQuals = static_cast<unsigned char>(getTypeQuals());
2534c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor    EPI.RefQualifier = getRefQualifier();
253560618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    if (EPI.ExceptionSpecType == EST_Dynamic) {
253660618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl      EPI.NumExceptions = NumExceptions;
253760618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl      EPI.Exceptions = exception_begin();
253860618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    } else if (EPI.ExceptionSpecType == EST_ComputedNoexcept) {
253960618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl      EPI.NoexceptExpr = getNoexceptExpr();
254060618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    }
2541e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall    return EPI;
2542e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall  }
2543e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall
254460618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  /// \brief Get the kind of exception specification on this function.
254560618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  ExceptionSpecificationType getExceptionSpecType() const {
254660618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    return static_cast<ExceptionSpecificationType>(ExceptionSpecType);
254760618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  }
254860618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  /// \brief Return whether this function has any kind of exception spec.
254960618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  bool hasExceptionSpec() const {
255060618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    return getExceptionSpecType() != EST_None;
255160618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  }
255260618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  /// \brief Return whether this function has a dynamic (throw) exception spec.
255360618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  bool hasDynamicExceptionSpec() const {
255460618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    return isDynamicExceptionSpec(getExceptionSpecType());
255560618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  }
2556fc8f0e14ad142ed811e90fbd9a30e419e301c717Chris Lattner  /// \brief Return whether this function has a noexcept exception spec.
255760618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  bool hasNoexceptExceptionSpec() const {
255860618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    return isNoexceptExceptionSpec(getExceptionSpecType());
255960618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  }
256060618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  /// \brief Result type of getNoexceptSpec().
256160618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  enum NoexceptResult {
256260618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    NR_NoNoexcept,  ///< There is no noexcept specifier.
256360618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    NR_BadNoexcept, ///< The noexcept specifier has a bad expression.
256460618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    NR_Dependent,   ///< The noexcept specifier is dependent.
256560618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    NR_Throw,       ///< The noexcept specifier evaluates to false.
256660618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    NR_Nothrow      ///< The noexcept specifier evaluates to true.
256760618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  };
256860618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  /// \brief Get the meaning of the noexcept spec on this function, if any.
25698026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redl  NoexceptResult getNoexceptSpec(ASTContext &Ctx) const;
2570465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  unsigned getNumExceptions() const { return NumExceptions; }
2571465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  QualType getExceptionType(unsigned i) const {
2572465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl    assert(i < NumExceptions && "Invalid exception number!");
2573465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl    return exception_begin()[i];
2574465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  }
257560618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  Expr *getNoexceptExpr() const {
257660618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    if (getExceptionSpecType() != EST_ComputedNoexcept)
257760618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl      return 0;
257860618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    // NoexceptExpr sits where the arguments end.
257960618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    return *reinterpret_cast<Expr *const *>(arg_type_end());
2580d3fd6bad1249d3f34d71b73e2333fab0db51cce4Anders Carlsson  }
25818026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redl  bool isNothrow(ASTContext &Ctx) const {
258260618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    ExceptionSpecificationType EST = getExceptionSpecType();
258360618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    if (EST == EST_DynamicNone || EST == EST_BasicNoexcept)
258460618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl      return true;
258560618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    if (EST != EST_ComputedNoexcept)
258660618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl      return false;
25878026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redl    return getNoexceptSpec(Ctx) == NR_Nothrow;
2588c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall  }
2589c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall
2590e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall  using FunctionType::isVariadic;
259160618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl
2592f5c65ffbd7374b6c8d9f1e361041578640cab320Douglas Gregor  /// \brief Determines whether this function prototype contains a
2593f5c65ffbd7374b6c8d9f1e361041578640cab320Douglas Gregor  /// parameter pack at the end.
2594f5c65ffbd7374b6c8d9f1e361041578640cab320Douglas Gregor  ///
2595f5c65ffbd7374b6c8d9f1e361041578640cab320Douglas Gregor  /// A function template whose last parameter is a parameter pack can be
2596f5c65ffbd7374b6c8d9f1e361041578640cab320Douglas Gregor  /// called with an arbitrary number of arguments, much like a variadic
2597f5c65ffbd7374b6c8d9f1e361041578640cab320Douglas Gregor  /// function. However,
2598f5c65ffbd7374b6c8d9f1e361041578640cab320Douglas Gregor  bool isTemplateVariadic() const;
2599f5c65ffbd7374b6c8d9f1e361041578640cab320Douglas Gregor
2600971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis  unsigned getTypeQuals() const { return FunctionType::getTypeQuals(); }
26011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2602c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor
2603c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor  /// \brief Retrieve the ref-qualifier associated with this function type.
2604c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor  RefQualifierKind getRefQualifier() const {
2605c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor    return FunctionType::getRefQualifier();
2606c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor  }
2607c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor
26085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  typedef const QualType *arg_type_iterator;
2609942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner  arg_type_iterator arg_type_begin() const {
2610942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner    return reinterpret_cast<const QualType *>(this+1);
2611942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner  }
2612942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner  arg_type_iterator arg_type_end() const { return arg_type_begin()+NumArgs; }
2613465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
2614465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  typedef const QualType *exception_iterator;
2615465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  exception_iterator exception_begin() const {
2616465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl    // exceptions begin where arguments end
2617465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl    return arg_type_end();
2618465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  }
2619465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  exception_iterator exception_end() const {
262060618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    if (getExceptionSpecType() != EST_Dynamic)
262160618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl      return exception_begin();
2622465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl    return exception_begin() + NumExceptions;
2623465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  }
2624465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
2625bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2626bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2627bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
26285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T) {
26295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T->getTypeClass() == FunctionProto;
26305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
263172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  static bool classof(const FunctionProtoType *) { return true; }
2632465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
26338026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redl  void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Ctx);
26345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static void Profile(llvm::FoldingSetNodeID &ID, QualType Result,
2635942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner                      arg_type_iterator ArgTys, unsigned NumArgs,
26368026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redl                      const ExtProtoInfo &EPI, const ASTContext &Context);
26375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
26385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
26395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2640ed97649e9574b9d854fa4d6109c9333ae0993554John McCall/// \brief Represents the dependent type named by a dependently-scoped
2641ed97649e9574b9d854fa4d6109c9333ae0993554John McCall/// typename using declaration, e.g.
2642ed97649e9574b9d854fa4d6109c9333ae0993554John McCall///   using typename Base<T>::foo;
2643ed97649e9574b9d854fa4d6109c9333ae0993554John McCall/// Template instantiation turns these into the underlying type.
2644ed97649e9574b9d854fa4d6109c9333ae0993554John McCallclass UnresolvedUsingType : public Type {
2645ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  UnresolvedUsingTypenameDecl *Decl;
2646ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
264719c8576b7328f4dc2d07682f5da552875c1912efJohn McCall  UnresolvedUsingType(const UnresolvedUsingTypenameDecl *D)
2648d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    : Type(UnresolvedUsing, QualType(), true, false,
2649d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor           /*ContainsUnexpandedParameterPack=*/false),
265019c8576b7328f4dc2d07682f5da552875c1912efJohn McCall      Decl(const_cast<UnresolvedUsingTypenameDecl*>(D)) {}
2651ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  friend class ASTContext; // ASTContext creates these.
2652ed97649e9574b9d854fa4d6109c9333ae0993554John McCallpublic:
2653ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
2654ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  UnresolvedUsingTypenameDecl *getDecl() const { return Decl; }
2655ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
2656ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  bool isSugared() const { return false; }
2657ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  QualType desugar() const { return QualType(this, 0); }
2658ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
2659ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  static bool classof(const Type *T) {
2660ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    return T->getTypeClass() == UnresolvedUsing;
2661ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  }
2662ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  static bool classof(const UnresolvedUsingType *) { return true; }
2663ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
2664ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  void Profile(llvm::FoldingSetNodeID &ID) {
2665ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    return Profile(ID, Decl);
2666ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  }
2667ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  static void Profile(llvm::FoldingSetNodeID &ID,
2668ed97649e9574b9d854fa4d6109c9333ae0993554John McCall                      UnresolvedUsingTypenameDecl *D) {
2669ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    ID.AddPointer(D);
2670ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  }
2671ed97649e9574b9d854fa4d6109c9333ae0993554John McCall};
2672ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
2673ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
26745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass TypedefType : public Type {
2675162e1c1b487352434552147967c3dd296ebee2f7Richard Smith  TypedefNameDecl *Decl;
2676c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanianprotected:
2677162e1c1b487352434552147967c3dd296ebee2f7Richard Smith  TypedefType(TypeClass tc, const TypedefNameDecl *D, QualType can)
2678d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    : Type(tc, can, can->isDependentType(), can->isVariablyModifiedType(),
2679d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor           /*ContainsUnexpandedParameterPack=*/false),
2680162e1c1b487352434552147967c3dd296ebee2f7Richard Smith      Decl(const_cast<TypedefNameDecl*>(D)) {
26815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    assert(!isa<TypedefType>(can) && "Invalid canonical type");
26825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
26835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
26845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
26851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2686162e1c1b487352434552147967c3dd296ebee2f7Richard Smith  TypedefNameDecl *getDecl() const { return Decl; }
26871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2688bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return true; }
2689bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const;
2690bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
269172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  static bool classof(const Type *T) { return T->getTypeClass() == Typedef; }
26925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const TypedefType *) { return true; }
26935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
26945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
269572564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// TypeOfExprType (GCC extension).
269672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregorclass TypeOfExprType : public Type {
2697d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  Expr *TOExpr;
26981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2699b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregorprotected:
2700dd0257c77719a13d4acd513df40b04300cbfc871Douglas Gregor  TypeOfExprType(Expr *E, QualType can = QualType());
2701d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  friend class ASTContext;  // ASTContext creates these.
2702d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroffpublic:
2703d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  Expr *getUnderlyingExpr() const { return TOExpr; }
27041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2705bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// \brief Remove a single level of sugar.
2706bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const;
2707bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
2708bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// \brief Returns whether this type directly provides sugar.
2709bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return true; }
2710bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
271172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  static bool classof(const Type *T) { return T->getTypeClass() == TypeOfExpr; }
271272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  static bool classof(const TypeOfExprType *) { return true; }
2713d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff};
2714d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff
2715c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// \brief Internal representation of canonical, dependent
27161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// typeof(expr) types.
2717c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor///
2718c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// This class is used internally by the ASTContext to manage
2719c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// canonical, dependent types, only. Clients will only see instances
2720c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// of this class via TypeOfExprType nodes.
27211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpclass DependentTypeOfExprType
2722b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor  : public TypeOfExprType, public llvm::FoldingSetNode {
27234ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  const ASTContext &Context;
27241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2725b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregorpublic:
27264ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  DependentTypeOfExprType(const ASTContext &Context, Expr *E)
2727b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor    : TypeOfExprType(E), Context(Context) { }
27281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2729bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2730bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2731bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
2732b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor  void Profile(llvm::FoldingSetNodeID &ID) {
2733b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor    Profile(ID, Context, getUnderlyingExpr());
2734b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor  }
27351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
27364ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
2737b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor                      Expr *E);
2738b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor};
27391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2740d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff/// TypeOfType (GCC extension).
2741d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroffclass TypeOfType : public Type {
2742d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  QualType TOType;
27431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  TypeOfType(QualType T, QualType can)
2744d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    : Type(TypeOf, can, T->isDependentType(), T->isVariablyModifiedType(),
2745d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor           T->containsUnexpandedParameterPack()),
274635495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor      TOType(T) {
2747d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff    assert(!isa<TypedefType>(can) && "Invalid canonical type");
2748d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  }
2749d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  friend class ASTContext;  // ASTContext creates these.
2750d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroffpublic:
2751d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  QualType getUnderlyingType() const { return TOType; }
27521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2753bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// \brief Remove a single level of sugar.
2754bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return getUnderlyingType(); }
2755bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
2756bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// \brief Returns whether this type directly provides sugar.
2757bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return true; }
2758bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
275972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  static bool classof(const Type *T) { return T->getTypeClass() == TypeOf; }
2760d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  static bool classof(const TypeOfType *) { return true; }
2761d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff};
27625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2763395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson/// DecltypeType (C++0x)
2764395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlssonclass DecltypeType : public Type {
2765395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson  Expr *E;
27661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2767563a03b1338d31c2462def43253a722bc885d384Anders Carlsson  // FIXME: We could get rid of UnderlyingType if we wanted to: We would have to
2768563a03b1338d31c2462def43253a722bc885d384Anders Carlsson  // Move getDesugaredType to ASTContext so that it can call getDecltypeForExpr
2769563a03b1338d31c2462def43253a722bc885d384Anders Carlsson  // from it.
2770563a03b1338d31c2462def43253a722bc885d384Anders Carlsson  QualType UnderlyingType;
27711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
27729d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregorprotected:
2773563a03b1338d31c2462def43253a722bc885d384Anders Carlsson  DecltypeType(Expr *E, QualType underlyingType, QualType can = QualType());
2774395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson  friend class ASTContext;  // ASTContext creates these.
2775395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlssonpublic:
2776395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson  Expr *getUnderlyingExpr() const { return E; }
2777563a03b1338d31c2462def43253a722bc885d384Anders Carlsson  QualType getUnderlyingType() const { return UnderlyingType; }
2778563a03b1338d31c2462def43253a722bc885d384Anders Carlsson
2779bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// \brief Remove a single level of sugar.
2780bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return getUnderlyingType(); }
2781bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
2782bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// \brief Returns whether this type directly provides sugar.
2783bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return !isDependentType(); }
2784bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
2785395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson  static bool classof(const Type *T) { return T->getTypeClass() == Decltype; }
2786395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson  static bool classof(const DecltypeType *) { return true; }
2787395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson};
27881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2789c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// \brief Internal representation of canonical, dependent
2790c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// decltype(expr) types.
2791c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor///
2792c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// This class is used internally by the ASTContext to manage
2793c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// canonical, dependent types, only. Clients will only see instances
2794c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// of this class via DecltypeType nodes.
27959d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregorclass DependentDecltypeType : public DecltypeType, public llvm::FoldingSetNode {
27964ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  const ASTContext &Context;
27971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
27989d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregorpublic:
27994ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  DependentDecltypeType(const ASTContext &Context, Expr *E);
28001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2801bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2802bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2803bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
28049d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor  void Profile(llvm::FoldingSetNodeID &ID) {
28059d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor    Profile(ID, Context, getUnderlyingExpr());
28069d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor  }
28071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
28084ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
28091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                      Expr *E);
28109d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor};
28111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
28125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass TagType : public Type {
2813ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl  /// Stores the TagDecl associated with this type. The decl may point to any
2814ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl  /// TagDecl that declares the entity.
2815ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl  TagDecl * decl;
28162ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor
28172ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregorprotected:
281819c8576b7328f4dc2d07682f5da552875c1912efJohn McCall  TagType(TypeClass TC, const TagDecl *D, QualType can);
28192ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor
28201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic:
2821ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl  TagDecl *getDecl() const;
28221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
28230b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor  /// @brief Determines whether this type is in the process of being
28241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// defined.
2825ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl  bool isBeingDefined() const;
28260b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor
28271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
282872564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor    return T->getTypeClass() >= TagFirst && T->getTypeClass() <= TagLast;
282972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  }
28305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const TagType *) { return true; }
283172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  static bool classof(const RecordType *) { return true; }
283272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  static bool classof(const EnumType *) { return true; }
28335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
28345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
28355edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner/// RecordType - This is a helper class that allows the use of isa/cast/dyncast
28365edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner/// to detect TagType objects of structs/unions/classes.
28375edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattnerclass RecordType : public TagType {
283849aa7ff1245abd03e6e998e01302df31e4c6f8f6Argyrios Kyrtzidisprotected:
283919c8576b7328f4dc2d07682f5da552875c1912efJohn McCall  explicit RecordType(const RecordDecl *D)
284019c8576b7328f4dc2d07682f5da552875c1912efJohn McCall    : TagType(Record, reinterpret_cast<const TagDecl*>(D), QualType()) { }
284172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  explicit RecordType(TypeClass TC, RecordDecl *D)
284219c8576b7328f4dc2d07682f5da552875c1912efJohn McCall    : TagType(TC, reinterpret_cast<const TagDecl*>(D), QualType()) { }
28432ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor  friend class ASTContext;   // ASTContext creates these.
28445edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattnerpublic:
28451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
28465edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner  RecordDecl *getDecl() const {
28475edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner    return reinterpret_cast<RecordDecl*>(TagType::getDecl());
28485edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner  }
28491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
28501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  // FIXME: This predicate is a helper to QualType/Type. It needs to
28515edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner  // recursively check all fields for const-ness. If any field is declared
28521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  // const, it needs to return false.
28535edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner  bool hasConstFields() const { return false; }
28545edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner
2855bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2856bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2857bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
28582daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner  static bool classof(const TagType *T);
28592daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner  static bool classof(const Type *T) {
28602daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner    return isa<TagType>(T) && classof(cast<TagType>(T));
28612daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner  }
28625edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner  static bool classof(const RecordType *) { return true; }
28635edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner};
28645edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner
28655edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner/// EnumType - This is a helper class that allows the use of isa/cast/dyncast
28665edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner/// to detect TagType objects of enums.
28675edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattnerclass EnumType : public TagType {
286819c8576b7328f4dc2d07682f5da552875c1912efJohn McCall  explicit EnumType(const EnumDecl *D)
286919c8576b7328f4dc2d07682f5da552875c1912efJohn McCall    : TagType(Enum, reinterpret_cast<const TagDecl*>(D), QualType()) { }
28702ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor  friend class ASTContext;   // ASTContext creates these.
28715edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattnerpublic:
28721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
28735edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner  EnumDecl *getDecl() const {
28745edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner    return reinterpret_cast<EnumDecl*>(TagType::getDecl());
28755edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner  }
28761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2877bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2878bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2879bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
28802daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner  static bool classof(const TagType *T);
28812daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner  static bool classof(const Type *T) {
28822daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner    return isa<TagType>(T) && classof(cast<TagType>(T));
28832daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner  }
28845edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner  static bool classof(const EnumType *) { return true; }
28855edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner};
28865edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner
28879d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall/// AttributedType - An attributed type is a type to which a type
28889d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall/// attribute has been applied.  The "modified type" is the
28899d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall/// fully-sugared type to which the attributed type was applied;
28909d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall/// generally it is not canonically equivalent to the attributed type.
28919d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall/// The "equivalent type" is the minimally-desugared type which the
28929d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall/// type is canonically equivalent to.
28939d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall///
28949d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall/// For example, in the following attributed type:
28959d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall///     int32_t __attribute__((vector_size(16)))
28969d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall///   - the modified type is the TypedefType for int32_t
28979d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall///   - the equivalent type is VectorType(16, int32_t)
28989d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall///   - the canonical type is VectorType(16, int)
28999d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCallclass AttributedType : public Type, public llvm::FoldingSetNode {
29009d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCallpublic:
29019d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  // It is really silly to have yet another attribute-kind enum, but
29029d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  // clang::attr::Kind doesn't currently cover the pure type attrs.
29039d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  enum Kind {
29049d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    // Expression operand.
2905170464b7c0a2c0c86f2821f14a46f0d540cb5e94Francois Pichet    attr_address_space,
2906170464b7c0a2c0c86f2821f14a46f0d540cb5e94Francois Pichet    attr_regparm,
2907170464b7c0a2c0c86f2821f14a46f0d540cb5e94Francois Pichet    attr_vector_size,
2908170464b7c0a2c0c86f2821f14a46f0d540cb5e94Francois Pichet    attr_neon_vector_type,
2909170464b7c0a2c0c86f2821f14a46f0d540cb5e94Francois Pichet    attr_neon_polyvector_type,
29109d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
2911170464b7c0a2c0c86f2821f14a46f0d540cb5e94Francois Pichet    FirstExprOperandKind = attr_address_space,
2912170464b7c0a2c0c86f2821f14a46f0d540cb5e94Francois Pichet    LastExprOperandKind = attr_neon_polyvector_type,
29139d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
29149d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    // Enumerated operand (string or keyword).
2915170464b7c0a2c0c86f2821f14a46f0d540cb5e94Francois Pichet    attr_objc_gc,
2916414d8967e1d760ea1e19a4aca96b13777a8cf8c5Anton Korobeynikov    attr_pcs,
29179d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
2918170464b7c0a2c0c86f2821f14a46f0d540cb5e94Francois Pichet    FirstEnumOperandKind = attr_objc_gc,
2919414d8967e1d760ea1e19a4aca96b13777a8cf8c5Anton Korobeynikov    LastEnumOperandKind = attr_pcs,
29209d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
29219d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    // No operand.
29223cd47e7883dbfce73189b583850cea81e1d1d261Francois Pichet    attr_noreturn,
29233cd47e7883dbfce73189b583850cea81e1d1d261Francois Pichet    attr_cdecl,
29243cd47e7883dbfce73189b583850cea81e1d1d261Francois Pichet    attr_fastcall,
29253cd47e7883dbfce73189b583850cea81e1d1d261Francois Pichet    attr_stdcall,
29263cd47e7883dbfce73189b583850cea81e1d1d261Francois Pichet    attr_thiscall,
29273cd47e7883dbfce73189b583850cea81e1d1d261Francois Pichet    attr_pascal
29289d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  };
29299d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
29309d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCallprivate:
29319d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  QualType ModifiedType;
29329d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  QualType EquivalentType;
29339d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
29349d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  friend class ASTContext; // creates these
29359d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
29369d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  AttributedType(QualType canon, Kind attrKind,
29379d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall                 QualType modified, QualType equivalent)
29389d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    : Type(Attributed, canon, canon->isDependentType(),
29399d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall           canon->isVariablyModifiedType(),
29409d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall           canon->containsUnexpandedParameterPack()),
29419d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall      ModifiedType(modified), EquivalentType(equivalent) {
29429d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    AttributedTypeBits.AttrKind = attrKind;
29439d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  }
29449d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
29459d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCallpublic:
29469d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  Kind getAttrKind() const {
29479d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    return static_cast<Kind>(AttributedTypeBits.AttrKind);
29489d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  }
29499d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
29509d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  QualType getModifiedType() const { return ModifiedType; }
29519d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  QualType getEquivalentType() const { return EquivalentType; }
29529d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
29539d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  bool isSugared() const { return true; }
29549d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  QualType desugar() const { return getEquivalentType(); }
29559d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
29569d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  void Profile(llvm::FoldingSetNodeID &ID) {
29579d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    Profile(ID, getAttrKind(), ModifiedType, EquivalentType);
29589d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  }
29599d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
29609d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  static void Profile(llvm::FoldingSetNodeID &ID, Kind attrKind,
29619d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall                      QualType modified, QualType equivalent) {
29629d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    ID.AddInteger(attrKind);
29639d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    ID.AddPointer(modified.getAsOpaquePtr());
29649d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    ID.AddPointer(equivalent.getAsOpaquePtr());
29659d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  }
29669d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
29679d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  static bool classof(const Type *T) {
29689d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    return T->getTypeClass() == Attributed;
29699d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  }
29709d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  static bool classof(const AttributedType *T) { return true; }
29719d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall};
29729d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
2973fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregorclass TemplateTypeParmType : public Type, public llvm::FoldingSetNode {
29744fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth  // Helper data collector for canonical types.
29754fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth  struct CanonicalTTPTInfo {
29764fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth    unsigned Depth : 15;
29774fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth    unsigned ParameterPack : 1;
29784fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth    unsigned Index : 16;
29794fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth  };
29804fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth
29814fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth  union {
29824fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth    // Info for the canonical type.
29834fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth    CanonicalTTPTInfo CanTTPTInfo;
29844fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth    // Info for the non-canonical type.
29854fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth    TemplateTypeParmDecl *TTPDecl;
29864fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth  };
298772c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor
29884fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth  /// Build a non-canonical type.
29894fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth  TemplateTypeParmType(TemplateTypeParmDecl *TTPDecl, QualType Canon)
299035495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    : Type(TemplateTypeParm, Canon, /*Dependent=*/true,
29914fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth           /*VariablyModified=*/false,
29925d65e34b08b3e57a4da834195757d0d15baaffd0Chandler Carruth           Canon->containsUnexpandedParameterPack()),
29934fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth      TTPDecl(TTPDecl) { }
299472c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor
29954fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth  /// Build the canonical type.
29961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  TemplateTypeParmType(unsigned D, unsigned I, bool PP)
299735495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    : Type(TemplateTypeParm, QualType(this, 0), /*Dependent=*/true,
29984fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth           /*VariablyModified=*/false, PP) {
29994fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth    CanTTPTInfo.Depth = D;
30004fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth    CanTTPTInfo.Index = I;
30014fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth    CanTTPTInfo.ParameterPack = PP;
30024fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth  }
300372c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor
3004fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor  friend class ASTContext;  // ASTContext creates these
300572c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor
30064fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth  const CanonicalTTPTInfo& getCanTTPTInfo() const {
30074fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth    QualType Can = getCanonicalTypeInternal();
30085d65e34b08b3e57a4da834195757d0d15baaffd0Chandler Carruth    return Can->castAs<TemplateTypeParmType>()->CanTTPTInfo;
30094fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth  }
30104fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth
3011fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregorpublic:
30124fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth  unsigned getDepth() const { return getCanTTPTInfo().Depth; }
30134fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth  unsigned getIndex() const { return getCanTTPTInfo().Index; }
30144fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth  bool isParameterPack() const { return getCanTTPTInfo().ParameterPack; }
30154fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth
30164fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth  TemplateTypeParmDecl *getDecl() const {
30174fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth    return isCanonicalUnqualified() ? 0 : TTPDecl;
30184fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth  }
30194fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth
3020b7efff4bae117604f442bb6859c844f90b15f3ffChandler Carruth  IdentifierInfo *getIdentifier() const;
30211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3022bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
3023bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
3024bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
3025fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor  void Profile(llvm::FoldingSetNodeID &ID) {
30264fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth    Profile(ID, getDepth(), getIndex(), isParameterPack(), getDecl());
3027fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor  }
3028fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor
30291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static void Profile(llvm::FoldingSetNodeID &ID, unsigned Depth,
30301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                      unsigned Index, bool ParameterPack,
30314fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth                      TemplateTypeParmDecl *TTPDecl) {
3032fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor    ID.AddInteger(Depth);
3033fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor    ID.AddInteger(Index);
303476e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson    ID.AddBoolean(ParameterPack);
30354fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth    ID.AddPointer(TTPDecl);
3036fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor  }
3037fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor
30381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
30391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == TemplateTypeParm;
304072c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor  }
304172c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor  static bool classof(const TemplateTypeParmType *T) { return true; }
304272c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor};
3043fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor
304449a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// \brief Represents the result of substituting a type for a template
304549a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// type parameter.
304649a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall///
304749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// Within an instantiated template, all template type parameters have
304849a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// been replaced with these.  They are used solely to record that a
304949a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// type was originally written as a template type parameter;
305049a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// therefore they are never canonical.
305149a832bd499d6f61c23655f1fac99f0dd229756eJohn McCallclass SubstTemplateTypeParmType : public Type, public llvm::FoldingSetNode {
305249a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  // The original type parameter.
305349a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  const TemplateTypeParmType *Replaced;
305449a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall
305549a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  SubstTemplateTypeParmType(const TemplateTypeParmType *Param, QualType Canon)
305635495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    : Type(SubstTemplateTypeParm, Canon, Canon->isDependentType(),
3057d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor           Canon->isVariablyModifiedType(),
3058d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor           Canon->containsUnexpandedParameterPack()),
305949a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall      Replaced(Param) { }
306049a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall
306149a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  friend class ASTContext;
306249a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall
306349a832bd499d6f61c23655f1fac99f0dd229756eJohn McCallpublic:
306449a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  /// Gets the template parameter that was substituted for.
306549a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  const TemplateTypeParmType *getReplacedParameter() const {
306649a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall    return Replaced;
306749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  }
306849a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall
306949a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  /// Gets the type that was substituted for the template
307049a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  /// parameter.
307149a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  QualType getReplacementType() const {
307249a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall    return getCanonicalTypeInternal();
307349a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  }
307449a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall
307549a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  bool isSugared() const { return true; }
307649a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  QualType desugar() const { return getReplacementType(); }
307749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall
307849a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  void Profile(llvm::FoldingSetNodeID &ID) {
307949a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall    Profile(ID, getReplacedParameter(), getReplacementType());
308049a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  }
308149a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  static void Profile(llvm::FoldingSetNodeID &ID,
308249a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall                      const TemplateTypeParmType *Replaced,
308349a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall                      QualType Replacement) {
308449a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall    ID.AddPointer(Replaced);
308549a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall    ID.AddPointer(Replacement.getAsOpaquePtr());
308649a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  }
308749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall
308849a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  static bool classof(const Type *T) {
308949a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall    return T->getTypeClass() == SubstTemplateTypeParm;
309049a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  }
309149a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  static bool classof(const SubstTemplateTypeParmType *T) { return true; }
309249a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall};
309349a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall
3094c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// \brief Represents the result of substituting a set of types for a template
3095c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// type parameter pack.
3096c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor///
3097c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// When a pack expansion in the source code contains multiple parameter packs
3098c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// and those parameter packs correspond to different levels of template
3099c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// parameter lists, this type node is used to represent a template type
3100c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// parameter pack from an outer level, which has already had its argument pack
3101c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// substituted but that still lives within a pack expansion that itself
3102c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// could not be instantiated. When actually performing a substitution into
3103c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// that pack expansion (e.g., when all template parameters have corresponding
3104c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// arguments), this type will be replaced with the \c SubstTemplateTypeParmType
3105c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// at the current pack substitution index.
3106c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregorclass SubstTemplateTypeParmPackType : public Type, public llvm::FoldingSetNode {
3107c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  /// \brief The original type parameter.
3108c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  const TemplateTypeParmType *Replaced;
3109c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor
3110c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  /// \brief A pointer to the set of template arguments that this
3111c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  /// parameter pack is instantiated with.
3112c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  const TemplateArgument *Arguments;
3113c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor
3114c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  /// \brief The number of template arguments in \c Arguments.
3115c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  unsigned NumArguments;
3116c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor
3117c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  SubstTemplateTypeParmPackType(const TemplateTypeParmType *Param,
3118c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor                                QualType Canon,
3119c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor                                const TemplateArgument &ArgPack);
3120c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor
3121c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  friend class ASTContext;
3122c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor
3123c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregorpublic:
3124b7efff4bae117604f442bb6859c844f90b15f3ffChandler Carruth  IdentifierInfo *getIdentifier() const { return Replaced->getIdentifier(); }
3125c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor
3126c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  /// Gets the template parameter that was substituted for.
3127c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  const TemplateTypeParmType *getReplacedParameter() const {
3128c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor    return Replaced;
3129c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  }
3130c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor
3131c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  bool isSugared() const { return false; }
3132c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  QualType desugar() const { return QualType(this, 0); }
3133c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor
3134c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  TemplateArgument getArgumentPack() const;
3135c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor
3136c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  void Profile(llvm::FoldingSetNodeID &ID);
3137c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  static void Profile(llvm::FoldingSetNodeID &ID,
3138c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor                      const TemplateTypeParmType *Replaced,
3139c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor                      const TemplateArgument &ArgPack);
3140c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor
3141c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  static bool classof(const Type *T) {
3142c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor    return T->getTypeClass() == SubstTemplateTypeParmPack;
3143c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  }
3144c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  static bool classof(const SubstTemplateTypeParmPackType *T) { return true; }
3145c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor};
3146c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor
314734b41d939a1328f484511c6002ba2456db879a29Richard Smith/// \brief Represents a C++0x auto type.
314834b41d939a1328f484511c6002ba2456db879a29Richard Smith///
314934b41d939a1328f484511c6002ba2456db879a29Richard Smith/// These types are usually a placeholder for a deduced type. However, within
315034b41d939a1328f484511c6002ba2456db879a29Richard Smith/// templates and before the initializer is attached, there is no deduced type
315134b41d939a1328f484511c6002ba2456db879a29Richard Smith/// and an auto type is type-dependent and canonical.
315234b41d939a1328f484511c6002ba2456db879a29Richard Smithclass AutoType : public Type, public llvm::FoldingSetNode {
315334b41d939a1328f484511c6002ba2456db879a29Richard Smith  AutoType(QualType DeducedType)
315434b41d939a1328f484511c6002ba2456db879a29Richard Smith    : Type(Auto, DeducedType.isNull() ? QualType(this, 0) : DeducedType,
315534b41d939a1328f484511c6002ba2456db879a29Richard Smith           /*Dependent=*/DeducedType.isNull(),
315634b41d939a1328f484511c6002ba2456db879a29Richard Smith           /*VariablyModified=*/false, /*ContainsParameterPack=*/false) {
315734b41d939a1328f484511c6002ba2456db879a29Richard Smith    assert((DeducedType.isNull() || !DeducedType->isDependentType()) &&
315834b41d939a1328f484511c6002ba2456db879a29Richard Smith           "deduced a dependent type for auto");
315934b41d939a1328f484511c6002ba2456db879a29Richard Smith  }
316034b41d939a1328f484511c6002ba2456db879a29Richard Smith
316134b41d939a1328f484511c6002ba2456db879a29Richard Smith  friend class ASTContext;  // ASTContext creates these
316234b41d939a1328f484511c6002ba2456db879a29Richard Smith
316334b41d939a1328f484511c6002ba2456db879a29Richard Smithpublic:
316434b41d939a1328f484511c6002ba2456db879a29Richard Smith  bool isSugared() const { return isDeduced(); }
316534b41d939a1328f484511c6002ba2456db879a29Richard Smith  QualType desugar() const { return getCanonicalTypeInternal(); }
316634b41d939a1328f484511c6002ba2456db879a29Richard Smith
316734b41d939a1328f484511c6002ba2456db879a29Richard Smith  QualType getDeducedType() const {
316834b41d939a1328f484511c6002ba2456db879a29Richard Smith    return isDeduced() ? getCanonicalTypeInternal() : QualType();
316934b41d939a1328f484511c6002ba2456db879a29Richard Smith  }
317034b41d939a1328f484511c6002ba2456db879a29Richard Smith  bool isDeduced() const {
317134b41d939a1328f484511c6002ba2456db879a29Richard Smith    return !isDependentType();
317234b41d939a1328f484511c6002ba2456db879a29Richard Smith  }
317334b41d939a1328f484511c6002ba2456db879a29Richard Smith
317434b41d939a1328f484511c6002ba2456db879a29Richard Smith  void Profile(llvm::FoldingSetNodeID &ID) {
317534b41d939a1328f484511c6002ba2456db879a29Richard Smith    Profile(ID, getDeducedType());
317634b41d939a1328f484511c6002ba2456db879a29Richard Smith  }
317734b41d939a1328f484511c6002ba2456db879a29Richard Smith
317834b41d939a1328f484511c6002ba2456db879a29Richard Smith  static void Profile(llvm::FoldingSetNodeID &ID,
317934b41d939a1328f484511c6002ba2456db879a29Richard Smith                      QualType Deduced) {
318034b41d939a1328f484511c6002ba2456db879a29Richard Smith    ID.AddPointer(Deduced.getAsOpaquePtr());
318134b41d939a1328f484511c6002ba2456db879a29Richard Smith  }
318234b41d939a1328f484511c6002ba2456db879a29Richard Smith
318334b41d939a1328f484511c6002ba2456db879a29Richard Smith  static bool classof(const Type *T) {
318434b41d939a1328f484511c6002ba2456db879a29Richard Smith    return T->getTypeClass() == Auto;
318534b41d939a1328f484511c6002ba2456db879a29Richard Smith  }
318634b41d939a1328f484511c6002ba2456db879a29Richard Smith  static bool classof(const AutoType *T) { return true; }
318734b41d939a1328f484511c6002ba2456db879a29Richard Smith};
318834b41d939a1328f484511c6002ba2456db879a29Richard Smith
31897532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// \brief Represents the type of a template specialization as written
31907532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// in the source code.
319155f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor///
31927532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// Template specialization types represent the syntactic form of a
31937532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// template-id that refers to a type, e.g., @c vector<int>. Some
31947532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// template specialization types are syntactic sugar, whose canonical
31957532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// type will point to some other type node that represents the
31967532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// instantiation or class template specialization. For example, a
319755f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor/// class template specialization type of @c vector<int> will refer to
31981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// a tag type for the instantiation
319955f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor/// @c std::vector<int, std::allocator<int>>.
32007532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor///
32017532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// Other template specialization types, for which the template name
32027532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// is dependent, may be canonical types. These types are always
32037532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// dependent.
32043e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith///
32053e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith/// An instance of this type is followed by an array of TemplateArgument*s,
32063e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith/// then, if the template specialization type is for a type alias template,
32073e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith/// a QualType representing the non-canonical aliased type.
32081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpclass TemplateSpecializationType
320955f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  : public Type, public llvm::FoldingSetNode {
321033500955d731c73717af52088b7fc0e7a85681e7John McCall  /// \brief The name of the template being specialized.
32117532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor  TemplateName Template;
321255f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
321340808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  /// \brief - The number of template arguments named in this class
321440808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  /// template specialization.
321555f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  unsigned NumArgs;
321655f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
3217ef99001908e799c388f1363b1e607dad5f5b57d3John McCall  TemplateSpecializationType(TemplateName T,
32187532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor                             const TemplateArgument *Args,
32193e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith                             unsigned NumArgs, QualType Canon,
32203e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith                             QualType Aliased);
322155f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
322255f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  friend class ASTContext;  // ASTContext creates these
322355f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
322455f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregorpublic:
322540808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  /// \brief Determine whether any of the given template arguments are
322640808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  /// dependent.
322740808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  static bool anyDependentTemplateArguments(const TemplateArgument *Args,
32281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                            unsigned NumArgs);
322940808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor
3230833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  static bool anyDependentTemplateArguments(const TemplateArgumentLoc *Args,
3231833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                            unsigned NumArgs);
3232833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
3233d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  static bool anyDependentTemplateArguments(const TemplateArgumentListInfo &);
3234d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall
3235df667e71b1daadeacb230cf94fc717843f1a138aDouglas Gregor  /// \brief Print a template argument list, including the '<' and '>'
3236df667e71b1daadeacb230cf94fc717843f1a138aDouglas Gregor  /// enclosing the template arguments.
3237df667e71b1daadeacb230cf94fc717843f1a138aDouglas Gregor  static std::string PrintTemplateArgumentList(const TemplateArgument *Args,
3238d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor                                               unsigned NumArgs,
3239dace95b13e2ceb0c3ec8de6babd926dc5114e1e5Douglas Gregor                                               const PrintingPolicy &Policy,
3240dace95b13e2ceb0c3ec8de6babd926dc5114e1e5Douglas Gregor                                               bool SkipBrackets = false);
3241df667e71b1daadeacb230cf94fc717843f1a138aDouglas Gregor
3242833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  static std::string PrintTemplateArgumentList(const TemplateArgumentLoc *Args,
3243833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                               unsigned NumArgs,
3244833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                               const PrintingPolicy &Policy);
3245833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
3246d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  static std::string PrintTemplateArgumentList(const TemplateArgumentListInfo &,
3247d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall                                               const PrintingPolicy &Policy);
3248d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall
324931f17ecbef57b5679c017c375db330546b7b5145John McCall  /// True if this template specialization type matches a current
325031f17ecbef57b5679c017c375db330546b7b5145John McCall  /// instantiation in the context in which it is found.
325131f17ecbef57b5679c017c375db330546b7b5145John McCall  bool isCurrentInstantiation() const {
325271d74bc0d6e522ce7c21a599db8e19d3883b518fJohn McCall    return isa<InjectedClassNameType>(getCanonicalTypeInternal());
325331f17ecbef57b5679c017c375db330546b7b5145John McCall  }
325431f17ecbef57b5679c017c375db330546b7b5145John McCall
32553e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  /// True if this template specialization type is for a type alias
32563e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  /// template.
32573e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  bool isTypeAlias() const;
32583e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  /// Get the aliased type, if this is a specialization of a type alias
32593e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  /// template.
32603e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  QualType getAliasedType() const {
32613e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith    assert(isTypeAlias() && "not a type alias template specialization");
32623e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith    return *reinterpret_cast<const QualType*>(end());
32633e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  }
32643e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith
326540808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  typedef const TemplateArgument * iterator;
326640808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor
326740808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  iterator begin() const { return getArgs(); }
326833500955d731c73717af52088b7fc0e7a85681e7John McCall  iterator end() const; // defined inline in TemplateBase.h
326940808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor
32707532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor  /// \brief Retrieve the name of the template that we are specializing.
32717532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor  TemplateName getTemplateName() const { return Template; }
327255f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
327340808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  /// \brief Retrieve the template arguments.
32741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  const TemplateArgument *getArgs() const {
327540808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor    return reinterpret_cast<const TemplateArgument *>(this + 1);
327640808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  }
327740808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor
327840808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  /// \brief Retrieve the number of template arguments.
327955f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  unsigned getNumArgs() const { return NumArgs; }
328055f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
328155f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  /// \brief Retrieve a specific template argument as a type.
328255f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  /// \precondition @c isArgType(Arg)
328333500955d731c73717af52088b7fc0e7a85681e7John McCall  const TemplateArgument &getArg(unsigned Idx) const; // in TemplateBase.h
328455f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
328531f17ecbef57b5679c017c375db330546b7b5145John McCall  bool isSugared() const {
32863e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith    return !isDependentType() || isCurrentInstantiation() || isTypeAlias();
328731f17ecbef57b5679c017c375db330546b7b5145John McCall  }
3288bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return getCanonicalTypeInternal(); }
3289bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
32904ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Ctx) {
329171d74bc0d6e522ce7c21a599db8e19d3883b518fJohn McCall    Profile(ID, Template, getArgs(), NumArgs, Ctx);
32923e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith    if (isTypeAlias())
32933e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith      getAliasedType().Profile(ID);
329455f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  }
329555f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
32967532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor  static void Profile(llvm::FoldingSetNodeID &ID, TemplateName T,
329731f17ecbef57b5679c017c375db330546b7b5145John McCall                      const TemplateArgument *Args,
329831f17ecbef57b5679c017c375db330546b7b5145John McCall                      unsigned NumArgs,
32994ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad                      const ASTContext &Context);
330055f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
33011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
33021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == TemplateSpecialization;
330355f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  }
33047532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor  static bool classof(const TemplateSpecializationType *T) { return true; }
330555f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor};
330655f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
330731f17ecbef57b5679c017c375db330546b7b5145John McCall/// \brief The injected class name of a C++ class template or class
330831f17ecbef57b5679c017c375db330546b7b5145John McCall/// template partial specialization.  Used to record that a type was
330931f17ecbef57b5679c017c375db330546b7b5145John McCall/// spelled with a bare identifier rather than as a template-id; the
331031f17ecbef57b5679c017c375db330546b7b5145John McCall/// equivalent for non-templated classes is just RecordType.
33113cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall///
331231f17ecbef57b5679c017c375db330546b7b5145John McCall/// Injected class name types are always dependent.  Template
331331f17ecbef57b5679c017c375db330546b7b5145John McCall/// instantiation turns these into RecordTypes.
33143cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall///
331531f17ecbef57b5679c017c375db330546b7b5145John McCall/// Injected class name types are always canonical.  This works
331631f17ecbef57b5679c017c375db330546b7b5145John McCall/// because it is impossible to compare an injected class name type
331731f17ecbef57b5679c017c375db330546b7b5145John McCall/// with the corresponding non-injected template type, for the same
331831f17ecbef57b5679c017c375db330546b7b5145John McCall/// reason that it is impossible to directly compare template
331931f17ecbef57b5679c017c375db330546b7b5145John McCall/// parameters from different dependent contexts: injected class name
332031f17ecbef57b5679c017c375db330546b7b5145John McCall/// types can only occur within the scope of a particular templated
332131f17ecbef57b5679c017c375db330546b7b5145John McCall/// declaration, and within that scope every template specialization
332231f17ecbef57b5679c017c375db330546b7b5145John McCall/// will canonicalize to the injected class name (when appropriate
332331f17ecbef57b5679c017c375db330546b7b5145John McCall/// according to the rules of the language).
33243cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCallclass InjectedClassNameType : public Type {
33253cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  CXXRecordDecl *Decl;
33263cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall
332731f17ecbef57b5679c017c375db330546b7b5145John McCall  /// The template specialization which this type represents.
332831f17ecbef57b5679c017c375db330546b7b5145John McCall  /// For example, in
332931f17ecbef57b5679c017c375db330546b7b5145John McCall  ///   template <class T> class A { ... };
333031f17ecbef57b5679c017c375db330546b7b5145John McCall  /// this is A<T>, whereas in
333131f17ecbef57b5679c017c375db330546b7b5145John McCall  ///   template <class X, class Y> class A<B<X,Y> > { ... };
333231f17ecbef57b5679c017c375db330546b7b5145John McCall  /// this is A<B<X,Y> >.
333331f17ecbef57b5679c017c375db330546b7b5145John McCall  ///
333431f17ecbef57b5679c017c375db330546b7b5145John McCall  /// It is always unqualified, always a template specialization type,
333531f17ecbef57b5679c017c375db330546b7b5145John McCall  /// and always dependent.
333631f17ecbef57b5679c017c375db330546b7b5145John McCall  QualType InjectedType;
33373cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall
33383cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  friend class ASTContext; // ASTContext creates these.
3339c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl  friend class ASTReader; // FIXME: ASTContext::getInjectedClassNameType is not
3340c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl                          // currently suitable for AST reading, too much
334143921b53b582145f0d1b7c48223bd4d9f0a9d1beArgyrios Kyrtzidis                          // interdependencies.
334231f17ecbef57b5679c017c375db330546b7b5145John McCall  InjectedClassNameType(CXXRecordDecl *D, QualType TST)
334335495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    : Type(InjectedClassName, QualType(), /*Dependent=*/true,
3344d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor           /*VariablyModified=*/false,
3345d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor           /*ContainsUnexpandedParameterPack=*/false),
334631f17ecbef57b5679c017c375db330546b7b5145John McCall      Decl(D), InjectedType(TST) {
33473cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall    assert(isa<TemplateSpecializationType>(TST));
33483cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall    assert(!TST.hasQualifiers());
334931f17ecbef57b5679c017c375db330546b7b5145John McCall    assert(TST->isDependentType());
33503cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  }
33513cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall
33523cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCallpublic:
335331f17ecbef57b5679c017c375db330546b7b5145John McCall  QualType getInjectedSpecializationType() const { return InjectedType; }
335431f17ecbef57b5679c017c375db330546b7b5145John McCall  const TemplateSpecializationType *getInjectedTST() const {
335531f17ecbef57b5679c017c375db330546b7b5145John McCall    return cast<TemplateSpecializationType>(InjectedType.getTypePtr());
33563cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  }
33573cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall
3358ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl  CXXRecordDecl *getDecl() const;
33593cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall
336031f17ecbef57b5679c017c375db330546b7b5145John McCall  bool isSugared() const { return false; }
336131f17ecbef57b5679c017c375db330546b7b5145John McCall  QualType desugar() const { return QualType(this, 0); }
33623cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall
33633cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  static bool classof(const Type *T) {
33643cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall    return T->getTypeClass() == InjectedClassName;
33653cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  }
33663cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  static bool classof(const InjectedClassNameType *T) { return true; }
33673cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall};
33683cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall
3369465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// \brief The kind of a tag type.
3370465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnaraenum TagTypeKind {
3371465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// \brief The "struct" keyword.
3372465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  TTK_Struct,
3373465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// \brief The "union" keyword.
3374465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  TTK_Union,
3375465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// \brief The "class" keyword.
3376465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  TTK_Class,
3377465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// \brief The "enum" keyword.
3378465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  TTK_Enum
3379465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara};
3380465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
33814a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// \brief The elaboration keyword that precedes a qualified type name or
33824a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// introduces an elaborated-type-specifier.
33834a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregorenum ElaboratedTypeKeyword {
33844a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor  /// \brief The "struct" keyword introduces the elaborated-type-specifier.
33854a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor  ETK_Struct,
33864a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor  /// \brief The "union" keyword introduces the elaborated-type-specifier.
33874a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor  ETK_Union,
3388465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// \brief The "class" keyword introduces the elaborated-type-specifier.
3389465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  ETK_Class,
33904a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor  /// \brief The "enum" keyword introduces the elaborated-type-specifier.
3391465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  ETK_Enum,
3392465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// \brief The "typename" keyword precedes the qualified type name, e.g.,
3393465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// \c typename T::type.
3394465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  ETK_Typename,
3395465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// \brief No keyword precedes the qualified type name.
3396465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  ETK_None
33974a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor};
3398465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
3399465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// A helper class for Type nodes having an ElaboratedTypeKeyword.
3400465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// The keyword in stored in the free bits of the base class.
3401465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// Also provides a few static helpers for converting and printing
3402465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// elaborated type keyword and tag type kind enumerations.
3403465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnaraclass TypeWithKeyword : public Type {
3404465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnaraprotected:
3405465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  TypeWithKeyword(ElaboratedTypeKeyword Keyword, TypeClass tc,
3406d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor                  QualType Canonical, bool Dependent, bool VariablyModified,
3407d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor                  bool ContainsUnexpandedParameterPack)
3408d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  : Type(tc, Canonical, Dependent, VariablyModified,
3409d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor         ContainsUnexpandedParameterPack) {
341077be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall    TypeWithKeywordBits.Keyword = Keyword;
341177be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall  }
3412465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
3413465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnarapublic:
3414465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  ElaboratedTypeKeyword getKeyword() const {
341577be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall    return static_cast<ElaboratedTypeKeyword>(TypeWithKeywordBits.Keyword);
3416465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  }
3417465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
3418465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// getKeywordForTypeSpec - Converts a type specifier (DeclSpec::TST)
3419465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// into an elaborated type keyword.
3420465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  static ElaboratedTypeKeyword getKeywordForTypeSpec(unsigned TypeSpec);
3421465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
3422465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// getTagTypeKindForTypeSpec - Converts a type specifier (DeclSpec::TST)
3423465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// into a tag type kind.  It is an error to provide a type specifier
3424465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// which *isn't* a tag kind here.
3425465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  static TagTypeKind getTagTypeKindForTypeSpec(unsigned TypeSpec);
3426465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
3427465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// getKeywordForTagDeclKind - Converts a TagTypeKind into an
3428465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// elaborated type keyword.
3429465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  static ElaboratedTypeKeyword getKeywordForTagTypeKind(TagTypeKind Tag);
3430465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
3431465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// getTagTypeKindForKeyword - Converts an elaborated type keyword into
3432465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  // a TagTypeKind. It is an error to provide an elaborated type keyword
3433465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// which *isn't* a tag kind here.
3434465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  static TagTypeKind getTagTypeKindForKeyword(ElaboratedTypeKeyword Keyword);
3435465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
3436465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  static bool KeywordIsTagTypeKind(ElaboratedTypeKeyword Keyword);
3437465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
3438465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  static const char *getKeywordName(ElaboratedTypeKeyword Keyword);
3439465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
3440465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  static const char *getTagTypeKindName(TagTypeKind Kind) {
3441465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    return getKeywordName(getKeywordForTagTypeKind(Kind));
3442465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  }
3443465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
3444465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  class CannotCastToThisType {};
3445465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  static CannotCastToThisType classof(const Type *);
3446465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara};
3447465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
3448465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// \brief Represents a type that was referred to using an elaborated type
3449465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// keyword, e.g., struct S, or via a qualified name, e.g., N::M::type,
3450465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// or both.
3451e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor///
3452e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor/// This type is used to keep track of a type name as written in the
3453465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// source code, including tag keywords and any nested-name-specifiers.
3454465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// The type itself is always "sugar", used to express what was written
3455465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// in the source code but containing no additional semantic information.
3456465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnaraclass ElaboratedType : public TypeWithKeyword, public llvm::FoldingSetNode {
3457465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
3458ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor  /// \brief The nested name specifier containing the qualifier.
3459ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor  NestedNameSpecifier *NNS;
3460e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor
3461e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor  /// \brief The type that this qualified name refers to.
3462e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor  QualType NamedType;
3463e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor
3464465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  ElaboratedType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS,
3465465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara                 QualType NamedType, QualType CanonType)
3466465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    : TypeWithKeyword(Keyword, Elaborated, CanonType,
346735495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor                      NamedType->isDependentType(),
3468d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor                      NamedType->isVariablyModifiedType(),
3469d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor                      NamedType->containsUnexpandedParameterPack()),
3470465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara      NNS(NNS), NamedType(NamedType) {
3471465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    assert(!(Keyword == ETK_None && NNS == 0) &&
3472465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara           "ElaboratedType cannot have elaborated type keyword "
3473465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara           "and name qualifier both null.");
3474465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  }
3475e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor
3476e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor  friend class ASTContext;  // ASTContext creates these
3477e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor
3478e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregorpublic:
347933500955d731c73717af52088b7fc0e7a85681e7John McCall  ~ElaboratedType();
3480465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
3481ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor  /// \brief Retrieve the qualification on this type.
3482ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor  NestedNameSpecifier *getQualifier() const { return NNS; }
3483e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor
3484e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor  /// \brief Retrieve the type named by the qualified-id.
3485e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor  QualType getNamedType() const { return NamedType; }
3486e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor
3487bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// \brief Remove a single level of sugar.
3488bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return getNamedType(); }
3489bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
3490bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// \brief Returns whether this type directly provides sugar.
3491bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return true; }
3492bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
3493e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor  void Profile(llvm::FoldingSetNodeID &ID) {
3494465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    Profile(ID, getKeyword(), NNS, NamedType);
3495e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor  }
3496e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor
3497465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  static void Profile(llvm::FoldingSetNodeID &ID, ElaboratedTypeKeyword Keyword,
3498465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara                      NestedNameSpecifier *NNS, QualType NamedType) {
3499465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    ID.AddInteger(Keyword);
3500ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor    ID.AddPointer(NNS);
3501ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor    NamedType.Profile(ID);
3502ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor  }
3503e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor
35041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
3505465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    return T->getTypeClass() == Elaborated;
3506e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor  }
3507465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  static bool classof(const ElaboratedType *T) { return true; }
3508e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor};
3509e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor
35104a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// \brief Represents a qualified type name for which the type name is
35114a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// dependent.
3512d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor///
35134a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// DependentNameType represents a class of dependent types that involve a
35144a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// dependent nested-name-specifier (e.g., "T::") followed by a (dependent)
35154a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// name of a type. The DependentNameType may start with a "typename" (for a
35164a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// typename-specifier), "class", "struct", "union", or "enum" (for a
35174a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// dependent elaborated-type-specifier), or nothing (in contexts where we
35184a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// know that we must be referring to a type, e.g., in a base class specifier).
3519465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnaraclass DependentNameType : public TypeWithKeyword, public llvm::FoldingSetNode {
3520465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
3521d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  /// \brief The nested name specifier containing the qualifier.
3522d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  NestedNameSpecifier *NNS;
3523d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor
3524d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  /// \brief The type that this typename specifier refers to.
352533500955d731c73717af52088b7fc0e7a85681e7John McCall  const IdentifierInfo *Name;
3526d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor
35274a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor  DependentNameType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS,
35284a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor                    const IdentifierInfo *Name, QualType CanonType)
352935495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    : TypeWithKeyword(Keyword, DependentName, CanonType, /*Dependent=*/true,
3530d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor                      /*VariablyModified=*/false,
3531d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor                      NNS->containsUnexpandedParameterPack()),
3532465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara      NNS(NNS), Name(Name) {
35331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    assert(NNS->isDependent() &&
35344714c12a1ab759156b78be8f109ea4c12213af57Douglas Gregor           "DependentNameType requires a dependent nested-name-specifier");
3535d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  }
3536d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor
3537d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  friend class ASTContext;  // ASTContext creates these
3538d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor
3539d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregorpublic:
3540d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  /// \brief Retrieve the qualification on this type.
3541d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  NestedNameSpecifier *getQualifier() const { return NNS; }
3542d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor
35431734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor  /// \brief Retrieve the type named by the typename specifier as an
35441734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor  /// identifier.
35451734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor  ///
35461734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor  /// This routine will return a non-NULL identifier pointer when the
35471734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor  /// form of the original typename was terminated by an identifier,
35481734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor  /// e.g., "typename T::type".
35491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  const IdentifierInfo *getIdentifier() const {
355033500955d731c73717af52088b7fc0e7a85681e7John McCall    return Name;
35511734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor  }
3552d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor
3553bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
3554bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
3555bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
3556d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  void Profile(llvm::FoldingSetNodeID &ID) {
3557465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    Profile(ID, getKeyword(), NNS, Name);
3558d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  }
3559d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor
35604a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor  static void Profile(llvm::FoldingSetNodeID &ID, ElaboratedTypeKeyword Keyword,
356133500955d731c73717af52088b7fc0e7a85681e7John McCall                      NestedNameSpecifier *NNS, const IdentifierInfo *Name) {
35624a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor    ID.AddInteger(Keyword);
3563d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor    ID.AddPointer(NNS);
356433500955d731c73717af52088b7fc0e7a85681e7John McCall    ID.AddPointer(Name);
3565d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  }
3566d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor
35671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
35684714c12a1ab759156b78be8f109ea4c12213af57Douglas Gregor    return T->getTypeClass() == DependentName;
3569d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  }
35704714c12a1ab759156b78be8f109ea4c12213af57Douglas Gregor  static bool classof(const DependentNameType *T) { return true; }
3571d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor};
3572d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor
357333500955d731c73717af52088b7fc0e7a85681e7John McCall/// DependentTemplateSpecializationType - Represents a template
357433500955d731c73717af52088b7fc0e7a85681e7John McCall/// specialization type whose template cannot be resolved, e.g.
357533500955d731c73717af52088b7fc0e7a85681e7John McCall///   A<T>::template B<T>
357633500955d731c73717af52088b7fc0e7a85681e7John McCallclass DependentTemplateSpecializationType :
357733500955d731c73717af52088b7fc0e7a85681e7John McCall  public TypeWithKeyword, public llvm::FoldingSetNode {
357833500955d731c73717af52088b7fc0e7a85681e7John McCall
357933500955d731c73717af52088b7fc0e7a85681e7John McCall  /// \brief The nested name specifier containing the qualifier.
358033500955d731c73717af52088b7fc0e7a85681e7John McCall  NestedNameSpecifier *NNS;
358133500955d731c73717af52088b7fc0e7a85681e7John McCall
358233500955d731c73717af52088b7fc0e7a85681e7John McCall  /// \brief The identifier of the template.
358333500955d731c73717af52088b7fc0e7a85681e7John McCall  const IdentifierInfo *Name;
358433500955d731c73717af52088b7fc0e7a85681e7John McCall
358533500955d731c73717af52088b7fc0e7a85681e7John McCall  /// \brief - The number of template arguments named in this class
358633500955d731c73717af52088b7fc0e7a85681e7John McCall  /// template specialization.
358733500955d731c73717af52088b7fc0e7a85681e7John McCall  unsigned NumArgs;
358833500955d731c73717af52088b7fc0e7a85681e7John McCall
358933500955d731c73717af52088b7fc0e7a85681e7John McCall  const TemplateArgument *getArgBuffer() const {
359033500955d731c73717af52088b7fc0e7a85681e7John McCall    return reinterpret_cast<const TemplateArgument*>(this+1);
359133500955d731c73717af52088b7fc0e7a85681e7John McCall  }
359233500955d731c73717af52088b7fc0e7a85681e7John McCall  TemplateArgument *getArgBuffer() {
359333500955d731c73717af52088b7fc0e7a85681e7John McCall    return reinterpret_cast<TemplateArgument*>(this+1);
359433500955d731c73717af52088b7fc0e7a85681e7John McCall  }
359533500955d731c73717af52088b7fc0e7a85681e7John McCall
3596ef99001908e799c388f1363b1e607dad5f5b57d3John McCall  DependentTemplateSpecializationType(ElaboratedTypeKeyword Keyword,
359733500955d731c73717af52088b7fc0e7a85681e7John McCall                                      NestedNameSpecifier *NNS,
359833500955d731c73717af52088b7fc0e7a85681e7John McCall                                      const IdentifierInfo *Name,
359933500955d731c73717af52088b7fc0e7a85681e7John McCall                                      unsigned NumArgs,
360033500955d731c73717af52088b7fc0e7a85681e7John McCall                                      const TemplateArgument *Args,
360133500955d731c73717af52088b7fc0e7a85681e7John McCall                                      QualType Canon);
360233500955d731c73717af52088b7fc0e7a85681e7John McCall
360333500955d731c73717af52088b7fc0e7a85681e7John McCall  friend class ASTContext;  // ASTContext creates these
360433500955d731c73717af52088b7fc0e7a85681e7John McCall
360533500955d731c73717af52088b7fc0e7a85681e7John McCallpublic:
360633500955d731c73717af52088b7fc0e7a85681e7John McCall  NestedNameSpecifier *getQualifier() const { return NNS; }
360733500955d731c73717af52088b7fc0e7a85681e7John McCall  const IdentifierInfo *getIdentifier() const { return Name; }
360833500955d731c73717af52088b7fc0e7a85681e7John McCall
360933500955d731c73717af52088b7fc0e7a85681e7John McCall  /// \brief Retrieve the template arguments.
361033500955d731c73717af52088b7fc0e7a85681e7John McCall  const TemplateArgument *getArgs() const {
361133500955d731c73717af52088b7fc0e7a85681e7John McCall    return getArgBuffer();
361233500955d731c73717af52088b7fc0e7a85681e7John McCall  }
361333500955d731c73717af52088b7fc0e7a85681e7John McCall
361433500955d731c73717af52088b7fc0e7a85681e7John McCall  /// \brief Retrieve the number of template arguments.
361533500955d731c73717af52088b7fc0e7a85681e7John McCall  unsigned getNumArgs() const { return NumArgs; }
361633500955d731c73717af52088b7fc0e7a85681e7John McCall
361733500955d731c73717af52088b7fc0e7a85681e7John McCall  const TemplateArgument &getArg(unsigned Idx) const; // in TemplateBase.h
361833500955d731c73717af52088b7fc0e7a85681e7John McCall
361933500955d731c73717af52088b7fc0e7a85681e7John McCall  typedef const TemplateArgument * iterator;
362033500955d731c73717af52088b7fc0e7a85681e7John McCall  iterator begin() const { return getArgs(); }
362133500955d731c73717af52088b7fc0e7a85681e7John McCall  iterator end() const; // inline in TemplateBase.h
362233500955d731c73717af52088b7fc0e7a85681e7John McCall
362333500955d731c73717af52088b7fc0e7a85681e7John McCall  bool isSugared() const { return false; }
362433500955d731c73717af52088b7fc0e7a85681e7John McCall  QualType desugar() const { return QualType(this, 0); }
362533500955d731c73717af52088b7fc0e7a85681e7John McCall
36264ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context) {
362733500955d731c73717af52088b7fc0e7a85681e7John McCall    Profile(ID, Context, getKeyword(), NNS, Name, NumArgs, getArgs());
362833500955d731c73717af52088b7fc0e7a85681e7John McCall  }
362933500955d731c73717af52088b7fc0e7a85681e7John McCall
363033500955d731c73717af52088b7fc0e7a85681e7John McCall  static void Profile(llvm::FoldingSetNodeID &ID,
36314ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad                      const ASTContext &Context,
363233500955d731c73717af52088b7fc0e7a85681e7John McCall                      ElaboratedTypeKeyword Keyword,
363333500955d731c73717af52088b7fc0e7a85681e7John McCall                      NestedNameSpecifier *Qualifier,
363433500955d731c73717af52088b7fc0e7a85681e7John McCall                      const IdentifierInfo *Name,
363533500955d731c73717af52088b7fc0e7a85681e7John McCall                      unsigned NumArgs,
363633500955d731c73717af52088b7fc0e7a85681e7John McCall                      const TemplateArgument *Args);
363733500955d731c73717af52088b7fc0e7a85681e7John McCall
363833500955d731c73717af52088b7fc0e7a85681e7John McCall  static bool classof(const Type *T) {
363933500955d731c73717af52088b7fc0e7a85681e7John McCall    return T->getTypeClass() == DependentTemplateSpecialization;
364033500955d731c73717af52088b7fc0e7a85681e7John McCall  }
364133500955d731c73717af52088b7fc0e7a85681e7John McCall  static bool classof(const DependentTemplateSpecializationType *T) {
364233500955d731c73717af52088b7fc0e7a85681e7John McCall    return true;
364333500955d731c73717af52088b7fc0e7a85681e7John McCall  }
364433500955d731c73717af52088b7fc0e7a85681e7John McCall};
364533500955d731c73717af52088b7fc0e7a85681e7John McCall
36467536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// \brief Represents a pack expansion of types.
36477536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor///
36487536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// Pack expansions are part of C++0x variadic templates. A pack
36497536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// expansion contains a pattern, which itself contains one or more
36507536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// "unexpanded" parameter packs. When instantiated, a pack expansion
36517536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// produces a series of types, each instantiated from the pattern of
36527536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// the expansion, where the Ith instantiation of the pattern uses the
36537536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// Ith arguments bound to each of the unexpanded parameter packs. The
36547536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// pack expansion is considered to "expand" these unexpanded
36557536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// parameter packs.
36567536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor///
36577536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// \code
36587536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// template<typename ...Types> struct tuple;
36597536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor///
36607536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// template<typename ...Types>
36617536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// struct tuple_of_references {
36627536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor///   typedef tuple<Types&...> type;
36637536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// };
36647536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// \endcode
36657536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor///
36667536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// Here, the pack expansion \c Types&... is represented via a
36677536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// PackExpansionType whose pattern is Types&.
36687536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregorclass PackExpansionType : public Type, public llvm::FoldingSetNode {
36697536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  /// \brief The pattern of the pack expansion.
36707536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  QualType Pattern;
36717536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor
3672cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  /// \brief The number of expansions that this pack expansion will
3673cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  /// generate when substituted (+1), or indicates that
3674cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  ///
3675cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  /// This field will only have a non-zero value when some of the parameter
3676cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  /// packs that occur within the pattern have been substituted but others have
3677cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  /// not.
3678cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  unsigned NumExpansions;
3679cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor
3680cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  PackExpansionType(QualType Pattern, QualType Canon,
3681cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor                    llvm::Optional<unsigned> NumExpansions)
36827536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor    : Type(PackExpansion, Canon, /*Dependent=*/true,
36837536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor           /*VariableModified=*/Pattern->isVariablyModifiedType(),
36847536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor           /*ContainsUnexpandedParameterPack=*/false),
3685cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor      Pattern(Pattern),
3686cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor      NumExpansions(NumExpansions? *NumExpansions + 1: 0) { }
36877536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor
36887536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  friend class ASTContext;  // ASTContext creates these
3689cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor
36907536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregorpublic:
36917536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  /// \brief Retrieve the pattern of this pack expansion, which is the
36927536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  /// type that will be repeatedly instantiated when instantiating the
36937536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  /// pack expansion itself.
36947536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  QualType getPattern() const { return Pattern; }
36957536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor
3696cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  /// \brief Retrieve the number of expansions that this pack expansion will
3697cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  /// generate, if known.
3698cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  llvm::Optional<unsigned> getNumExpansions() const {
3699cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor    if (NumExpansions)
3700cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor      return NumExpansions - 1;
3701cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor
3702cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor    return llvm::Optional<unsigned>();
3703cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  }
3704cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor
37057536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  bool isSugared() const { return false; }
37067536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  QualType desugar() const { return QualType(this, 0); }
37077536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor
37087536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  void Profile(llvm::FoldingSetNodeID &ID) {
3709cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor    Profile(ID, getPattern(), getNumExpansions());
37107536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  }
37117536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor
3712cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  static void Profile(llvm::FoldingSetNodeID &ID, QualType Pattern,
3713cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor                      llvm::Optional<unsigned> NumExpansions) {
37147536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor    ID.AddPointer(Pattern.getAsOpaquePtr());
3715cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor    ID.AddBoolean(NumExpansions);
3716cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor    if (NumExpansions)
3717cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor      ID.AddInteger(*NumExpansions);
37187536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  }
37197536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor
37207536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  static bool classof(const Type *T) {
37217536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor    return T->getTypeClass() == PackExpansion;
37227536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  }
37237536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  static bool classof(const PackExpansionType *T) {
37247536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor    return true;
37257536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  }
37267536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor};
37277536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor
3728c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// ObjCObjectType - Represents a class type in Objective C.
3729c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// Every Objective C type is a combination of a base type and a
3730c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// list of protocols.
3731c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall///
3732c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// Given the following declarations:
3733c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall///   @class C;
3734c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall///   @protocol P;
3735c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall///
3736c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// 'C' is an ObjCInterfaceType C.  It is sugar for an ObjCObjectType
3737c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// with base C and no protocols.
3738c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall///
3739c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// 'C<P>' is an ObjCObjectType with base C and protocol list [P].
3740c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall///
3741e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// 'id' is a TypedefType which is sugar for an ObjCPointerType whose
3742e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// pointee is an ObjCObjectType with base BuiltinType::ObjCIdType
3743e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// and no protocols.
3744c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall///
3745e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// 'id<P>' is an ObjCPointerType whose pointee is an ObjCObjecType
3746e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// with base BuiltinType::ObjCIdType and protocol list [P].  Eventually
3747e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// this should get its own sugar class to better represent the source.
3748c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallclass ObjCObjectType : public Type {
3749b870b88df784c2940efce448ebfaf54dece14666John McCall  // ObjCObjectType.NumProtocols - the number of protocols stored
3750b870b88df784c2940efce448ebfaf54dece14666John McCall  // after the ObjCObjectPointerType node.
375171c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  //
375271c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  // These protocols are those written directly on the type.  If
375371c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  // protocol qualifiers ever become additive, the iterators will need
375471c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  // to get kindof complicated.
375571c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  //
375671c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  // In the canonical object type, these are sorted alphabetically
375771c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  // and uniqued.
3758c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff
3759c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  /// Either a BuiltinType or an InterfaceType or sugar for either.
3760c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  QualType BaseType;
3761c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3762c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  ObjCProtocolDecl * const *getProtocolStorage() const {
3763c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return const_cast<ObjCObjectType*>(this)->getProtocolStorage();
3764c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  }
3765c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3766c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  ObjCProtocolDecl **getProtocolStorage();
3767c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3768c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallprotected:
3769c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  ObjCObjectType(QualType Canonical, QualType Base,
3770c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall                 ObjCProtocolDecl * const *Protocols, unsigned NumProtocols);
3771c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3772c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  enum Nonce_ObjCInterface { Nonce_ObjCInterface };
3773c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  ObjCObjectType(enum Nonce_ObjCInterface)
3774d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor        : Type(ObjCInterface, QualType(), false, false, false),
377571c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall      BaseType(QualType(this_(), 0)) {
3776b870b88df784c2940efce448ebfaf54dece14666John McCall    ObjCObjectTypeBits.NumProtocols = 0;
377771c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  }
3778c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff
37793536b443bc50d58a79f14fca9b6842541a434854Steve Naroffpublic:
3780e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// getBaseType - Gets the base type of this object type.  This is
3781e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// always (possibly sugar for) one of:
3782e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///  - the 'id' builtin type (as opposed to the 'id' type visible to the
3783e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///    user, which is a typedef for an ObjCPointerType)
3784e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///  - the 'Class' builtin type (same caveat)
3785e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///  - an ObjCObjectType (currently always an ObjCInterfaceType)
3786c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  QualType getBaseType() const { return BaseType; }
378771842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek
3788c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool isObjCId() const {
3789c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getBaseType()->isSpecificBuiltinType(BuiltinType::ObjCId);
3790c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  }
3791c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool isObjCClass() const {
3792c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getBaseType()->isSpecificBuiltinType(BuiltinType::ObjCClass);
3793c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  }
3794c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool isObjCUnqualifiedId() const { return qual_empty() && isObjCId(); }
3795c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool isObjCUnqualifiedClass() const { return qual_empty() && isObjCClass(); }
3796c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool isObjCUnqualifiedIdOrClass() const {
3797c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    if (!qual_empty()) return false;
3798c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    if (const BuiltinType *T = getBaseType()->getAs<BuiltinType>())
3799c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall      return T->getKind() == BuiltinType::ObjCId ||
3800c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall             T->getKind() == BuiltinType::ObjCClass;
3801c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return false;
3802c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  }
3803c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool isObjCQualifiedId() const { return !qual_empty() && isObjCId(); }
3804c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool isObjCQualifiedClass() const { return !qual_empty() && isObjCClass(); }
3805c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3806c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  /// Gets the interface declaration for this object type, if the base type
3807c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  /// really is an interface.
3808c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  ObjCInterfaceDecl *getInterface() const;
3809c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3810c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  typedef ObjCProtocolDecl * const *qual_iterator;
3811c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3812c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  qual_iterator qual_begin() const { return getProtocolStorage(); }
3813c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  qual_iterator qual_end() const { return qual_begin() + getNumProtocols(); }
3814c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3815c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool qual_empty() const { return getNumProtocols() == 0; }
38161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3817c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff  /// getNumProtocols - Return the number of qualifying protocols in this
3818c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff  /// interface type, or 0 if there are none.
3819b870b88df784c2940efce448ebfaf54dece14666John McCall  unsigned getNumProtocols() const { return ObjCObjectTypeBits.NumProtocols; }
382014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff
3821c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  /// \brief Fetch a protocol by index.
382273dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor  ObjCProtocolDecl *getProtocol(unsigned I) const {
382373dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor    assert(I < getNumProtocols() && "Out-of-range protocol access");
382473dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor    return qual_begin()[I];
382573dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor  }
382673dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor
3827bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
3828bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
3829bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
3830c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  static bool classof(const Type *T) {
3831c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return T->getTypeClass() == ObjCObject ||
3832c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall           T->getTypeClass() == ObjCInterface;
3833c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  }
3834c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  static bool classof(const ObjCObjectType *) { return true; }
3835c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall};
3836c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3837c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// ObjCObjectTypeImpl - A class providing a concrete implementation
3838c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// of ObjCObjectType, so as to not increase the footprint of
3839c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// ObjCInterfaceType.  Code outside of ASTContext and the core type
3840c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// system should not reference this type.
3841c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallclass ObjCObjectTypeImpl : public ObjCObjectType, public llvm::FoldingSetNode {
3842c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  friend class ASTContext;
3843c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3844c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  // If anyone adds fields here, ObjCObjectType::getProtocolStorage()
3845c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  // will need to be modified.
3846c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3847c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  ObjCObjectTypeImpl(QualType Canonical, QualType Base,
3848c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall                     ObjCProtocolDecl * const *Protocols,
3849c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall                     unsigned NumProtocols)
3850c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    : ObjCObjectType(Canonical, Base, Protocols, NumProtocols) {}
3851c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3852c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallpublic:
3853c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff  void Profile(llvm::FoldingSetNodeID &ID);
38541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static void Profile(llvm::FoldingSetNodeID &ID,
3855c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall                      QualType Base,
3856c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall                      ObjCProtocolDecl *const *protocols,
3857c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall                      unsigned NumProtocols);
3858c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall};
38591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3860c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallinline ObjCProtocolDecl **ObjCObjectType::getProtocolStorage() {
3861c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  return reinterpret_cast<ObjCProtocolDecl**>(
3862c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall            static_cast<ObjCObjectTypeImpl*>(this) + 1);
3863c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall}
3864c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3865c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// ObjCInterfaceType - Interfaces are the core concept in Objective-C for
3866c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// object oriented design.  They basically correspond to C++ classes.  There
3867c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// are two kinds of interface types, normal interfaces like "NSString" and
3868c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// qualified interfaces, which are qualified with a protocol list like
3869c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// "NSString<NSCopyable, NSAmazing>".
3870e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall///
3871e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// ObjCInterfaceType guarantees the following properties when considered
3872e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// as a subtype of its superclass, ObjCObjectType:
3873e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall///   - There are no protocol qualifiers.  To reinforce this, code which
3874e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall///     tries to invoke the protocol methods via an ObjCInterfaceType will
3875e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall///     fail to compile.
3876e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall///   - It is its own base type.  That is, if T is an ObjCInterfaceType*,
3877e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall///     T->getBaseType() == QualType(T, 0).
3878c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallclass ObjCInterfaceType : public ObjCObjectType {
3879c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  ObjCInterfaceDecl *Decl;
3880c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3881c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  ObjCInterfaceType(const ObjCInterfaceDecl *D)
3882c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    : ObjCObjectType(Nonce_ObjCInterface),
3883c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall      Decl(const_cast<ObjCInterfaceDecl*>(D)) {}
3884c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  friend class ASTContext;  // ASTContext creates these.
38851fb0caaa7bef765b85972274e3b434af2572c141John McCall
3886c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallpublic:
3887e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// getDecl - Get the declaration of this interface.
3888deacbdca554298ccdf636f19c6094a8825ec6b34Douglas Gregor  ObjCInterfaceDecl *getDecl() const { return Decl; }
3889c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3890c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool isSugared() const { return false; }
3891c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  QualType desugar() const { return QualType(this, 0); }
38920b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor
38931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
38941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == ObjCInterface;
38953536b443bc50d58a79f14fca9b6842541a434854Steve Naroff  }
3896a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const ObjCInterfaceType *) { return true; }
3897c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3898c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  // Nonsense to "hide" certain members of ObjCObjectType within this
3899c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  // class.  People asking for protocols on an ObjCInterfaceType are
3900c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  // not going to get what they want: ObjCInterfaceTypes are
3901c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  // guaranteed to have no protocols.
3902c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  enum {
3903c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    qual_iterator,
3904c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    qual_begin,
3905c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    qual_end,
3906c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    getNumProtocols,
3907c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    getProtocol
3908c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  };
39093536b443bc50d58a79f14fca9b6842541a434854Steve Naroff};
39103536b443bc50d58a79f14fca9b6842541a434854Steve Naroff
3911c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallinline ObjCInterfaceDecl *ObjCObjectType::getInterface() const {
3912c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  if (const ObjCInterfaceType *T =
3913c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall        getBaseType()->getAs<ObjCInterfaceType>())
3914c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return T->getDecl();
3915c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  return 0;
3916c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall}
3917c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3918e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// ObjCObjectPointerType - Used to represent a pointer to an
3919e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// Objective C object.  These are constructed from pointer
3920e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// declarators when the pointee type is an ObjCObjectType (or sugar
3921e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// for one).  In addition, the 'id' and 'Class' types are typedefs
3922e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// for these, and the protocol-qualified types 'id<P>' and 'Class<P>'
3923e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// are translated into these.
392414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff///
3925e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// Pointers to pointers to Objective C objects are still PointerTypes;
3926e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// only the first level of pointer gets it own type implementation.
392714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroffclass ObjCObjectPointerType : public Type, public llvm::FoldingSetNode {
3928e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  QualType PointeeType;
39291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3930c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  ObjCObjectPointerType(QualType Canonical, QualType Pointee)
3931d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    : Type(ObjCObjectPointer, Canonical, false, false, false),
3932c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall      PointeeType(Pointee) {}
393314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  friend class ASTContext;  // ASTContext creates these.
39341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
393514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroffpublic:
3936e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// getPointeeType - Gets the type pointed to by this ObjC pointer.
3937e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// The result will always be an ObjCObjectType or sugar thereof.
393814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  QualType getPointeeType() const { return PointeeType; }
393914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff
3940e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// getObjCObjectType - Gets the type pointed to by this ObjC
3941e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// pointer.  This method always returns non-null.
3942e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///
3943e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// This method is equivalent to getPointeeType() except that
3944e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// it discards any typedefs (or other sugar) between this
3945e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// type and the "outermost" object type.  So for:
3946e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///   @class A; @protocol P; @protocol Q;
3947e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///   typedef A<P> AP;
3948e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///   typedef A A1;
3949e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///   typedef A1<P> A1P;
3950e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///   typedef A1P<Q> A1PQ;
3951e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// For 'A*', getObjectType() will return 'A'.
3952e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// For 'A<P>*', getObjectType() will return 'A<P>'.
3953e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// For 'AP*', getObjectType() will return 'A<P>'.
3954e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// For 'A1*', getObjectType() will return 'A'.
3955e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// For 'A1<P>*', getObjectType() will return 'A1<P>'.
3956e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// For 'A1P*', getObjectType() will return 'A1<P>'.
3957e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// For 'A1PQ*', getObjectType() will return 'A1<Q>', because
3958e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///   adding protocols to a protocol-qualified base discards the
3959e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///   old qualifiers (for now).  But if it didn't, getObjectType()
3960e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///   would return 'A1P<Q>' (and we'd have to make iterating over
3961e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///   qualifiers more complicated).
3962c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  const ObjCObjectType *getObjectType() const {
3963d0370f59e79702ac908c81bf556519f91e9ca297John McCall    return PointeeType->castAs<ObjCObjectType>();
3964c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  }
3965c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3966e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// getInterfaceType - If this pointer points to an Objective C
3967e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// @interface type, gets the type for that interface.  Any protocol
3968e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// qualifiers on the interface are ignored.
3969e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///
3970e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// \return null if the base type for this pointer is 'id' or 'Class'
39711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  const ObjCInterfaceType *getInterfaceType() const {
3972c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getObjectType()->getBaseType()->getAs<ObjCInterfaceType>();
397314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  }
3974e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall
3975e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// getInterfaceDecl - If this pointer points to an Objective @interface
3976e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// type, gets the declaration for that interface.
3977e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///
3978e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// \return null if the base type for this pointer is 'id' or 'Class'
397914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  ObjCInterfaceDecl *getInterfaceDecl() const {
3980e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall    return getObjectType()->getInterface();
398114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  }
3982e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall
3983e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// isObjCIdType - True if this is equivalent to the 'id' type, i.e. if
3984e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// its object type is the primitive 'id' type with no protocols.
398514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  bool isObjCIdType() const {
3986c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getObjectType()->isObjCUnqualifiedId();
398714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  }
3988e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall
3989e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// isObjCClassType - True if this is equivalent to the 'Class' type,
3990e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// i.e. if its object tive is the primitive 'Class' type with no protocols.
399114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  bool isObjCClassType() const {
3992c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getObjectType()->isObjCUnqualifiedClass();
3993de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff  }
39948d2c0a9814e56c2b22e22d1045181c735aef62fdFariborz Jahanian
3995e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// isObjCQualifiedIdType - True if this is equivalent to 'id<P>' for some
3996e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// non-empty set of protocols.
39971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  bool isObjCQualifiedIdType() const {
3998c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getObjectType()->isObjCQualifiedId();
3999de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff  }
4000e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall
4001e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// isObjCQualifiedClassType - True if this is equivalent to 'Class<P>' for
4002e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// some non-empty set of protocols.
4003470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroff  bool isObjCQualifiedClassType() const {
4004c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getObjectType()->isObjCQualifiedClass();
400514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  }
4006e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall
4007e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// An iterator over the qualifiers on the object type.  Provided
4008e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// for convenience.  This will always iterate over the full set of
4009e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// protocols on a type, not just those provided directly.
4010c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  typedef ObjCObjectType::qual_iterator qual_iterator;
401114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff
401271842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek  qual_iterator qual_begin() const {
4013c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getObjectType()->qual_begin();
401471842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek  }
4015c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  qual_iterator qual_end() const {
4016c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getObjectType()->qual_end();
401771842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek  }
4018c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool qual_empty() const { return getObjectType()->qual_empty(); }
401914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff
4020e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// getNumProtocols - Return the number of qualifying protocols on
4021e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// the object type.
4022c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  unsigned getNumProtocols() const {
4023c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getObjectType()->getNumProtocols();
4024c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  }
402514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff
4026e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// \brief Retrieve a qualifying protocol by index on the object
4027e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// type.
402873dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor  ObjCProtocolDecl *getProtocol(unsigned I) const {
4029c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getObjectType()->getProtocol(I);
403073dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor  }
403173dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor
4032bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
4033bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
4034bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
4035e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  void Profile(llvm::FoldingSetNodeID &ID) {
4036e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall    Profile(ID, getPointeeType());
4037e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  }
4038c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  static void Profile(llvm::FoldingSetNodeID &ID, QualType T) {
4039c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    ID.AddPointer(T.getAsOpaquePtr());
4040c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  }
40411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
40421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == ObjCObjectPointer;
404314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  }
404414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  static bool classof(const ObjCObjectPointerType *) { return true; }
404514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff};
40461bb8a45f7386a23871598d05141a07af03067925Argyrios Kyrtzidis
40470953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// A qualifier set is used to build a set of qualifiers.
40480953e767ff7817f97b3ab20896b229891eeff45bJohn McCallclass QualifierCollector : public Qualifiers {
40490953e767ff7817f97b3ab20896b229891eeff45bJohn McCallpublic:
405049f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  QualifierCollector(Qualifiers Qs = Qualifiers()) : Qualifiers(Qs) {}
40510953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
40520953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// Collect any qualifiers on the given type and return an
40533b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  /// unqualified type.  The qualifiers are assumed to be consistent
40543b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  /// with those already in the type.
40553b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  const Type *strip(QualType type) {
40563b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    addFastQualifiers(type.getLocalFastQualifiers());
40573b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    if (!type.hasLocalNonFastQualifiers())
40583b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall      return type.getTypePtrUnsafe();
40593b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
40603b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    const ExtQuals *extQuals = type.getExtQualsUnsafe();
40613b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    addConsistentQualifiers(extQuals->getQualifiers());
40623b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    return extQuals->getBaseType();
40630953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
40640953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
40650953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// Apply the collected qualifiers to the given type.
40664ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  QualType apply(const ASTContext &Context, QualType QT) const;
40670953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
40680953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// Apply the collected qualifiers to the given type.
40694ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  QualType apply(const ASTContext &Context, const Type* T) const;
40700953e767ff7817f97b3ab20896b229891eeff45bJohn McCall};
40710953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
40720953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
4073611c1fff195d32df97706e0920c92468b2509900Chris Lattner// Inline function definitions.
40745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
40753b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallinline const Type *QualType::getTypePtr() const {
40763b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  return getCommonPtr()->BaseType;
40773b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall}
40783b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
40793b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallinline const Type *QualType::getTypePtrOrNull() const {
40803b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  return (isNull() ? 0 : getCommonPtr()->BaseType);
40813b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall}
40823b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
40833b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallinline SplitQualType QualType::split() const {
40843b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  if (!hasLocalNonFastQualifiers())
40853b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    return SplitQualType(getTypePtrUnsafe(),
40863b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall                         Qualifiers::fromFastMask(getLocalFastQualifiers()));
40873b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
40883b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  const ExtQuals *eq = getExtQualsUnsafe();
40893b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  Qualifiers qs = eq->getQualifiers();
40903b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  qs.addFastQualifiers(getLocalFastQualifiers());
40913b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  return SplitQualType(eq->getBaseType(), qs);
40923b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall}
40933b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
40943b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallinline Qualifiers QualType::getLocalQualifiers() const {
40953b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  Qualifiers Quals;
40963b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  if (hasLocalNonFastQualifiers())
40973b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    Quals = getExtQualsUnsafe()->getQualifiers();
40983b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  Quals.addFastQualifiers(getLocalFastQualifiers());
40993b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  return Quals;
41003b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall}
41013b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
41023b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallinline Qualifiers QualType::getQualifiers() const {
41033b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  Qualifiers quals = getCommonPtr()->CanonicalType.getLocalQualifiers();
41043b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  quals.addFastQualifiers(getLocalFastQualifiers());
41053b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  return quals;
41063b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall}
41073b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
41083b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallinline unsigned QualType::getCVRQualifiers() const {
41093b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  unsigned cvr = getCommonPtr()->CanonicalType.getLocalCVRQualifiers();
41103b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  cvr |= getLocalCVRQualifiers();
41113b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  return cvr;
41123b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall}
41133b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
41143b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallinline QualType QualType::getCanonicalType() const {
41153b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  QualType canon = getCommonPtr()->CanonicalType;
41163b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  return canon.withFastQualifiers(getLocalFastQualifiers());
41173b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall}
41183b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
4119467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCallinline bool QualType::isCanonical() const {
41203b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  return getTypePtr()->isCanonicalUnqualified();
4121467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall}
4122467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall
412354e14c4db764c0636160d26c5bbf491637c83a76John McCallinline bool QualType::isCanonicalAsParam() const {
41243b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  if (!isCanonical()) return false;
4125a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  if (hasLocalQualifiers()) return false;
4126745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian
412754e14c4db764c0636160d26c5bbf491637c83a76John McCall  const Type *T = getTypePtr();
41283b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  if (T->isVariablyModifiedType() && T->hasSizedVLAType())
41293b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    return false;
41303b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
41313b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  return !isa<FunctionType>(T) && !isa<ArrayType>(T);
413254e14c4db764c0636160d26c5bbf491637c83a76John McCall}
413354e14c4db764c0636160d26c5bbf491637c83a76John McCall
4134fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregorinline bool QualType::isConstQualified() const {
4135fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  return isLocalConstQualified() ||
41363b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall         getCommonPtr()->CanonicalType.isLocalConstQualified();
4137fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor}
4138fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor
4139fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregorinline bool QualType::isRestrictQualified() const {
4140fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  return isLocalRestrictQualified() ||
41413b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall         getCommonPtr()->CanonicalType.isLocalRestrictQualified();
4142fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor}
4143fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor
4144fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor
4145fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregorinline bool QualType::isVolatileQualified() const {
4146fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  return isLocalVolatileQualified() ||
41473b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall         getCommonPtr()->CanonicalType.isLocalVolatileQualified();
4148fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor}
4149fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor
4150fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregorinline bool QualType::hasQualifiers() const {
4151fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  return hasLocalQualifiers() ||
41523b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall         getCommonPtr()->CanonicalType.hasLocalQualifiers();
4153fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor}
415462c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall
415562c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCallinline QualType QualType::getUnqualifiedType() const {
415662c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  if (!getTypePtr()->getCanonicalTypeInternal().hasLocalQualifiers())
415762c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall    return QualType(getTypePtr(), 0);
415862c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall
415962c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  return QualType(getSplitUnqualifiedTypeImpl(*this).first, 0);
416062c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall}
416162c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall
416262c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCallinline SplitQualType QualType::getSplitUnqualifiedType() const {
416362c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  if (!getTypePtr()->getCanonicalTypeInternal().hasLocalQualifiers())
416462c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall    return split();
416562c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall
416662c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  return getSplitUnqualifiedTypeImpl(*this);
4167fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor}
4168fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor
416949f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCallinline void QualType::removeLocalConst() {
417049f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  removeLocalFastQualifiers(Qualifiers::Const);
41710953e767ff7817f97b3ab20896b229891eeff45bJohn McCall}
41720953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
417349f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCallinline void QualType::removeLocalRestrict() {
417449f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  removeLocalFastQualifiers(Qualifiers::Restrict);
41750953e767ff7817f97b3ab20896b229891eeff45bJohn McCall}
41760953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
417749f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCallinline void QualType::removeLocalVolatile() {
417849f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  removeLocalFastQualifiers(Qualifiers::Volatile);
41790953e767ff7817f97b3ab20896b229891eeff45bJohn McCall}
41800953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
418149f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCallinline void QualType::removeLocalCVRQualifiers(unsigned Mask) {
41826b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall  assert(!(Mask & ~Qualifiers::CVRMask) && "mask has non-CVR bits");
4183c3c0af36bac3d71f61dd758585ab307892545de4Douglas Gregor  assert((int)Qualifiers::CVRMask == (int)Qualifiers::FastMask);
41840953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
41850953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Fast path: we don't need to touch the slow qualifiers.
418649f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  removeLocalFastQualifiers(Mask);
4187ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb}
4188ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb
4189ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb/// getAddressSpace - Return the address space of this type.
4190ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lambinline unsigned QualType::getAddressSpace() const {
41913b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  return getQualifiers().getAddressSpace();
4192ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb}
4193611c1fff195d32df97706e0920c92468b2509900Chris Lattner
4194d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian/// getObjCGCAttr - Return the gc attribute of this type.
41950953e767ff7817f97b3ab20896b229891eeff45bJohn McCallinline Qualifiers::GC QualType::getObjCGCAttr() const {
41963b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  return getQualifiers().getObjCGCAttr();
4197d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian}
41982455636163fdd18581d7fdae816433f886d88213Mike Stump
4199264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindolainline FunctionType::ExtInfo getFunctionExtInfo(const Type &t) {
4200264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola  if (const PointerType *PT = t.getAs<PointerType>()) {
4201183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall    if (const FunctionType *FT = PT->getPointeeType()->getAs<FunctionType>())
4202264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola      return FT->getExtInfo();
4203264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola  } else if (const FunctionType *FT = t.getAs<FunctionType>())
4204264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    return FT->getExtInfo();
42052455636163fdd18581d7fdae816433f886d88213Mike Stump
4206264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola  return FunctionType::ExtInfo();
42072455636163fdd18581d7fdae816433f886d88213Mike Stump}
42081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4209264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindolainline FunctionType::ExtInfo getFunctionExtInfo(QualType t) {
4210264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola  return getFunctionExtInfo(*t);
4211ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor}
4212ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor
4213e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// isMoreQualifiedThan - Determine whether this type is more
4214e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// qualified than the Other type. For example, "const volatile int"
4215e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// is more qualified than "const int", "volatile int", and
4216e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// "int". However, it is not more qualified than "const volatile
4217e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// int".
421862c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCallinline bool QualType::isMoreQualifiedThan(QualType other) const {
421962c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  Qualifiers myQuals = getQualifiers();
422062c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  Qualifiers otherQuals = other.getQualifiers();
422162c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  return (myQuals != otherQuals && myQuals.compatiblyIncludes(otherQuals));
4222e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor}
4223e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor
4224e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// isAtLeastAsQualifiedAs - Determine whether this type is at last
4225e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// as qualified as the Other type. For example, "const volatile
4226e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// int" is at least as qualified as "const int", "volatile int",
4227e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// "int", and "const volatile int".
422862c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCallinline bool QualType::isAtLeastAsQualifiedAs(QualType other) const {
422962c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  return getQualifiers().compatiblyIncludes(other.getQualifiers());
4230e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor}
4231e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor
4232e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// getNonReferenceType - If Type is a reference type (e.g., const
4233e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// int&), returns the type that the reference refers to ("const
4234e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// int"). Otherwise, returns the type itself. This routine is used
4235e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// throughout Sema to implement C++ 5p6:
4236e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor///
4237e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor///   If an expression initially has the type "reference to T" (8.3.2,
4238e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor///   8.5.3), the type is adjusted to "T" prior to any further
4239e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor///   analysis, the expression designates the object or function
4240e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor///   denoted by the reference, and the expression is an lvalue.
4241e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregorinline QualType QualType::getNonReferenceType() const {
42426217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek  if (const ReferenceType *RefType = (*this)->getAs<ReferenceType>())
4243e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor    return RefType->getPointeeType();
4244e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor  else
4245e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor    return *this;
4246e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor}
4247e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor
4248aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth/// \brief Tests whether the type is categorized as a fundamental type.
4249aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth///
4250aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth/// \returns True for types specified in C++0x [basic.fundamental].
4251aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruthinline bool Type::isFundamentalType() const {
4252aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth  return isVoidType() ||
4253aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth         // FIXME: It's really annoying that we don't have an
4254aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth         // 'isArithmeticType()' which agrees with the standard definition.
4255aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth         (isArithmeticType() && !isEnumeralType());
4256aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth}
4257aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth
4258aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth/// \brief Tests whether the type is categorized as a compound type.
4259aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth///
4260aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth/// \returns True for types specified in C++0x [basic.compound].
4261aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruthinline bool Type::isCompoundType() const {
4262aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth  // C++0x [basic.compound]p1:
4263aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth  //   Compound types can be constructed in the following ways:
4264aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth  //    -- arrays of objects of a given type [...];
4265aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth  return isArrayType() ||
4266aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth  //    -- functions, which have parameters of given types [...];
4267aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth         isFunctionType() ||
4268aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth  //    -- pointers to void or objects or functions [...];
4269aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth         isPointerType() ||
4270aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth  //    -- references to objects or functions of a given type. [...]
4271aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth         isReferenceType() ||
4272aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth  //    -- classes containing a sequence of objects of various types, [...];
4273aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth         isRecordType() ||
4274aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth  //    -- unions, which ar classes capable of containing objects of different types at different times;
4275aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth         isUnionType() ||
4276aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth  //    -- enumerations, which comprise a set of named constant values. [...];
4277aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth         isEnumeralType() ||
4278aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth  //    -- pointers to non-static class members, [...].
4279aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth         isMemberPointerType();
4280aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth}
4281aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth
4282611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isFunctionType() const {
4283a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<FunctionType>(CanonicalType);
4284611c1fff195d32df97706e0920c92468b2509900Chris Lattner}
4285611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isPointerType() const {
4286a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<PointerType>(CanonicalType);
4287611c1fff195d32df97706e0920c92468b2509900Chris Lattner}
428858f9f2c884af6b72d036b746a016d8031d31cb7aSteve Naroffinline bool Type::isAnyPointerType() const {
428958f9f2c884af6b72d036b746a016d8031d31cb7aSteve Naroff  return isPointerType() || isObjCObjectPointerType();
429058f9f2c884af6b72d036b746a016d8031d31cb7aSteve Naroff}
42915618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroffinline bool Type::isBlockPointerType() const {
4292a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<BlockPointerType>(CanonicalType);
42935618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff}
4294bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattnerinline bool Type::isReferenceType() const {
4295a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<ReferenceType>(CanonicalType);
4296bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner}
42977c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlinline bool Type::isLValueReferenceType() const {
4298a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<LValueReferenceType>(CanonicalType);
42997c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl}
43007c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlinline bool Type::isRValueReferenceType() const {
4301a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<RValueReferenceType>(CanonicalType);
43027c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl}
4303498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenekinline bool Type::isFunctionPointerType() const {
4304d0370f59e79702ac908c81bf556519f91e9ca297John McCall  if (const PointerType *T = getAs<PointerType>())
4305498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek    return T->getPointeeType()->isFunctionType();
4306498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek  else
4307498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek    return false;
4308498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek}
4309f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlinline bool Type::isMemberPointerType() const {
4310a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<MemberPointerType>(CanonicalType);
4311f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl}
4312f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlinline bool Type::isMemberFunctionPointerType() const {
43136217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek  if (const MemberPointerType* T = getAs<MemberPointerType>())
43140bab0cdab751248ca389a5592bcb70eac5d39260John McCall    return T->isMemberFunctionPointer();
4315f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  else
4316f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    return false;
4317f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl}
4318db68e28c05a67735211e688009890cf834c22e75Douglas Gregorinline bool Type::isMemberDataPointerType() const {
4319db68e28c05a67735211e688009890cf834c22e75Douglas Gregor  if (const MemberPointerType* T = getAs<MemberPointerType>())
43200bab0cdab751248ca389a5592bcb70eac5d39260John McCall    return T->isMemberDataPointer();
4321db68e28c05a67735211e688009890cf834c22e75Douglas Gregor  else
4322db68e28c05a67735211e688009890cf834c22e75Douglas Gregor    return false;
4323db68e28c05a67735211e688009890cf834c22e75Douglas Gregor}
4324611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isArrayType() const {
4325a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<ArrayType>(CanonicalType);
4326611c1fff195d32df97706e0920c92468b2509900Chris Lattner}
4327c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattnerinline bool Type::isConstantArrayType() const {
4328a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<ConstantArrayType>(CanonicalType);
4329c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner}
4330c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattnerinline bool Type::isIncompleteArrayType() const {
4331a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<IncompleteArrayType>(CanonicalType);
4332c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner}
4333c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattnerinline bool Type::isVariableArrayType() const {
4334a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<VariableArrayType>(CanonicalType);
4335c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner}
4336898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorinline bool Type::isDependentSizedArrayType() const {
4337a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<DependentSizedArrayType>(CanonicalType);
4338898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor}
43393ff83dd534ccc828203670ce3f5125a4eb4199f8John McCallinline bool Type::isBuiltinType() const {
43403ff83dd534ccc828203670ce3f5125a4eb4199f8John McCall  return isa<BuiltinType>(CanonicalType);
43413ff83dd534ccc828203670ce3f5125a4eb4199f8John McCall}
4342611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isRecordType() const {
4343a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<RecordType>(CanonicalType);
4344611c1fff195d32df97706e0920c92468b2509900Chris Lattner}
43453ff83dd534ccc828203670ce3f5125a4eb4199f8John McCallinline bool Type::isEnumeralType() const {
43463ff83dd534ccc828203670ce3f5125a4eb4199f8John McCall  return isa<EnumType>(CanonicalType);
43473ff83dd534ccc828203670ce3f5125a4eb4199f8John McCall}
4348f23d364084d1aabea688222780d6fc1dd8c7f78cChris Lattnerinline bool Type::isAnyComplexType() const {
4349a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<ComplexType>(CanonicalType);
4350f23d364084d1aabea688222780d6fc1dd8c7f78cChris Lattner}
4351611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isVectorType() const {
4352a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<VectorType>(CanonicalType);
4353611c1fff195d32df97706e0920c92468b2509900Chris Lattner}
4354213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begemaninline bool Type::isExtVectorType() const {
4355a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<ExtVectorType>(CanonicalType);
4356611c1fff195d32df97706e0920c92468b2509900Chris Lattner}
4357d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroffinline bool Type::isObjCObjectPointerType() const {
4358a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<ObjCObjectPointerType>(CanonicalType);
4359d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff}
4360c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallinline bool Type::isObjCObjectType() const {
4361c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  return isa<ObjCObjectType>(CanonicalType);
4362368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner}
4363569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregorinline bool Type::isObjCObjectOrInterfaceType() const {
4364569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor  return isa<ObjCInterfaceType>(CanonicalType) ||
4365569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor    isa<ObjCObjectType>(CanonicalType);
4366569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor}
4367569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor
4368a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekinline bool Type::isObjCQualifiedIdType() const {
4369183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>())
4370d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff    return OPT->isObjCQualifiedIdType();
4371d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff  return false;
4372d58fabf7ed279be18a5e82617f809c9deff9be67Fariborz Jahanian}
4373470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroffinline bool Type::isObjCQualifiedClassType() const {
4374183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>())
4375470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroff    return OPT->isObjCQualifiedClassType();
4376470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroff  return false;
4377470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroff}
437814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroffinline bool Type::isObjCIdType() const {
4379183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>())
438014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff    return OPT->isObjCIdType();
438114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  return false;
438214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff}
438314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroffinline bool Type::isObjCClassType() const {
4384183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>())
438514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff    return OPT->isObjCClassType();
438614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  return false;
438714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff}
438813dcd00615de5c4279d97bdf63cd5f0a14fd9dccFariborz Jahanianinline bool Type::isObjCSelType() const {
43898d2c0a9814e56c2b22e22d1045181c735aef62fdFariborz Jahanian  if (const PointerType *OPT = getAs<PointerType>())
43908d2c0a9814e56c2b22e22d1045181c735aef62fdFariborz Jahanian    return OPT->getPointeeType()->isSpecificBuiltinType(BuiltinType::ObjCSel);
439113dcd00615de5c4279d97bdf63cd5f0a14fd9dccFariborz Jahanian  return false;
439213dcd00615de5c4279d97bdf63cd5f0a14fd9dccFariborz Jahanian}
4393de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroffinline bool Type::isObjCBuiltinType() const {
439413dcd00615de5c4279d97bdf63cd5f0a14fd9dccFariborz Jahanian  return isObjCIdType() || isObjCClassType() || isObjCSelType();
4395de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff}
439672c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregorinline bool Type::isTemplateTypeParmType() const {
4397a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<TemplateTypeParmType>(CanonicalType);
439872c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor}
439972c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor
4400e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbarinline bool Type::isSpecificBuiltinType(unsigned K) const {
4401183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  if (const BuiltinType *BT = getAs<BuiltinType>())
4402e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar    if (BT->getKind() == (BuiltinType::Kind) K)
4403e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar      return true;
4404e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar  return false;
4405e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar}
4406e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar
44072a984cad5ac3fdceeff2bd99daa7b90979313475John McCallinline bool Type::isPlaceholderType() const {
44082a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  if (const BuiltinType *BT = getAs<BuiltinType>())
44092a984cad5ac3fdceeff2bd99daa7b90979313475John McCall    return BT->isPlaceholderType();
44102a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  return false;
44112a984cad5ac3fdceeff2bd99daa7b90979313475John McCall}
44122a984cad5ac3fdceeff2bd99daa7b90979313475John McCall
4413864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCallinline bool Type::isSpecificPlaceholderType(unsigned K) const {
4414864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall  if (const BuiltinType *BT = dyn_cast<BuiltinType>(this))
4415864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall    return (BT->getKind() == (BuiltinType::Kind) K);
4416864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall  return false;
4417864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall}
4418864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall
4419063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor/// \brief Determines whether this is a type for which one can define
4420063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor/// an overloaded operator.
4421063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregorinline bool Type::isOverloadableType() const {
4422063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  return isDependentType() || isRecordType() || isEnumeralType();
4423904eed3f6148758d39a2d3c88f3133274460d645Douglas Gregor}
4424904eed3f6148758d39a2d3c88f3133274460d645Douglas Gregor
44258958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbarinline bool Type::hasPointerRepresentation() const {
44268958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar  return (isPointerType() || isReferenceType() || isBlockPointerType() ||
4427c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall          isObjCObjectPointerType() || isNullPtrType());
44288958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar}
44298958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar
4430820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanianinline bool Type::hasObjCPointerRepresentation() const {
4431c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  return isObjCObjectPointerType();
4432820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian}
4433820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian
4434d0370f59e79702ac908c81bf556519f91e9ca297John McCallinline const Type *Type::getBaseElementTypeUnsafe() const {
4435d0370f59e79702ac908c81bf556519f91e9ca297John McCall  const Type *type = this;
4436d0370f59e79702ac908c81bf556519f91e9ca297John McCall  while (const ArrayType *arrayType = type->getAsArrayTypeUnsafe())
4437d0370f59e79702ac908c81bf556519f91e9ca297John McCall    type = arrayType->getElementType().getTypePtr();
4438d0370f59e79702ac908c81bf556519f91e9ca297John McCall  return type;
4439d0370f59e79702ac908c81bf556519f91e9ca297John McCall}
4440d0370f59e79702ac908c81bf556519f91e9ca297John McCall
444122caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner/// Insertion operator for diagnostics.  This allows sending QualType's into a
444222caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner/// diagnostic with <<.
444322caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattnerinline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
444422caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner                                           QualType T) {
444522caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner  DB.AddTaggedVal(reinterpret_cast<intptr_t>(T.getAsOpaquePtr()),
444622caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner                  Diagnostic::ak_qualtype);
444722caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner  return DB;
444822caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner}
44491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
445047c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth/// Insertion operator for partial diagnostics.  This allows sending QualType's
445147c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth/// into a diagnostic with <<.
445247c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruthinline const PartialDiagnostic &operator<<(const PartialDiagnostic &PD,
445347c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth                                           QualType T) {
445447c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth  PD.AddTaggedVal(reinterpret_cast<intptr_t>(T.getAsOpaquePtr()),
445547c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth                  Diagnostic::ak_qualtype);
445647c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth  return PD;
445747c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth}
445847c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth
445989c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor// Helper class template that is used by Type::getAs to ensure that one does
446089c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor// not try to look through a qualified type to get to an array type.
446189c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregortemplate<typename T,
446289c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor         bool isArrayType = (llvm::is_same<T, ArrayType>::value ||
446389c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor                             llvm::is_base_of<ArrayType, T>::value)>
446489c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregorstruct ArrayType_cannot_be_used_with_getAs { };
446589c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor
446689c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregortemplate<typename T>
446789c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregorstruct ArrayType_cannot_be_used_with_getAs<T, true>;
446889c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor
44691a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek/// Member-template getAs<specific type>'.
44701a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenektemplate <typename T> const T *Type::getAs() const {
447189c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor  ArrayType_cannot_be_used_with_getAs<T> at;
447289c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor  (void)at;
447389c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor
44741a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek  // If this is directly a T type, return it.
44751a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek  if (const T *Ty = dyn_cast<T>(this))
44761a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek    return Ty;
44771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
44781a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek  // If the canonical form of this type isn't the right kind, reject it.
44790953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  if (!isa<T>(CanonicalType))
44801a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek    return 0;
44811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
44820953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // If this is a typedef for the type, strip the typedef off without
44831a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek  // losing all typedef information.
4484bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  return cast<T>(getUnqualifiedDesugaredType());
44851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump}
448622caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner
44873b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallinline const ArrayType *Type::getAsArrayTypeUnsafe() const {
44883b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  // If this is directly an array type, return it.
44893b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  if (const ArrayType *arr = dyn_cast<ArrayType>(this))
44903b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    return arr;
44913b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
44923b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  // If the canonical form of this type isn't the right kind, reject it.
44933b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  if (!isa<ArrayType>(CanonicalType))
44943b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    return 0;
44953b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
44963b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  // If this is a typedef for the type, strip the typedef off without
44973b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  // losing all typedef information.
44983b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  return cast<ArrayType>(getUnqualifiedDesugaredType());
44993b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall}
45003b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
4501d0370f59e79702ac908c81bf556519f91e9ca297John McCalltemplate <typename T> const T *Type::castAs() const {
4502d0370f59e79702ac908c81bf556519f91e9ca297John McCall  ArrayType_cannot_be_used_with_getAs<T> at;
4503d0370f59e79702ac908c81bf556519f91e9ca297John McCall  (void) at;
4504d0370f59e79702ac908c81bf556519f91e9ca297John McCall
4505d0370f59e79702ac908c81bf556519f91e9ca297John McCall  assert(isa<T>(CanonicalType));
4506d0370f59e79702ac908c81bf556519f91e9ca297John McCall  if (const T *ty = dyn_cast<T>(this)) return ty;
4507d0370f59e79702ac908c81bf556519f91e9ca297John McCall  return cast<T>(getUnqualifiedDesugaredType());
4508d0370f59e79702ac908c81bf556519f91e9ca297John McCall}
4509d0370f59e79702ac908c81bf556519f91e9ca297John McCall
4510d0370f59e79702ac908c81bf556519f91e9ca297John McCallinline const ArrayType *Type::castAsArrayTypeUnsafe() const {
4511d0370f59e79702ac908c81bf556519f91e9ca297John McCall  assert(isa<ArrayType>(CanonicalType));
4512d0370f59e79702ac908c81bf556519f91e9ca297John McCall  if (const ArrayType *arr = dyn_cast<ArrayType>(this)) return arr;
4513d0370f59e79702ac908c81bf556519f91e9ca297John McCall  return cast<ArrayType>(getUnqualifiedDesugaredType());
4514d0370f59e79702ac908c81bf556519f91e9ca297John McCall}
4515d0370f59e79702ac908c81bf556519f91e9ca297John McCall
45165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}  // end namespace clang
45175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
45185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif
4519