Type.h revision 2234873111009eb8655d63362cedc422eb9fc517
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;
765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class TypedefDecl;
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
302b87786f045d798b070980c108c922e1475d27b15Douglas Gregor  bool isSupersetOf(Qualifiers Other) const;
303b87786f045d798b070980c108c922e1475d27b15Douglas Gregor
3040953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool operator==(Qualifiers Other) const { return Mask == Other.Mask; }
3050953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool operator!=(Qualifiers Other) const { return Mask != Other.Mask; }
3060953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3070953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  operator bool() const { return hasQualifiers(); }
3080953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3090953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  Qualifiers &operator+=(Qualifiers R) {
3100953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    addQualifiers(R);
3110953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return *this;
3120953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
3130953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3140953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Union two qualifier sets.  If an enumerated qualifier appears
3150953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // in both sets, use the one from the right.
3160953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  friend Qualifiers operator+(Qualifiers L, Qualifiers R) {
3170953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    L += R;
3180953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return L;
3190953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
3203cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor
3213cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor  Qualifiers &operator-=(Qualifiers R) {
3223cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor    Mask = Mask & ~(R.Mask);
3233cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor    return *this;
3243cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor  }
3250953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3263cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor  /// \brief Compute the difference between two qualifier sets.
3273cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor  friend Qualifiers operator-(Qualifiers L, Qualifiers R) {
3283cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor    L -= R;
3293cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor    return L;
3303cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor  }
3313cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor
3320953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  std::string getAsString() const;
3330953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  std::string getAsString(const PrintingPolicy &Policy) const {
3340953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    std::string Buffer;
3350953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    getAsStringInternal(Buffer, Policy);
3360953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return Buffer;
3370953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
3380953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void getAsStringInternal(std::string &S, const PrintingPolicy &Policy) const;
3390953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3400953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void Profile(llvm::FoldingSetNodeID &ID) const {
3410953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    ID.AddInteger(Mask);
3420953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
3430953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3440953e767ff7817f97b3ab20896b229891eeff45bJohn McCallprivate:
3450953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3460953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // bits:     |0 1 2|3 .. 4|5  ..  31|
3470953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  //           |C R V|GCAttr|AddrSpace|
3480953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  uint32_t Mask;
3490953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3500953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  static const uint32_t GCAttrMask = 0x18;
3510953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  static const uint32_t GCAttrShift = 3;
3520953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  static const uint32_t AddressSpaceMask = ~(CVRMask | GCAttrMask);
3530953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  static const uint32_t AddressSpaceShift = 5;
3540953e767ff7817f97b3ab20896b229891eeff45bJohn McCall};
3550953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
356ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor/// CallingConv - Specifies the calling convention that a function uses.
357ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregorenum CallingConv {
358ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor  CC_Default,
359ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor  CC_C,           // __attribute__((cdecl))
360ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor  CC_X86StdCall,  // __attribute__((stdcall))
361f813a2c03fcb05381b3252010435f557eb6b3cdeDouglas Gregor  CC_X86FastCall, // __attribute__((fastcall))
36252fc314e1b5e1baee6305067cf831763d02bd243Dawn Perchik  CC_X86ThisCall, // __attribute__((thiscall))
3639c6082fe89c61af697f017aa80937581cc2128d8Tilmann Scheller  CC_X86Pascal    // __attribute__((pascal))
364ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor};
365ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor
36649f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCalltypedef std::pair<const Type*, Qualifiers> SplitQualType;
3670953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3680953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// QualType - For efficiency, we don't store CV-qualified types as nodes on
3690953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// their own: instead each reference to a type stores the qualifiers.  This
3700953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// greatly reduces the number of nodes we need to allocate for types (for
3710953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// example we only need one for 'int', 'const int', 'volatile int',
3720953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// 'const volatile int', etc).
3730953e767ff7817f97b3ab20896b229891eeff45bJohn McCall///
3740953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// As an added efficiency bonus, instead of making this a pair, we
3750953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// just store the two bits we care about in the low bits of the
3760953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// pointer.  To handle the packing/unpacking, we make QualType be a
3770953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// simple wrapper class that acts like a smart pointer.  A third bit
3780953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// indicates whether there are extended qualifiers present, in which
3790953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// case the pointer points to a special structure.
3800953e767ff7817f97b3ab20896b229891eeff45bJohn McCallclass QualType {
3810953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Thankfully, these are efficiently composable.
3820953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  llvm::PointerIntPair<llvm::PointerUnion<const Type*,const ExtQuals*>,
3830953e767ff7817f97b3ab20896b229891eeff45bJohn McCall                       Qualifiers::FastWidth> Value;
3840953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3850953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  const ExtQuals *getExtQualsUnsafe() const {
3860953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return Value.getPointer().get<const ExtQuals*>();
3870953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
3880953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3890953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  const Type *getTypePtrUnsafe() const {
3900953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return Value.getPointer().get<const Type*>();
3910953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
3920953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3933b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  const ExtQualsTypeCommonBase *getCommonPtr() const {
3943b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    assert(!isNull() && "Cannot retrieve a NULL type pointer");
3953b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    uintptr_t CommonPtrVal
3963b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall      = reinterpret_cast<uintptr_t>(Value.getOpaqueValue());
3973b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    CommonPtrVal &= ~(uintptr_t)((1 << TypeAlignmentInBits) - 1);
3983b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    return reinterpret_cast<ExtQualsTypeCommonBase*>(CommonPtrVal);
3993b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  }
4003b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
4010953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  friend class QualifierCollector;
4020953e767ff7817f97b3ab20896b229891eeff45bJohn McCallpublic:
4035cf243a883872441d73ca49cea7e20de5802629bChris Lattner  QualType() {}
4041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4055cf243a883872441d73ca49cea7e20de5802629bChris Lattner  QualType(const Type *Ptr, unsigned Quals)
4060953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    : Value(Ptr, Quals) {}
4070953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  QualType(const ExtQuals *Ptr, unsigned Quals)
4080953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    : Value(Ptr, Quals) {}
4090953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
410a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  unsigned getLocalFastQualifiers() const { return Value.getInt(); }
411a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  void setLocalFastQualifiers(unsigned Quals) { Value.setInt(Quals); }
4125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4130953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// Retrieves a pointer to the underlying (unqualified) type.
4140953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// This should really return a const Type, but it's not worth
4150953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// changing all the users right now.
4161ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor  ///
4171ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor  /// This function requires that the type not be NULL. If the type might be
4181ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor  /// NULL, use the (slightly less efficient) \c getTypePtrOrNull().
4193b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  const Type *getTypePtr() const;
4201ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor
4213b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  const Type *getTypePtrOrNull() const;
4221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
42349f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  /// Divides a QualType into its unqualified type and a set of local
42449f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  /// qualifiers.
4253b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  SplitQualType split() const;
42649f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall
4275cf243a883872441d73ca49cea7e20de5802629bChris Lattner  void *getAsOpaquePtr() const { return Value.getOpaqueValue(); }
428f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  static QualType getFromOpaquePtr(const void *Ptr) {
4295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    QualType T;
430f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall    T.Value.setFromOpaqueValue(const_cast<void*>(Ptr));
4315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T;
4325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
4331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
434f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const Type &operator*() const {
4355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return *getTypePtr();
4365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
4375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
438f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const Type *operator->() const {
4395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return getTypePtr();
4405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
4411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
442467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall  bool isCanonical() const;
44354e14c4db764c0636160d26c5bbf491637c83a76John McCall  bool isCanonicalAsParam() const;
444467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall
4455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isNull - Return true if this QualType doesn't point to a type yet.
4465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isNull() const {
4470953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return Value.getPointer().isNull();
4485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
4495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
450a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Determine whether this particular QualType instance has the
451a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// "const" qualifier set, without looking through typedefs that may have
452a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// added "const" at a different level.
453a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  bool isLocalConstQualified() const {
454a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor    return (getLocalFastQualifiers() & Qualifiers::Const);
4550953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
456a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor
457a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Determine whether this type is const-qualified.
458fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  bool isConstQualified() const;
459a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor
460a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Determine whether this particular QualType instance has the
461a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// "restrict" qualifier set, without looking through typedefs that may have
462a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// added "restrict" at a different level.
463a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  bool isLocalRestrictQualified() const {
464a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor    return (getLocalFastQualifiers() & Qualifiers::Restrict);
465a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  }
466a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor
467a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Determine whether this type is restrict-qualified.
468fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  bool isRestrictQualified() const;
469a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor
470a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Determine whether this particular QualType instance has the
471a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// "volatile" qualifier set, without looking through typedefs that may have
472a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// added "volatile" at a different level.
473a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  bool isLocalVolatileQualified() const {
474f7616b9067790757f4e12e834b216c53c8c04ebeDouglas Gregor    return (getLocalFastQualifiers() & Qualifiers::Volatile);
4755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
4760953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
477a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Determine whether this type is volatile-qualified.
478fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  bool isVolatileQualified() const;
479a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor
480a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Determine whether this particular QualType instance has any
481a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// qualifiers, without looking through any typedefs that might add
482a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// qualifiers at a different level.
483a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  bool hasLocalQualifiers() const {
484a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor    return getLocalFastQualifiers() || hasLocalNonFastQualifiers();
4850953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
4860953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
487a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Determine whether this type has any qualifiers.
488fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  bool hasQualifiers() const;
489a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor
490a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Determine whether this particular QualType instance has any
491a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// "non-fast" qualifiers, e.g., those that are stored in an ExtQualType
492a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// instance.
493a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  bool hasLocalNonFastQualifiers() const {
494a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor    return Value.getPointer().is<const ExtQuals*>();
4950953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
4960953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
497a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Retrieve the set of qualifiers local to this particular QualType
498a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// instance, not including any qualifiers acquired through typedefs or
499a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// other sugar.
5003b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  Qualifiers getLocalQualifiers() const;
5010953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
502a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Retrieve the set of qualifiers applied to this type.
503fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  Qualifiers getQualifiers() const;
504a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor
505a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Retrieve the set of CVR (const-volatile-restrict) qualifiers
506a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// local to this particular QualType instance, not including any qualifiers
507a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// acquired through typedefs or other sugar.
508a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  unsigned getLocalCVRQualifiers() const {
509f7616b9067790757f4e12e834b216c53c8c04ebeDouglas Gregor    return getLocalFastQualifiers();
5105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
511b381aac9bae6d608c72267dd0ed08ec6369e94e4Nuno Lopes
512a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Retrieve the set of CVR (const-volatile-restrict) qualifiers
513a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// applied to this type.
514fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  unsigned getCVRQualifiers() const;
515e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth
516bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isConstant(ASTContext& Ctx) const {
517bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall    return QualType::isConstant(*this, Ctx);
518bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  }
5191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5200953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Don't promise in the API that anything besides 'const' can be
5210953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // easily added.
5220953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
5230953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// addConst - add the specified type qualifier to this QualType.
5240953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void addConst() {
5250953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    addFastQualifiers(Qualifiers::Const);
5260953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
5270953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  QualType withConst() const {
5280953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return withFastQualifiers(Qualifiers::Const);
5290953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
5300953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
5310953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void addFastQualifiers(unsigned TQs) {
5320953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(!(TQs & ~Qualifiers::FastMask)
5330953e767ff7817f97b3ab20896b229891eeff45bJohn McCall           && "non-fast qualifier bits set in mask!");
5340953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Value.setInt(Value.getInt() | TQs);
5350953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
5360953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
53749f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  void removeLocalConst();
53849f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  void removeLocalVolatile();
53949f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  void removeLocalRestrict();
54049f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  void removeLocalCVRQualifiers(unsigned Mask);
5410953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
54249f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  void removeLocalFastQualifiers() { Value.setInt(0); }
54349f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  void removeLocalFastQualifiers(unsigned Mask) {
5440953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(!(Mask & ~Qualifiers::FastMask) && "mask has non-fast qualifiers");
5450953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Value.setInt(Value.getInt() & ~Mask);
5460953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
5475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
5480953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Creates a type with the given qualifiers in addition to any
5490953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // qualifiers already on this type.
5500953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  QualType withFastQualifiers(unsigned TQs) const {
5510953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    QualType T = *this;
5520953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    T.addFastQualifiers(TQs);
5530953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return T;
5540953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
5551c6a38bcea17801e9a4738753aee845381af2b6cSanjiv Gupta
5560953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Creates a type with exactly the given fast qualifiers, removing
5570953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // any existing fast qualifiers.
55849f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  QualType withExactLocalFastQualifiers(unsigned TQs) const {
55949f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall    return withoutLocalFastQualifiers().withFastQualifiers(TQs);
5605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
5610953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
5620953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Removes fast qualifiers, but leaves any extended qualifiers in place.
56349f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  QualType withoutLocalFastQualifiers() const {
5640953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    QualType T = *this;
56549f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall    T.removeLocalFastQualifiers();
5660953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return T;
567c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  }
568971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis
5693b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  QualType getCanonicalType() const;
5703b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
571a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Return this type with all of the instance-specific qualifiers
572a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// removed, but without removing any qualifiers that may have been applied
573a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// through typedefs.
574a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  QualType getLocalUnqualifiedType() const { return QualType(getTypePtr(), 0); }
5751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
57662c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// \brief Retrieve the unqualified variant of the given type,
57762c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// removing as little sugar as possible.
57862c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  ///
57962c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// This routine looks through various kinds of sugar to find the
58062c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// least-desugared type that is unqualified. For example, given:
58162c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  ///
58262c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// \code
58362c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// typedef int Integer;
58462c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// typedef const Integer CInteger;
58562c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// typedef CInteger DifferenceType;
58662c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// \endcode
58762c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  ///
58862c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// Executing \c getUnqualifiedType() on the type \c DifferenceType will
58962c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// desugar until we hit the type \c Integer, which has no qualifiers on it.
59062c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  ///
59162c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// The resulting type might still be qualified if it's an array
59262c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// type.  To strip qualifiers even from within an array type, use
59362c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// ASTContext::getUnqualifiedArrayType.
59462c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  inline QualType getUnqualifiedType() const;
59562c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall
59662c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// getSplitUnqualifiedType - Retrieve the unqualified variant of the
59762c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// given type, removing as little sugar as possible.
59862c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  ///
59962c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// Like getUnqualifiedType(), but also returns the set of
60062c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// qualifiers that were built up.
60162c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  ///
60262c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// The resulting type might still be qualified if it's an array
60362c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// type.  To strip qualifiers even from within an array type, use
60462c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// ASTContext::getUnqualifiedArrayType.
60562c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  inline SplitQualType getSplitUnqualifiedType() const;
606a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor
607e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor  bool isMoreQualifiedThan(QualType Other) const;
608e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor  bool isAtLeastAsQualifiedAs(QualType Other) const;
609e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor  QualType getNonReferenceType() const;
6101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6116398235d7890a81b785ea5af3b6e66d86bf184ccDouglas Gregor  /// \brief Determine the type of a (typically non-lvalue) expression with the
6126398235d7890a81b785ea5af3b6e66d86bf184ccDouglas Gregor  /// specified result type.
6135291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor  ///
6146398235d7890a81b785ea5af3b6e66d86bf184ccDouglas Gregor  /// This routine should be used for expressions for which the return type is
6156398235d7890a81b785ea5af3b6e66d86bf184ccDouglas Gregor  /// explicitly specified (e.g., in a cast or call) and isn't necessarily
6166398235d7890a81b785ea5af3b6e66d86bf184ccDouglas Gregor  /// an lvalue. It removes a top-level reference (since there are no
6175291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor  /// expressions of reference type) and deletes top-level cvr-qualifiers
6185291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor  /// from non-class types (in C++) or all types (in C).
6196398235d7890a81b785ea5af3b6e66d86bf184ccDouglas Gregor  QualType getNonLValueExprType(ASTContext &Context) const;
6205291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor
6212fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner  /// getDesugaredType - Return the specified type with any "sugar" removed from
6222fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner  /// the type.  This takes off typedefs, typeof's etc.  If the outer level of
6232fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner  /// the type is already concrete, it returns it unmodified.  This is similar
6242fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner  /// to getting the canonical type, but it doesn't remove *all* typedefs.  For
6252fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner  /// example, it returns "T*" as "T*", (not as "int*"), because the pointer is
6262fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner  /// concrete.
6270953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  ///
6280953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// Qualifiers are left in place.
6294ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  QualType getDesugaredType(const ASTContext &Context) const {
63049f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall    return getDesugaredType(*this, Context);
63149f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  }
63249f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall
63349f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  SplitQualType getSplitDesugaredType() const {
63449f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall    return getSplitDesugaredType(*this);
635bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  }
63698cd599ee8a9b259ed7388ee2921a20d97658864Douglas Gregor
637075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  /// IgnoreParens - Returns the specified type after dropping any
638075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  /// outer-level parentheses.
639075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  QualType IgnoreParens() const {
640723df245307a530da5433dfb43accf187dc3e243Abramo Bagnara    if (isa<ParenType>(*this))
641723df245307a530da5433dfb43accf187dc3e243Abramo Bagnara      return QualType::IgnoreParens(*this);
642723df245307a530da5433dfb43accf187dc3e243Abramo Bagnara    return *this;
643075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  }
644075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
6455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// operator==/!= - Indicate whether the specified types and qualifiers are
6465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// identical.
64750d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor  friend bool operator==(const QualType &LHS, const QualType &RHS) {
64850d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor    return LHS.Value == RHS.Value;
6495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
65050d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor  friend bool operator!=(const QualType &LHS, const QualType &RHS) {
65150d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor    return LHS.Value != RHS.Value;
6525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
65349f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  std::string getAsString() const {
65449f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall    return getAsString(split());
65549f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  }
65649f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  static std::string getAsString(SplitQualType split) {
65749f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall    return getAsString(split.first, split.second);
65849f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  }
65949f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  static std::string getAsString(const Type *ty, Qualifiers qs);
660d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor
661d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor  std::string getAsString(const PrintingPolicy &Policy) const {
6625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    std::string S;
663d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor    getAsStringInternal(S, Policy);
6645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return S;
6655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
666e4f2142d00fa5fdb580c4e2413da91882d955381Chris Lattner  void getAsStringInternal(std::string &Str,
66749f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall                           const PrintingPolicy &Policy) const {
66849f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall    return getAsStringInternal(split(), Str, Policy);
66949f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  }
67049f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  static void getAsStringInternal(SplitQualType split, std::string &out,
67149f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall                                  const PrintingPolicy &policy) {
67249f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall    return getAsStringInternal(split.first, split.second, out, policy);
67349f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  }
67449f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  static void getAsStringInternal(const Type *ty, Qualifiers qs,
67549f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall                                  std::string &out,
67649f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall                                  const PrintingPolicy &policy);
6771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
678c36d405a02fab41f6c45cb2bc750d64949742903Chris Lattner  void dump(const char *s) const;
679c36d405a02fab41f6c45cb2bc750d64949742903Chris Lattner  void dump() const;
6801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6813f2dcb1ca8bd2d5d3ccc5c80f4ab06f949d88a89Ted Kremenek  void Profile(llvm::FoldingSetNodeID &ID) const {
6823f2dcb1ca8bd2d5d3ccc5c80f4ab06f949d88a89Ted Kremenek    ID.AddPointer(getAsOpaquePtr());
6833f2dcb1ca8bd2d5d3ccc5c80f4ab06f949d88a89Ted Kremenek  }
6845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
685ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb  /// getAddressSpace - Return the address space of this type.
686ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb  inline unsigned getAddressSpace() const;
6871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
688d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian  /// GCAttrTypesAttr - Returns gc attribute of this type.
6890953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  inline Qualifiers::GC getObjCGCAttr() const;
690f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian
691f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian  /// isObjCGCWeak true when Type is objc's weak.
692f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian  bool isObjCGCWeak() const {
6930953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return getObjCGCAttr() == Qualifiers::Weak;
694f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian  }
695f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian
696f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian  /// isObjCGCStrong true when Type is objc's strong.
697f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian  bool isObjCGCStrong() const {
6980953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return getObjCGCAttr() == Qualifiers::Strong;
699f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian  }
7002455636163fdd18581d7fdae816433f886d88213Mike Stump
7010d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall  enum DestructionKind {
7020d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall    DK_none,
7030d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall    DK_cxx_destructor
7040d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall  };
7050d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall
7060d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall  /// isDestructedType - nonzero if objects of this type require
7070d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall  /// non-trivial work to clean up after.  Non-zero because it's
7080d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall  /// conceivable that qualifiers (objc_gc(weak)?) could make
7090d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall  /// something require destruction.
7100d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall  DestructionKind isDestructedType() const {
7110d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall    return isDestructedTypeImpl(*this);
7120d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall  }
7130d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall
714bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCallprivate:
715bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  // These methods are implemented in a separate translation unit;
716bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  // "static"-ize them to avoid creating temporary QualTypes in the
717bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  // caller.
718bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  static bool isConstant(QualType T, ASTContext& Ctx);
7194ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  static QualType getDesugaredType(QualType T, const ASTContext &Context);
72049f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  static SplitQualType getSplitDesugaredType(QualType T);
72162c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  static SplitQualType getSplitUnqualifiedTypeImpl(QualType type);
722075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  static QualType IgnoreParens(QualType T);
7230d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall  static DestructionKind isDestructedTypeImpl(QualType type);
7245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
7255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end clang.
7275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace llvm {
7295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Implement simplify_type for QualType, so that we can dyn_cast from QualType
7305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// to a specific Type class.
7315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencertemplate<> struct simplify_type<const ::clang::QualType> {
732f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  typedef const ::clang::Type *SimpleType;
7335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static SimpleType getSimplifiedValue(const ::clang::QualType &Val) {
7344472fc641ea3069463798fb56a04043c28ea2910Douglas Gregor    return Val.getTypePtr();
7355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
7365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
7375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencertemplate<> struct simplify_type< ::clang::QualType>
7385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  : public simplify_type<const ::clang::QualType> {};
7391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7404e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner// Teach SmallPtrSet that QualType is "basically a pointer".
7414e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattnertemplate<>
742daae940507f2e93c6fa12e8062fa958e34cc2d1cChris Lattnerclass PointerLikeTypeTraits<clang::QualType> {
7434e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattnerpublic:
7444e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner  static inline void *getAsVoidPointer(clang::QualType P) {
7454e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner    return P.getAsOpaquePtr();
7464e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner  }
7474e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner  static inline clang::QualType getFromVoidPointer(void *P) {
7484e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner    return clang::QualType::getFromOpaquePtr(P);
7494e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner  }
7500953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Various qualifiers go in low bits.
7510eda3b31a672ea486fa92b9bc49a2c91be856b53Chris Lattner  enum { NumLowBitsAvailable = 0 };
7524e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner};
7531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
75473af669633e13c813f80cd15ecf3e6414778aee4Ted Kremenek} // end namespace llvm
7555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang {
7575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7583b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// \brief Base class that is common to both the \c ExtQuals and \c Type
7593b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// classes, which allows \c QualType to access the common fields between the
7603b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// two.
7613b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall///
7623b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallclass ExtQualsTypeCommonBase {
7633b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  ExtQualsTypeCommonBase(const Type *baseType, QualType canon)
7643b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    : BaseType(baseType), CanonicalType(canon) {}
7653b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
7663b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  /// \brief The "base" type of an extended qualifiers type (\c ExtQuals) or
7673b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  /// a self-referential pointer (for \c Type).
7683b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  ///
7693b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  /// This pointer allows an efficient mapping from a QualType to its
7703b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  /// underlying type pointer.
7713b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  const Type *const BaseType;
7723b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
7733b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  /// \brief The canonical type of this type.  A QualType.
7743b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  QualType CanonicalType;
7753b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
7763b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  friend class QualType;
7773b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  friend class Type;
7783b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  friend class ExtQuals;
7793b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall};
7803b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
7813b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// ExtQuals - We can encode up to four bits in the low bits of a
7823b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// type pointer, but there are many more type qualifiers that we want
7833b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// to be able to apply to an arbitrary type.  Therefore we have this
7843b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// struct, intended to be heap-allocated and used by QualType to
7853b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// store qualifiers.
7863b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall///
7873b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// The current design tags the 'const', 'restrict', and 'volatile' qualifiers
7883b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// in three low bits on the QualType pointer; a fourth bit records whether
7893b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// the pointer is an ExtQuals node. The extended qualifiers (address spaces,
7903b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// Objective-C GC attributes) are much more rare.
7913b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallclass ExtQuals : public ExtQualsTypeCommonBase, public llvm::FoldingSetNode {
7923b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  // NOTE: changing the fast qualifiers should be straightforward as
7933b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  // long as you don't make 'const' non-fast.
7943b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  // 1. Qualifiers:
7953b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  //    a) Modify the bitmasks (Qualifiers::TQ and DeclSpec::TQ).
7963b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  //       Fast qualifiers must occupy the low-order bits.
7973b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  //    b) Update Qualifiers::FastWidth and FastMask.
7983b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  // 2. QualType:
7993b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  //    a) Update is{Volatile,Restrict}Qualified(), defined inline.
8003b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  //    b) Update remove{Volatile,Restrict}, defined near the end of
8013b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  //       this header.
8023b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  // 3. ASTContext:
8033b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  //    a) Update get{Volatile,Restrict}Type.
8043b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
8053b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  /// Quals - the immutable set of qualifiers applied by this
8063b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  /// node;  always contains extended qualifiers.
8073b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  Qualifiers Quals;
8083b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
8093b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  ExtQuals *this_() { return this; }
8103b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
8113b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallpublic:
8123b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  ExtQuals(const Type *baseType, QualType canon, Qualifiers quals)
8133b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    : ExtQualsTypeCommonBase(baseType,
8143b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall                             canon.isNull() ? QualType(this_(), 0) : canon),
8153b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall      Quals(quals)
8163b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  {
8173b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    assert(Quals.hasNonFastQualifiers()
8183b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall           && "ExtQuals created with no fast qualifiers");
8193b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    assert(!Quals.hasFastQualifiers()
8203b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall           && "ExtQuals created with fast qualifiers");
8213b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  }
8223b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
8233b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  Qualifiers getQualifiers() const { return Quals; }
8243b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
8253b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  bool hasObjCGCAttr() const { return Quals.hasObjCGCAttr(); }
8263b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  Qualifiers::GC getObjCGCAttr() const { return Quals.getObjCGCAttr(); }
8273b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
8283b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  bool hasAddressSpace() const { return Quals.hasAddressSpace(); }
8293b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  unsigned getAddressSpace() const { return Quals.getAddressSpace(); }
8303b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
8313b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  const Type *getBaseType() const { return BaseType; }
8323b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
8333b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallpublic:
8343b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  void Profile(llvm::FoldingSetNodeID &ID) const {
8353b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    Profile(ID, getBaseType(), Quals);
8363b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  }
8373b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  static void Profile(llvm::FoldingSetNodeID &ID,
8383b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall                      const Type *BaseType,
8393b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall                      Qualifiers Quals) {
8403b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    assert(!Quals.hasFastQualifiers() && "fast qualifiers in ExtQuals hash!");
8413b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    ID.AddPointer(BaseType);
8423b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    Quals.Profile(ID);
8433b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  }
8443b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall};
8453b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
846c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor/// \brief The kind of C++0x ref-qualifier associated with a function type,
847c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor/// which determines whether a member function's "this" object can be an
848c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor/// lvalue, rvalue, or neither.
849c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregorenum RefQualifierKind {
850c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor  /// \brief No ref-qualifier was provided.
851c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor  RQ_None = 0,
852c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor  /// \brief An lvalue ref-qualifier was provided (\c &).
853c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor  RQ_LValue,
854c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor  /// \brief An rvalue ref-qualifier was provided (\c &&).
855c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor  RQ_RValue
856c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor};
857c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor
8585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Type - This is the base class of the type hierarchy.  A central concept
8595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// with types is that each type always has a canonical type.  A canonical type
8605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// is the type with any typedef names stripped out of it or the types it
8615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// references.  For example, consider:
8625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
8635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///  typedef int  foo;
8645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///  typedef foo* bar;
8655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///    'int *'    'foo *'    'bar'
8665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
8675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// There will be a Type object created for 'int'.  Since int is canonical, its
8685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// canonicaltype pointer points to itself.  There is also a Type for 'foo' (a
86972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// TypedefType).  Its CanonicalType pointer points to the 'int' Type.  Next
8705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// there is a PointerType that represents 'int*', which, like 'int', is
8715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// canonical.  Finally, there is a PointerType type for 'foo*' whose canonical
87272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// type is 'int*', and there is a TypedefType for 'bar', whose canonical type
8735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// is also 'int*'.
8745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
8755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Non-canonical types are useful for emitting diagnostics, without losing
8765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// information about typedefs being used.  Canonical types are useful for type
8775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// comparisons (they allow by-pointer equality tests) and useful for reasoning
8785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// about whether something has a particular form (e.g. is a function type),
8795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// because they implicitly, recursively, strip all typedefs out of a type.
8805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
8815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Types, once created, are immutable.
8825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
8831ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregorclass Type : public ExtQualsTypeCommonBase {
8845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
8855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  enum TypeClass {
88672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#define TYPE(Class, Base) Class,
88727935ee59c30b0d8b610ab676aab8e65350af932John McCall#define LAST_TYPE(Class) TypeLast = Class,
88872564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#define ABSTRACT_TYPE(Class, Base)
88972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#include "clang/AST/TypeNodes.def"
89072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor    TagFirst = Record, TagLast = Enum
8915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
8921bb8a45f7386a23871598d05141a07af03067925Argyrios Kyrtzidis
8935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate:
894c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  Type(const Type&);           // DO NOT IMPLEMENT.
895c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  void operator=(const Type&); // DO NOT IMPLEMENT.
896c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
897b870b88df784c2940efce448ebfaf54dece14666John McCall  /// Bitfields required by the Type class.
898b870b88df784c2940efce448ebfaf54dece14666John McCall  class TypeBitfields {
899b870b88df784c2940efce448ebfaf54dece14666John McCall    friend class Type;
900b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall    template <class T> friend class TypePropertyCache;
90127935ee59c30b0d8b610ab676aab8e65350af932John McCall
902b870b88df784c2940efce448ebfaf54dece14666John McCall    /// TypeClass bitfield - Enum that specifies what subclass this belongs to.
903b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned TC : 8;
904b870b88df784c2940efce448ebfaf54dece14666John McCall
905b870b88df784c2940efce448ebfaf54dece14666John McCall    /// Dependent - Whether this type is a dependent type (C++ [temp.dep.type]).
906b870b88df784c2940efce448ebfaf54dece14666John McCall    /// Note that this should stay at the end of the ivars for Type so that
907b870b88df784c2940efce448ebfaf54dece14666John McCall    /// subclasses can pack their bitfields into the same word.
908bdb5b0e8ad8ed297ad01eb2ccd0d6d5ed6058033Francois Pichet    unsigned Dependent : 1;
90960e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
910b870b88df784c2940efce448ebfaf54dece14666John McCall    /// \brief Whether this type is a variably-modified type (C99 6.7.5).
911bdb5b0e8ad8ed297ad01eb2ccd0d6d5ed6058033Francois Pichet    unsigned VariablyModified : 1;
912d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor
913d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    /// \brief Whether this type contains an unexpanded parameter pack
914d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    /// (for C++0x variadic templates).
915d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    unsigned ContainsUnexpandedParameterPack : 1;
91635495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor
9171fb0caaa7bef765b85972274e3b434af2572c141John McCall    /// \brief Nonzero if the cache (i.e. the bitfields here starting
9181fb0caaa7bef765b85972274e3b434af2572c141John McCall    /// with 'Cache') is valid.  If so, then this is a
9191fb0caaa7bef765b85972274e3b434af2572c141John McCall    /// LangOptions::VisibilityMode+1.
9201fb0caaa7bef765b85972274e3b434af2572c141John McCall    mutable unsigned CacheValidAndVisibility : 2;
92160e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
922b870b88df784c2940efce448ebfaf54dece14666John McCall    /// \brief Linkage of this type.
923b870b88df784c2940efce448ebfaf54dece14666John McCall    mutable unsigned CachedLinkage : 2;
92407a353c2af3a3c557205466d4f4ed2513462ebfeSebastian Redl
925b870b88df784c2940efce448ebfaf54dece14666John McCall    /// \brief Whether this type involves and local or unnamed types.
926bdb5b0e8ad8ed297ad01eb2ccd0d6d5ed6058033Francois Pichet    mutable unsigned CachedLocalOrUnnamed : 1;
927db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor
928b870b88df784c2940efce448ebfaf54dece14666John McCall    /// \brief FromAST - Whether this type comes from an AST file.
929bdb5b0e8ad8ed297ad01eb2ccd0d6d5ed6058033Francois Pichet    mutable unsigned FromAST : 1;
930b870b88df784c2940efce448ebfaf54dece14666John McCall
9311fb0caaa7bef765b85972274e3b434af2572c141John McCall    bool isCacheValid() const {
9321fb0caaa7bef765b85972274e3b434af2572c141John McCall      return (CacheValidAndVisibility != 0);
9331fb0caaa7bef765b85972274e3b434af2572c141John McCall    }
9341fb0caaa7bef765b85972274e3b434af2572c141John McCall    Visibility getVisibility() const {
9351fb0caaa7bef765b85972274e3b434af2572c141John McCall      assert(isCacheValid() && "getting linkage from invalid cache");
9361fb0caaa7bef765b85972274e3b434af2572c141John McCall      return static_cast<Visibility>(CacheValidAndVisibility-1);
9371fb0caaa7bef765b85972274e3b434af2572c141John McCall    }
9381fb0caaa7bef765b85972274e3b434af2572c141John McCall    Linkage getLinkage() const {
9391fb0caaa7bef765b85972274e3b434af2572c141John McCall      assert(isCacheValid() && "getting linkage from invalid cache");
9401fb0caaa7bef765b85972274e3b434af2572c141John McCall      return static_cast<Linkage>(CachedLinkage);
9411fb0caaa7bef765b85972274e3b434af2572c141John McCall    }
9421fb0caaa7bef765b85972274e3b434af2572c141John McCall    bool hasLocalOrUnnamedType() const {
9431fb0caaa7bef765b85972274e3b434af2572c141John McCall      assert(isCacheValid() && "getting linkage from invalid cache");
9441fb0caaa7bef765b85972274e3b434af2572c141John McCall      return CachedLocalOrUnnamed;
9451fb0caaa7bef765b85972274e3b434af2572c141John McCall    }
946b870b88df784c2940efce448ebfaf54dece14666John McCall  };
947d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  enum { NumTypeBits = 17 };
948b870b88df784c2940efce448ebfaf54dece14666John McCall
949b870b88df784c2940efce448ebfaf54dece14666John McCallprotected:
950b870b88df784c2940efce448ebfaf54dece14666John McCall  // These classes allow subclasses to somewhat cleanly pack bitfields
951b870b88df784c2940efce448ebfaf54dece14666John McCall  // into Type.
952b870b88df784c2940efce448ebfaf54dece14666John McCall
953b870b88df784c2940efce448ebfaf54dece14666John McCall  class ArrayTypeBitfields {
954b870b88df784c2940efce448ebfaf54dece14666John McCall    friend class ArrayType;
955b870b88df784c2940efce448ebfaf54dece14666John McCall
956b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned : NumTypeBits;
957b870b88df784c2940efce448ebfaf54dece14666John McCall
958b870b88df784c2940efce448ebfaf54dece14666John McCall    /// IndexTypeQuals - CVR qualifiers from declarations like
959b870b88df784c2940efce448ebfaf54dece14666John McCall    /// 'int X[static restrict 4]'. For function parameters only.
960b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned IndexTypeQuals : 3;
961b870b88df784c2940efce448ebfaf54dece14666John McCall
962b870b88df784c2940efce448ebfaf54dece14666John McCall    /// SizeModifier - storage class qualifiers from declarations like
963b870b88df784c2940efce448ebfaf54dece14666John McCall    /// 'int X[static restrict 4]'. For function parameters only.
964b870b88df784c2940efce448ebfaf54dece14666John McCall    /// Actually an ArrayType::ArraySizeModifier.
965b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned SizeModifier : 3;
966b870b88df784c2940efce448ebfaf54dece14666John McCall  };
967b870b88df784c2940efce448ebfaf54dece14666John McCall
968b870b88df784c2940efce448ebfaf54dece14666John McCall  class BuiltinTypeBitfields {
969b870b88df784c2940efce448ebfaf54dece14666John McCall    friend class BuiltinType;
970b870b88df784c2940efce448ebfaf54dece14666John McCall
971b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned : NumTypeBits;
972b870b88df784c2940efce448ebfaf54dece14666John McCall
973b870b88df784c2940efce448ebfaf54dece14666John McCall    /// The kind (BuiltinType::Kind) of builtin type this is.
974b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned Kind : 8;
975b870b88df784c2940efce448ebfaf54dece14666John McCall  };
976b870b88df784c2940efce448ebfaf54dece14666John McCall
977b870b88df784c2940efce448ebfaf54dece14666John McCall  class FunctionTypeBitfields {
978b870b88df784c2940efce448ebfaf54dece14666John McCall    friend class FunctionType;
979b870b88df784c2940efce448ebfaf54dece14666John McCall
980b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned : NumTypeBits;
981b870b88df784c2940efce448ebfaf54dece14666John McCall
982b870b88df784c2940efce448ebfaf54dece14666John McCall    /// Extra information which affects how the function is called, like
983b870b88df784c2940efce448ebfaf54dece14666John McCall    /// regparm and the calling convention.
984b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned ExtInfo : 8;
985b870b88df784c2940efce448ebfaf54dece14666John McCall
986e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall    /// Whether the function is variadic.  Only used by FunctionProtoType.
987e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall    unsigned Variadic : 1;
988b870b88df784c2940efce448ebfaf54dece14666John McCall
989b870b88df784c2940efce448ebfaf54dece14666John McCall    /// TypeQuals - Used only by FunctionProtoType, put here to pack with the
990b870b88df784c2940efce448ebfaf54dece14666John McCall    /// other bitfields.
991b870b88df784c2940efce448ebfaf54dece14666John McCall    /// The qualifiers are part of FunctionProtoType because...
992b870b88df784c2940efce448ebfaf54dece14666John McCall    ///
993b870b88df784c2940efce448ebfaf54dece14666John McCall    /// C++ 8.3.5p4: The return type, the parameter type list and the
994b870b88df784c2940efce448ebfaf54dece14666John McCall    /// cv-qualifier-seq, [...], are part of the function type.
995b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned TypeQuals : 3;
996c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor
997c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor    /// \brief The ref-qualifier associated with a \c FunctionProtoType.
998c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor    ///
999c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor    /// This is a value of type \c RefQualifierKind.
1000c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor    unsigned RefQualifier : 2;
1001b870b88df784c2940efce448ebfaf54dece14666John McCall  };
1002b870b88df784c2940efce448ebfaf54dece14666John McCall
1003b870b88df784c2940efce448ebfaf54dece14666John McCall  class ObjCObjectTypeBitfields {
1004b870b88df784c2940efce448ebfaf54dece14666John McCall    friend class ObjCObjectType;
1005b870b88df784c2940efce448ebfaf54dece14666John McCall
1006b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned : NumTypeBits;
1007b870b88df784c2940efce448ebfaf54dece14666John McCall
1008b870b88df784c2940efce448ebfaf54dece14666John McCall    /// NumProtocols - The number of protocols stored directly on this
1009b870b88df784c2940efce448ebfaf54dece14666John McCall    /// object type.
1010b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned NumProtocols : 32 - NumTypeBits;
1011b870b88df784c2940efce448ebfaf54dece14666John McCall  };
1012b870b88df784c2940efce448ebfaf54dece14666John McCall
1013b870b88df784c2940efce448ebfaf54dece14666John McCall  class ReferenceTypeBitfields {
1014b870b88df784c2940efce448ebfaf54dece14666John McCall    friend class ReferenceType;
1015b870b88df784c2940efce448ebfaf54dece14666John McCall
1016b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned : NumTypeBits;
1017b870b88df784c2940efce448ebfaf54dece14666John McCall
1018b870b88df784c2940efce448ebfaf54dece14666John McCall    /// True if the type was originally spelled with an lvalue sigil.
1019b870b88df784c2940efce448ebfaf54dece14666John McCall    /// This is never true of rvalue references but can also be false
1020b870b88df784c2940efce448ebfaf54dece14666John McCall    /// on lvalue references because of C++0x [dcl.typedef]p9,
1021b870b88df784c2940efce448ebfaf54dece14666John McCall    /// as follows:
1022b870b88df784c2940efce448ebfaf54dece14666John McCall    ///
1023b870b88df784c2940efce448ebfaf54dece14666John McCall    ///   typedef int &ref;    // lvalue, spelled lvalue
1024b870b88df784c2940efce448ebfaf54dece14666John McCall    ///   typedef int &&rvref; // rvalue
1025b870b88df784c2940efce448ebfaf54dece14666John McCall    ///   ref &a;              // lvalue, inner ref, spelled lvalue
1026b870b88df784c2940efce448ebfaf54dece14666John McCall    ///   ref &&a;             // lvalue, inner ref
1027b870b88df784c2940efce448ebfaf54dece14666John McCall    ///   rvref &a;            // lvalue, inner ref, spelled lvalue
1028b870b88df784c2940efce448ebfaf54dece14666John McCall    ///   rvref &&a;           // rvalue, inner ref
1029bdb5b0e8ad8ed297ad01eb2ccd0d6d5ed6058033Francois Pichet    unsigned SpelledAsLValue : 1;
1030b870b88df784c2940efce448ebfaf54dece14666John McCall
1031b870b88df784c2940efce448ebfaf54dece14666John McCall    /// True if the inner type is a reference type.  This only happens
1032b870b88df784c2940efce448ebfaf54dece14666John McCall    /// in non-canonical forms.
1033bdb5b0e8ad8ed297ad01eb2ccd0d6d5ed6058033Francois Pichet    unsigned InnerRef : 1;
1034b870b88df784c2940efce448ebfaf54dece14666John McCall  };
1035b870b88df784c2940efce448ebfaf54dece14666John McCall
103677be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall  class TypeWithKeywordBitfields {
103777be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall    friend class TypeWithKeyword;
103877be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall
103977be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall    unsigned : NumTypeBits;
104077be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall
104177be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall    /// An ElaboratedTypeKeyword.  8 bits for efficient access.
104277be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall    unsigned Keyword : 8;
104377be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall  };
104477be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall
1045b870b88df784c2940efce448ebfaf54dece14666John McCall  class VectorTypeBitfields {
1046b870b88df784c2940efce448ebfaf54dece14666John McCall    friend class VectorType;
104707a353c2af3a3c557205466d4f4ed2513462ebfeSebastian Redl
1048b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned : NumTypeBits;
104971c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall
1050e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson    /// VecKind - The kind of vector, either a generic vector type or some
1051e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson    /// target-specific vector type such as for AltiVec or Neon.
1052cc3b946c35c4372272034e6f0663089477a9a5bdBob Wilson    unsigned VecKind : 3;
1053b870b88df784c2940efce448ebfaf54dece14666John McCall
1054b870b88df784c2940efce448ebfaf54dece14666John McCall    /// NumElements - The number of elements in the vector.
1055cc3b946c35c4372272034e6f0663089477a9a5bdBob Wilson    unsigned NumElements : 29 - NumTypeBits;
1056b870b88df784c2940efce448ebfaf54dece14666John McCall  };
1057b870b88df784c2940efce448ebfaf54dece14666John McCall
10589d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  class AttributedTypeBitfields {
10599d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    friend class AttributedType;
10609d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
10619d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    unsigned : NumTypeBits;
10629d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
10639d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    /// AttrKind - an AttributedType::Kind
10649d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    unsigned AttrKind : 32 - NumTypeBits;
10659d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  };
10669d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
1067b870b88df784c2940efce448ebfaf54dece14666John McCall  union {
1068b870b88df784c2940efce448ebfaf54dece14666John McCall    TypeBitfields TypeBits;
1069b870b88df784c2940efce448ebfaf54dece14666John McCall    ArrayTypeBitfields ArrayTypeBits;
10709d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    AttributedTypeBitfields AttributedTypeBits;
1071b870b88df784c2940efce448ebfaf54dece14666John McCall    BuiltinTypeBitfields BuiltinTypeBits;
1072b870b88df784c2940efce448ebfaf54dece14666John McCall    FunctionTypeBitfields FunctionTypeBits;
1073b870b88df784c2940efce448ebfaf54dece14666John McCall    ObjCObjectTypeBitfields ObjCObjectTypeBits;
1074b870b88df784c2940efce448ebfaf54dece14666John McCall    ReferenceTypeBitfields ReferenceTypeBits;
107577be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall    TypeWithKeywordBitfields TypeWithKeywordBits;
1076b870b88df784c2940efce448ebfaf54dece14666John McCall    VectorTypeBitfields VectorTypeBits;
1077b870b88df784c2940efce448ebfaf54dece14666John McCall  };
1078b870b88df784c2940efce448ebfaf54dece14666John McCall
1079b870b88df784c2940efce448ebfaf54dece14666John McCallprivate:
10803c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief Set whether this type comes from an AST file.
10813c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  void setFromAST(bool V = true) const {
1082b870b88df784c2940efce448ebfaf54dece14666John McCall    TypeBits.FromAST = V;
108307a353c2af3a3c557205466d4f4ed2513462ebfeSebastian Redl  }
108407a353c2af3a3c557205466d4f4ed2513462ebfeSebastian Redl
1085b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall  template <class T> friend class TypePropertyCache;
10861fb0caaa7bef765b85972274e3b434af2572c141John McCall
10875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprotected:
1088124dd7b5777e29ecac006822bd4d4623f0dc4264Hartmut Kaiser  // silence VC++ warning C4355: 'this' : used in base member initializer list
1089124dd7b5777e29ecac006822bd4d4623f0dc4264Hartmut Kaiser  Type *this_() { return this; }
10903b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  Type(TypeClass tc, QualType canon, bool Dependent, bool VariablyModified,
1091d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor       bool ContainsUnexpandedParameterPack)
10923b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    : ExtQualsTypeCommonBase(this,
10933b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall                             canon.isNull() ? QualType(this_(), 0) : canon) {
1094b870b88df784c2940efce448ebfaf54dece14666John McCall    TypeBits.TC = tc;
1095b870b88df784c2940efce448ebfaf54dece14666John McCall    TypeBits.Dependent = Dependent;
1096b870b88df784c2940efce448ebfaf54dece14666John McCall    TypeBits.VariablyModified = VariablyModified;
1097d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    TypeBits.ContainsUnexpandedParameterPack = ContainsUnexpandedParameterPack;
10981fb0caaa7bef765b85972274e3b434af2572c141John McCall    TypeBits.CacheValidAndVisibility = 0;
1099b870b88df784c2940efce448ebfaf54dece14666John McCall    TypeBits.CachedLocalOrUnnamed = false;
1100b870b88df784c2940efce448ebfaf54dece14666John McCall    TypeBits.CachedLinkage = NoLinkage;
1101b870b88df784c2940efce448ebfaf54dece14666John McCall    TypeBits.FromAST = false;
1102b870b88df784c2940efce448ebfaf54dece14666John McCall  }
11035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;
11041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1105b870b88df784c2940efce448ebfaf54dece14666John McCall  void setDependent(bool D = true) { TypeBits.Dependent = D; }
1106b870b88df784c2940efce448ebfaf54dece14666John McCall  void setVariablyModified(bool VM = true) { TypeBits.VariablyModified = VM; }
1107d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  void setContainsUnexpandedParameterPack(bool PP = true) {
1108d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    TypeBits.ContainsUnexpandedParameterPack = PP;
1109d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  }
1110d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor
11118b9023ba35a86838789e2c9034a6128728c547aaChris Lattnerpublic:
1112b870b88df784c2940efce448ebfaf54dece14666John McCall  TypeClass getTypeClass() const { return static_cast<TypeClass>(TypeBits.TC); }
11131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
11143c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief Whether this type comes from an AST file.
1115b870b88df784c2940efce448ebfaf54dece14666John McCall  bool isFromAST() const { return TypeBits.FromAST; }
111607a353c2af3a3c557205466d4f4ed2513462ebfeSebastian Redl
1117d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// \brief Whether this type is or contains an unexpanded parameter
1118d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// pack, used to support C++0x variadic templates.
1119d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  ///
1120d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// A type that contains a parameter pack shall be expanded by the
1121d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// ellipsis operator at some point. For example, the typedef in the
1122d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// following example contains an unexpanded parameter pack 'T':
1123d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  ///
1124d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// \code
1125d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// template<typename ...T>
1126d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// struct X {
1127d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  ///   typedef T* pointer_types; // ill-formed; T is a parameter pack.
1128d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// };
1129d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// \endcode
1130d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  ///
1131d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// Note that this routine does not specify which
1132d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  bool containsUnexpandedParameterPack() const {
1133d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    return TypeBits.ContainsUnexpandedParameterPack;
1134d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  }
1135d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor
11363b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  /// Determines if this type would be canonical if it had no further
11373b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  /// qualification.
1138467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall  bool isCanonicalUnqualified() const {
11393b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    return CanonicalType == QualType(this, 0);
1140467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall  }
11415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
11421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// Types are partitioned into 3 broad categories (C99 6.2.5p1):
11435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// object types, function types, and incomplete types.
11441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
11455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isIncompleteType - Return true if this is an incomplete type.
11465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// A type that can describe objects, but which lacks information needed to
11475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// determine its size (e.g. void, or a fwd declared struct). Clients of this
11481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// routine will need to determine if the size is actually required.
11495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isIncompleteType() const;
1150d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner
1151d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner  /// isIncompleteOrObjectType - Return true if this is an incomplete or object
1152d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner  /// type, in other words, not a function type.
1153d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner  bool isIncompleteOrObjectType() const {
1154d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner    return !isFunctionType();
1155d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner  }
11562fdc5e8199e1e239620f2faae88997153703e16fDouglas Gregor
11572fdc5e8199e1e239620f2faae88997153703e16fDouglas Gregor  /// \brief Determine whether this type is an object type.
11582fdc5e8199e1e239620f2faae88997153703e16fDouglas Gregor  bool isObjectType() const {
11592fdc5e8199e1e239620f2faae88997153703e16fDouglas Gregor    // C++ [basic.types]p8:
11602fdc5e8199e1e239620f2faae88997153703e16fDouglas Gregor    //   An object type is a (possibly cv-qualified) type that is not a
11612fdc5e8199e1e239620f2faae88997153703e16fDouglas Gregor    //   function type, not a reference type, and not a void type.
11622fdc5e8199e1e239620f2faae88997153703e16fDouglas Gregor    return !isReferenceType() && !isFunctionType() && !isVoidType();
11632fdc5e8199e1e239620f2faae88997153703e16fDouglas Gregor  }
116464b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
116564b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  /// isPODType - Return true if this is a plain-old-data type (C++ 3.9p10).
116664b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  bool isPODType() const;
116764b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
1168ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl  /// isLiteralType - Return true if this is a literal type
1169ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl  /// (C++0x [basic.types]p10)
1170ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl  bool isLiteralType() const;
1171ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl
11725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// Helper methods to distinguish type categories. All type predicates
1173ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb  /// operate on the canonical type, ignoring typedefs and qualifiers.
1174e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar
11759b065ddabf572772991a4aadad5bf4921fac5069Tom Care  /// isBuiltinType - returns true if the type is a builtin type.
11769b065ddabf572772991a4aadad5bf4921fac5069Tom Care  bool isBuiltinType() const;
11779b065ddabf572772991a4aadad5bf4921fac5069Tom Care
1178e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar  /// isSpecificBuiltinType - Test for a particular builtin type.
1179e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar  bool isSpecificBuiltinType(unsigned K) const;
11801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
11812a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  /// isPlaceholderType - Test for a type which does not represent an
11822a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  /// actual type-system type but is instead used as a placeholder for
11832a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  /// various convenient purposes within Clang.  All such types are
11842a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  /// BuiltinTypes.
11852a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  bool isPlaceholderType() const;
11862a984cad5ac3fdceeff2bd99daa7b90979313475John McCall
118796d2c438f5c9ada8229f7f2ac049d2e9957bc954Steve Naroff  /// isIntegerType() does *not* include complex integers (a GCC extension).
118896d2c438f5c9ada8229f7f2ac049d2e9957bc954Steve Naroff  /// isComplexIntegerType() can be used to test for complex integers.
11895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isIntegerType() const;     // C99 6.2.5p17 (int, char, bool, enum)
119013b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff  bool isEnumeralType() const;
119113b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff  bool isBooleanType() const;
119213b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff  bool isCharType() const;
119377a52233f7c0f162672652051bfe78b65ad4f789Douglas Gregor  bool isWideCharType() const;
119420093b4bf698f292c664676987541d5103b65b15Douglas Gregor  bool isAnyCharacterType() const;
11959d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor  bool isIntegralType(ASTContext &Ctx) const;
119620093b4bf698f292c664676987541d5103b65b15Douglas Gregor
11972ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor  /// \brief Determine whether this type is an integral or enumeration type.
11982ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor  bool isIntegralOrEnumerationType() const;
11991274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor  /// \brief Determine whether this type is an integral or unscoped enumeration
12001274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor  /// type.
12011274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor  bool isIntegralOrUnscopedEnumerationType() const;
12022ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor
12035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// Floating point categories.
12045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isRealFloatingType() const; // C99 6.2.5p10 (float, double, long double)
120502f62a9fedbc370fba081303399410a3afdde29fSteve Naroff  /// isComplexType() does *not* include complex integers (a GCC extension).
120602f62a9fedbc370fba081303399410a3afdde29fSteve Naroff  /// isComplexIntegerType() can be used to test for complex integers.
12075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isComplexType() const;      // C99 6.2.5p11 (complex)
1208f23d364084d1aabea688222780d6fc1dd8c7f78cChris Lattner  bool isAnyComplexType() const;   // C99 6.2.5p11 (complex) + Complex Int.
12095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isFloatingType() const;     // C99 6.2.5p11 (real floating + complex)
12105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isRealType() const;         // C99 6.2.5p17 (real floating + integer)
12115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isArithmeticType() const;   // C99 6.2.5p18 (integer + floating)
1212c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  bool isVoidType() const;         // C99 6.2.5p19
1213c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  bool isDerivedType() const;      // C99 6.2.5p20
1214c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  bool isScalarType() const;       // C99 6.2.5p21 (arithmetic + pointers)
1215d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor  bool isAggregateType() const;
12161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1217c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  // Type Predicates: Check to see if this type is structurally the specified
1218ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb  // type, ignoring typedefs and qualifiers.
1219c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  bool isFunctionType() const;
1220183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  bool isFunctionNoProtoType() const { return getAs<FunctionNoProtoType>(); }
1221183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  bool isFunctionProtoType() const { return getAs<FunctionProtoType>(); }
1222befee48ff2a1dab236c5700f00ecca1cfdcd5837Chris Lattner  bool isPointerType() const;
122358f9f2c884af6b72d036b746a016d8031d31cb7aSteve Naroff  bool isAnyPointerType() const;   // Any C pointer or ObjC object pointer
12245618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  bool isBlockPointerType() const;
12257154a77e7c1f23418342d3b72836ab504aa7821eSteve Naroff  bool isVoidPointerType() const;
1226a1d9fdea79ba7bbd71862b9f9f78f5f117331fc7Chris Lattner  bool isReferenceType() const;
12277c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  bool isLValueReferenceType() const;
12287c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  bool isRValueReferenceType() const;
1229bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner  bool isFunctionPointerType() const;
1230f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  bool isMemberPointerType() const;
1231f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  bool isMemberFunctionPointerType() const;
1232db68e28c05a67735211e688009890cf834c22e75Douglas Gregor  bool isMemberDataPointerType() const;
1233c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  bool isArrayType() const;
1234c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  bool isConstantArrayType() const;
1235c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  bool isIncompleteArrayType() const;
1236c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  bool isVariableArrayType() const;
1237898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  bool isDependentSizedArrayType() const;
1238c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  bool isRecordType() const;
12391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  bool isClassType() const;
12401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  bool isStructureType() const;
1241fb87b89fc9eb103e19fb8e4b925c23f0bd091b99Douglas Gregor  bool isStructureOrClassType() const;
12424cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroff  bool isUnionType() const;
1243368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner  bool isComplexIntegerType() const;            // GCC _Complex integer type.
1244368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner  bool isVectorType() const;                    // GCC vector type.
1245213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman  bool isExtVectorType() const;                 // Extended vector type.
1246d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff  bool isObjCObjectPointerType() const;         // Pointer to *any* ObjC object.
124714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  // FIXME: change this to 'raw' interface type, so we can used 'interface' type
124814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  // for the common case.
1249c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool isObjCObjectType() const;                // NSString or typeof(*(id)0)
1250368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner  bool isObjCQualifiedInterfaceType() const;    // NSString<foo>
1251368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner  bool isObjCQualifiedIdType() const;           // id<foo>
1252470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroff  bool isObjCQualifiedClassType() const;        // Class<foo>
1253569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor  bool isObjCObjectOrInterfaceType() const;
125414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  bool isObjCIdType() const;                    // id
125514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  bool isObjCClassType() const;                 // Class
125613dcd00615de5c4279d97bdf63cd5f0a14fd9dccFariborz Jahanian  bool isObjCSelType() const;                 // Class
1257de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff  bool isObjCBuiltinType() const;               // 'id' or 'Class'
125872c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor  bool isTemplateTypeParmType() const;          // C++ template type parameter
12596e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl  bool isNullPtrType() const;                   // C++0x nullptr_t
1260898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
1261daa8e4e888758d55a7a759dd4a91b83921cef222John McCall  enum ScalarTypeKind {
1262daa8e4e888758d55a7a759dd4a91b83921cef222John McCall    STK_Pointer,
1263daa8e4e888758d55a7a759dd4a91b83921cef222John McCall    STK_MemberPointer,
1264daa8e4e888758d55a7a759dd4a91b83921cef222John McCall    STK_Bool,
1265daa8e4e888758d55a7a759dd4a91b83921cef222John McCall    STK_Integral,
1266daa8e4e888758d55a7a759dd4a91b83921cef222John McCall    STK_Floating,
1267daa8e4e888758d55a7a759dd4a91b83921cef222John McCall    STK_IntegralComplex,
1268daa8e4e888758d55a7a759dd4a91b83921cef222John McCall    STK_FloatingComplex
1269daa8e4e888758d55a7a759dd4a91b83921cef222John McCall  };
1270daa8e4e888758d55a7a759dd4a91b83921cef222John McCall  /// getScalarTypeKind - Given that this is a scalar type, classify it.
1271daa8e4e888758d55a7a759dd4a91b83921cef222John McCall  ScalarTypeKind getScalarTypeKind() const;
1272daa8e4e888758d55a7a759dd4a91b83921cef222John McCall
1273898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// isDependentType - Whether this type is a dependent type, meaning
12741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// that its definition somehow depends on a template parameter
1275898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// (C++ [temp.dep.type]).
1276b870b88df784c2940efce448ebfaf54dece14666John McCall  bool isDependentType() const { return TypeBits.Dependent; }
127735495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor
127835495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor  /// \brief Whether this type is a variably-modified type (C99 6.7.5).
1279b870b88df784c2940efce448ebfaf54dece14666John McCall  bool isVariablyModifiedType() const { return TypeBits.VariablyModified; }
12803b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
12813b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  /// \brief Whether this type involves a variable-length array type
12823b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  /// with a definite size.
12833b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  bool hasSizedVLAType() const;
128435495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor
1285db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor  /// \brief Whether this type is or contains a local or unnamed type.
1286db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor  bool hasUnnamedOrLocalType() const;
1287db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor
1288063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  bool isOverloadableType() const;
128972c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor
12904033642464e8ba0982f88f34cffad808d247b393Douglas Gregor  /// \brief Determine wither this type is a C++ elaborated-type-specifier.
12914033642464e8ba0982f88f34cffad808d247b393Douglas Gregor  bool isElaboratedTypeSpecifier() const;
12924033642464e8ba0982f88f34cffad808d247b393Douglas Gregor
12938958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar  /// hasPointerRepresentation - Whether this type is represented
12948958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar  /// natively as a pointer; this includes pointers, references, block
12958958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar  /// pointers, and Objective-C interface, qualified id, and qualified
12966e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl  /// interface types, as well as nullptr_t.
12978958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar  bool hasPointerRepresentation() const;
12988958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar
1299820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian  /// hasObjCPointerRepresentation - Whether this type can represent
1300820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian  /// an objective pointer type for the purpose of GC'ability
13011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  bool hasObjCPointerRepresentation() const;
1302820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian
1303f60946222721d9ba3c059563935c17b84703187aDouglas Gregor  /// \brief Determine whether this type has an integer representation
1304f60946222721d9ba3c059563935c17b84703187aDouglas Gregor  /// of some sort, e.g., it is an integer type or a vector.
1305f60946222721d9ba3c059563935c17b84703187aDouglas Gregor  bool hasIntegerRepresentation() const;
1306f60946222721d9ba3c059563935c17b84703187aDouglas Gregor
1307f60946222721d9ba3c059563935c17b84703187aDouglas Gregor  /// \brief Determine whether this type has an signed integer representation
1308f60946222721d9ba3c059563935c17b84703187aDouglas Gregor  /// of some sort, e.g., it is an signed integer type or a vector.
1309f60946222721d9ba3c059563935c17b84703187aDouglas Gregor  bool hasSignedIntegerRepresentation() const;
1310f60946222721d9ba3c059563935c17b84703187aDouglas Gregor
1311f60946222721d9ba3c059563935c17b84703187aDouglas Gregor  /// \brief Determine whether this type has an unsigned integer representation
1312f60946222721d9ba3c059563935c17b84703187aDouglas Gregor  /// of some sort, e.g., it is an unsigned integer type or a vector.
1313f60946222721d9ba3c059563935c17b84703187aDouglas Gregor  bool hasUnsignedIntegerRepresentation() const;
1314f60946222721d9ba3c059563935c17b84703187aDouglas Gregor
13158eee119bf4f1693dde17b8552c1f9f81bf2b681eDouglas Gregor  /// \brief Determine whether this type has a floating-point representation
13168eee119bf4f1693dde17b8552c1f9f81bf2b681eDouglas Gregor  /// of some sort, e.g., it is a floating-point type or a vector thereof.
13178eee119bf4f1693dde17b8552c1f9f81bf2b681eDouglas Gregor  bool hasFloatingRepresentation() const;
1318f60946222721d9ba3c059563935c17b84703187aDouglas Gregor
1319c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  // Type Checking Functions: Check to see if this type is structurally the
1320f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner  // specified type, ignoring typedefs and qualifiers, and return a pointer to
1321f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner  // the best type we can.
1322769c9cfc6e06bd9d8ffe7a4397b939f19b0e4dc3Ted Kremenek  const RecordType *getAsStructureType() const;
1323898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// NOTE: getAs*ArrayType are methods on ASTContext.
1324c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  const RecordType *getAsUnionType() const;
13254cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroff  const ComplexType *getAsComplexIntegerType() const; // GCC complex int type.
132614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  // The following is a convenience method that returns an ObjCObjectPointerType
132714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  // for object declared using an interface.
132814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  const ObjCObjectPointerType *getAsObjCInterfacePointerType() const;
132914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  const ObjCObjectPointerType *getAsObjCQualifiedIdType() const;
1330c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  const ObjCObjectType *getAsObjCQualifiedInterfaceType() const;
1331a91d6a6619a91d0ca7102d8ab5678d855f04d850Fariborz Jahanian  const CXXRecordDecl *getCXXRecordDeclForPointerType() const;
13321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1333c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor  /// \brief Retrieves the CXXRecordDecl that this type refers to, either
1334c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor  /// because the type is a RecordType or because it is the injected-class-name
1335c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor  /// type of a class template or class template partial specialization.
1336c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor  CXXRecordDecl *getAsCXXRecordDecl() const;
133734b41d939a1328f484511c6002ba2456db879a29Richard Smith
133834b41d939a1328f484511c6002ba2456db879a29Richard Smith  /// \brief Get the AutoType whose type will be deduced for a variable with
133934b41d939a1328f484511c6002ba2456db879a29Richard Smith  /// an initializer of this type. This looks through declarators like pointer
134034b41d939a1328f484511c6002ba2456db879a29Richard Smith  /// types, but not through decltype or typedefs.
134134b41d939a1328f484511c6002ba2456db879a29Richard Smith  AutoType *getContainedAutoType() const;
1342c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor
1343d0370f59e79702ac908c81bf556519f91e9ca297John McCall  /// Member-template getAs<specific type>'.  Look through sugar for
1344d0370f59e79702ac908c81bf556519f91e9ca297John McCall  /// an instance of <specific type>.   This scheme will eventually
1345d0370f59e79702ac908c81bf556519f91e9ca297John McCall  /// replace the specific getAsXXXX methods above.
1346d0370f59e79702ac908c81bf556519f91e9ca297John McCall  ///
1347d0370f59e79702ac908c81bf556519f91e9ca297John McCall  /// There are some specializations of this member template listed
1348d0370f59e79702ac908c81bf556519f91e9ca297John McCall  /// immediately following this class.
13491a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek  template <typename T> const T *getAs() const;
13501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
13513b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  /// A variant of getAs<> for array types which silently discards
13523b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  /// qualifiers from the outermost type.
13533b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  const ArrayType *getAsArrayTypeUnsafe() const;
13543b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
1355d0370f59e79702ac908c81bf556519f91e9ca297John McCall  /// Member-template castAs<specific type>.  Look through sugar for
1356d0370f59e79702ac908c81bf556519f91e9ca297John McCall  /// the underlying instance of <specific type>.
1357d0370f59e79702ac908c81bf556519f91e9ca297John McCall  ///
1358d0370f59e79702ac908c81bf556519f91e9ca297John McCall  /// This method has the same relationship to getAs<T> as cast<T> has
1359d0370f59e79702ac908c81bf556519f91e9ca297John McCall  /// to dyn_cast<T>; which is to say, the underlying type *must*
1360d0370f59e79702ac908c81bf556519f91e9ca297John McCall  /// have the intended type, and this method will never return null.
1361d0370f59e79702ac908c81bf556519f91e9ca297John McCall  template <typename T> const T *castAs() const;
1362d0370f59e79702ac908c81bf556519f91e9ca297John McCall
1363d0370f59e79702ac908c81bf556519f91e9ca297John McCall  /// A variant of castAs<> for array type which silently discards
1364d0370f59e79702ac908c81bf556519f91e9ca297John McCall  /// qualifiers from the outermost type.
1365d0370f59e79702ac908c81bf556519f91e9ca297John McCall  const ArrayType *castAsArrayTypeUnsafe() const;
1366d0370f59e79702ac908c81bf556519f91e9ca297John McCall
1367d0370f59e79702ac908c81bf556519f91e9ca297John McCall  /// getBaseElementTypeUnsafe - Get the base element type of this
1368d0370f59e79702ac908c81bf556519f91e9ca297John McCall  /// type, potentially discarding type qualifiers.  This method
1369d0370f59e79702ac908c81bf556519f91e9ca297John McCall  /// should never be used when type qualifiers are meaningful.
1370d0370f59e79702ac908c81bf556519f91e9ca297John McCall  const Type *getBaseElementTypeUnsafe() const;
1371d0370f59e79702ac908c81bf556519f91e9ca297John McCall
1372c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  /// getArrayElementTypeNoTypeQual - If this is an array type, return the
1373c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  /// element type of the array, potentially with type qualifiers missing.
1374c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  /// This method should never be used when type qualifiers are meaningful.
1375c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  const Type *getArrayElementTypeNoTypeQual() const;
13761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1377f8910df57799256c1897a8610dc52685729ae90eSteve Naroff  /// getPointeeType - If this is a pointer, ObjC object pointer, or block
1378f8910df57799256c1897a8610dc52685729ae90eSteve Naroff  /// pointer, this returns the respective pointee.
137914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  QualType getPointeeType() const;
13801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1381bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// getUnqualifiedDesugaredType() - Return the specified type with
1382bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// any "sugar" removed from the type, removing any typedefs,
1383bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// typeofs, etc., as well as any qualifiers.
1384bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  const Type *getUnqualifiedDesugaredType() const;
13851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
13865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// More type predicates useful for type checking/promotion
13875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isPromotableIntegerType() const; // C99 6.3.1.1p2
13885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
13895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isSignedIntegerType - Return true if this is an integer type that is
1390d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner  /// signed, according to C99 6.2.5p4 [char, signed char, short, int, long..],
1391d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner  /// an enum decl which has a signed representation, or a vector of signed
1392d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner  /// integer element type.
13935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isSignedIntegerType() const;
13945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
13955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isUnsignedIntegerType - Return true if this is an integer type that is
1396d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner  /// unsigned, according to C99 6.2.5p6 [which returns true for _Bool], an enum
1397d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner  /// decl which has an unsigned representation, or a vector of unsigned integer
1398d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner  /// element type.
13995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isUnsignedIntegerType() const;
1400d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner
14015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isConstantSizeType - Return true if this is not a variable sized type,
14029bfa73c5ab7bf4b0e749d04f29da6884e8d5bd9fChris Lattner  /// according to the rules of C99 6.7.5p3.  It is not legal to call this on
14039bfa73c5ab7bf4b0e749d04f29da6884e8d5bd9fChris Lattner  /// incomplete types.
14043c2b3170041f69a92904e3bab9b6d654eaf260acEli Friedman  bool isConstantSizeType() const;
1405c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner
140622b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman  /// isSpecifierType - Returns true if this type can be represented by some
140722b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman  /// set of type specifiers.
140822b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman  bool isSpecifierType() const;
140922b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman
14100b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor  /// \brief Determine the linkage of this type.
141160e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor  Linkage getLinkage() const;
14121fb0caaa7bef765b85972274e3b434af2572c141John McCall
14131fb0caaa7bef765b85972274e3b434af2572c141John McCall  /// \brief Determine the visibility of this type.
14141fb0caaa7bef765b85972274e3b434af2572c141John McCall  Visibility getVisibility() const;
14151fb0caaa7bef765b85972274e3b434af2572c141John McCall
14161fb0caaa7bef765b85972274e3b434af2572c141John McCall  /// \brief Determine the linkage and visibility of this type.
14171fb0caaa7bef765b85972274e3b434af2572c141John McCall  std::pair<Linkage,Visibility> getLinkageAndVisibility() const;
141860e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
141960e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor  /// \brief Note that the linkage is no longer known.
142060e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor  void ClearLinkageCache();
142160e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
142260e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor  const char *getTypeClassName() const;
14230b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor
1424ead608af31b6c9abeae1ca6d0b75094dac4641c0John McCall  QualType getCanonicalTypeInternal() const {
1425ead608af31b6c9abeae1ca6d0b75094dac4641c0John McCall    return CanonicalType;
1426ead608af31b6c9abeae1ca6d0b75094dac4641c0John McCall  }
1427ead608af31b6c9abeae1ca6d0b75094dac4641c0John McCall  CanQualType getCanonicalTypeUnqualified() const; // in CanonicalType.h
1428c36d405a02fab41f6c45cb2bc750d64949742903Chris Lattner  void dump() const;
14295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *) { return true; }
1430be191100e034b23a3e13053757a57b7f5068c24aArgyrios Kyrtzidis
1431c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl  friend class ASTReader;
1432a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian Redl  friend class ASTWriter;
14335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
14345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1435183700f494ec9b6701b6efe82bcb25f4c79ba561John McCalltemplate <> inline const TypedefType *Type::getAs() const {
1436183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  return dyn_cast<TypedefType>(this);
1437183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall}
1438183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall
1439183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall// We can do canonical leaf types faster, because we don't have to
1440183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall// worry about preserving child type decoration.
1441183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall#define TYPE(Class, Base)
1442183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall#define LEAF_TYPE(Class) \
1443183700f494ec9b6701b6efe82bcb25f4c79ba561John McCalltemplate <> inline const Class##Type *Type::getAs() const { \
14440953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  return dyn_cast<Class##Type>(CanonicalType); \
1445d0370f59e79702ac908c81bf556519f91e9ca297John McCall} \
1446d0370f59e79702ac908c81bf556519f91e9ca297John McCalltemplate <> inline const Class##Type *Type::castAs() const { \
1447d0370f59e79702ac908c81bf556519f91e9ca297John McCall  return cast<Class##Type>(CanonicalType); \
1448183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall}
1449183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall#include "clang/AST/TypeNodes.def"
1450183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall
1451183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall
14525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// BuiltinType - This class is used for builtin types like 'int'.  Builtin
14535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// types are always canonical and have a literal name field.
14545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass BuiltinType : public Type {
14555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
14565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  enum Kind {
14575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Void,
14581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
14595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Bool,     // This is bool and/or _Bool.
14605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Char_U,   // This is 'char' for targets where char is unsigned.
14615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    UChar,    // This is explicitly qualified unsigned char.
14623f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner    WChar_U,  // This is 'wchar_t' for C++, when unsigned.
1463f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith    Char16,   // This is 'char16_t' for C++.
1464f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith    Char32,   // This is 'char32_t' for C++.
14655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    UShort,
14665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    UInt,
14675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ULong,
14685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ULongLong,
14692df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner    UInt128,  // __uint128_t
14701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
14715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Char_S,   // This is 'char' for targets where char is signed.
14725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    SChar,    // This is explicitly qualified signed char.
14733f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner    WChar_S,  // This is 'wchar_t' for C++, when signed.
14745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Short,
14755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Int,
14765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Long,
14775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    LongLong,
14782df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner    Int128,   // __int128_t
14791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
14808e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor    Float, Double, LongDouble,
14818e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor
14826e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl    NullPtr,  // This is the type of C++0x 'nullptr'.
14836e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl
14842a984cad5ac3fdceeff2bd99daa7b90979313475John McCall    /// This represents the type of an expression whose type is
14852a984cad5ac3fdceeff2bd99daa7b90979313475John McCall    /// totally unknown, e.g. 'T::foo'.  It is permitted for this to
14862a984cad5ac3fdceeff2bd99daa7b90979313475John McCall    /// appear in situations where the structure of the type is
14872a984cad5ac3fdceeff2bd99daa7b90979313475John McCall    /// theoretically deducible.
14882a984cad5ac3fdceeff2bd99daa7b90979313475John McCall    Dependent,
14892a984cad5ac3fdceeff2bd99daa7b90979313475John McCall
1490898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    Overload,  // This represents the type of an overloaded function declaration.
14911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1492e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall    /// The primitive Objective C 'id' type.  The type pointed to by the
1493e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall    /// user-visible 'id' type.  Only ever shows up in an AST as the base
1494e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall    /// type of an ObjCObjectType.
1495e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall    ObjCId,
1496e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall
1497e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall    /// The primitive Objective C 'Class' type.  The type pointed to by the
1498e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall    /// user-visible 'Class' type.  Only ever shows up in an AST as the
1499e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall    /// base type of an ObjCObjectType.
1500e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall    ObjCClass,
1501e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall
150213dcd00615de5c4279d97bdf63cd5f0a14fd9dccFariborz Jahanian    ObjCSel    // This represents the ObjC 'SEL' type.
15035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
150471c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall
15055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
15061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  BuiltinType(Kind K)
150735495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    : Type(Builtin, QualType(), /*Dependent=*/(K == Dependent),
1508d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor           /*VariablyModified=*/false,
1509d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor           /*Unexpanded paramter pack=*/false) {
1510b870b88df784c2940efce448ebfaf54dece14666John McCall    BuiltinTypeBits.Kind = K;
151171c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  }
15121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1513b870b88df784c2940efce448ebfaf54dece14666John McCall  Kind getKind() const { return static_cast<Kind>(BuiltinTypeBits.Kind); }
1514e4f2142d00fa5fdb580c4e2413da91882d955381Chris Lattner  const char *getName(const LangOptions &LO) const;
15151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1516bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1517bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1518bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
1519680523a91dd3351389667c8de17121ba7ae82673John McCall  bool isInteger() const {
152071c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    return getKind() >= Bool && getKind() <= Int128;
1521680523a91dd3351389667c8de17121ba7ae82673John McCall  }
1522680523a91dd3351389667c8de17121ba7ae82673John McCall
1523680523a91dd3351389667c8de17121ba7ae82673John McCall  bool isSignedInteger() const {
152471c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    return getKind() >= Char_S && getKind() <= Int128;
1525680523a91dd3351389667c8de17121ba7ae82673John McCall  }
1526680523a91dd3351389667c8de17121ba7ae82673John McCall
1527680523a91dd3351389667c8de17121ba7ae82673John McCall  bool isUnsignedInteger() const {
152871c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    return getKind() >= Bool && getKind() <= UInt128;
1529680523a91dd3351389667c8de17121ba7ae82673John McCall  }
1530680523a91dd3351389667c8de17121ba7ae82673John McCall
1531680523a91dd3351389667c8de17121ba7ae82673John McCall  bool isFloatingPoint() const {
153271c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    return getKind() >= Float && getKind() <= LongDouble;
1533680523a91dd3351389667c8de17121ba7ae82673John McCall  }
1534680523a91dd3351389667c8de17121ba7ae82673John McCall
15352a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  /// Determines whether this type is a "forbidden" placeholder type,
15362a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  /// i.e. a type which cannot appear in arbitrary positions in a
15372a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  /// fully-formed expression.
15382a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  bool isPlaceholderType() const {
153934b41d939a1328f484511c6002ba2456db879a29Richard Smith    return getKind() == Overload;
15402a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  }
15412a984cad5ac3fdceeff2bd99daa7b90979313475John McCall
15425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T) { return T->getTypeClass() == Builtin; }
15435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const BuiltinType *) { return true; }
15445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
15455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
15465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ComplexType - C99 6.2.5p11 - Complex values.  This supports the C99 complex
15475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// types (_Complex float etc) as well as the GCC integer complex extensions.
15485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
15495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ComplexType : public Type, public llvm::FoldingSetNode {
15505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType ElementType;
15515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ComplexType(QualType Element, QualType CanonicalPtr) :
155235495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    Type(Complex, CanonicalPtr, Element->isDependentType(),
1553d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor         Element->isVariablyModifiedType(),
1554d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor         Element->containsUnexpandedParameterPack()),
1555898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    ElementType(Element) {
15565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
15575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
155860e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
15595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
15605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType getElementType() const { return ElementType; }
15611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1562bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1563bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1564bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
15655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void Profile(llvm::FoldingSetNodeID &ID) {
15665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Profile(ID, getElementType());
15675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
15685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static void Profile(llvm::FoldingSetNodeID &ID, QualType Element) {
15695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ID.AddPointer(Element.getAsOpaquePtr());
15705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
15711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
15725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T) { return T->getTypeClass() == Complex; }
15735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const ComplexType *) { return true; }
15745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
15755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1576075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara/// ParenType - Sugar for parentheses used when specifying types.
1577075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara///
1578075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnaraclass ParenType : public Type, public llvm::FoldingSetNode {
1579075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  QualType Inner;
1580075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
1581075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  ParenType(QualType InnerType, QualType CanonType) :
1582075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara    Type(Paren, CanonType, InnerType->isDependentType(),
1583d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor         InnerType->isVariablyModifiedType(),
1584d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor         InnerType->containsUnexpandedParameterPack()),
1585075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara    Inner(InnerType) {
1586075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  }
1587075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  friend class ASTContext;  // ASTContext creates these.
1588075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
1589075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnarapublic:
1590075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
1591075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  QualType getInnerType() const { return Inner; }
1592075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
1593075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  bool isSugared() const { return true; }
1594075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  QualType desugar() const { return getInnerType(); }
1595075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
1596075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  void Profile(llvm::FoldingSetNodeID &ID) {
1597075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara    Profile(ID, getInnerType());
1598075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  }
1599075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  static void Profile(llvm::FoldingSetNodeID &ID, QualType Inner) {
1600075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara    Inner.Profile(ID);
1601075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  }
1602075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
1603075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  static bool classof(const Type *T) { return T->getTypeClass() == Paren; }
1604075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  static bool classof(const ParenType *) { return true; }
1605075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara};
1606075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
160768694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar/// PointerType - C99 6.7.5.1 - Pointer Declarators.
1608bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner///
160968694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbarclass PointerType : public Type, public llvm::FoldingSetNode {
1610bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner  QualType PointeeType;
16115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
16125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  PointerType(QualType Pointee, QualType CanonicalPtr) :
161335495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    Type(Pointer, CanonicalPtr, Pointee->isDependentType(),
1614d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor         Pointee->isVariablyModifiedType(),
1615d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor         Pointee->containsUnexpandedParameterPack()),
161635495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    PointeeType(Pointee) {
16175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
16185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
161960e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
16205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
16211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
162268694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar  QualType getPointeeType() const { return PointeeType; }
162368694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar
1624bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1625bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1626bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
16275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void Profile(llvm::FoldingSetNodeID &ID) {
16285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Profile(ID, getPointeeType());
16295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
16305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) {
16315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ID.AddPointer(Pointee.getAsOpaquePtr());
16325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
16331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
16345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T) { return T->getTypeClass() == Pointer; }
16355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const PointerType *) { return true; }
16365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
16375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
16385618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff/// BlockPointerType - pointer to a block type.
16395618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff/// This type is to represent types syntactically represented as
16405618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff/// "void (^)(int)", etc. Pointee is required to always be a function type.
16415618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff///
16425618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroffclass BlockPointerType : public Type, public llvm::FoldingSetNode {
16435618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  QualType PointeeType;  // Block is some kind of pointer type
16445618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  BlockPointerType(QualType Pointee, QualType CanonicalCls) :
164535495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    Type(BlockPointer, CanonicalCls, Pointee->isDependentType(),
1646d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor         Pointee->isVariablyModifiedType(),
1647d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor         Pointee->containsUnexpandedParameterPack()),
1648898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    PointeeType(Pointee) {
16495618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  }
16505618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  friend class ASTContext;  // ASTContext creates these.
165160e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
16525618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroffpublic:
16531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
16545618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  // Get the pointee type. Pointee is required to always be a function type.
16555618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  QualType getPointeeType() const { return PointeeType; }
16565618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff
1657bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1658bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1659bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
16605618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  void Profile(llvm::FoldingSetNodeID &ID) {
16615618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff      Profile(ID, getPointeeType());
16625618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  }
16635618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) {
16645618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff      ID.AddPointer(Pointee.getAsOpaquePtr());
16655618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  }
16661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
16671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
16681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == BlockPointer;
16695618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  }
16705618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  static bool classof(const BlockPointerType *) { return true; }
16715618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff};
16725618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff
16737c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// ReferenceType - Base for LValueReferenceType and RValueReferenceType
16745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
167568694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbarclass ReferenceType : public Type, public llvm::FoldingSetNode {
167668694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar  QualType PointeeType;
167768694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar
16787c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlprotected:
167954e14c4db764c0636160d26c5bbf491637c83a76John McCall  ReferenceType(TypeClass tc, QualType Referencee, QualType CanonicalRef,
168054e14c4db764c0636160d26c5bbf491637c83a76John McCall                bool SpelledAsLValue) :
168135495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    Type(tc, CanonicalRef, Referencee->isDependentType(),
1682d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor         Referencee->isVariablyModifiedType(),
1683d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor         Referencee->containsUnexpandedParameterPack()),
1684d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    PointeeType(Referencee)
1685d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  {
1686b870b88df784c2940efce448ebfaf54dece14666John McCall    ReferenceTypeBits.SpelledAsLValue = SpelledAsLValue;
1687b870b88df784c2940efce448ebfaf54dece14666John McCall    ReferenceTypeBits.InnerRef = Referencee->isReferenceType();
16885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
168960e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
16905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
1691b870b88df784c2940efce448ebfaf54dece14666John McCall  bool isSpelledAsLValue() const { return ReferenceTypeBits.SpelledAsLValue; }
1692b870b88df784c2940efce448ebfaf54dece14666John McCall  bool isInnerRef() const { return ReferenceTypeBits.InnerRef; }
169373dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor
169454e14c4db764c0636160d26c5bbf491637c83a76John McCall  QualType getPointeeTypeAsWritten() const { return PointeeType; }
169554e14c4db764c0636160d26c5bbf491637c83a76John McCall  QualType getPointeeType() const {
169654e14c4db764c0636160d26c5bbf491637c83a76John McCall    // FIXME: this might strip inner qualifiers; okay?
169754e14c4db764c0636160d26c5bbf491637c83a76John McCall    const ReferenceType *T = this;
169871c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    while (T->isInnerRef())
1699d0370f59e79702ac908c81bf556519f91e9ca297John McCall      T = T->PointeeType->castAs<ReferenceType>();
170054e14c4db764c0636160d26c5bbf491637c83a76John McCall    return T->PointeeType;
170154e14c4db764c0636160d26c5bbf491637c83a76John McCall  }
170268694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar
17035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void Profile(llvm::FoldingSetNodeID &ID) {
170471c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    Profile(ID, PointeeType, isSpelledAsLValue());
17055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
170654e14c4db764c0636160d26c5bbf491637c83a76John McCall  static void Profile(llvm::FoldingSetNodeID &ID,
170754e14c4db764c0636160d26c5bbf491637c83a76John McCall                      QualType Referencee,
170854e14c4db764c0636160d26c5bbf491637c83a76John McCall                      bool SpelledAsLValue) {
17095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ID.AddPointer(Referencee.getAsOpaquePtr());
171054e14c4db764c0636160d26c5bbf491637c83a76John McCall    ID.AddBoolean(SpelledAsLValue);
17115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
17125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
17137c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  static bool classof(const Type *T) {
17147c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl    return T->getTypeClass() == LValueReference ||
17157c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl           T->getTypeClass() == RValueReference;
17167c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  }
17175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const ReferenceType *) { return true; }
17187c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl};
17197c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl
17207c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// LValueReferenceType - C++ [dcl.ref] - Lvalue reference
17217c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl///
17227c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlclass LValueReferenceType : public ReferenceType {
172354e14c4db764c0636160d26c5bbf491637c83a76John McCall  LValueReferenceType(QualType Referencee, QualType CanonicalRef,
172454e14c4db764c0636160d26c5bbf491637c83a76John McCall                      bool SpelledAsLValue) :
172554e14c4db764c0636160d26c5bbf491637c83a76John McCall    ReferenceType(LValueReference, Referencee, CanonicalRef, SpelledAsLValue)
172654e14c4db764c0636160d26c5bbf491637c83a76John McCall  {}
17277c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  friend class ASTContext; // ASTContext creates these
17287c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlpublic:
1729bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1730bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1731bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
17327c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  static bool classof(const Type *T) {
17337c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl    return T->getTypeClass() == LValueReference;
17347c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  }
17357c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  static bool classof(const LValueReferenceType *) { return true; }
17367c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl};
17377c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl
17387c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// RValueReferenceType - C++0x [dcl.ref] - Rvalue reference
17397c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl///
17407c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlclass RValueReferenceType : public ReferenceType {
17417c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  RValueReferenceType(QualType Referencee, QualType CanonicalRef) :
174254e14c4db764c0636160d26c5bbf491637c83a76John McCall    ReferenceType(RValueReference, Referencee, CanonicalRef, false) {
17437c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  }
17447c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  friend class ASTContext; // ASTContext creates these
17457c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlpublic:
1746bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1747bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1748bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
17497c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  static bool classof(const Type *T) {
17507c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl    return T->getTypeClass() == RValueReference;
17517c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  }
17527c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  static bool classof(const RValueReferenceType *) { return true; }
1753f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl};
1754f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl
1755f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl/// MemberPointerType - C++ 8.3.3 - Pointers to members
1756f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl///
1757f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlclass MemberPointerType : public Type, public llvm::FoldingSetNode {
1758f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  QualType PointeeType;
1759f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  /// The class of which the pointee is a member. Must ultimately be a
1760f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  /// RecordType, but could be a typedef or a template parameter too.
1761f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  const Type *Class;
1762f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl
1763f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  MemberPointerType(QualType Pointee, const Type *Cls, QualType CanonicalPtr) :
1764f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    Type(MemberPointer, CanonicalPtr,
176535495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor         Cls->isDependentType() || Pointee->isDependentType(),
1766d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor         Pointee->isVariablyModifiedType(),
1767d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor         (Cls->containsUnexpandedParameterPack() ||
1768d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor          Pointee->containsUnexpandedParameterPack())),
1769f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    PointeeType(Pointee), Class(Cls) {
1770f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  }
1771f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  friend class ASTContext; // ASTContext creates these.
177260e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
1773f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlpublic:
1774f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  QualType getPointeeType() const { return PointeeType; }
1775f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl
17760bab0cdab751248ca389a5592bcb70eac5d39260John McCall  /// Returns true if the member type (i.e. the pointee type) is a
17770bab0cdab751248ca389a5592bcb70eac5d39260John McCall  /// function type rather than a data-member type.
17780bab0cdab751248ca389a5592bcb70eac5d39260John McCall  bool isMemberFunctionPointer() const {
17790bab0cdab751248ca389a5592bcb70eac5d39260John McCall    return PointeeType->isFunctionProtoType();
17800bab0cdab751248ca389a5592bcb70eac5d39260John McCall  }
17810bab0cdab751248ca389a5592bcb70eac5d39260John McCall
17820bab0cdab751248ca389a5592bcb70eac5d39260John McCall  /// Returns true if the member type (i.e. the pointee type) is a
17830bab0cdab751248ca389a5592bcb70eac5d39260John McCall  /// data type rather than a function type.
17840bab0cdab751248ca389a5592bcb70eac5d39260John McCall  bool isMemberDataPointer() const {
17850bab0cdab751248ca389a5592bcb70eac5d39260John McCall    return !PointeeType->isFunctionProtoType();
17860bab0cdab751248ca389a5592bcb70eac5d39260John McCall  }
17870bab0cdab751248ca389a5592bcb70eac5d39260John McCall
1788f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  const Type *getClass() const { return Class; }
1789f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl
1790bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1791bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1792bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
1793f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  void Profile(llvm::FoldingSetNodeID &ID) {
1794f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    Profile(ID, getPointeeType(), getClass());
1795f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  }
1796f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee,
1797f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl                      const Type *Class) {
1798f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    ID.AddPointer(Pointee.getAsOpaquePtr());
1799f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    ID.AddPointer(Class);
1800f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  }
1801f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl
1802f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  static bool classof(const Type *T) {
1803f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    return T->getTypeClass() == MemberPointer;
1804f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  }
1805f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  static bool classof(const MemberPointerType *) { return true; }
18065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
18075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
18085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ArrayType - C99 6.7.5.2 - Array Declarators.
18095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
18102e7d352dbec06755105237afba183492d31d03cbTed Kremenekclass ArrayType : public Type, public llvm::FoldingSetNode {
18115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
18125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// ArraySizeModifier - Capture whether this is a normal array (e.g. int X[4])
1813898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// an array with a static size (e.g. int X[static 4]), or an array
1814898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// with a star size (e.g. int X[*]).
1815898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// 'static' is only allowed on function parameters.
18165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  enum ArraySizeModifier {
18175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Normal, Static, Star
18185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
18195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate:
1820fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  /// ElementType - The element type of the array.
1821fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  QualType ElementType;
18221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1823fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroffprotected:
1824898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  // C++ [temp.dep.type]p1:
1825898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  //   A type is dependent if it is...
1826898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  //     - an array type constructed from any dependent type or whose
1827898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  //       size is specified by a constant expression that is
1828898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  //       value-dependent,
1829c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff  ArrayType(TypeClass tc, QualType et, QualType can,
1830d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor            ArraySizeModifier sm, unsigned tq,
1831d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor            bool ContainsUnexpandedParameterPack)
183235495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    : Type(tc, can, et->isDependentType() || tc == DependentSizedArray,
1833d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor           (tc == VariableArray || et->isVariablyModifiedType()),
1834d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor           ContainsUnexpandedParameterPack),
183571c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall      ElementType(et) {
1836b870b88df784c2940efce448ebfaf54dece14666John McCall    ArrayTypeBits.IndexTypeQuals = tq;
1837b870b88df784c2940efce448ebfaf54dece14666John McCall    ArrayTypeBits.SizeModifier = sm;
183871c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  }
1839898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
1840fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  friend class ASTContext;  // ASTContext creates these.
184160e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
1842fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroffpublic:
1843fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  QualType getElementType() const { return ElementType; }
1844ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek  ArraySizeModifier getSizeModifier() const {
1845b870b88df784c2940efce448ebfaf54dece14666John McCall    return ArraySizeModifier(ArrayTypeBits.SizeModifier);
1846ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek  }
18470953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  Qualifiers getIndexTypeQualifiers() const {
184871c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    return Qualifiers::fromCVRMask(getIndexTypeCVRQualifiers());
184971c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  }
185071c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  unsigned getIndexTypeCVRQualifiers() const {
1851b870b88df784c2940efce448ebfaf54dece14666John McCall    return ArrayTypeBits.IndexTypeQuals;
18520953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
18531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1854fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  static bool classof(const Type *T) {
1855fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff    return T->getTypeClass() == ConstantArray ||
1856c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman           T->getTypeClass() == VariableArray ||
1857898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor           T->getTypeClass() == IncompleteArray ||
1858898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor           T->getTypeClass() == DependentSizedArray;
1859fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  }
1860fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  static bool classof(const ArrayType *) { return true; }
1861fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff};
1862fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff
18637e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// ConstantArrayType - This class represents the canonical version of
18647e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// C arrays with a specified constant size.  For example, the canonical
18657e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// type for 'int A[4 + 4*100]' is a ConstantArrayType where the element
18667e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// type is 'int' and the size is 404.
18672e7d352dbec06755105237afba183492d31d03cbTed Kremenekclass ConstantArrayType : public ArrayType {
1868fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  llvm::APInt Size; // Allows us to unique the type.
18691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
18700be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner  ConstantArrayType(QualType et, QualType can, const llvm::APInt &size,
1871c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff                    ArraySizeModifier sm, unsigned tq)
1872d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    : ArrayType(ConstantArray, et, can, sm, tq,
1873d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor                et->containsUnexpandedParameterPack()),
18747e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor      Size(size) {}
18757e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregorprotected:
18767e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  ConstantArrayType(TypeClass tc, QualType et, QualType can,
18777e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor                    const llvm::APInt &size, ArraySizeModifier sm, unsigned tq)
1878d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    : ArrayType(tc, et, can, sm, tq, et->containsUnexpandedParameterPack()),
1879d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor      Size(size) {}
1880fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  friend class ASTContext;  // ASTContext creates these.
1881fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroffpublic:
1882c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  const llvm::APInt &getSize() const { return Size; }
1883bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1884bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1885bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
18862767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor
18872767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor  /// \brief Determine the number of bits required to address a member of
18882767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor  // an array with the given element type and number of elements.
18892767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor  static unsigned getNumAddressingBits(ASTContext &Context,
18902767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor                                       QualType ElementType,
18912767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor                                       const llvm::APInt &NumElements);
18922767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor
18932767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor  /// \brief Determine the maximum number of active bits that an array's size
18942767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor  /// can require, which limits the maximum size of the array.
18952767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor  static unsigned getMaxSizeBits(ASTContext &Context);
18962767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor
1897fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  void Profile(llvm::FoldingSetNodeID &ID) {
18981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    Profile(ID, getElementType(), getSize(),
18990953e767ff7817f97b3ab20896b229891eeff45bJohn McCall            getSizeModifier(), getIndexTypeCVRQualifiers());
1900fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  }
1901fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  static void Profile(llvm::FoldingSetNodeID &ID, QualType ET,
19020be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner                      const llvm::APInt &ArraySize, ArraySizeModifier SizeMod,
19030be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner                      unsigned TypeQuals) {
1904fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff    ID.AddPointer(ET.getAsOpaquePtr());
1905fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff    ID.AddInteger(ArraySize.getZExtValue());
19060be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner    ID.AddInteger(SizeMod);
19070be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner    ID.AddInteger(TypeQuals);
1908fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  }
19097e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  static bool classof(const Type *T) {
191046a617a792bfab0d9b1e057371ea3b9540802226John McCall    return T->getTypeClass() == ConstantArray;
1911fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  }
1912fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  static bool classof(const ConstantArrayType *) { return true; }
1913fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff};
1914fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff
1915da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// IncompleteArrayType - This class represents C arrays with an unspecified
1916da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// size.  For example 'int A[]' has an IncompleteArrayType where the element
1917da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// type is 'int' and the size is unspecified.
1918c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedmanclass IncompleteArrayType : public ArrayType {
19197e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor
1920c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman  IncompleteArrayType(QualType et, QualType can,
19217e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor                      ArraySizeModifier sm, unsigned tq)
1922d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    : ArrayType(IncompleteArray, et, can, sm, tq,
1923d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor                et->containsUnexpandedParameterPack()) {}
1924c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman  friend class ASTContext;  // ASTContext creates these.
1925c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedmanpublic:
1926bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1927bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1928bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
19291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
19301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == IncompleteArray;
1931c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman  }
1932c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman  static bool classof(const IncompleteArrayType *) { return true; }
19331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1934c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman  friend class StmtIteratorBase;
19351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1936c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman  void Profile(llvm::FoldingSetNodeID &ID) {
19370953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Profile(ID, getElementType(), getSizeModifier(),
19380953e767ff7817f97b3ab20896b229891eeff45bJohn McCall            getIndexTypeCVRQualifiers());
1939c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman  }
19401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
19410be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner  static void Profile(llvm::FoldingSetNodeID &ID, QualType ET,
19420be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner                      ArraySizeModifier SizeMod, unsigned TypeQuals) {
1943c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman    ID.AddPointer(ET.getAsOpaquePtr());
19440be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner    ID.AddInteger(SizeMod);
19450be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner    ID.AddInteger(TypeQuals);
1946c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman  }
1947c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman};
1948c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman
1949da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// VariableArrayType - This class represents C arrays with a specified size
1950da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// which is not an integer-constant-expression.  For example, 'int s[x+foo()]'.
1951da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// Since the size expression is an arbitrary expression, we store it as such.
1952da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner///
1953da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// Note: VariableArrayType's aren't uniqued (since the expressions aren't) and
1954da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// should not be: two lexically equivalent variable array types could mean
1955da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// different things, for example, these variables do not have the same type
1956da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// dynamically:
1957da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner///
1958da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// void foo(int x) {
1959da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner///   int Y[x];
1960da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner///   ++x;
1961da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner///   int Z[x];
1962da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// }
1963da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner///
19642e7d352dbec06755105237afba183492d31d03cbTed Kremenekclass VariableArrayType : public ArrayType {
19651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// SizeExpr - An assignment expression. VLA's are only permitted within
19661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// a function block.
1967b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek  Stmt *SizeExpr;
19687e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  /// Brackets - The left and right array brackets.
19697e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  SourceRange Brackets;
19707e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor
1971c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff  VariableArrayType(QualType et, QualType can, Expr *e,
19727e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor                    ArraySizeModifier sm, unsigned tq,
19737e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor                    SourceRange brackets)
1974d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    : ArrayType(VariableArray, et, can, sm, tq,
1975d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor                et->containsUnexpandedParameterPack()),
19767e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor      SizeExpr((Stmt*) e), Brackets(brackets) {}
19775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
19784b05b1dee6cc65ae61d93dab7edff72710f24589Ted Kremenek
19795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
19801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Expr *getSizeExpr() const {
1981b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek    // We use C-style casts instead of cast<> here because we do not wish
1982b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek    // to have a dependency of Type.h on Stmt.h/Expr.h.
1983b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek    return (Expr*) SizeExpr;
1984b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek  }
19857e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  SourceRange getBracketsRange() const { return Brackets; }
19867e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  SourceLocation getLBracketLoc() const { return Brackets.getBegin(); }
19877e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  SourceLocation getRBracketLoc() const { return Brackets.getEnd(); }
19881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1989bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1990bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1991bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
19921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
19931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == VariableArray;
19945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
1995fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  static bool classof(const VariableArrayType *) { return true; }
19961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
199792866e2e90f6d93fb95e25a7ac4438e239d89ce6Ted Kremenek  friend class StmtIteratorBase;
19981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
19992bd24ba6d10f8c811c8e2a57c8397e07082ba497Ted Kremenek  void Profile(llvm::FoldingSetNodeID &ID) {
2000bc5e150b6d94cf131f7d01bc715571b741c5b408Chris Lattner    assert(0 && "Cannnot unique VariableArrayTypes.");
20012bd24ba6d10f8c811c8e2a57c8397e07082ba497Ted Kremenek  }
20025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
20035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2004898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// DependentSizedArrayType - This type represents an array type in
2005898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// C++ whose size is a value-dependent expression. For example:
2006cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor///
2007cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor/// \code
20081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// template<typename T, int Size>
2009898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// class array {
2010898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor///   T data[Size];
2011898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// };
2012cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor/// \endcode
2013cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor///
2014898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// For these types, we won't actually know what the array bound is
2015898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// until template instantiation occurs, at which point this will
2016898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// become either a ConstantArrayType or a VariableArrayType.
2017898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorclass DependentSizedArrayType : public ArrayType {
20184ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  const ASTContext &Context;
20191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2020cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor  /// \brief An assignment expression that will instantiate to the
2021898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// size of the array.
2022cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor  ///
2023cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor  /// The expression itself might be NULL, in which case the array
2024cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor  /// type will have its size deduced from an initializer.
2025898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  Stmt *SizeExpr;
2026cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor
20277e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  /// Brackets - The left and right array brackets.
20287e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  SourceRange Brackets;
20291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
20304ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  DependentSizedArrayType(const ASTContext &Context, QualType et, QualType can,
203104d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor                          Expr *e, ArraySizeModifier sm, unsigned tq,
2032d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor                          SourceRange brackets);
2033d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor
2034898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  friend class ASTContext;  // ASTContext creates these.
2035898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
2036898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorpublic:
20371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Expr *getSizeExpr() const {
2038898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    // We use C-style casts instead of cast<> here because we do not wish
2039898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    // to have a dependency of Type.h on Stmt.h/Expr.h.
2040898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    return (Expr*) SizeExpr;
2041898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  }
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() == DependentSizedArray;
2051898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  }
2052898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  static bool classof(const DependentSizedArrayType *) { return true; }
20531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2054898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  friend class StmtIteratorBase;
20551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
20561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2057898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  void Profile(llvm::FoldingSetNodeID &ID) {
20581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    Profile(ID, Context, getElementType(),
20590953e767ff7817f97b3ab20896b229891eeff45bJohn McCall            getSizeModifier(), getIndexTypeCVRQualifiers(), getSizeExpr());
2060898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  }
20611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
20624ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
20631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                      QualType ET, ArraySizeModifier SizeMod,
206404d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor                      unsigned TypeQuals, Expr *E);
2065898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor};
2066898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
2067f6ddb737cb882ffbf0b75a9abd50b930cc2b9068Douglas Gregor/// DependentSizedExtVectorType - This type represent an extended vector type
20689cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// where either the type or size is dependent. For example:
20699cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// @code
20709cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// template<typename T, int Size>
20719cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// class vector {
20729cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor///   typedef T __attribute__((ext_vector_type(Size))) type;
20739cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// }
20749cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// @endcode
20752ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregorclass DependentSizedExtVectorType : public Type, public llvm::FoldingSetNode {
20764ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  const ASTContext &Context;
20779cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor  Expr *SizeExpr;
20789cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor  /// ElementType - The element type of the array.
20799cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor  QualType ElementType;
20809cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor  SourceLocation loc;
20811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
20824ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  DependentSizedExtVectorType(const ASTContext &Context, QualType ElementType,
2083d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor                              QualType can, Expr *SizeExpr, SourceLocation loc);
2084d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor
20859cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor  friend class ASTContext;
20869cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor
20879cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregorpublic:
20882ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor  Expr *getSizeExpr() const { return SizeExpr; }
20899cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor  QualType getElementType() const { return ElementType; }
20909cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor  SourceLocation getAttributeLoc() const { return loc; }
20919cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor
2092bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2093bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2094bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
20951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
20961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == DependentSizedExtVector;
20979cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor  }
20981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const DependentSizedExtVectorType *) { return true; }
20992ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor
21002ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor  void Profile(llvm::FoldingSetNodeID &ID) {
21012ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor    Profile(ID, Context, getElementType(), getSizeExpr());
21022ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor  }
21031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
21044ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
21052ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor                      QualType ElementType, Expr *SizeExpr);
21069cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor};
21071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
21089cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor
210973322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// VectorType - GCC generic vector type. This type is created using
21101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// __attribute__((vector_size(n)), where "n" specifies the vector size in
211182287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson/// bytes; or from an Altivec __vector or vector declaration.
211282287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson/// Since the constructor takes the number of vector elements, the
211373322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// client is responsible for converting the size into the number of elements.
21145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass VectorType : public Type, public llvm::FoldingSetNode {
2115788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattnerpublic:
2116e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson  enum VectorKind {
2117e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson    GenericVector,  // not a target-specific vector type
2118e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson    AltiVecVector,  // is AltiVec vector
2119e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson    AltiVecPixel,   // is AltiVec 'vector Pixel'
2120e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson    AltiVecBool,    // is AltiVec 'vector bool ...'
2121491328c90c00ecad6ad27fa0ab3cdf9195a4a820Bob Wilson    NeonVector,     // is ARM Neon vector
2122491328c90c00ecad6ad27fa0ab3cdf9195a4a820Bob Wilson    NeonPolyVector  // is ARM Neon polynomial vector
2123788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner  };
212473322924127c873c13101b705dd823f5539ffa5fSteve Naroffprotected:
21255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// ElementType - The element type of the vector.
21265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType ElementType;
21271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
212882287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson  VectorType(QualType vecType, unsigned nElements, QualType canonType,
2129d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor             VectorKind vecKind);
213035495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor
21311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  VectorType(TypeClass tc, QualType vecType, unsigned nElements,
2132d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor             QualType canonType, VectorKind vecKind);
2133d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor
21345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
213560e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
21365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
21371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
21385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType getElementType() const { return ElementType; }
2139b870b88df784c2940efce448ebfaf54dece14666John McCall  unsigned getNumElements() const { return VectorTypeBits.NumElements; }
21405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2141bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2142bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2143bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
2144e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson  VectorKind getVectorKind() const {
2145e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson    return VectorKind(VectorTypeBits.VecKind);
214671c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  }
2147788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner
21485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void Profile(llvm::FoldingSetNodeID &ID) {
214971c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    Profile(ID, getElementType(), getNumElements(),
2150e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson            getTypeClass(), getVectorKind());
21515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
21521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static void Profile(llvm::FoldingSetNodeID &ID, QualType ElementType,
215382287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson                      unsigned NumElements, TypeClass TypeClass,
2154e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson                      VectorKind VecKind) {
21555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ID.AddPointer(ElementType.getAsOpaquePtr());
21565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ID.AddInteger(NumElements);
215773322924127c873c13101b705dd823f5539ffa5fSteve Naroff    ID.AddInteger(TypeClass);
2158e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson    ID.AddInteger(VecKind);
215973322924127c873c13101b705dd823f5539ffa5fSteve Naroff  }
21600b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor
21611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
21621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == Vector || T->getTypeClass() == ExtVector;
21635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
21645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const VectorType *) { return true; }
21655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
21665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2167213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman/// ExtVectorType - Extended vector type. This type is created using
2168213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman/// __attribute__((ext_vector_type(n)), where "n" is the number of elements.
2169213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman/// Unlike vector_size, ext_vector_type is only allowed on typedef's. This
2170fcac0fff877a461bc5d5a57e6c6727a4c819d95aSteve Naroff/// class enables syntactic extensions, like Vector Components for accessing
2171fcac0fff877a461bc5d5a57e6c6727a4c819d95aSteve Naroff/// points, colors, and textures (modeled after OpenGL Shading Language).
2172213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begemanclass ExtVectorType : public VectorType {
2173213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman  ExtVectorType(QualType vecType, unsigned nElements, QualType canonType) :
2174e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson    VectorType(ExtVector, vecType, nElements, canonType, GenericVector) {}
217573322924127c873c13101b705dd823f5539ffa5fSteve Naroff  friend class ASTContext;  // ASTContext creates these.
217673322924127c873c13101b705dd823f5539ffa5fSteve Naroffpublic:
217788dca0464804b8b26ae605f89784c927e8493dddChris Lattner  static int getPointAccessorIdx(char c) {
217888dca0464804b8b26ae605f89784c927e8493dddChris Lattner    switch (c) {
217988dca0464804b8b26ae605f89784c927e8493dddChris Lattner    default: return -1;
218088dca0464804b8b26ae605f89784c927e8493dddChris Lattner    case 'x': return 0;
218188dca0464804b8b26ae605f89784c927e8493dddChris Lattner    case 'y': return 1;
218288dca0464804b8b26ae605f89784c927e8493dddChris Lattner    case 'z': return 2;
218388dca0464804b8b26ae605f89784c927e8493dddChris Lattner    case 'w': return 3;
218488dca0464804b8b26ae605f89784c927e8493dddChris Lattner    }
2185e1b31fedbc006e6e4071bbb4f74c6116b56cfa9fSteve Naroff  }
2186353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman  static int getNumericAccessorIdx(char c) {
218788dca0464804b8b26ae605f89784c927e8493dddChris Lattner    switch (c) {
2188353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      default: return -1;
2189353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '0': return 0;
2190353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '1': return 1;
2191353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '2': return 2;
2192353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '3': return 3;
2193353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '4': return 4;
2194353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '5': return 5;
2195353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '6': return 6;
2196353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '7': return 7;
2197353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '8': return 8;
2198353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '9': return 9;
2199131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman      case 'A':
2200353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case 'a': return 10;
2201131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman      case 'B':
2202353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case 'b': return 11;
2203131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman      case 'C':
2204353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case 'c': return 12;
2205131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman      case 'D':
2206353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case 'd': return 13;
2207131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman      case 'E':
2208353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case 'e': return 14;
2209131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman      case 'F':
2210353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case 'f': return 15;
221188dca0464804b8b26ae605f89784c927e8493dddChris Lattner    }
2212e1b31fedbc006e6e4071bbb4f74c6116b56cfa9fSteve Naroff  }
22131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2214b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner  static int getAccessorIdx(char c) {
2215b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner    if (int idx = getPointAccessorIdx(c)+1) return idx-1;
2216353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman    return getNumericAccessorIdx(c);
2217b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner  }
22181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
221988dca0464804b8b26ae605f89784c927e8493dddChris Lattner  bool isAccessorWithinNumElements(char c) const {
2220b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner    if (int idx = getAccessorIdx(c)+1)
222171c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall      return unsigned(idx-1) < getNumElements();
222288dca0464804b8b26ae605f89784c927e8493dddChris Lattner    return false;
2223e1b31fedbc006e6e4071bbb4f74c6116b56cfa9fSteve Naroff  }
2224bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2225bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2226bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
22271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
22281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == ExtVector;
222973322924127c873c13101b705dd823f5539ffa5fSteve Naroff  }
2230213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman  static bool classof(const ExtVectorType *) { return true; }
223173322924127c873c13101b705dd823f5539ffa5fSteve Naroff};
223273322924127c873c13101b705dd823f5539ffa5fSteve Naroff
22335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// FunctionType - C99 6.7.5.3 - Function Declarators.  This is the common base
223472564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// class of FunctionNoProtoType and FunctionProtoType.
22355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
22365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass FunctionType : public Type {
22375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // The type returned by the function.
22385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType ResultType;
2239264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola
2240264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola public:
2241373920bd733b1d28fe7bf209945a62eb9248d948John McCall  /// ExtInfo - A class which abstracts out some details necessary for
2242373920bd733b1d28fe7bf209945a62eb9248d948John McCall  /// making a call.
2243373920bd733b1d28fe7bf209945a62eb9248d948John McCall  ///
2244373920bd733b1d28fe7bf209945a62eb9248d948John McCall  /// It is not actually used directly for storing this information in
2245373920bd733b1d28fe7bf209945a62eb9248d948John McCall  /// a FunctionType, although FunctionType does currently use the
2246373920bd733b1d28fe7bf209945a62eb9248d948John McCall  /// same bit-pattern.
2247373920bd733b1d28fe7bf209945a62eb9248d948John McCall  ///
2248075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  // If you add a field (say Foo), other than the obvious places (both,
2249075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  // constructors, compile failures), what you need to update is
2250075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  // * Operator==
2251425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola  // * getFoo
2252425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola  // * withFoo
2253425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola  // * functionType. Add Foo, getFoo.
2254425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola  // * ASTContext::getFooType
2255425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola  // * ASTContext::mergeFunctionTypes
2256425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola  // * FunctionNoProtoType::Profile
2257425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola  // * FunctionProtoType::Profile
2258425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola  // * TypePrinter::PrintFunctionProto
22593c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  // * AST read and write
2260425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola  // * Codegen
2261264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola  class ExtInfo {
2262373920bd733b1d28fe7bf209945a62eb9248d948John McCall    // Feel free to rearrange or add bits, but if you go over 8,
2263373920bd733b1d28fe7bf209945a62eb9248d948John McCall    // you'll need to adjust both the Bits field below and
2264373920bd733b1d28fe7bf209945a62eb9248d948John McCall    // Type::FunctionTypeBitfields.
2265373920bd733b1d28fe7bf209945a62eb9248d948John McCall
2266373920bd733b1d28fe7bf209945a62eb9248d948John McCall    //   |  CC  |noreturn|regparm
2267373920bd733b1d28fe7bf209945a62eb9248d948John McCall    //   |0 .. 2|   3    |4 ..  6
2268b870b88df784c2940efce448ebfaf54dece14666John McCall    enum { CallConvMask = 0x7 };
2269b870b88df784c2940efce448ebfaf54dece14666John McCall    enum { NoReturnMask = 0x8 };
2270b870b88df784c2940efce448ebfaf54dece14666John McCall    enum { RegParmMask = ~(CallConvMask | NoReturnMask),
2271b870b88df784c2940efce448ebfaf54dece14666John McCall           RegParmOffset = 4 };
2272b870b88df784c2940efce448ebfaf54dece14666John McCall
2273373920bd733b1d28fe7bf209945a62eb9248d948John McCall    unsigned char Bits;
227471c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall
2275373920bd733b1d28fe7bf209945a62eb9248d948John McCall    ExtInfo(unsigned Bits) : Bits(static_cast<unsigned char>(Bits)) {}
227671c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall
227771c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    friend class FunctionType;
227871c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall
2279264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola   public:
2280264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    // Constructor with no defaults. Use this when you know that you
22813c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl    // have all the elements (when reading an AST file for example).
228271c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    ExtInfo(bool noReturn, unsigned regParm, CallingConv cc) {
2283b870b88df784c2940efce448ebfaf54dece14666John McCall      Bits = ((unsigned) cc) |
2284b870b88df784c2940efce448ebfaf54dece14666John McCall             (noReturn ? NoReturnMask : 0) |
2285b870b88df784c2940efce448ebfaf54dece14666John McCall             (regParm << RegParmOffset);
228671c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    }
2287264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola
2288264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    // Constructor with all defaults. Use when for example creating a
2289264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    // function know to use defaults.
229071c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    ExtInfo() : Bits(0) {}
2291264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola
2292b870b88df784c2940efce448ebfaf54dece14666John McCall    bool getNoReturn() const { return Bits & NoReturnMask; }
2293b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned getRegParm() const { return Bits >> RegParmOffset; }
2294b870b88df784c2940efce448ebfaf54dece14666John McCall    CallingConv getCC() const { return CallingConv(Bits & CallConvMask); }
2295264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola
229671c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    bool operator==(ExtInfo Other) const {
229771c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall      return Bits == Other.Bits;
2298264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    }
229971c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    bool operator!=(ExtInfo Other) const {
230071c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall      return Bits != Other.Bits;
2301264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    }
2302264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola
2303264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    // Note that we don't have setters. That is by design, use
2304264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    // the following with methods instead of mutating these objects.
2305264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola
2306264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    ExtInfo withNoReturn(bool noReturn) const {
230771c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall      if (noReturn)
230871c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall        return ExtInfo(Bits | NoReturnMask);
230971c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall      else
231071c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall        return ExtInfo(Bits & ~NoReturnMask);
2311425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola    }
2312425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola
2313425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola    ExtInfo withRegParm(unsigned RegParm) const {
2314b870b88df784c2940efce448ebfaf54dece14666John McCall      return ExtInfo((Bits & ~RegParmMask) | (RegParm << RegParmOffset));
2315264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    }
2316264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola
2317264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    ExtInfo withCallingConv(CallingConv cc) const {
2318b870b88df784c2940efce448ebfaf54dece14666John McCall      return ExtInfo((Bits & ~CallConvMask) | (unsigned) cc);
2319264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    }
2320264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola
2321e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall    void Profile(llvm::FoldingSetNodeID &ID) const {
232271c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall      ID.AddInteger(Bits);
232371c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    }
2324264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola  };
2325264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola
23265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprotected:
2327e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall  FunctionType(TypeClass tc, QualType res, bool variadic,
2328c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor               unsigned typeQuals, RefQualifierKind RefQualifier,
2329c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor               QualType Canonical, bool Dependent,
2330d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor               bool VariablyModified, bool ContainsUnexpandedParameterPack,
2331d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor               ExtInfo Info)
2332d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    : Type(tc, Canonical, Dependent, VariablyModified,
2333d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor           ContainsUnexpandedParameterPack),
2334d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor      ResultType(res) {
2335b870b88df784c2940efce448ebfaf54dece14666John McCall    FunctionTypeBits.ExtInfo = Info.Bits;
2336e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall    FunctionTypeBits.Variadic = variadic;
2337b870b88df784c2940efce448ebfaf54dece14666John McCall    FunctionTypeBits.TypeQuals = typeQuals;
2338c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor    FunctionTypeBits.RefQualifier = static_cast<unsigned>(RefQualifier);
233971c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  }
2340e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall  bool isVariadic() const { return FunctionTypeBits.Variadic; }
2341b870b88df784c2940efce448ebfaf54dece14666John McCall  unsigned getTypeQuals() const { return FunctionTypeBits.TypeQuals; }
2342c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor
2343c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor  RefQualifierKind getRefQualifier() const {
2344c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor    return static_cast<RefQualifierKind>(FunctionTypeBits.RefQualifier);
2345c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor  }
2346c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor
23475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
23481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
23495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType getResultType() const { return ResultType; }
23505291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor
2351b870b88df784c2940efce448ebfaf54dece14666John McCall  unsigned getRegParmType() const { return getExtInfo().getRegParm(); }
2352b870b88df784c2940efce448ebfaf54dece14666John McCall  bool getNoReturnAttr() const { return getExtInfo().getNoReturn(); }
2353b870b88df784c2940efce448ebfaf54dece14666John McCall  CallingConv getCallConv() const { return getExtInfo().getCC(); }
2354b870b88df784c2940efce448ebfaf54dece14666John McCall  ExtInfo getExtInfo() const { return ExtInfo(FunctionTypeBits.ExtInfo); }
23555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
23565291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor  /// \brief Determine the type of an expression that calls a function of
23575291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor  /// this type.
23585291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor  QualType getCallResultType(ASTContext &Context) const {
23596398235d7890a81b785ea5af3b6e66d86bf184ccDouglas Gregor    return getResultType().getNonLValueExprType(Context);
23605291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor  }
23615291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor
236204a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall  static llvm::StringRef getNameForCallConv(CallingConv CC);
236304a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall
23645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T) {
23655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T->getTypeClass() == FunctionNoProto ||
23665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer           T->getTypeClass() == FunctionProto;
23675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
23685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const FunctionType *) { return true; }
23695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
23705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
237172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// FunctionNoProtoType - Represents a K&R-style 'int foo()' function, which has
23725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// no information available about its arguments.
237372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregorclass FunctionNoProtoType : public FunctionType, public llvm::FoldingSetNode {
237471c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  FunctionNoProtoType(QualType Result, QualType Canonical, ExtInfo Info)
2375c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor    : FunctionType(FunctionNoProto, Result, false, 0, RQ_None, Canonical,
237635495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor                   /*Dependent=*/false, Result->isVariablyModifiedType(),
2377d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor                   /*ContainsUnexpandedParameterPack=*/false, Info) {}
2378d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor
23795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
238060e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
23815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
23825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // No additional state past what FunctionType provides.
23831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2384bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2385bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2386bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
23875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void Profile(llvm::FoldingSetNodeID &ID) {
2388264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    Profile(ID, getResultType(), getExtInfo());
23895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
23902455636163fdd18581d7fdae816433f886d88213Mike Stump  static void Profile(llvm::FoldingSetNodeID &ID, QualType ResultType,
239171c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall                      ExtInfo Info) {
239271c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    Info.Profile(ID);
23935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ID.AddPointer(ResultType.getAsOpaquePtr());
23945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
23951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
23965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T) {
23975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T->getTypeClass() == FunctionNoProto;
23985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
239972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  static bool classof(const FunctionNoProtoType *) { return true; }
24005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
24015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
240272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// FunctionProtoType - Represents a prototype with argument type info, e.g.
24035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 'int foo(int)' or 'int foo(void)'.  'void' is represented as having no
2404465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl/// arguments, not as having a single void argument. Such a type can have an
2405465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl/// exception specification, but this specification is not part of the canonical
2406465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl/// type.
240772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregorclass FunctionProtoType : public FunctionType, public llvm::FoldingSetNode {
2408e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCallpublic:
2409e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall  /// ExtProtoInfo - Extra information about a function prototype.
2410e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall  struct ExtProtoInfo {
2411e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall    ExtProtoInfo() :
24128b5b4099c61a136e9a1714c4d8a593febe942268Sebastian Redl      Variadic(false), ExceptionSpecType(EST_None), TypeQuals(0),
24138b5b4099c61a136e9a1714c4d8a593febe942268Sebastian Redl      RefQualifier(RQ_None), NumExceptions(0), Exceptions(0), NoexceptExpr(0) {}
2414e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall
2415e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall    FunctionType::ExtInfo ExtInfo;
2416e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall    bool Variadic;
24178b5b4099c61a136e9a1714c4d8a593febe942268Sebastian Redl    ExceptionSpecificationType ExceptionSpecType;
2418e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall    unsigned char TypeQuals;
2419c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor    RefQualifierKind RefQualifier;
2420e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall    unsigned NumExceptions;
2421e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall    const QualType *Exceptions;
24228b5b4099c61a136e9a1714c4d8a593febe942268Sebastian Redl    Expr *NoexceptExpr;
2423e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall  };
2424e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall
2425e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCallprivate:
2426d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// \brief Determine whether there are any argument types that
2427d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// contain an unexpanded parameter pack.
2428d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  static bool containsAnyUnexpandedParameterPack(const QualType *ArgArray,
2429d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor                                                 unsigned numArgs) {
2430d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    for (unsigned Idx = 0; Idx < numArgs; ++Idx)
2431d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor      if (ArgArray[Idx]->containsUnexpandedParameterPack())
2432d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor        return true;
2433d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor
2434d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    return false;
2435d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  }
2436d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor
2437e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall  FunctionProtoType(QualType result, const QualType *args, unsigned numArgs,
24388026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redl                    QualType canonical, const ExtProtoInfo &epi);
2439465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
24405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// NumArgs - The number of arguments this function has, not counting '...'.
2441465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  unsigned NumArgs : 20;
2442465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
2443465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  /// NumExceptions - The number of types in the exception spec, if any.
244460618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  unsigned NumExceptions : 9;
2445465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
244660618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  /// ExceptionSpecType - The type of exception specification this function has.
244760618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  unsigned ExceptionSpecType : 3;
2448465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
2449942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner  /// ArgInfo - There is an variable size array after the class in memory that
2450942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner  /// holds the argument types.
2451465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
2452465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  /// Exceptions - There is another variable size array after ArgInfo that
2453465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  /// holds the exception types.
2454465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
245560618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  /// NoexceptExpr - Instead of Exceptions, there may be a single Expr* pointing
245660618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  /// to the expression in the noexcept() specifier.
245760618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl
24585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
24594b05b1dee6cc65ae61d93dab7edff72710f24589Ted Kremenek
24605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
24615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned getNumArgs() const { return NumArgs; }
24625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType getArgType(unsigned i) const {
24635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    assert(i < NumArgs && "Invalid argument number!");
2464942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner    return arg_type_begin()[i];
24655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
2466465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
2467e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall  ExtProtoInfo getExtProtoInfo() const {
2468e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall    ExtProtoInfo EPI;
2469e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall    EPI.ExtInfo = getExtInfo();
2470e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall    EPI.Variadic = isVariadic();
247160618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    EPI.ExceptionSpecType = getExceptionSpecType();
2472e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall    EPI.TypeQuals = static_cast<unsigned char>(getTypeQuals());
2473c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor    EPI.RefQualifier = getRefQualifier();
247460618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    if (EPI.ExceptionSpecType == EST_Dynamic) {
247560618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl      EPI.NumExceptions = NumExceptions;
247660618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl      EPI.Exceptions = exception_begin();
247760618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    } else if (EPI.ExceptionSpecType == EST_ComputedNoexcept) {
247860618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl      EPI.NoexceptExpr = getNoexceptExpr();
247960618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    }
2480e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall    return EPI;
2481e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall  }
2482e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall
248360618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  /// \brief Get the kind of exception specification on this function.
248460618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  ExceptionSpecificationType getExceptionSpecType() const {
248560618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    return static_cast<ExceptionSpecificationType>(ExceptionSpecType);
248660618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  }
248760618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  /// \brief Return whether this function has any kind of exception spec.
248860618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  bool hasExceptionSpec() const {
248960618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    return getExceptionSpecType() != EST_None;
249060618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  }
249160618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  /// \brief Return whether this function has a dynamic (throw) exception spec.
249260618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  bool hasDynamicExceptionSpec() const {
249360618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    return isDynamicExceptionSpec(getExceptionSpecType());
249460618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  }
249560618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  /// \brief Return whther this function has a noexcept exception spec.
249660618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  bool hasNoexceptExceptionSpec() const {
249760618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    return isNoexceptExceptionSpec(getExceptionSpecType());
249860618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  }
249960618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  /// \brief Result type of getNoexceptSpec().
250060618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  enum NoexceptResult {
250160618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    NR_NoNoexcept,  ///< There is no noexcept specifier.
250260618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    NR_BadNoexcept, ///< The noexcept specifier has a bad expression.
250360618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    NR_Dependent,   ///< The noexcept specifier is dependent.
250460618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    NR_Throw,       ///< The noexcept specifier evaluates to false.
250560618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    NR_Nothrow      ///< The noexcept specifier evaluates to true.
250660618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  };
250760618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  /// \brief Get the meaning of the noexcept spec on this function, if any.
25088026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redl  NoexceptResult getNoexceptSpec(ASTContext &Ctx) const;
2509465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  unsigned getNumExceptions() const { return NumExceptions; }
2510465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  QualType getExceptionType(unsigned i) const {
2511465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl    assert(i < NumExceptions && "Invalid exception number!");
2512465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl    return exception_begin()[i];
2513465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  }
251460618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  Expr *getNoexceptExpr() const {
251560618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    if (getExceptionSpecType() != EST_ComputedNoexcept)
251660618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl      return 0;
251760618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    // NoexceptExpr sits where the arguments end.
251860618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    return *reinterpret_cast<Expr *const *>(arg_type_end());
2519d3fd6bad1249d3f34d71b73e2333fab0db51cce4Anders Carlsson  }
25208026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redl  bool isNothrow(ASTContext &Ctx) const {
252160618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    ExceptionSpecificationType EST = getExceptionSpecType();
252260618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    if (EST == EST_DynamicNone || EST == EST_BasicNoexcept)
252360618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl      return true;
252460618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    if (EST != EST_ComputedNoexcept)
252560618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl      return false;
25268026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redl    return getNoexceptSpec(Ctx) == NR_Nothrow;
2527c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall  }
2528c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall
2529e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall  using FunctionType::isVariadic;
253060618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl
2531f5c65ffbd7374b6c8d9f1e361041578640cab320Douglas Gregor  /// \brief Determines whether this function prototype contains a
2532f5c65ffbd7374b6c8d9f1e361041578640cab320Douglas Gregor  /// parameter pack at the end.
2533f5c65ffbd7374b6c8d9f1e361041578640cab320Douglas Gregor  ///
2534f5c65ffbd7374b6c8d9f1e361041578640cab320Douglas Gregor  /// A function template whose last parameter is a parameter pack can be
2535f5c65ffbd7374b6c8d9f1e361041578640cab320Douglas Gregor  /// called with an arbitrary number of arguments, much like a variadic
2536f5c65ffbd7374b6c8d9f1e361041578640cab320Douglas Gregor  /// function. However,
2537f5c65ffbd7374b6c8d9f1e361041578640cab320Douglas Gregor  bool isTemplateVariadic() const;
2538f5c65ffbd7374b6c8d9f1e361041578640cab320Douglas Gregor
2539971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis  unsigned getTypeQuals() const { return FunctionType::getTypeQuals(); }
25401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2541c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor
2542c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor  /// \brief Retrieve the ref-qualifier associated with this function type.
2543c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor  RefQualifierKind getRefQualifier() const {
2544c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor    return FunctionType::getRefQualifier();
2545c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor  }
2546c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor
25475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  typedef const QualType *arg_type_iterator;
2548942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner  arg_type_iterator arg_type_begin() const {
2549942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner    return reinterpret_cast<const QualType *>(this+1);
2550942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner  }
2551942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner  arg_type_iterator arg_type_end() const { return arg_type_begin()+NumArgs; }
2552465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
2553465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  typedef const QualType *exception_iterator;
2554465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  exception_iterator exception_begin() const {
2555465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl    // exceptions begin where arguments end
2556465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl    return arg_type_end();
2557465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  }
2558465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  exception_iterator exception_end() const {
255960618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    if (getExceptionSpecType() != EST_Dynamic)
256060618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl      return exception_begin();
2561465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl    return exception_begin() + NumExceptions;
2562465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  }
2563465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
2564bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2565bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2566bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
25675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T) {
25685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T->getTypeClass() == FunctionProto;
25695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
257072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  static bool classof(const FunctionProtoType *) { return true; }
2571465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
25728026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redl  void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Ctx);
25735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static void Profile(llvm::FoldingSetNodeID &ID, QualType Result,
2574942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner                      arg_type_iterator ArgTys, unsigned NumArgs,
25758026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redl                      const ExtProtoInfo &EPI, const ASTContext &Context);
25765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
25775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
25785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2579ed97649e9574b9d854fa4d6109c9333ae0993554John McCall/// \brief Represents the dependent type named by a dependently-scoped
2580ed97649e9574b9d854fa4d6109c9333ae0993554John McCall/// typename using declaration, e.g.
2581ed97649e9574b9d854fa4d6109c9333ae0993554John McCall///   using typename Base<T>::foo;
2582ed97649e9574b9d854fa4d6109c9333ae0993554John McCall/// Template instantiation turns these into the underlying type.
2583ed97649e9574b9d854fa4d6109c9333ae0993554John McCallclass UnresolvedUsingType : public Type {
2584ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  UnresolvedUsingTypenameDecl *Decl;
2585ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
258619c8576b7328f4dc2d07682f5da552875c1912efJohn McCall  UnresolvedUsingType(const UnresolvedUsingTypenameDecl *D)
2587d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    : Type(UnresolvedUsing, QualType(), true, false,
2588d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor           /*ContainsUnexpandedParameterPack=*/false),
258919c8576b7328f4dc2d07682f5da552875c1912efJohn McCall      Decl(const_cast<UnresolvedUsingTypenameDecl*>(D)) {}
2590ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  friend class ASTContext; // ASTContext creates these.
2591ed97649e9574b9d854fa4d6109c9333ae0993554John McCallpublic:
2592ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
2593ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  UnresolvedUsingTypenameDecl *getDecl() const { return Decl; }
2594ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
2595ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  bool isSugared() const { return false; }
2596ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  QualType desugar() const { return QualType(this, 0); }
2597ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
2598ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  static bool classof(const Type *T) {
2599ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    return T->getTypeClass() == UnresolvedUsing;
2600ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  }
2601ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  static bool classof(const UnresolvedUsingType *) { return true; }
2602ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
2603ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  void Profile(llvm::FoldingSetNodeID &ID) {
2604ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    return Profile(ID, Decl);
2605ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  }
2606ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  static void Profile(llvm::FoldingSetNodeID &ID,
2607ed97649e9574b9d854fa4d6109c9333ae0993554John McCall                      UnresolvedUsingTypenameDecl *D) {
2608ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    ID.AddPointer(D);
2609ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  }
2610ed97649e9574b9d854fa4d6109c9333ae0993554John McCall};
2611ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
2612ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
26135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass TypedefType : public Type {
26145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  TypedefDecl *Decl;
2615c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanianprotected:
261619c8576b7328f4dc2d07682f5da552875c1912efJohn McCall  TypedefType(TypeClass tc, const TypedefDecl *D, QualType can)
2617d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    : Type(tc, can, can->isDependentType(), can->isVariablyModifiedType(),
2618d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor           /*ContainsUnexpandedParameterPack=*/false),
261919c8576b7328f4dc2d07682f5da552875c1912efJohn McCall      Decl(const_cast<TypedefDecl*>(D)) {
26205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    assert(!isa<TypedefType>(can) && "Invalid canonical type");
26215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
26225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
26235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
26241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
26255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  TypedefDecl *getDecl() const { return Decl; }
26261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2627bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return true; }
2628bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const;
2629bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
263072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  static bool classof(const Type *T) { return T->getTypeClass() == Typedef; }
26315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const TypedefType *) { return true; }
26325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
26335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
263472564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// TypeOfExprType (GCC extension).
263572564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregorclass TypeOfExprType : public Type {
2636d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  Expr *TOExpr;
26371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2638b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregorprotected:
2639dd0257c77719a13d4acd513df40b04300cbfc871Douglas Gregor  TypeOfExprType(Expr *E, QualType can = QualType());
2640d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  friend class ASTContext;  // ASTContext creates these.
2641d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroffpublic:
2642d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  Expr *getUnderlyingExpr() const { return TOExpr; }
26431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2644bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// \brief Remove a single level of sugar.
2645bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const;
2646bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
2647bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// \brief Returns whether this type directly provides sugar.
2648bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return true; }
2649bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
265072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  static bool classof(const Type *T) { return T->getTypeClass() == TypeOfExpr; }
265172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  static bool classof(const TypeOfExprType *) { return true; }
2652d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff};
2653d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff
2654c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// \brief Internal representation of canonical, dependent
26551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// typeof(expr) types.
2656c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor///
2657c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// This class is used internally by the ASTContext to manage
2658c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// canonical, dependent types, only. Clients will only see instances
2659c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// of this class via TypeOfExprType nodes.
26601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpclass DependentTypeOfExprType
2661b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor  : public TypeOfExprType, public llvm::FoldingSetNode {
26624ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  const ASTContext &Context;
26631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2664b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregorpublic:
26654ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  DependentTypeOfExprType(const ASTContext &Context, Expr *E)
2666b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor    : TypeOfExprType(E), Context(Context) { }
26671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2668bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2669bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2670bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
2671b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor  void Profile(llvm::FoldingSetNodeID &ID) {
2672b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor    Profile(ID, Context, getUnderlyingExpr());
2673b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor  }
26741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
26754ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
2676b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor                      Expr *E);
2677b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor};
26781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2679d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff/// TypeOfType (GCC extension).
2680d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroffclass TypeOfType : public Type {
2681d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  QualType TOType;
26821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  TypeOfType(QualType T, QualType can)
2683d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    : Type(TypeOf, can, T->isDependentType(), T->isVariablyModifiedType(),
2684d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor           T->containsUnexpandedParameterPack()),
268535495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor      TOType(T) {
2686d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff    assert(!isa<TypedefType>(can) && "Invalid canonical type");
2687d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  }
2688d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  friend class ASTContext;  // ASTContext creates these.
2689d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroffpublic:
2690d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  QualType getUnderlyingType() const { return TOType; }
26911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2692bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// \brief Remove a single level of sugar.
2693bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return getUnderlyingType(); }
2694bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
2695bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// \brief Returns whether this type directly provides sugar.
2696bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return true; }
2697bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
269872564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  static bool classof(const Type *T) { return T->getTypeClass() == TypeOf; }
2699d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  static bool classof(const TypeOfType *) { return true; }
2700d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff};
27015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2702395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson/// DecltypeType (C++0x)
2703395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlssonclass DecltypeType : public Type {
2704395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson  Expr *E;
27051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2706563a03b1338d31c2462def43253a722bc885d384Anders Carlsson  // FIXME: We could get rid of UnderlyingType if we wanted to: We would have to
2707563a03b1338d31c2462def43253a722bc885d384Anders Carlsson  // Move getDesugaredType to ASTContext so that it can call getDecltypeForExpr
2708563a03b1338d31c2462def43253a722bc885d384Anders Carlsson  // from it.
2709563a03b1338d31c2462def43253a722bc885d384Anders Carlsson  QualType UnderlyingType;
27101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
27119d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregorprotected:
2712563a03b1338d31c2462def43253a722bc885d384Anders Carlsson  DecltypeType(Expr *E, QualType underlyingType, QualType can = QualType());
2713395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson  friend class ASTContext;  // ASTContext creates these.
2714395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlssonpublic:
2715395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson  Expr *getUnderlyingExpr() const { return E; }
2716563a03b1338d31c2462def43253a722bc885d384Anders Carlsson  QualType getUnderlyingType() const { return UnderlyingType; }
2717563a03b1338d31c2462def43253a722bc885d384Anders Carlsson
2718bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// \brief Remove a single level of sugar.
2719bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return getUnderlyingType(); }
2720bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
2721bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// \brief Returns whether this type directly provides sugar.
2722bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return !isDependentType(); }
2723bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
2724395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson  static bool classof(const Type *T) { return T->getTypeClass() == Decltype; }
2725395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson  static bool classof(const DecltypeType *) { return true; }
2726395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson};
27271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2728c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// \brief Internal representation of canonical, dependent
2729c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// decltype(expr) types.
2730c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor///
2731c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// This class is used internally by the ASTContext to manage
2732c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// canonical, dependent types, only. Clients will only see instances
2733c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// of this class via DecltypeType nodes.
27349d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregorclass DependentDecltypeType : public DecltypeType, public llvm::FoldingSetNode {
27354ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  const ASTContext &Context;
27361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
27379d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregorpublic:
27384ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  DependentDecltypeType(const ASTContext &Context, Expr *E);
27391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2740bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2741bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2742bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
27439d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor  void Profile(llvm::FoldingSetNodeID &ID) {
27449d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor    Profile(ID, Context, getUnderlyingExpr());
27459d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor  }
27461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
27474ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
27481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                      Expr *E);
27499d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor};
27501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
27515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass TagType : public Type {
2752ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl  /// Stores the TagDecl associated with this type. The decl may point to any
2753ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl  /// TagDecl that declares the entity.
2754ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl  TagDecl * decl;
27552ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor
27562ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregorprotected:
275719c8576b7328f4dc2d07682f5da552875c1912efJohn McCall  TagType(TypeClass TC, const TagDecl *D, QualType can);
27582ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor
27591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic:
2760ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl  TagDecl *getDecl() const;
27611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
27620b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor  /// @brief Determines whether this type is in the process of being
27631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// defined.
2764ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl  bool isBeingDefined() const;
27650b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor
27661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
276772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor    return T->getTypeClass() >= TagFirst && T->getTypeClass() <= TagLast;
276872564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  }
27695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const TagType *) { return true; }
277072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  static bool classof(const RecordType *) { return true; }
277172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  static bool classof(const EnumType *) { return true; }
27725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
27735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
27745edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner/// RecordType - This is a helper class that allows the use of isa/cast/dyncast
27755edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner/// to detect TagType objects of structs/unions/classes.
27765edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattnerclass RecordType : public TagType {
277749aa7ff1245abd03e6e998e01302df31e4c6f8f6Argyrios Kyrtzidisprotected:
277819c8576b7328f4dc2d07682f5da552875c1912efJohn McCall  explicit RecordType(const RecordDecl *D)
277919c8576b7328f4dc2d07682f5da552875c1912efJohn McCall    : TagType(Record, reinterpret_cast<const TagDecl*>(D), QualType()) { }
278072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  explicit RecordType(TypeClass TC, RecordDecl *D)
278119c8576b7328f4dc2d07682f5da552875c1912efJohn McCall    : TagType(TC, reinterpret_cast<const TagDecl*>(D), QualType()) { }
27822ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor  friend class ASTContext;   // ASTContext creates these.
27835edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattnerpublic:
27841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
27855edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner  RecordDecl *getDecl() const {
27865edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner    return reinterpret_cast<RecordDecl*>(TagType::getDecl());
27875edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner  }
27881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
27891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  // FIXME: This predicate is a helper to QualType/Type. It needs to
27905edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner  // recursively check all fields for const-ness. If any field is declared
27911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  // const, it needs to return false.
27925edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner  bool hasConstFields() const { return false; }
27935edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner
2794bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2795bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2796bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
27972daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner  static bool classof(const TagType *T);
27982daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner  static bool classof(const Type *T) {
27992daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner    return isa<TagType>(T) && classof(cast<TagType>(T));
28002daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner  }
28015edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner  static bool classof(const RecordType *) { return true; }
28025edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner};
28035edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner
28045edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner/// EnumType - This is a helper class that allows the use of isa/cast/dyncast
28055edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner/// to detect TagType objects of enums.
28065edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattnerclass EnumType : public TagType {
280719c8576b7328f4dc2d07682f5da552875c1912efJohn McCall  explicit EnumType(const EnumDecl *D)
280819c8576b7328f4dc2d07682f5da552875c1912efJohn McCall    : TagType(Enum, reinterpret_cast<const TagDecl*>(D), QualType()) { }
28092ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor  friend class ASTContext;   // ASTContext creates these.
28105edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattnerpublic:
28111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
28125edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner  EnumDecl *getDecl() const {
28135edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner    return reinterpret_cast<EnumDecl*>(TagType::getDecl());
28145edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner  }
28151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2816bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2817bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2818bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
28192daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner  static bool classof(const TagType *T);
28202daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner  static bool classof(const Type *T) {
28212daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner    return isa<TagType>(T) && classof(cast<TagType>(T));
28222daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner  }
28235edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner  static bool classof(const EnumType *) { return true; }
28245edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner};
28255edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner
28269d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall/// AttributedType - An attributed type is a type to which a type
28279d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall/// attribute has been applied.  The "modified type" is the
28289d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall/// fully-sugared type to which the attributed type was applied;
28299d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall/// generally it is not canonically equivalent to the attributed type.
28309d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall/// The "equivalent type" is the minimally-desugared type which the
28319d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall/// type is canonically equivalent to.
28329d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall///
28339d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall/// For example, in the following attributed type:
28349d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall///     int32_t __attribute__((vector_size(16)))
28359d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall///   - the modified type is the TypedefType for int32_t
28369d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall///   - the equivalent type is VectorType(16, int32_t)
28379d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall///   - the canonical type is VectorType(16, int)
28389d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCallclass AttributedType : public Type, public llvm::FoldingSetNode {
28399d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCallpublic:
28409d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  // It is really silly to have yet another attribute-kind enum, but
28419d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  // clang::attr::Kind doesn't currently cover the pure type attrs.
28429d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  enum Kind {
28439d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    // Expression operand.
2844170464b7c0a2c0c86f2821f14a46f0d540cb5e94Francois Pichet    attr_address_space,
2845170464b7c0a2c0c86f2821f14a46f0d540cb5e94Francois Pichet    attr_regparm,
2846170464b7c0a2c0c86f2821f14a46f0d540cb5e94Francois Pichet    attr_vector_size,
2847170464b7c0a2c0c86f2821f14a46f0d540cb5e94Francois Pichet    attr_neon_vector_type,
2848170464b7c0a2c0c86f2821f14a46f0d540cb5e94Francois Pichet    attr_neon_polyvector_type,
28499d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
2850170464b7c0a2c0c86f2821f14a46f0d540cb5e94Francois Pichet    FirstExprOperandKind = attr_address_space,
2851170464b7c0a2c0c86f2821f14a46f0d540cb5e94Francois Pichet    LastExprOperandKind = attr_neon_polyvector_type,
28529d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
28539d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    // Enumerated operand (string or keyword).
2854170464b7c0a2c0c86f2821f14a46f0d540cb5e94Francois Pichet    attr_objc_gc,
28559d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
2856170464b7c0a2c0c86f2821f14a46f0d540cb5e94Francois Pichet    FirstEnumOperandKind = attr_objc_gc,
2857170464b7c0a2c0c86f2821f14a46f0d540cb5e94Francois Pichet    LastEnumOperandKind = attr_objc_gc,
28589d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
28599d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    // No operand.
28603cd47e7883dbfce73189b583850cea81e1d1d261Francois Pichet    attr_noreturn,
28613cd47e7883dbfce73189b583850cea81e1d1d261Francois Pichet    attr_cdecl,
28623cd47e7883dbfce73189b583850cea81e1d1d261Francois Pichet    attr_fastcall,
28633cd47e7883dbfce73189b583850cea81e1d1d261Francois Pichet    attr_stdcall,
28643cd47e7883dbfce73189b583850cea81e1d1d261Francois Pichet    attr_thiscall,
28653cd47e7883dbfce73189b583850cea81e1d1d261Francois Pichet    attr_pascal
28669d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  };
28679d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
28689d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCallprivate:
28699d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  QualType ModifiedType;
28709d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  QualType EquivalentType;
28719d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
28729d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  friend class ASTContext; // creates these
28739d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
28749d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  AttributedType(QualType canon, Kind attrKind,
28759d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall                 QualType modified, QualType equivalent)
28769d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    : Type(Attributed, canon, canon->isDependentType(),
28779d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall           canon->isVariablyModifiedType(),
28789d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall           canon->containsUnexpandedParameterPack()),
28799d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall      ModifiedType(modified), EquivalentType(equivalent) {
28809d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    AttributedTypeBits.AttrKind = attrKind;
28819d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  }
28829d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
28839d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCallpublic:
28849d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  Kind getAttrKind() const {
28859d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    return static_cast<Kind>(AttributedTypeBits.AttrKind);
28869d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  }
28879d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
28889d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  QualType getModifiedType() const { return ModifiedType; }
28899d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  QualType getEquivalentType() const { return EquivalentType; }
28909d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
28919d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  bool isSugared() const { return true; }
28929d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  QualType desugar() const { return getEquivalentType(); }
28939d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
28949d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  void Profile(llvm::FoldingSetNodeID &ID) {
28959d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    Profile(ID, getAttrKind(), ModifiedType, EquivalentType);
28969d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  }
28979d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
28989d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  static void Profile(llvm::FoldingSetNodeID &ID, Kind attrKind,
28999d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall                      QualType modified, QualType equivalent) {
29009d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    ID.AddInteger(attrKind);
29019d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    ID.AddPointer(modified.getAsOpaquePtr());
29029d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    ID.AddPointer(equivalent.getAsOpaquePtr());
29039d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  }
29049d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
29059d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  static bool classof(const Type *T) {
29069d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    return T->getTypeClass() == Attributed;
29079d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  }
29089d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  static bool classof(const AttributedType *T) { return true; }
29099d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall};
29109d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
2911fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregorclass TemplateTypeParmType : public Type, public llvm::FoldingSetNode {
2912efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor  unsigned Depth : 15;
2913efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor  unsigned ParameterPack : 1;
291477be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall  unsigned Index : 16;
2915efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor  IdentifierInfo *Name;
291672c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor
2917efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor  TemplateTypeParmType(unsigned D, unsigned I, bool PP, IdentifierInfo *N,
2918efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor                       QualType Canon)
291935495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    : Type(TemplateTypeParm, Canon, /*Dependent=*/true,
2920d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor           /*VariablyModified=*/false, PP),
292177be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall      Depth(D), ParameterPack(PP), Index(I), Name(N) { }
292272c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor
29231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  TemplateTypeParmType(unsigned D, unsigned I, bool PP)
292435495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    : Type(TemplateTypeParm, QualType(this, 0), /*Dependent=*/true,
2925d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor           /*VariablyModified=*/false, PP),
292677be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall      Depth(D), ParameterPack(PP), Index(I), Name(0) { }
292772c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor
2928fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor  friend class ASTContext;  // ASTContext creates these
292972c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor
2930fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregorpublic:
2931efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor  unsigned getDepth() const { return Depth; }
2932efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor  unsigned getIndex() const { return Index; }
2933efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor  bool isParameterPack() const { return ParameterPack; }
2934efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor  IdentifierInfo *getName() const { return Name; }
29351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2936bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2937bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2938bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
2939fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor  void Profile(llvm::FoldingSetNodeID &ID) {
2940efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor    Profile(ID, Depth, Index, ParameterPack, Name);
2941fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor  }
2942fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor
29431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static void Profile(llvm::FoldingSetNodeID &ID, unsigned Depth,
29441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                      unsigned Index, bool ParameterPack,
2945efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor                      IdentifierInfo *Name) {
2946fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor    ID.AddInteger(Depth);
2947fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor    ID.AddInteger(Index);
294876e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson    ID.AddBoolean(ParameterPack);
2949efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor    ID.AddPointer(Name);
2950fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor  }
2951fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor
29521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
29531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == TemplateTypeParm;
295472c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor  }
295572c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor  static bool classof(const TemplateTypeParmType *T) { return true; }
295672c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor};
2957fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor
295849a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// \brief Represents the result of substituting a type for a template
295949a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// type parameter.
296049a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall///
296149a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// Within an instantiated template, all template type parameters have
296249a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// been replaced with these.  They are used solely to record that a
296349a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// type was originally written as a template type parameter;
296449a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// therefore they are never canonical.
296549a832bd499d6f61c23655f1fac99f0dd229756eJohn McCallclass SubstTemplateTypeParmType : public Type, public llvm::FoldingSetNode {
296649a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  // The original type parameter.
296749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  const TemplateTypeParmType *Replaced;
296849a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall
296949a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  SubstTemplateTypeParmType(const TemplateTypeParmType *Param, QualType Canon)
297035495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    : Type(SubstTemplateTypeParm, Canon, Canon->isDependentType(),
2971d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor           Canon->isVariablyModifiedType(),
2972d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor           Canon->containsUnexpandedParameterPack()),
297349a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall      Replaced(Param) { }
297449a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall
297549a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  friend class ASTContext;
297649a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall
297749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCallpublic:
2978efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor  IdentifierInfo *getName() const { return Replaced->getName(); }
2979efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor
298049a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  /// Gets the template parameter that was substituted for.
298149a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  const TemplateTypeParmType *getReplacedParameter() const {
298249a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall    return Replaced;
298349a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  }
298449a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall
298549a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  /// Gets the type that was substituted for the template
298649a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  /// parameter.
298749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  QualType getReplacementType() const {
298849a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall    return getCanonicalTypeInternal();
298949a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  }
299049a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall
299149a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  bool isSugared() const { return true; }
299249a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  QualType desugar() const { return getReplacementType(); }
299349a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall
299449a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  void Profile(llvm::FoldingSetNodeID &ID) {
299549a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall    Profile(ID, getReplacedParameter(), getReplacementType());
299649a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  }
299749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  static void Profile(llvm::FoldingSetNodeID &ID,
299849a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall                      const TemplateTypeParmType *Replaced,
299949a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall                      QualType Replacement) {
300049a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall    ID.AddPointer(Replaced);
300149a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall    ID.AddPointer(Replacement.getAsOpaquePtr());
300249a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  }
300349a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall
300449a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  static bool classof(const Type *T) {
300549a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall    return T->getTypeClass() == SubstTemplateTypeParm;
300649a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  }
300749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  static bool classof(const SubstTemplateTypeParmType *T) { return true; }
300849a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall};
300949a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall
3010c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// \brief Represents the result of substituting a set of types for a template
3011c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// type parameter pack.
3012c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor///
3013c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// When a pack expansion in the source code contains multiple parameter packs
3014c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// and those parameter packs correspond to different levels of template
3015c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// parameter lists, this type node is used to represent a template type
3016c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// parameter pack from an outer level, which has already had its argument pack
3017c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// substituted but that still lives within a pack expansion that itself
3018c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// could not be instantiated. When actually performing a substitution into
3019c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// that pack expansion (e.g., when all template parameters have corresponding
3020c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// arguments), this type will be replaced with the \c SubstTemplateTypeParmType
3021c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// at the current pack substitution index.
3022c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregorclass SubstTemplateTypeParmPackType : public Type, public llvm::FoldingSetNode {
3023c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  /// \brief The original type parameter.
3024c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  const TemplateTypeParmType *Replaced;
3025c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor
3026c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  /// \brief A pointer to the set of template arguments that this
3027c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  /// parameter pack is instantiated with.
3028c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  const TemplateArgument *Arguments;
3029c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor
3030c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  /// \brief The number of template arguments in \c Arguments.
3031c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  unsigned NumArguments;
3032c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor
3033c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  SubstTemplateTypeParmPackType(const TemplateTypeParmType *Param,
3034c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor                                QualType Canon,
3035c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor                                const TemplateArgument &ArgPack);
3036c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor
3037c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  friend class ASTContext;
3038c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor
3039c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregorpublic:
3040c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  IdentifierInfo *getName() const { return Replaced->getName(); }
3041c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor
3042c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  /// Gets the template parameter that was substituted for.
3043c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  const TemplateTypeParmType *getReplacedParameter() const {
3044c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor    return Replaced;
3045c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  }
3046c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor
3047c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  bool isSugared() const { return false; }
3048c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  QualType desugar() const { return QualType(this, 0); }
3049c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor
3050c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  TemplateArgument getArgumentPack() const;
3051c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor
3052c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  void Profile(llvm::FoldingSetNodeID &ID);
3053c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  static void Profile(llvm::FoldingSetNodeID &ID,
3054c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor                      const TemplateTypeParmType *Replaced,
3055c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor                      const TemplateArgument &ArgPack);
3056c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor
3057c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  static bool classof(const Type *T) {
3058c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor    return T->getTypeClass() == SubstTemplateTypeParmPack;
3059c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  }
3060c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  static bool classof(const SubstTemplateTypeParmPackType *T) { return true; }
3061c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor};
3062c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor
306334b41d939a1328f484511c6002ba2456db879a29Richard Smith/// \brief Represents a C++0x auto type.
306434b41d939a1328f484511c6002ba2456db879a29Richard Smith///
306534b41d939a1328f484511c6002ba2456db879a29Richard Smith/// These types are usually a placeholder for a deduced type. However, within
306634b41d939a1328f484511c6002ba2456db879a29Richard Smith/// templates and before the initializer is attached, there is no deduced type
306734b41d939a1328f484511c6002ba2456db879a29Richard Smith/// and an auto type is type-dependent and canonical.
306834b41d939a1328f484511c6002ba2456db879a29Richard Smithclass AutoType : public Type, public llvm::FoldingSetNode {
306934b41d939a1328f484511c6002ba2456db879a29Richard Smith  AutoType(QualType DeducedType)
307034b41d939a1328f484511c6002ba2456db879a29Richard Smith    : Type(Auto, DeducedType.isNull() ? QualType(this, 0) : DeducedType,
307134b41d939a1328f484511c6002ba2456db879a29Richard Smith           /*Dependent=*/DeducedType.isNull(),
307234b41d939a1328f484511c6002ba2456db879a29Richard Smith           /*VariablyModified=*/false, /*ContainsParameterPack=*/false) {
307334b41d939a1328f484511c6002ba2456db879a29Richard Smith    assert((DeducedType.isNull() || !DeducedType->isDependentType()) &&
307434b41d939a1328f484511c6002ba2456db879a29Richard Smith           "deduced a dependent type for auto");
307534b41d939a1328f484511c6002ba2456db879a29Richard Smith  }
307634b41d939a1328f484511c6002ba2456db879a29Richard Smith
307734b41d939a1328f484511c6002ba2456db879a29Richard Smith  friend class ASTContext;  // ASTContext creates these
307834b41d939a1328f484511c6002ba2456db879a29Richard Smith
307934b41d939a1328f484511c6002ba2456db879a29Richard Smithpublic:
308034b41d939a1328f484511c6002ba2456db879a29Richard Smith  bool isSugared() const { return isDeduced(); }
308134b41d939a1328f484511c6002ba2456db879a29Richard Smith  QualType desugar() const { return getCanonicalTypeInternal(); }
308234b41d939a1328f484511c6002ba2456db879a29Richard Smith
308334b41d939a1328f484511c6002ba2456db879a29Richard Smith  QualType getDeducedType() const {
308434b41d939a1328f484511c6002ba2456db879a29Richard Smith    return isDeduced() ? getCanonicalTypeInternal() : QualType();
308534b41d939a1328f484511c6002ba2456db879a29Richard Smith  }
308634b41d939a1328f484511c6002ba2456db879a29Richard Smith  bool isDeduced() const {
308734b41d939a1328f484511c6002ba2456db879a29Richard Smith    return !isDependentType();
308834b41d939a1328f484511c6002ba2456db879a29Richard Smith  }
308934b41d939a1328f484511c6002ba2456db879a29Richard Smith
309034b41d939a1328f484511c6002ba2456db879a29Richard Smith  void Profile(llvm::FoldingSetNodeID &ID) {
309134b41d939a1328f484511c6002ba2456db879a29Richard Smith    Profile(ID, getDeducedType());
309234b41d939a1328f484511c6002ba2456db879a29Richard Smith  }
309334b41d939a1328f484511c6002ba2456db879a29Richard Smith
309434b41d939a1328f484511c6002ba2456db879a29Richard Smith  static void Profile(llvm::FoldingSetNodeID &ID,
309534b41d939a1328f484511c6002ba2456db879a29Richard Smith                      QualType Deduced) {
309634b41d939a1328f484511c6002ba2456db879a29Richard Smith    ID.AddPointer(Deduced.getAsOpaquePtr());
309734b41d939a1328f484511c6002ba2456db879a29Richard Smith  }
309834b41d939a1328f484511c6002ba2456db879a29Richard Smith
309934b41d939a1328f484511c6002ba2456db879a29Richard Smith  static bool classof(const Type *T) {
310034b41d939a1328f484511c6002ba2456db879a29Richard Smith    return T->getTypeClass() == Auto;
310134b41d939a1328f484511c6002ba2456db879a29Richard Smith  }
310234b41d939a1328f484511c6002ba2456db879a29Richard Smith  static bool classof(const AutoType *T) { return true; }
310334b41d939a1328f484511c6002ba2456db879a29Richard Smith};
310434b41d939a1328f484511c6002ba2456db879a29Richard Smith
31057532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// \brief Represents the type of a template specialization as written
31067532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// in the source code.
310755f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor///
31087532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// Template specialization types represent the syntactic form of a
31097532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// template-id that refers to a type, e.g., @c vector<int>. Some
31107532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// template specialization types are syntactic sugar, whose canonical
31117532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// type will point to some other type node that represents the
31127532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// instantiation or class template specialization. For example, a
311355f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor/// class template specialization type of @c vector<int> will refer to
31141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// a tag type for the instantiation
311555f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor/// @c std::vector<int, std::allocator<int>>.
31167532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor///
31177532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// Other template specialization types, for which the template name
31187532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// is dependent, may be canonical types. These types are always
31197532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// dependent.
31201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpclass TemplateSpecializationType
312155f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  : public Type, public llvm::FoldingSetNode {
312233500955d731c73717af52088b7fc0e7a85681e7John McCall  /// \brief The name of the template being specialized.
31237532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor  TemplateName Template;
312455f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
312540808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  /// \brief - The number of template arguments named in this class
312640808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  /// template specialization.
312755f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  unsigned NumArgs;
312855f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
3129ef99001908e799c388f1363b1e607dad5f5b57d3John McCall  TemplateSpecializationType(TemplateName T,
31307532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor                             const TemplateArgument *Args,
31317532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor                             unsigned NumArgs, QualType Canon);
313255f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
313355f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  friend class ASTContext;  // ASTContext creates these
313455f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
313555f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregorpublic:
313640808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  /// \brief Determine whether any of the given template arguments are
313740808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  /// dependent.
313840808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  static bool anyDependentTemplateArguments(const TemplateArgument *Args,
31391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                            unsigned NumArgs);
314040808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor
3141833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  static bool anyDependentTemplateArguments(const TemplateArgumentLoc *Args,
3142833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                            unsigned NumArgs);
3143833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
3144d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  static bool anyDependentTemplateArguments(const TemplateArgumentListInfo &);
3145d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall
3146df667e71b1daadeacb230cf94fc717843f1a138aDouglas Gregor  /// \brief Print a template argument list, including the '<' and '>'
3147df667e71b1daadeacb230cf94fc717843f1a138aDouglas Gregor  /// enclosing the template arguments.
3148df667e71b1daadeacb230cf94fc717843f1a138aDouglas Gregor  static std::string PrintTemplateArgumentList(const TemplateArgument *Args,
3149d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor                                               unsigned NumArgs,
3150dace95b13e2ceb0c3ec8de6babd926dc5114e1e5Douglas Gregor                                               const PrintingPolicy &Policy,
3151dace95b13e2ceb0c3ec8de6babd926dc5114e1e5Douglas Gregor                                               bool SkipBrackets = false);
3152df667e71b1daadeacb230cf94fc717843f1a138aDouglas Gregor
3153833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  static std::string PrintTemplateArgumentList(const TemplateArgumentLoc *Args,
3154833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                               unsigned NumArgs,
3155833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                               const PrintingPolicy &Policy);
3156833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
3157d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  static std::string PrintTemplateArgumentList(const TemplateArgumentListInfo &,
3158d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall                                               const PrintingPolicy &Policy);
3159d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall
316031f17ecbef57b5679c017c375db330546b7b5145John McCall  /// True if this template specialization type matches a current
316131f17ecbef57b5679c017c375db330546b7b5145John McCall  /// instantiation in the context in which it is found.
316231f17ecbef57b5679c017c375db330546b7b5145John McCall  bool isCurrentInstantiation() const {
316371d74bc0d6e522ce7c21a599db8e19d3883b518fJohn McCall    return isa<InjectedClassNameType>(getCanonicalTypeInternal());
316431f17ecbef57b5679c017c375db330546b7b5145John McCall  }
316531f17ecbef57b5679c017c375db330546b7b5145John McCall
316640808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  typedef const TemplateArgument * iterator;
316740808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor
316840808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  iterator begin() const { return getArgs(); }
316933500955d731c73717af52088b7fc0e7a85681e7John McCall  iterator end() const; // defined inline in TemplateBase.h
317040808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor
31717532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor  /// \brief Retrieve the name of the template that we are specializing.
31727532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor  TemplateName getTemplateName() const { return Template; }
317355f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
317440808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  /// \brief Retrieve the template arguments.
31751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  const TemplateArgument *getArgs() const {
317640808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor    return reinterpret_cast<const TemplateArgument *>(this + 1);
317740808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  }
317840808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor
317940808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  /// \brief Retrieve the number of template arguments.
318055f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  unsigned getNumArgs() const { return NumArgs; }
318155f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
318255f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  /// \brief Retrieve a specific template argument as a type.
318355f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  /// \precondition @c isArgType(Arg)
318433500955d731c73717af52088b7fc0e7a85681e7John McCall  const TemplateArgument &getArg(unsigned Idx) const; // in TemplateBase.h
318555f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
318631f17ecbef57b5679c017c375db330546b7b5145John McCall  bool isSugared() const {
318731f17ecbef57b5679c017c375db330546b7b5145John McCall    return !isDependentType() || isCurrentInstantiation();
318831f17ecbef57b5679c017c375db330546b7b5145John McCall  }
3189bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return getCanonicalTypeInternal(); }
3190bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
31914ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Ctx) {
319271d74bc0d6e522ce7c21a599db8e19d3883b518fJohn McCall    Profile(ID, Template, getArgs(), NumArgs, Ctx);
319355f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  }
319455f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
31957532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor  static void Profile(llvm::FoldingSetNodeID &ID, TemplateName T,
319631f17ecbef57b5679c017c375db330546b7b5145John McCall                      const TemplateArgument *Args,
319731f17ecbef57b5679c017c375db330546b7b5145John McCall                      unsigned NumArgs,
31984ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad                      const ASTContext &Context);
319955f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
32001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
32011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == TemplateSpecialization;
320255f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  }
32037532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor  static bool classof(const TemplateSpecializationType *T) { return true; }
320455f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor};
320555f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
320631f17ecbef57b5679c017c375db330546b7b5145John McCall/// \brief The injected class name of a C++ class template or class
320731f17ecbef57b5679c017c375db330546b7b5145John McCall/// template partial specialization.  Used to record that a type was
320831f17ecbef57b5679c017c375db330546b7b5145John McCall/// spelled with a bare identifier rather than as a template-id; the
320931f17ecbef57b5679c017c375db330546b7b5145John McCall/// equivalent for non-templated classes is just RecordType.
32103cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall///
321131f17ecbef57b5679c017c375db330546b7b5145John McCall/// Injected class name types are always dependent.  Template
321231f17ecbef57b5679c017c375db330546b7b5145John McCall/// instantiation turns these into RecordTypes.
32133cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall///
321431f17ecbef57b5679c017c375db330546b7b5145John McCall/// Injected class name types are always canonical.  This works
321531f17ecbef57b5679c017c375db330546b7b5145John McCall/// because it is impossible to compare an injected class name type
321631f17ecbef57b5679c017c375db330546b7b5145John McCall/// with the corresponding non-injected template type, for the same
321731f17ecbef57b5679c017c375db330546b7b5145John McCall/// reason that it is impossible to directly compare template
321831f17ecbef57b5679c017c375db330546b7b5145John McCall/// parameters from different dependent contexts: injected class name
321931f17ecbef57b5679c017c375db330546b7b5145John McCall/// types can only occur within the scope of a particular templated
322031f17ecbef57b5679c017c375db330546b7b5145John McCall/// declaration, and within that scope every template specialization
322131f17ecbef57b5679c017c375db330546b7b5145John McCall/// will canonicalize to the injected class name (when appropriate
322231f17ecbef57b5679c017c375db330546b7b5145John McCall/// according to the rules of the language).
32233cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCallclass InjectedClassNameType : public Type {
32243cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  CXXRecordDecl *Decl;
32253cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall
322631f17ecbef57b5679c017c375db330546b7b5145John McCall  /// The template specialization which this type represents.
322731f17ecbef57b5679c017c375db330546b7b5145John McCall  /// For example, in
322831f17ecbef57b5679c017c375db330546b7b5145John McCall  ///   template <class T> class A { ... };
322931f17ecbef57b5679c017c375db330546b7b5145John McCall  /// this is A<T>, whereas in
323031f17ecbef57b5679c017c375db330546b7b5145John McCall  ///   template <class X, class Y> class A<B<X,Y> > { ... };
323131f17ecbef57b5679c017c375db330546b7b5145John McCall  /// this is A<B<X,Y> >.
323231f17ecbef57b5679c017c375db330546b7b5145John McCall  ///
323331f17ecbef57b5679c017c375db330546b7b5145John McCall  /// It is always unqualified, always a template specialization type,
323431f17ecbef57b5679c017c375db330546b7b5145John McCall  /// and always dependent.
323531f17ecbef57b5679c017c375db330546b7b5145John McCall  QualType InjectedType;
32363cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall
32373cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  friend class ASTContext; // ASTContext creates these.
3238c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl  friend class ASTReader; // FIXME: ASTContext::getInjectedClassNameType is not
3239c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl                          // currently suitable for AST reading, too much
324043921b53b582145f0d1b7c48223bd4d9f0a9d1beArgyrios Kyrtzidis                          // interdependencies.
324131f17ecbef57b5679c017c375db330546b7b5145John McCall  InjectedClassNameType(CXXRecordDecl *D, QualType TST)
324235495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    : Type(InjectedClassName, QualType(), /*Dependent=*/true,
3243d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor           /*VariablyModified=*/false,
3244d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor           /*ContainsUnexpandedParameterPack=*/false),
324531f17ecbef57b5679c017c375db330546b7b5145John McCall      Decl(D), InjectedType(TST) {
32463cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall    assert(isa<TemplateSpecializationType>(TST));
32473cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall    assert(!TST.hasQualifiers());
324831f17ecbef57b5679c017c375db330546b7b5145John McCall    assert(TST->isDependentType());
32493cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  }
32503cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall
32513cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCallpublic:
325231f17ecbef57b5679c017c375db330546b7b5145John McCall  QualType getInjectedSpecializationType() const { return InjectedType; }
325331f17ecbef57b5679c017c375db330546b7b5145John McCall  const TemplateSpecializationType *getInjectedTST() const {
325431f17ecbef57b5679c017c375db330546b7b5145John McCall    return cast<TemplateSpecializationType>(InjectedType.getTypePtr());
32553cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  }
32563cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall
3257ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl  CXXRecordDecl *getDecl() const;
32583cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall
325931f17ecbef57b5679c017c375db330546b7b5145John McCall  bool isSugared() const { return false; }
326031f17ecbef57b5679c017c375db330546b7b5145John McCall  QualType desugar() const { return QualType(this, 0); }
32613cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall
32623cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  static bool classof(const Type *T) {
32633cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall    return T->getTypeClass() == InjectedClassName;
32643cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  }
32653cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  static bool classof(const InjectedClassNameType *T) { return true; }
32663cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall};
32673cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall
3268465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// \brief The kind of a tag type.
3269465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnaraenum TagTypeKind {
3270465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// \brief The "struct" keyword.
3271465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  TTK_Struct,
3272465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// \brief The "union" keyword.
3273465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  TTK_Union,
3274465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// \brief The "class" keyword.
3275465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  TTK_Class,
3276465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// \brief The "enum" keyword.
3277465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  TTK_Enum
3278465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara};
3279465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
32804a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// \brief The elaboration keyword that precedes a qualified type name or
32814a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// introduces an elaborated-type-specifier.
32824a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregorenum ElaboratedTypeKeyword {
32834a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor  /// \brief The "struct" keyword introduces the elaborated-type-specifier.
32844a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor  ETK_Struct,
32854a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor  /// \brief The "union" keyword introduces the elaborated-type-specifier.
32864a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor  ETK_Union,
3287465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// \brief The "class" keyword introduces the elaborated-type-specifier.
3288465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  ETK_Class,
32894a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor  /// \brief The "enum" keyword introduces the elaborated-type-specifier.
3290465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  ETK_Enum,
3291465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// \brief The "typename" keyword precedes the qualified type name, e.g.,
3292465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// \c typename T::type.
3293465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  ETK_Typename,
3294465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// \brief No keyword precedes the qualified type name.
3295465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  ETK_None
32964a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor};
3297465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
3298465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// A helper class for Type nodes having an ElaboratedTypeKeyword.
3299465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// The keyword in stored in the free bits of the base class.
3300465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// Also provides a few static helpers for converting and printing
3301465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// elaborated type keyword and tag type kind enumerations.
3302465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnaraclass TypeWithKeyword : public Type {
3303465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnaraprotected:
3304465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  TypeWithKeyword(ElaboratedTypeKeyword Keyword, TypeClass tc,
3305d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor                  QualType Canonical, bool Dependent, bool VariablyModified,
3306d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor                  bool ContainsUnexpandedParameterPack)
3307d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  : Type(tc, Canonical, Dependent, VariablyModified,
3308d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor         ContainsUnexpandedParameterPack) {
330977be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall    TypeWithKeywordBits.Keyword = Keyword;
331077be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall  }
3311465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
3312465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnarapublic:
3313465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  ElaboratedTypeKeyword getKeyword() const {
331477be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall    return static_cast<ElaboratedTypeKeyword>(TypeWithKeywordBits.Keyword);
3315465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  }
3316465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
3317465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// getKeywordForTypeSpec - Converts a type specifier (DeclSpec::TST)
3318465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// into an elaborated type keyword.
3319465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  static ElaboratedTypeKeyword getKeywordForTypeSpec(unsigned TypeSpec);
3320465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
3321465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// getTagTypeKindForTypeSpec - Converts a type specifier (DeclSpec::TST)
3322465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// into a tag type kind.  It is an error to provide a type specifier
3323465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// which *isn't* a tag kind here.
3324465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  static TagTypeKind getTagTypeKindForTypeSpec(unsigned TypeSpec);
3325465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
3326465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// getKeywordForTagDeclKind - Converts a TagTypeKind into an
3327465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// elaborated type keyword.
3328465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  static ElaboratedTypeKeyword getKeywordForTagTypeKind(TagTypeKind Tag);
3329465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
3330465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// getTagTypeKindForKeyword - Converts an elaborated type keyword into
3331465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  // a TagTypeKind. It is an error to provide an elaborated type keyword
3332465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// which *isn't* a tag kind here.
3333465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  static TagTypeKind getTagTypeKindForKeyword(ElaboratedTypeKeyword Keyword);
3334465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
3335465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  static bool KeywordIsTagTypeKind(ElaboratedTypeKeyword Keyword);
3336465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
3337465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  static const char *getKeywordName(ElaboratedTypeKeyword Keyword);
3338465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
3339465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  static const char *getTagTypeKindName(TagTypeKind Kind) {
3340465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    return getKeywordName(getKeywordForTagTypeKind(Kind));
3341465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  }
3342465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
3343465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  class CannotCastToThisType {};
3344465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  static CannotCastToThisType classof(const Type *);
3345465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara};
3346465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
3347465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// \brief Represents a type that was referred to using an elaborated type
3348465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// keyword, e.g., struct S, or via a qualified name, e.g., N::M::type,
3349465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// or both.
3350e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor///
3351e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor/// This type is used to keep track of a type name as written in the
3352465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// source code, including tag keywords and any nested-name-specifiers.
3353465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// The type itself is always "sugar", used to express what was written
3354465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// in the source code but containing no additional semantic information.
3355465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnaraclass ElaboratedType : public TypeWithKeyword, public llvm::FoldingSetNode {
3356465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
3357ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor  /// \brief The nested name specifier containing the qualifier.
3358ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor  NestedNameSpecifier *NNS;
3359e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor
3360e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor  /// \brief The type that this qualified name refers to.
3361e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor  QualType NamedType;
3362e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor
3363465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  ElaboratedType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS,
3364465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara                 QualType NamedType, QualType CanonType)
3365465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    : TypeWithKeyword(Keyword, Elaborated, CanonType,
336635495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor                      NamedType->isDependentType(),
3367d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor                      NamedType->isVariablyModifiedType(),
3368d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor                      NamedType->containsUnexpandedParameterPack()),
3369465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara      NNS(NNS), NamedType(NamedType) {
3370465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    assert(!(Keyword == ETK_None && NNS == 0) &&
3371465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara           "ElaboratedType cannot have elaborated type keyword "
3372465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara           "and name qualifier both null.");
3373465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  }
3374e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor
3375e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor  friend class ASTContext;  // ASTContext creates these
3376e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor
3377e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregorpublic:
337833500955d731c73717af52088b7fc0e7a85681e7John McCall  ~ElaboratedType();
3379465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
3380ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor  /// \brief Retrieve the qualification on this type.
3381ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor  NestedNameSpecifier *getQualifier() const { return NNS; }
3382e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor
3383e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor  /// \brief Retrieve the type named by the qualified-id.
3384e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor  QualType getNamedType() const { return NamedType; }
3385e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor
3386bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// \brief Remove a single level of sugar.
3387bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return getNamedType(); }
3388bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
3389bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// \brief Returns whether this type directly provides sugar.
3390bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return true; }
3391bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
3392e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor  void Profile(llvm::FoldingSetNodeID &ID) {
3393465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    Profile(ID, getKeyword(), NNS, NamedType);
3394e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor  }
3395e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor
3396465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  static void Profile(llvm::FoldingSetNodeID &ID, ElaboratedTypeKeyword Keyword,
3397465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara                      NestedNameSpecifier *NNS, QualType NamedType) {
3398465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    ID.AddInteger(Keyword);
3399ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor    ID.AddPointer(NNS);
3400ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor    NamedType.Profile(ID);
3401ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor  }
3402e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor
34031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
3404465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    return T->getTypeClass() == Elaborated;
3405e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor  }
3406465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  static bool classof(const ElaboratedType *T) { return true; }
3407e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor};
3408e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor
34094a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// \brief Represents a qualified type name for which the type name is
34104a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// dependent.
3411d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor///
34124a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// DependentNameType represents a class of dependent types that involve a
34134a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// dependent nested-name-specifier (e.g., "T::") followed by a (dependent)
34144a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// name of a type. The DependentNameType may start with a "typename" (for a
34154a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// typename-specifier), "class", "struct", "union", or "enum" (for a
34164a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// dependent elaborated-type-specifier), or nothing (in contexts where we
34174a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// know that we must be referring to a type, e.g., in a base class specifier).
3418465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnaraclass DependentNameType : public TypeWithKeyword, public llvm::FoldingSetNode {
3419465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
3420d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  /// \brief The nested name specifier containing the qualifier.
3421d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  NestedNameSpecifier *NNS;
3422d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor
3423d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  /// \brief The type that this typename specifier refers to.
342433500955d731c73717af52088b7fc0e7a85681e7John McCall  const IdentifierInfo *Name;
3425d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor
34264a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor  DependentNameType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS,
34274a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor                    const IdentifierInfo *Name, QualType CanonType)
342835495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    : TypeWithKeyword(Keyword, DependentName, CanonType, /*Dependent=*/true,
3429d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor                      /*VariablyModified=*/false,
3430d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor                      NNS->containsUnexpandedParameterPack()),
3431465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara      NNS(NNS), Name(Name) {
34321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    assert(NNS->isDependent() &&
34334714c12a1ab759156b78be8f109ea4c12213af57Douglas Gregor           "DependentNameType requires a dependent nested-name-specifier");
3434d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  }
3435d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor
3436d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  friend class ASTContext;  // ASTContext creates these
3437d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor
3438d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregorpublic:
3439d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  /// \brief Retrieve the qualification on this type.
3440d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  NestedNameSpecifier *getQualifier() const { return NNS; }
3441d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor
34421734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor  /// \brief Retrieve the type named by the typename specifier as an
34431734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor  /// identifier.
34441734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor  ///
34451734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor  /// This routine will return a non-NULL identifier pointer when the
34461734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor  /// form of the original typename was terminated by an identifier,
34471734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor  /// e.g., "typename T::type".
34481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  const IdentifierInfo *getIdentifier() const {
344933500955d731c73717af52088b7fc0e7a85681e7John McCall    return Name;
34501734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor  }
3451d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor
3452bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
3453bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
3454bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
3455d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  void Profile(llvm::FoldingSetNodeID &ID) {
3456465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    Profile(ID, getKeyword(), NNS, Name);
3457d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  }
3458d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor
34594a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor  static void Profile(llvm::FoldingSetNodeID &ID, ElaboratedTypeKeyword Keyword,
346033500955d731c73717af52088b7fc0e7a85681e7John McCall                      NestedNameSpecifier *NNS, const IdentifierInfo *Name) {
34614a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor    ID.AddInteger(Keyword);
3462d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor    ID.AddPointer(NNS);
346333500955d731c73717af52088b7fc0e7a85681e7John McCall    ID.AddPointer(Name);
3464d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  }
3465d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor
34661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
34674714c12a1ab759156b78be8f109ea4c12213af57Douglas Gregor    return T->getTypeClass() == DependentName;
3468d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  }
34694714c12a1ab759156b78be8f109ea4c12213af57Douglas Gregor  static bool classof(const DependentNameType *T) { return true; }
3470d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor};
3471d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor
347233500955d731c73717af52088b7fc0e7a85681e7John McCall/// DependentTemplateSpecializationType - Represents a template
347333500955d731c73717af52088b7fc0e7a85681e7John McCall/// specialization type whose template cannot be resolved, e.g.
347433500955d731c73717af52088b7fc0e7a85681e7John McCall///   A<T>::template B<T>
347533500955d731c73717af52088b7fc0e7a85681e7John McCallclass DependentTemplateSpecializationType :
347633500955d731c73717af52088b7fc0e7a85681e7John McCall  public TypeWithKeyword, public llvm::FoldingSetNode {
347733500955d731c73717af52088b7fc0e7a85681e7John McCall
347833500955d731c73717af52088b7fc0e7a85681e7John McCall  /// \brief The nested name specifier containing the qualifier.
347933500955d731c73717af52088b7fc0e7a85681e7John McCall  NestedNameSpecifier *NNS;
348033500955d731c73717af52088b7fc0e7a85681e7John McCall
348133500955d731c73717af52088b7fc0e7a85681e7John McCall  /// \brief The identifier of the template.
348233500955d731c73717af52088b7fc0e7a85681e7John McCall  const IdentifierInfo *Name;
348333500955d731c73717af52088b7fc0e7a85681e7John McCall
348433500955d731c73717af52088b7fc0e7a85681e7John McCall  /// \brief - The number of template arguments named in this class
348533500955d731c73717af52088b7fc0e7a85681e7John McCall  /// template specialization.
348633500955d731c73717af52088b7fc0e7a85681e7John McCall  unsigned NumArgs;
348733500955d731c73717af52088b7fc0e7a85681e7John McCall
348833500955d731c73717af52088b7fc0e7a85681e7John McCall  const TemplateArgument *getArgBuffer() const {
348933500955d731c73717af52088b7fc0e7a85681e7John McCall    return reinterpret_cast<const TemplateArgument*>(this+1);
349033500955d731c73717af52088b7fc0e7a85681e7John McCall  }
349133500955d731c73717af52088b7fc0e7a85681e7John McCall  TemplateArgument *getArgBuffer() {
349233500955d731c73717af52088b7fc0e7a85681e7John McCall    return reinterpret_cast<TemplateArgument*>(this+1);
349333500955d731c73717af52088b7fc0e7a85681e7John McCall  }
349433500955d731c73717af52088b7fc0e7a85681e7John McCall
3495ef99001908e799c388f1363b1e607dad5f5b57d3John McCall  DependentTemplateSpecializationType(ElaboratedTypeKeyword Keyword,
349633500955d731c73717af52088b7fc0e7a85681e7John McCall                                      NestedNameSpecifier *NNS,
349733500955d731c73717af52088b7fc0e7a85681e7John McCall                                      const IdentifierInfo *Name,
349833500955d731c73717af52088b7fc0e7a85681e7John McCall                                      unsigned NumArgs,
349933500955d731c73717af52088b7fc0e7a85681e7John McCall                                      const TemplateArgument *Args,
350033500955d731c73717af52088b7fc0e7a85681e7John McCall                                      QualType Canon);
350133500955d731c73717af52088b7fc0e7a85681e7John McCall
350233500955d731c73717af52088b7fc0e7a85681e7John McCall  friend class ASTContext;  // ASTContext creates these
350333500955d731c73717af52088b7fc0e7a85681e7John McCall
350433500955d731c73717af52088b7fc0e7a85681e7John McCallpublic:
350533500955d731c73717af52088b7fc0e7a85681e7John McCall  NestedNameSpecifier *getQualifier() const { return NNS; }
350633500955d731c73717af52088b7fc0e7a85681e7John McCall  const IdentifierInfo *getIdentifier() const { return Name; }
350733500955d731c73717af52088b7fc0e7a85681e7John McCall
350833500955d731c73717af52088b7fc0e7a85681e7John McCall  /// \brief Retrieve the template arguments.
350933500955d731c73717af52088b7fc0e7a85681e7John McCall  const TemplateArgument *getArgs() const {
351033500955d731c73717af52088b7fc0e7a85681e7John McCall    return getArgBuffer();
351133500955d731c73717af52088b7fc0e7a85681e7John McCall  }
351233500955d731c73717af52088b7fc0e7a85681e7John McCall
351333500955d731c73717af52088b7fc0e7a85681e7John McCall  /// \brief Retrieve the number of template arguments.
351433500955d731c73717af52088b7fc0e7a85681e7John McCall  unsigned getNumArgs() const { return NumArgs; }
351533500955d731c73717af52088b7fc0e7a85681e7John McCall
351633500955d731c73717af52088b7fc0e7a85681e7John McCall  const TemplateArgument &getArg(unsigned Idx) const; // in TemplateBase.h
351733500955d731c73717af52088b7fc0e7a85681e7John McCall
351833500955d731c73717af52088b7fc0e7a85681e7John McCall  typedef const TemplateArgument * iterator;
351933500955d731c73717af52088b7fc0e7a85681e7John McCall  iterator begin() const { return getArgs(); }
352033500955d731c73717af52088b7fc0e7a85681e7John McCall  iterator end() const; // inline in TemplateBase.h
352133500955d731c73717af52088b7fc0e7a85681e7John McCall
352233500955d731c73717af52088b7fc0e7a85681e7John McCall  bool isSugared() const { return false; }
352333500955d731c73717af52088b7fc0e7a85681e7John McCall  QualType desugar() const { return QualType(this, 0); }
352433500955d731c73717af52088b7fc0e7a85681e7John McCall
35254ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context) {
352633500955d731c73717af52088b7fc0e7a85681e7John McCall    Profile(ID, Context, getKeyword(), NNS, Name, NumArgs, getArgs());
352733500955d731c73717af52088b7fc0e7a85681e7John McCall  }
352833500955d731c73717af52088b7fc0e7a85681e7John McCall
352933500955d731c73717af52088b7fc0e7a85681e7John McCall  static void Profile(llvm::FoldingSetNodeID &ID,
35304ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad                      const ASTContext &Context,
353133500955d731c73717af52088b7fc0e7a85681e7John McCall                      ElaboratedTypeKeyword Keyword,
353233500955d731c73717af52088b7fc0e7a85681e7John McCall                      NestedNameSpecifier *Qualifier,
353333500955d731c73717af52088b7fc0e7a85681e7John McCall                      const IdentifierInfo *Name,
353433500955d731c73717af52088b7fc0e7a85681e7John McCall                      unsigned NumArgs,
353533500955d731c73717af52088b7fc0e7a85681e7John McCall                      const TemplateArgument *Args);
353633500955d731c73717af52088b7fc0e7a85681e7John McCall
353733500955d731c73717af52088b7fc0e7a85681e7John McCall  static bool classof(const Type *T) {
353833500955d731c73717af52088b7fc0e7a85681e7John McCall    return T->getTypeClass() == DependentTemplateSpecialization;
353933500955d731c73717af52088b7fc0e7a85681e7John McCall  }
354033500955d731c73717af52088b7fc0e7a85681e7John McCall  static bool classof(const DependentTemplateSpecializationType *T) {
354133500955d731c73717af52088b7fc0e7a85681e7John McCall    return true;
354233500955d731c73717af52088b7fc0e7a85681e7John McCall  }
354333500955d731c73717af52088b7fc0e7a85681e7John McCall};
354433500955d731c73717af52088b7fc0e7a85681e7John McCall
35457536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// \brief Represents a pack expansion of types.
35467536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor///
35477536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// Pack expansions are part of C++0x variadic templates. A pack
35487536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// expansion contains a pattern, which itself contains one or more
35497536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// "unexpanded" parameter packs. When instantiated, a pack expansion
35507536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// produces a series of types, each instantiated from the pattern of
35517536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// the expansion, where the Ith instantiation of the pattern uses the
35527536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// Ith arguments bound to each of the unexpanded parameter packs. The
35537536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// pack expansion is considered to "expand" these unexpanded
35547536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// parameter packs.
35557536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor///
35567536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// \code
35577536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// template<typename ...Types> struct tuple;
35587536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor///
35597536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// template<typename ...Types>
35607536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// struct tuple_of_references {
35617536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor///   typedef tuple<Types&...> type;
35627536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// };
35637536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// \endcode
35647536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor///
35657536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// Here, the pack expansion \c Types&... is represented via a
35667536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// PackExpansionType whose pattern is Types&.
35677536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregorclass PackExpansionType : public Type, public llvm::FoldingSetNode {
35687536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  /// \brief The pattern of the pack expansion.
35697536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  QualType Pattern;
35707536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor
3571cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  /// \brief The number of expansions that this pack expansion will
3572cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  /// generate when substituted (+1), or indicates that
3573cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  ///
3574cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  /// This field will only have a non-zero value when some of the parameter
3575cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  /// packs that occur within the pattern have been substituted but others have
3576cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  /// not.
3577cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  unsigned NumExpansions;
3578cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor
3579cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  PackExpansionType(QualType Pattern, QualType Canon,
3580cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor                    llvm::Optional<unsigned> NumExpansions)
35817536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor    : Type(PackExpansion, Canon, /*Dependent=*/true,
35827536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor           /*VariableModified=*/Pattern->isVariablyModifiedType(),
35837536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor           /*ContainsUnexpandedParameterPack=*/false),
3584cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor      Pattern(Pattern),
3585cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor      NumExpansions(NumExpansions? *NumExpansions + 1: 0) { }
35867536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor
35877536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  friend class ASTContext;  // ASTContext creates these
3588cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor
35897536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregorpublic:
35907536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  /// \brief Retrieve the pattern of this pack expansion, which is the
35917536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  /// type that will be repeatedly instantiated when instantiating the
35927536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  /// pack expansion itself.
35937536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  QualType getPattern() const { return Pattern; }
35947536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor
3595cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  /// \brief Retrieve the number of expansions that this pack expansion will
3596cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  /// generate, if known.
3597cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  llvm::Optional<unsigned> getNumExpansions() const {
3598cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor    if (NumExpansions)
3599cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor      return NumExpansions - 1;
3600cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor
3601cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor    return llvm::Optional<unsigned>();
3602cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  }
3603cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor
36047536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  bool isSugared() const { return false; }
36057536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  QualType desugar() const { return QualType(this, 0); }
36067536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor
36077536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  void Profile(llvm::FoldingSetNodeID &ID) {
3608cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor    Profile(ID, getPattern(), getNumExpansions());
36097536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  }
36107536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor
3611cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  static void Profile(llvm::FoldingSetNodeID &ID, QualType Pattern,
3612cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor                      llvm::Optional<unsigned> NumExpansions) {
36137536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor    ID.AddPointer(Pattern.getAsOpaquePtr());
3614cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor    ID.AddBoolean(NumExpansions);
3615cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor    if (NumExpansions)
3616cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor      ID.AddInteger(*NumExpansions);
36177536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  }
36187536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor
36197536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  static bool classof(const Type *T) {
36207536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor    return T->getTypeClass() == PackExpansion;
36217536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  }
36227536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  static bool classof(const PackExpansionType *T) {
36237536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor    return true;
36247536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  }
36257536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor};
36267536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor
3627c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// ObjCObjectType - Represents a class type in Objective C.
3628c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// Every Objective C type is a combination of a base type and a
3629c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// list of protocols.
3630c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall///
3631c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// Given the following declarations:
3632c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall///   @class C;
3633c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall///   @protocol P;
3634c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall///
3635c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// 'C' is an ObjCInterfaceType C.  It is sugar for an ObjCObjectType
3636c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// with base C and no protocols.
3637c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall///
3638c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// 'C<P>' is an ObjCObjectType with base C and protocol list [P].
3639c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall///
3640e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// 'id' is a TypedefType which is sugar for an ObjCPointerType whose
3641e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// pointee is an ObjCObjectType with base BuiltinType::ObjCIdType
3642e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// and no protocols.
3643c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall///
3644e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// 'id<P>' is an ObjCPointerType whose pointee is an ObjCObjecType
3645e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// with base BuiltinType::ObjCIdType and protocol list [P].  Eventually
3646e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// this should get its own sugar class to better represent the source.
3647c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallclass ObjCObjectType : public Type {
3648b870b88df784c2940efce448ebfaf54dece14666John McCall  // ObjCObjectType.NumProtocols - the number of protocols stored
3649b870b88df784c2940efce448ebfaf54dece14666John McCall  // after the ObjCObjectPointerType node.
365071c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  //
365171c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  // These protocols are those written directly on the type.  If
365271c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  // protocol qualifiers ever become additive, the iterators will need
365371c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  // to get kindof complicated.
365471c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  //
365571c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  // In the canonical object type, these are sorted alphabetically
365671c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  // and uniqued.
3657c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff
3658c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  /// Either a BuiltinType or an InterfaceType or sugar for either.
3659c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  QualType BaseType;
3660c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3661c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  ObjCProtocolDecl * const *getProtocolStorage() const {
3662c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return const_cast<ObjCObjectType*>(this)->getProtocolStorage();
3663c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  }
3664c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3665c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  ObjCProtocolDecl **getProtocolStorage();
3666c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3667c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallprotected:
3668c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  ObjCObjectType(QualType Canonical, QualType Base,
3669c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall                 ObjCProtocolDecl * const *Protocols, unsigned NumProtocols);
3670c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3671c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  enum Nonce_ObjCInterface { Nonce_ObjCInterface };
3672c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  ObjCObjectType(enum Nonce_ObjCInterface)
3673d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor        : Type(ObjCInterface, QualType(), false, false, false),
367471c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall      BaseType(QualType(this_(), 0)) {
3675b870b88df784c2940efce448ebfaf54dece14666John McCall    ObjCObjectTypeBits.NumProtocols = 0;
367671c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  }
3677c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff
36783536b443bc50d58a79f14fca9b6842541a434854Steve Naroffpublic:
3679e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// getBaseType - Gets the base type of this object type.  This is
3680e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// always (possibly sugar for) one of:
3681e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///  - the 'id' builtin type (as opposed to the 'id' type visible to the
3682e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///    user, which is a typedef for an ObjCPointerType)
3683e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///  - the 'Class' builtin type (same caveat)
3684e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///  - an ObjCObjectType (currently always an ObjCInterfaceType)
3685c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  QualType getBaseType() const { return BaseType; }
368671842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek
3687c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool isObjCId() const {
3688c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getBaseType()->isSpecificBuiltinType(BuiltinType::ObjCId);
3689c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  }
3690c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool isObjCClass() const {
3691c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getBaseType()->isSpecificBuiltinType(BuiltinType::ObjCClass);
3692c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  }
3693c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool isObjCUnqualifiedId() const { return qual_empty() && isObjCId(); }
3694c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool isObjCUnqualifiedClass() const { return qual_empty() && isObjCClass(); }
3695c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool isObjCUnqualifiedIdOrClass() const {
3696c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    if (!qual_empty()) return false;
3697c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    if (const BuiltinType *T = getBaseType()->getAs<BuiltinType>())
3698c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall      return T->getKind() == BuiltinType::ObjCId ||
3699c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall             T->getKind() == BuiltinType::ObjCClass;
3700c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return false;
3701c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  }
3702c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool isObjCQualifiedId() const { return !qual_empty() && isObjCId(); }
3703c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool isObjCQualifiedClass() const { return !qual_empty() && isObjCClass(); }
3704c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3705c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  /// Gets the interface declaration for this object type, if the base type
3706c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  /// really is an interface.
3707c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  ObjCInterfaceDecl *getInterface() const;
3708c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3709c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  typedef ObjCProtocolDecl * const *qual_iterator;
3710c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3711c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  qual_iterator qual_begin() const { return getProtocolStorage(); }
3712c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  qual_iterator qual_end() const { return qual_begin() + getNumProtocols(); }
3713c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3714c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool qual_empty() const { return getNumProtocols() == 0; }
37151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3716c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff  /// getNumProtocols - Return the number of qualifying protocols in this
3717c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff  /// interface type, or 0 if there are none.
3718b870b88df784c2940efce448ebfaf54dece14666John McCall  unsigned getNumProtocols() const { return ObjCObjectTypeBits.NumProtocols; }
371914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff
3720c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  /// \brief Fetch a protocol by index.
372173dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor  ObjCProtocolDecl *getProtocol(unsigned I) const {
372273dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor    assert(I < getNumProtocols() && "Out-of-range protocol access");
372373dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor    return qual_begin()[I];
372473dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor  }
372573dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor
3726bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
3727bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
3728bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
3729c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  static bool classof(const Type *T) {
3730c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return T->getTypeClass() == ObjCObject ||
3731c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall           T->getTypeClass() == ObjCInterface;
3732c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  }
3733c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  static bool classof(const ObjCObjectType *) { return true; }
3734c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall};
3735c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3736c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// ObjCObjectTypeImpl - A class providing a concrete implementation
3737c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// of ObjCObjectType, so as to not increase the footprint of
3738c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// ObjCInterfaceType.  Code outside of ASTContext and the core type
3739c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// system should not reference this type.
3740c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallclass ObjCObjectTypeImpl : public ObjCObjectType, public llvm::FoldingSetNode {
3741c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  friend class ASTContext;
3742c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3743c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  // If anyone adds fields here, ObjCObjectType::getProtocolStorage()
3744c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  // will need to be modified.
3745c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3746c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  ObjCObjectTypeImpl(QualType Canonical, QualType Base,
3747c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall                     ObjCProtocolDecl * const *Protocols,
3748c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall                     unsigned NumProtocols)
3749c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    : ObjCObjectType(Canonical, Base, Protocols, NumProtocols) {}
3750c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3751c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallpublic:
3752c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff  void Profile(llvm::FoldingSetNodeID &ID);
37531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static void Profile(llvm::FoldingSetNodeID &ID,
3754c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall                      QualType Base,
3755c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall                      ObjCProtocolDecl *const *protocols,
3756c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall                      unsigned NumProtocols);
3757c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall};
37581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3759c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallinline ObjCProtocolDecl **ObjCObjectType::getProtocolStorage() {
3760c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  return reinterpret_cast<ObjCProtocolDecl**>(
3761c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall            static_cast<ObjCObjectTypeImpl*>(this) + 1);
3762c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall}
3763c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3764c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// ObjCInterfaceType - Interfaces are the core concept in Objective-C for
3765c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// object oriented design.  They basically correspond to C++ classes.  There
3766c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// are two kinds of interface types, normal interfaces like "NSString" and
3767c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// qualified interfaces, which are qualified with a protocol list like
3768c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// "NSString<NSCopyable, NSAmazing>".
3769e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall///
3770e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// ObjCInterfaceType guarantees the following properties when considered
3771e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// as a subtype of its superclass, ObjCObjectType:
3772e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall///   - There are no protocol qualifiers.  To reinforce this, code which
3773e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall///     tries to invoke the protocol methods via an ObjCInterfaceType will
3774e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall///     fail to compile.
3775e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall///   - It is its own base type.  That is, if T is an ObjCInterfaceType*,
3776e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall///     T->getBaseType() == QualType(T, 0).
3777c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallclass ObjCInterfaceType : public ObjCObjectType {
3778c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  ObjCInterfaceDecl *Decl;
3779c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3780c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  ObjCInterfaceType(const ObjCInterfaceDecl *D)
3781c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    : ObjCObjectType(Nonce_ObjCInterface),
3782c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall      Decl(const_cast<ObjCInterfaceDecl*>(D)) {}
3783c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  friend class ASTContext;  // ASTContext creates these.
37841fb0caaa7bef765b85972274e3b434af2572c141John McCall
3785c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallpublic:
3786e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// getDecl - Get the declaration of this interface.
3787deacbdca554298ccdf636f19c6094a8825ec6b34Douglas Gregor  ObjCInterfaceDecl *getDecl() const { return Decl; }
3788c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3789c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool isSugared() const { return false; }
3790c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  QualType desugar() const { return QualType(this, 0); }
37910b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor
37921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
37931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == ObjCInterface;
37943536b443bc50d58a79f14fca9b6842541a434854Steve Naroff  }
3795a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const ObjCInterfaceType *) { return true; }
3796c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3797c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  // Nonsense to "hide" certain members of ObjCObjectType within this
3798c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  // class.  People asking for protocols on an ObjCInterfaceType are
3799c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  // not going to get what they want: ObjCInterfaceTypes are
3800c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  // guaranteed to have no protocols.
3801c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  enum {
3802c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    qual_iterator,
3803c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    qual_begin,
3804c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    qual_end,
3805c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    getNumProtocols,
3806c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    getProtocol
3807c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  };
38083536b443bc50d58a79f14fca9b6842541a434854Steve Naroff};
38093536b443bc50d58a79f14fca9b6842541a434854Steve Naroff
3810c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallinline ObjCInterfaceDecl *ObjCObjectType::getInterface() const {
3811c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  if (const ObjCInterfaceType *T =
3812c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall        getBaseType()->getAs<ObjCInterfaceType>())
3813c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return T->getDecl();
3814c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  return 0;
3815c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall}
3816c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3817e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// ObjCObjectPointerType - Used to represent a pointer to an
3818e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// Objective C object.  These are constructed from pointer
3819e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// declarators when the pointee type is an ObjCObjectType (or sugar
3820e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// for one).  In addition, the 'id' and 'Class' types are typedefs
3821e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// for these, and the protocol-qualified types 'id<P>' and 'Class<P>'
3822e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// are translated into these.
382314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff///
3824e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// Pointers to pointers to Objective C objects are still PointerTypes;
3825e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// only the first level of pointer gets it own type implementation.
382614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroffclass ObjCObjectPointerType : public Type, public llvm::FoldingSetNode {
3827e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  QualType PointeeType;
38281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3829c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  ObjCObjectPointerType(QualType Canonical, QualType Pointee)
3830d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    : Type(ObjCObjectPointer, Canonical, false, false, false),
3831c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall      PointeeType(Pointee) {}
383214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  friend class ASTContext;  // ASTContext creates these.
38331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
383414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroffpublic:
3835e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// getPointeeType - Gets the type pointed to by this ObjC pointer.
3836e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// The result will always be an ObjCObjectType or sugar thereof.
383714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  QualType getPointeeType() const { return PointeeType; }
383814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff
3839e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// getObjCObjectType - Gets the type pointed to by this ObjC
3840e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// pointer.  This method always returns non-null.
3841e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///
3842e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// This method is equivalent to getPointeeType() except that
3843e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// it discards any typedefs (or other sugar) between this
3844e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// type and the "outermost" object type.  So for:
3845e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///   @class A; @protocol P; @protocol Q;
3846e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///   typedef A<P> AP;
3847e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///   typedef A A1;
3848e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///   typedef A1<P> A1P;
3849e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///   typedef A1P<Q> A1PQ;
3850e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// For 'A*', getObjectType() will return 'A'.
3851e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// For 'A<P>*', getObjectType() will return 'A<P>'.
3852e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// For 'AP*', getObjectType() will return 'A<P>'.
3853e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// For 'A1*', getObjectType() will return 'A'.
3854e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// For 'A1<P>*', getObjectType() will return 'A1<P>'.
3855e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// For 'A1P*', getObjectType() will return 'A1<P>'.
3856e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// For 'A1PQ*', getObjectType() will return 'A1<Q>', because
3857e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///   adding protocols to a protocol-qualified base discards the
3858e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///   old qualifiers (for now).  But if it didn't, getObjectType()
3859e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///   would return 'A1P<Q>' (and we'd have to make iterating over
3860e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///   qualifiers more complicated).
3861c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  const ObjCObjectType *getObjectType() const {
3862d0370f59e79702ac908c81bf556519f91e9ca297John McCall    return PointeeType->castAs<ObjCObjectType>();
3863c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  }
3864c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3865e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// getInterfaceType - If this pointer points to an Objective C
3866e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// @interface type, gets the type for that interface.  Any protocol
3867e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// qualifiers on the interface are ignored.
3868e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///
3869e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// \return null if the base type for this pointer is 'id' or 'Class'
38701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  const ObjCInterfaceType *getInterfaceType() const {
3871c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getObjectType()->getBaseType()->getAs<ObjCInterfaceType>();
387214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  }
3873e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall
3874e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// getInterfaceDecl - If this pointer points to an Objective @interface
3875e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// type, gets the declaration for that interface.
3876e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///
3877e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// \return null if the base type for this pointer is 'id' or 'Class'
387814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  ObjCInterfaceDecl *getInterfaceDecl() const {
3879e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall    return getObjectType()->getInterface();
388014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  }
3881e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall
3882e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// isObjCIdType - True if this is equivalent to the 'id' type, i.e. if
3883e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// its object type is the primitive 'id' type with no protocols.
388414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  bool isObjCIdType() const {
3885c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getObjectType()->isObjCUnqualifiedId();
388614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  }
3887e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall
3888e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// isObjCClassType - True if this is equivalent to the 'Class' type,
3889e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// i.e. if its object tive is the primitive 'Class' type with no protocols.
389014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  bool isObjCClassType() const {
3891c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getObjectType()->isObjCUnqualifiedClass();
3892de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff  }
38938d2c0a9814e56c2b22e22d1045181c735aef62fdFariborz Jahanian
3894e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// isObjCQualifiedIdType - True if this is equivalent to 'id<P>' for some
3895e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// non-empty set of protocols.
38961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  bool isObjCQualifiedIdType() const {
3897c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getObjectType()->isObjCQualifiedId();
3898de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff  }
3899e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall
3900e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// isObjCQualifiedClassType - True if this is equivalent to 'Class<P>' for
3901e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// some non-empty set of protocols.
3902470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroff  bool isObjCQualifiedClassType() const {
3903c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getObjectType()->isObjCQualifiedClass();
390414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  }
3905e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall
3906e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// An iterator over the qualifiers on the object type.  Provided
3907e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// for convenience.  This will always iterate over the full set of
3908e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// protocols on a type, not just those provided directly.
3909c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  typedef ObjCObjectType::qual_iterator qual_iterator;
391014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff
391171842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek  qual_iterator qual_begin() const {
3912c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getObjectType()->qual_begin();
391371842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek  }
3914c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  qual_iterator qual_end() const {
3915c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getObjectType()->qual_end();
391671842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek  }
3917c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool qual_empty() const { return getObjectType()->qual_empty(); }
391814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff
3919e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// getNumProtocols - Return the number of qualifying protocols on
3920e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// the object type.
3921c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  unsigned getNumProtocols() const {
3922c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getObjectType()->getNumProtocols();
3923c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  }
392414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff
3925e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// \brief Retrieve a qualifying protocol by index on the object
3926e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// type.
392773dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor  ObjCProtocolDecl *getProtocol(unsigned I) const {
3928c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getObjectType()->getProtocol(I);
392973dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor  }
393073dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor
3931bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
3932bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
3933bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
3934e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  void Profile(llvm::FoldingSetNodeID &ID) {
3935e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall    Profile(ID, getPointeeType());
3936e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  }
3937c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  static void Profile(llvm::FoldingSetNodeID &ID, QualType T) {
3938c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    ID.AddPointer(T.getAsOpaquePtr());
3939c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  }
39401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
39411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == ObjCObjectPointer;
394214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  }
394314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  static bool classof(const ObjCObjectPointerType *) { return true; }
394414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff};
39451bb8a45f7386a23871598d05141a07af03067925Argyrios Kyrtzidis
39460953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// A qualifier set is used to build a set of qualifiers.
39470953e767ff7817f97b3ab20896b229891eeff45bJohn McCallclass QualifierCollector : public Qualifiers {
39480953e767ff7817f97b3ab20896b229891eeff45bJohn McCallpublic:
394949f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  QualifierCollector(Qualifiers Qs = Qualifiers()) : Qualifiers(Qs) {}
39500953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
39510953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// Collect any qualifiers on the given type and return an
39523b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  /// unqualified type.  The qualifiers are assumed to be consistent
39533b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  /// with those already in the type.
39543b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  const Type *strip(QualType type) {
39553b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    addFastQualifiers(type.getLocalFastQualifiers());
39563b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    if (!type.hasLocalNonFastQualifiers())
39573b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall      return type.getTypePtrUnsafe();
39583b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
39593b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    const ExtQuals *extQuals = type.getExtQualsUnsafe();
39603b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    addConsistentQualifiers(extQuals->getQualifiers());
39613b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    return extQuals->getBaseType();
39620953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
39630953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
39640953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// Apply the collected qualifiers to the given type.
39654ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  QualType apply(const ASTContext &Context, QualType QT) const;
39660953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
39670953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// Apply the collected qualifiers to the given type.
39684ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  QualType apply(const ASTContext &Context, const Type* T) const;
39690953e767ff7817f97b3ab20896b229891eeff45bJohn McCall};
39700953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
39710953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3972611c1fff195d32df97706e0920c92468b2509900Chris Lattner// Inline function definitions.
39735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
39743b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallinline const Type *QualType::getTypePtr() const {
39753b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  return getCommonPtr()->BaseType;
39763b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall}
39773b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
39783b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallinline const Type *QualType::getTypePtrOrNull() const {
39793b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  return (isNull() ? 0 : getCommonPtr()->BaseType);
39803b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall}
39813b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
39823b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallinline SplitQualType QualType::split() const {
39833b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  if (!hasLocalNonFastQualifiers())
39843b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    return SplitQualType(getTypePtrUnsafe(),
39853b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall                         Qualifiers::fromFastMask(getLocalFastQualifiers()));
39863b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
39873b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  const ExtQuals *eq = getExtQualsUnsafe();
39883b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  Qualifiers qs = eq->getQualifiers();
39893b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  qs.addFastQualifiers(getLocalFastQualifiers());
39903b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  return SplitQualType(eq->getBaseType(), qs);
39913b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall}
39923b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
39933b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallinline Qualifiers QualType::getLocalQualifiers() const {
39943b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  Qualifiers Quals;
39953b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  if (hasLocalNonFastQualifiers())
39963b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    Quals = getExtQualsUnsafe()->getQualifiers();
39973b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  Quals.addFastQualifiers(getLocalFastQualifiers());
39983b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  return Quals;
39993b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall}
40003b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
40013b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallinline Qualifiers QualType::getQualifiers() const {
40023b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  Qualifiers quals = getCommonPtr()->CanonicalType.getLocalQualifiers();
40033b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  quals.addFastQualifiers(getLocalFastQualifiers());
40043b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  return quals;
40053b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall}
40063b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
40073b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallinline unsigned QualType::getCVRQualifiers() const {
40083b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  unsigned cvr = getCommonPtr()->CanonicalType.getLocalCVRQualifiers();
40093b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  cvr |= getLocalCVRQualifiers();
40103b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  return cvr;
40113b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall}
40123b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
40133b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallinline QualType QualType::getCanonicalType() const {
40143b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  QualType canon = getCommonPtr()->CanonicalType;
40153b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  return canon.withFastQualifiers(getLocalFastQualifiers());
40163b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall}
40173b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
4018467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCallinline bool QualType::isCanonical() const {
40193b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  return getTypePtr()->isCanonicalUnqualified();
4020467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall}
4021467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall
402254e14c4db764c0636160d26c5bbf491637c83a76John McCallinline bool QualType::isCanonicalAsParam() const {
40233b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  if (!isCanonical()) return false;
4024a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  if (hasLocalQualifiers()) return false;
4025745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian
402654e14c4db764c0636160d26c5bbf491637c83a76John McCall  const Type *T = getTypePtr();
40273b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  if (T->isVariablyModifiedType() && T->hasSizedVLAType())
40283b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    return false;
40293b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
40303b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  return !isa<FunctionType>(T) && !isa<ArrayType>(T);
403154e14c4db764c0636160d26c5bbf491637c83a76John McCall}
403254e14c4db764c0636160d26c5bbf491637c83a76John McCall
4033fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregorinline bool QualType::isConstQualified() const {
4034fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  return isLocalConstQualified() ||
40353b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall         getCommonPtr()->CanonicalType.isLocalConstQualified();
4036fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor}
4037fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor
4038fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregorinline bool QualType::isRestrictQualified() const {
4039fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  return isLocalRestrictQualified() ||
40403b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall         getCommonPtr()->CanonicalType.isLocalRestrictQualified();
4041fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor}
4042fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor
4043fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor
4044fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregorinline bool QualType::isVolatileQualified() const {
4045fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  return isLocalVolatileQualified() ||
40463b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall         getCommonPtr()->CanonicalType.isLocalVolatileQualified();
4047fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor}
4048fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor
4049fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregorinline bool QualType::hasQualifiers() const {
4050fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  return hasLocalQualifiers() ||
40513b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall         getCommonPtr()->CanonicalType.hasLocalQualifiers();
4052fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor}
405362c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall
405462c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCallinline QualType QualType::getUnqualifiedType() const {
405562c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  if (!getTypePtr()->getCanonicalTypeInternal().hasLocalQualifiers())
405662c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall    return QualType(getTypePtr(), 0);
405762c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall
405862c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  return QualType(getSplitUnqualifiedTypeImpl(*this).first, 0);
405962c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall}
406062c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall
406162c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCallinline SplitQualType QualType::getSplitUnqualifiedType() const {
406262c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  if (!getTypePtr()->getCanonicalTypeInternal().hasLocalQualifiers())
406362c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall    return split();
406462c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall
406562c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  return getSplitUnqualifiedTypeImpl(*this);
4066fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor}
4067fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor
406849f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCallinline void QualType::removeLocalConst() {
406949f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  removeLocalFastQualifiers(Qualifiers::Const);
40700953e767ff7817f97b3ab20896b229891eeff45bJohn McCall}
40710953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
407249f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCallinline void QualType::removeLocalRestrict() {
407349f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  removeLocalFastQualifiers(Qualifiers::Restrict);
40740953e767ff7817f97b3ab20896b229891eeff45bJohn McCall}
40750953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
407649f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCallinline void QualType::removeLocalVolatile() {
407749f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  removeLocalFastQualifiers(Qualifiers::Volatile);
40780953e767ff7817f97b3ab20896b229891eeff45bJohn McCall}
40790953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
408049f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCallinline void QualType::removeLocalCVRQualifiers(unsigned Mask) {
40816b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall  assert(!(Mask & ~Qualifiers::CVRMask) && "mask has non-CVR bits");
4082c3c0af36bac3d71f61dd758585ab307892545de4Douglas Gregor  assert((int)Qualifiers::CVRMask == (int)Qualifiers::FastMask);
40830953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
40840953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Fast path: we don't need to touch the slow qualifiers.
408549f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  removeLocalFastQualifiers(Mask);
4086ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb}
4087ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb
4088ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb/// getAddressSpace - Return the address space of this type.
4089ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lambinline unsigned QualType::getAddressSpace() const {
40903b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  return getQualifiers().getAddressSpace();
4091ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb}
4092611c1fff195d32df97706e0920c92468b2509900Chris Lattner
4093d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian/// getObjCGCAttr - Return the gc attribute of this type.
40940953e767ff7817f97b3ab20896b229891eeff45bJohn McCallinline Qualifiers::GC QualType::getObjCGCAttr() const {
40953b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  return getQualifiers().getObjCGCAttr();
4096d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian}
40972455636163fdd18581d7fdae816433f886d88213Mike Stump
4098264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindolainline FunctionType::ExtInfo getFunctionExtInfo(const Type &t) {
4099264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola  if (const PointerType *PT = t.getAs<PointerType>()) {
4100183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall    if (const FunctionType *FT = PT->getPointeeType()->getAs<FunctionType>())
4101264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola      return FT->getExtInfo();
4102264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola  } else if (const FunctionType *FT = t.getAs<FunctionType>())
4103264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    return FT->getExtInfo();
41042455636163fdd18581d7fdae816433f886d88213Mike Stump
4105264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola  return FunctionType::ExtInfo();
41062455636163fdd18581d7fdae816433f886d88213Mike Stump}
41071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4108264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindolainline FunctionType::ExtInfo getFunctionExtInfo(QualType t) {
4109264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola  return getFunctionExtInfo(*t);
4110ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor}
4111ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor
4112b87786f045d798b070980c108c922e1475d27b15Douglas Gregor/// \brief Determine whether this set of qualifiers is a superset of the given
4113b87786f045d798b070980c108c922e1475d27b15Douglas Gregor/// set of qualifiers.
4114b87786f045d798b070980c108c922e1475d27b15Douglas Gregorinline bool Qualifiers::isSupersetOf(Qualifiers Other) const {
4115b87786f045d798b070980c108c922e1475d27b15Douglas Gregor  return Mask != Other.Mask && (Mask | Other.Mask) == Mask;
4116b87786f045d798b070980c108c922e1475d27b15Douglas Gregor}
4117b87786f045d798b070980c108c922e1475d27b15Douglas Gregor
4118e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// isMoreQualifiedThan - Determine whether this type is more
4119e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// qualified than the Other type. For example, "const volatile int"
4120e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// is more qualified than "const int", "volatile int", and
4121e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// "int". However, it is not more qualified than "const volatile
4122e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// int".
412362c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCallinline bool QualType::isMoreQualifiedThan(QualType other) const {
412462c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  Qualifiers myQuals = getQualifiers();
412562c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  Qualifiers otherQuals = other.getQualifiers();
412662c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  return (myQuals != otherQuals && myQuals.compatiblyIncludes(otherQuals));
4127e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor}
4128e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor
4129e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// isAtLeastAsQualifiedAs - Determine whether this type is at last
4130e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// as qualified as the Other type. For example, "const volatile
4131e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// int" is at least as qualified as "const int", "volatile int",
4132e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// "int", and "const volatile int".
413362c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCallinline bool QualType::isAtLeastAsQualifiedAs(QualType other) const {
413462c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  return getQualifiers().compatiblyIncludes(other.getQualifiers());
4135e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor}
4136e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor
4137e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// getNonReferenceType - If Type is a reference type (e.g., const
4138e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// int&), returns the type that the reference refers to ("const
4139e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// int"). Otherwise, returns the type itself. This routine is used
4140e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// throughout Sema to implement C++ 5p6:
4141e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor///
4142e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor///   If an expression initially has the type "reference to T" (8.3.2,
4143e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor///   8.5.3), the type is adjusted to "T" prior to any further
4144e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor///   analysis, the expression designates the object or function
4145e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor///   denoted by the reference, and the expression is an lvalue.
4146e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregorinline QualType QualType::getNonReferenceType() const {
41476217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek  if (const ReferenceType *RefType = (*this)->getAs<ReferenceType>())
4148e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor    return RefType->getPointeeType();
4149e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor  else
4150e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor    return *this;
4151e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor}
4152e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor
4153611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isFunctionType() const {
4154a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<FunctionType>(CanonicalType);
4155611c1fff195d32df97706e0920c92468b2509900Chris Lattner}
4156611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isPointerType() const {
4157a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<PointerType>(CanonicalType);
4158611c1fff195d32df97706e0920c92468b2509900Chris Lattner}
415958f9f2c884af6b72d036b746a016d8031d31cb7aSteve Naroffinline bool Type::isAnyPointerType() const {
416058f9f2c884af6b72d036b746a016d8031d31cb7aSteve Naroff  return isPointerType() || isObjCObjectPointerType();
416158f9f2c884af6b72d036b746a016d8031d31cb7aSteve Naroff}
41625618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroffinline bool Type::isBlockPointerType() const {
4163a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<BlockPointerType>(CanonicalType);
41645618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff}
4165bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattnerinline bool Type::isReferenceType() const {
4166a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<ReferenceType>(CanonicalType);
4167bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner}
41687c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlinline bool Type::isLValueReferenceType() const {
4169a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<LValueReferenceType>(CanonicalType);
41707c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl}
41717c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlinline bool Type::isRValueReferenceType() const {
4172a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<RValueReferenceType>(CanonicalType);
41737c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl}
4174498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenekinline bool Type::isFunctionPointerType() const {
4175d0370f59e79702ac908c81bf556519f91e9ca297John McCall  if (const PointerType *T = getAs<PointerType>())
4176498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek    return T->getPointeeType()->isFunctionType();
4177498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek  else
4178498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek    return false;
4179498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek}
4180f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlinline bool Type::isMemberPointerType() const {
4181a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<MemberPointerType>(CanonicalType);
4182f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl}
4183f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlinline bool Type::isMemberFunctionPointerType() const {
41846217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek  if (const MemberPointerType* T = getAs<MemberPointerType>())
41850bab0cdab751248ca389a5592bcb70eac5d39260John McCall    return T->isMemberFunctionPointer();
4186f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  else
4187f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    return false;
4188f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl}
4189db68e28c05a67735211e688009890cf834c22e75Douglas Gregorinline bool Type::isMemberDataPointerType() const {
4190db68e28c05a67735211e688009890cf834c22e75Douglas Gregor  if (const MemberPointerType* T = getAs<MemberPointerType>())
41910bab0cdab751248ca389a5592bcb70eac5d39260John McCall    return T->isMemberDataPointer();
4192db68e28c05a67735211e688009890cf834c22e75Douglas Gregor  else
4193db68e28c05a67735211e688009890cf834c22e75Douglas Gregor    return false;
4194db68e28c05a67735211e688009890cf834c22e75Douglas Gregor}
4195611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isArrayType() const {
4196a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<ArrayType>(CanonicalType);
4197611c1fff195d32df97706e0920c92468b2509900Chris Lattner}
4198c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattnerinline bool Type::isConstantArrayType() const {
4199a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<ConstantArrayType>(CanonicalType);
4200c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner}
4201c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattnerinline bool Type::isIncompleteArrayType() const {
4202a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<IncompleteArrayType>(CanonicalType);
4203c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner}
4204c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattnerinline bool Type::isVariableArrayType() const {
4205a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<VariableArrayType>(CanonicalType);
4206c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner}
4207898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorinline bool Type::isDependentSizedArrayType() const {
4208a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<DependentSizedArrayType>(CanonicalType);
4209898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor}
42103ff83dd534ccc828203670ce3f5125a4eb4199f8John McCallinline bool Type::isBuiltinType() const {
42113ff83dd534ccc828203670ce3f5125a4eb4199f8John McCall  return isa<BuiltinType>(CanonicalType);
42123ff83dd534ccc828203670ce3f5125a4eb4199f8John McCall}
4213611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isRecordType() const {
4214a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<RecordType>(CanonicalType);
4215611c1fff195d32df97706e0920c92468b2509900Chris Lattner}
42163ff83dd534ccc828203670ce3f5125a4eb4199f8John McCallinline bool Type::isEnumeralType() const {
42173ff83dd534ccc828203670ce3f5125a4eb4199f8John McCall  return isa<EnumType>(CanonicalType);
42183ff83dd534ccc828203670ce3f5125a4eb4199f8John McCall}
4219f23d364084d1aabea688222780d6fc1dd8c7f78cChris Lattnerinline bool Type::isAnyComplexType() const {
4220a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<ComplexType>(CanonicalType);
4221f23d364084d1aabea688222780d6fc1dd8c7f78cChris Lattner}
4222611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isVectorType() const {
4223a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<VectorType>(CanonicalType);
4224611c1fff195d32df97706e0920c92468b2509900Chris Lattner}
4225213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begemaninline bool Type::isExtVectorType() const {
4226a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<ExtVectorType>(CanonicalType);
4227611c1fff195d32df97706e0920c92468b2509900Chris Lattner}
4228d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroffinline bool Type::isObjCObjectPointerType() const {
4229a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<ObjCObjectPointerType>(CanonicalType);
4230d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff}
4231c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallinline bool Type::isObjCObjectType() const {
4232c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  return isa<ObjCObjectType>(CanonicalType);
4233368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner}
4234569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregorinline bool Type::isObjCObjectOrInterfaceType() const {
4235569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor  return isa<ObjCInterfaceType>(CanonicalType) ||
4236569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor    isa<ObjCObjectType>(CanonicalType);
4237569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor}
4238569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor
4239a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekinline bool Type::isObjCQualifiedIdType() const {
4240183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>())
4241d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff    return OPT->isObjCQualifiedIdType();
4242d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff  return false;
4243d58fabf7ed279be18a5e82617f809c9deff9be67Fariborz Jahanian}
4244470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroffinline bool Type::isObjCQualifiedClassType() const {
4245183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>())
4246470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroff    return OPT->isObjCQualifiedClassType();
4247470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroff  return false;
4248470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroff}
424914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroffinline bool Type::isObjCIdType() const {
4250183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>())
425114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff    return OPT->isObjCIdType();
425214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  return false;
425314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff}
425414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroffinline bool Type::isObjCClassType() const {
4255183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>())
425614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff    return OPT->isObjCClassType();
425714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  return false;
425814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff}
425913dcd00615de5c4279d97bdf63cd5f0a14fd9dccFariborz Jahanianinline bool Type::isObjCSelType() const {
42608d2c0a9814e56c2b22e22d1045181c735aef62fdFariborz Jahanian  if (const PointerType *OPT = getAs<PointerType>())
42618d2c0a9814e56c2b22e22d1045181c735aef62fdFariborz Jahanian    return OPT->getPointeeType()->isSpecificBuiltinType(BuiltinType::ObjCSel);
426213dcd00615de5c4279d97bdf63cd5f0a14fd9dccFariborz Jahanian  return false;
426313dcd00615de5c4279d97bdf63cd5f0a14fd9dccFariborz Jahanian}
4264de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroffinline bool Type::isObjCBuiltinType() const {
426513dcd00615de5c4279d97bdf63cd5f0a14fd9dccFariborz Jahanian  return isObjCIdType() || isObjCClassType() || isObjCSelType();
4266de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff}
426772c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregorinline bool Type::isTemplateTypeParmType() const {
4268a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<TemplateTypeParmType>(CanonicalType);
426972c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor}
427072c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor
4271e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbarinline bool Type::isSpecificBuiltinType(unsigned K) const {
4272183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  if (const BuiltinType *BT = getAs<BuiltinType>())
4273e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar    if (BT->getKind() == (BuiltinType::Kind) K)
4274e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar      return true;
4275e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar  return false;
4276e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar}
4277e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar
42782a984cad5ac3fdceeff2bd99daa7b90979313475John McCallinline bool Type::isPlaceholderType() const {
42792a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  if (const BuiltinType *BT = getAs<BuiltinType>())
42802a984cad5ac3fdceeff2bd99daa7b90979313475John McCall    return BT->isPlaceholderType();
42812a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  return false;
42822a984cad5ac3fdceeff2bd99daa7b90979313475John McCall}
42832a984cad5ac3fdceeff2bd99daa7b90979313475John McCall
4284063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor/// \brief Determines whether this is a type for which one can define
4285063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor/// an overloaded operator.
4286063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregorinline bool Type::isOverloadableType() const {
4287063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  return isDependentType() || isRecordType() || isEnumeralType();
4288904eed3f6148758d39a2d3c88f3133274460d645Douglas Gregor}
4289904eed3f6148758d39a2d3c88f3133274460d645Douglas Gregor
42908958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbarinline bool Type::hasPointerRepresentation() const {
42918958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar  return (isPointerType() || isReferenceType() || isBlockPointerType() ||
4292c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall          isObjCObjectPointerType() || isNullPtrType());
42938958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar}
42948958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar
4295820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanianinline bool Type::hasObjCPointerRepresentation() const {
4296c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  return isObjCObjectPointerType();
4297820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian}
4298820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian
4299d0370f59e79702ac908c81bf556519f91e9ca297John McCallinline const Type *Type::getBaseElementTypeUnsafe() const {
4300d0370f59e79702ac908c81bf556519f91e9ca297John McCall  const Type *type = this;
4301d0370f59e79702ac908c81bf556519f91e9ca297John McCall  while (const ArrayType *arrayType = type->getAsArrayTypeUnsafe())
4302d0370f59e79702ac908c81bf556519f91e9ca297John McCall    type = arrayType->getElementType().getTypePtr();
4303d0370f59e79702ac908c81bf556519f91e9ca297John McCall  return type;
4304d0370f59e79702ac908c81bf556519f91e9ca297John McCall}
4305d0370f59e79702ac908c81bf556519f91e9ca297John McCall
430622caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner/// Insertion operator for diagnostics.  This allows sending QualType's into a
430722caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner/// diagnostic with <<.
430822caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattnerinline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
430922caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner                                           QualType T) {
431022caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner  DB.AddTaggedVal(reinterpret_cast<intptr_t>(T.getAsOpaquePtr()),
431122caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner                  Diagnostic::ak_qualtype);
431222caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner  return DB;
431322caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner}
43141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
431547c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth/// Insertion operator for partial diagnostics.  This allows sending QualType's
431647c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth/// into a diagnostic with <<.
431747c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruthinline const PartialDiagnostic &operator<<(const PartialDiagnostic &PD,
431847c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth                                           QualType T) {
431947c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth  PD.AddTaggedVal(reinterpret_cast<intptr_t>(T.getAsOpaquePtr()),
432047c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth                  Diagnostic::ak_qualtype);
432147c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth  return PD;
432247c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth}
432347c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth
432489c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor// Helper class template that is used by Type::getAs to ensure that one does
432589c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor// not try to look through a qualified type to get to an array type.
432689c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregortemplate<typename T,
432789c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor         bool isArrayType = (llvm::is_same<T, ArrayType>::value ||
432889c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor                             llvm::is_base_of<ArrayType, T>::value)>
432989c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregorstruct ArrayType_cannot_be_used_with_getAs { };
433089c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor
433189c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregortemplate<typename T>
433289c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregorstruct ArrayType_cannot_be_used_with_getAs<T, true>;
433389c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor
43341a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek/// Member-template getAs<specific type>'.
43351a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenektemplate <typename T> const T *Type::getAs() const {
433689c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor  ArrayType_cannot_be_used_with_getAs<T> at;
433789c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor  (void)at;
433889c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor
43391a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek  // If this is directly a T type, return it.
43401a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek  if (const T *Ty = dyn_cast<T>(this))
43411a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek    return Ty;
43421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
43431a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek  // If the canonical form of this type isn't the right kind, reject it.
43440953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  if (!isa<T>(CanonicalType))
43451a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek    return 0;
43461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
43470953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // If this is a typedef for the type, strip the typedef off without
43481a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek  // losing all typedef information.
4349bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  return cast<T>(getUnqualifiedDesugaredType());
43501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump}
435122caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner
43523b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallinline const ArrayType *Type::getAsArrayTypeUnsafe() const {
43533b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  // If this is directly an array type, return it.
43543b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  if (const ArrayType *arr = dyn_cast<ArrayType>(this))
43553b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    return arr;
43563b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
43573b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  // If the canonical form of this type isn't the right kind, reject it.
43583b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  if (!isa<ArrayType>(CanonicalType))
43593b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    return 0;
43603b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
43613b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  // If this is a typedef for the type, strip the typedef off without
43623b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  // losing all typedef information.
43633b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  return cast<ArrayType>(getUnqualifiedDesugaredType());
43643b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall}
43653b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
4366d0370f59e79702ac908c81bf556519f91e9ca297John McCalltemplate <typename T> const T *Type::castAs() const {
4367d0370f59e79702ac908c81bf556519f91e9ca297John McCall  ArrayType_cannot_be_used_with_getAs<T> at;
4368d0370f59e79702ac908c81bf556519f91e9ca297John McCall  (void) at;
4369d0370f59e79702ac908c81bf556519f91e9ca297John McCall
4370d0370f59e79702ac908c81bf556519f91e9ca297John McCall  assert(isa<T>(CanonicalType));
4371d0370f59e79702ac908c81bf556519f91e9ca297John McCall  if (const T *ty = dyn_cast<T>(this)) return ty;
4372d0370f59e79702ac908c81bf556519f91e9ca297John McCall  return cast<T>(getUnqualifiedDesugaredType());
4373d0370f59e79702ac908c81bf556519f91e9ca297John McCall}
4374d0370f59e79702ac908c81bf556519f91e9ca297John McCall
4375d0370f59e79702ac908c81bf556519f91e9ca297John McCallinline const ArrayType *Type::castAsArrayTypeUnsafe() const {
4376d0370f59e79702ac908c81bf556519f91e9ca297John McCall  assert(isa<ArrayType>(CanonicalType));
4377d0370f59e79702ac908c81bf556519f91e9ca297John McCall  if (const ArrayType *arr = dyn_cast<ArrayType>(this)) return arr;
4378d0370f59e79702ac908c81bf556519f91e9ca297John McCall  return cast<ArrayType>(getUnqualifiedDesugaredType());
4379d0370f59e79702ac908c81bf556519f91e9ca297John McCall}
4380d0370f59e79702ac908c81bf556519f91e9ca297John McCall
43815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}  // end namespace clang
43825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
43835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif
4384