Type.h revision 075f8f1b6bed4d1b224c74f87508534cc6392ce6
15f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===--- Type.h - C Language Family Type Representation ---------*- C++ -*-===//
25f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
35f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//                     The LLVM Compiler Infrastructure
45f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
50bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// This file is distributed under the University of Illinois Open Source
60bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// License. See LICENSE.TXT for details.
75f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
85f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
95f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//  This file defines the Type interface and subclasses.
115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#ifndef LLVM_CLANG_AST_TYPE_H
155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#define LLVM_CLANG_AST_TYPE_H
165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1722caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner#include "clang/Basic/Diagnostic.h"
181734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor#include "clang/Basic/IdentifierTable.h"
190b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor#include "clang/Basic/Linkage.h"
2047c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth#include "clang/Basic/PartialDiagnostic.h"
211fb0caaa7bef765b85972274e3b434af2572c141John McCall#include "clang/Basic/Visibility.h"
22e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor#include "clang/AST/NestedNameSpecifier.h"
237532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor#include "clang/AST/TemplateName.h"
245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "llvm/Support/Casting.h"
2550d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor#include "llvm/Support/type_traits.h"
26fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff#include "llvm/ADT/APSInt.h"
275cf243a883872441d73ca49cea7e20de5802629bChris Lattner#include "llvm/ADT/FoldingSet.h"
285cf243a883872441d73ca49cea7e20de5802629bChris Lattner#include "llvm/ADT/PointerIntPair.h"
291734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor#include "llvm/ADT/PointerUnion.h"
307532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor
315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing llvm::isa;
325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing llvm::cast;
335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing llvm::cast_or_null;
345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing llvm::dyn_cast;
355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing llvm::dyn_cast_or_null;
366b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCallnamespace clang {
376b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall  enum {
38f7616b9067790757f4e12e834b216c53c8c04ebeDouglas Gregor    TypeAlignmentInBits = 4,
396b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall    TypeAlignment = 1 << TypeAlignmentInBits
406b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall  };
41aed1df80bf64228e1429c1edc408397f9174847cChris Lattner  class Type;
42aed1df80bf64228e1429c1edc408397f9174847cChris Lattner  class ExtQuals;
43aed1df80bf64228e1429c1edc408397f9174847cChris Lattner  class QualType;
446b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall}
455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
464e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattnernamespace llvm {
474e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner  template <typename T>
48daae940507f2e93c6fa12e8062fa958e34cc2d1cChris Lattner  class PointerLikeTypeTraits;
49bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner  template<>
50bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner  class PointerLikeTypeTraits< ::clang::Type*> {
51bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner  public:
52bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner    static inline void *getAsVoidPointer(::clang::Type *P) { return P; }
53bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner    static inline ::clang::Type *getFromVoidPointer(void *P) {
54bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner      return static_cast< ::clang::Type*>(P);
55bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner    }
566b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall    enum { NumLowBitsAvailable = clang::TypeAlignmentInBits };
57bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner  };
580953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  template<>
590953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  class PointerLikeTypeTraits< ::clang::ExtQuals*> {
600953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  public:
610953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    static inline void *getAsVoidPointer(::clang::ExtQuals *P) { return P; }
620953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    static inline ::clang::ExtQuals *getFromVoidPointer(void *P) {
630953e767ff7817f97b3ab20896b229891eeff45bJohn McCall      return static_cast< ::clang::ExtQuals*>(P);
640953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    }
656b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall    enum { NumLowBitsAvailable = clang::TypeAlignmentInBits };
660953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  };
67aed1df80bf64228e1429c1edc408397f9174847cChris Lattner
68aed1df80bf64228e1429c1edc408397f9174847cChris Lattner  template <>
69aed1df80bf64228e1429c1edc408397f9174847cChris Lattner  struct isPodLike<clang::QualType> { static const bool value = true; };
704e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner}
714e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner
725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang {
735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class ASTContext;
745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class TypedefDecl;
7555f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  class TemplateDecl;
7672c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor  class TemplateTypeParmDecl;
77aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor  class NonTypeTemplateParmDecl;
787532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor  class TemplateTemplateParmDecl;
795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class TagDecl;
805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class RecordDecl;
8149aa7ff1245abd03e6e998e01302df31e4c6f8f6Argyrios Kyrtzidis  class CXXRecordDecl;
825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class EnumDecl;
8321d50e12c3c412d8457071dc419363b7a7e8b855Ted Kremenek  class FieldDecl;
84a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  class ObjCInterfaceDecl;
85a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  class ObjCProtocolDecl;
86a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  class ObjCMethodDecl;
87ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  class UnresolvedUsingTypenameDecl;
885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class Expr;
89b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek  class Stmt;
905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class SourceLocation;
9192866e2e90f6d93fb95e25a7ac4438e239d89ce6Ted Kremenek  class StmtIteratorBase;
9240808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  class TemplateArgument;
93833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  class TemplateArgumentLoc;
94d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  class TemplateArgumentListInfo;
95ead608af31b6c9abeae1ca6d0b75094dac4641c0John McCall  class Type;
96465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  class ElaboratedType;
973b4ea54acf01f72f6eb74d96689dda86d950228fDaniel Dunbar  struct PrintingPolicy;
9872564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor
99ead608af31b6c9abeae1ca6d0b75094dac4641c0John McCall  template <typename> class CanQual;
100ead608af31b6c9abeae1ca6d0b75094dac4641c0John McCall  typedef CanQual<Type> CanQualType;
101ead608af31b6c9abeae1ca6d0b75094dac4641c0John McCall
10272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  // Provide forward declarations for all of the *Type classes
10372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#define TYPE(Class, Base) class Class##Type;
10472564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#include "clang/AST/TypeNodes.def"
105f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl
1060953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// Qualifiers - The collection of all-type qualifiers we support.
1070953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// Clang supports five independent qualifiers:
1080953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// * C99: const, volatile, and restrict
1090953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// * Embedded C (TR18037): address spaces
1100953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// * Objective C: the GC attributes (none, weak, or strong)
1110953e767ff7817f97b3ab20896b229891eeff45bJohn McCallclass Qualifiers {
1125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
1130953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  enum TQ { // NOTE: These flags must be kept in sync with DeclSpec::TQ.
1145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Const    = 0x1,
1155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Restrict = 0x2,
1165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Volatile = 0x4,
1170953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    CVRMask = Const | Volatile | Restrict
1185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
1191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1200953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  enum GC {
121d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian    GCNone = 0,
122d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian    Weak,
123d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian    Strong
124d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian  };
125efadb7768e7c7418185f5a4010ecd8b21ca9731bJohn McCall
1260953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  enum {
1270953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    /// The maximum supported address space number.
1280953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    /// 24 bits should be enough for anyone.
1290953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    MaxAddressSpace = 0xffffffu,
1300953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
1310953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    /// The width of the "fast" qualifier mask.
132f7616b9067790757f4e12e834b216c53c8c04ebeDouglas Gregor    FastWidth = 3,
1330953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
1340953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    /// The fast qualifier mask.
1350953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    FastMask = (1 << FastWidth) - 1
1360953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  };
1370953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
1380953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  Qualifiers() : Mask(0) {}
1390953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
1400953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  static Qualifiers fromFastMask(unsigned Mask) {
1410953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Qualifiers Qs;
1420953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Qs.addFastQualifiers(Mask);
1430953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return Qs;
1440953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
1450953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
1460953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  static Qualifiers fromCVRMask(unsigned CVR) {
1470953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Qualifiers Qs;
1480953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Qs.addCVRQualifiers(CVR);
1490953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return Qs;
1500953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
1510953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
1520953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Deserialize qualifiers from an opaque representation.
1530953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  static Qualifiers fromOpaqueValue(unsigned opaque) {
1540953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Qualifiers Qs;
1550953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Qs.Mask = opaque;
1560953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return Qs;
1570953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
1580953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
1590953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Serialize these qualifiers into an opaque representation.
1600953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  unsigned getAsOpaqueValue() const {
1610953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return Mask;
1620953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
1630953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
1640953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool hasConst() const { return Mask & Const; }
1650953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void setConst(bool flag) {
1660953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask = (Mask & ~Const) | (flag ? Const : 0);
1670953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
1680953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void removeConst() { Mask &= ~Const; }
1690953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void addConst() { Mask |= Const; }
1700953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
1710953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool hasVolatile() const { return Mask & Volatile; }
1720953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void setVolatile(bool flag) {
1730953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask = (Mask & ~Volatile) | (flag ? Volatile : 0);
1740953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
1750953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void removeVolatile() { Mask &= ~Volatile; }
1760953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void addVolatile() { Mask |= Volatile; }
1770953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
1780953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool hasRestrict() const { return Mask & Restrict; }
1790953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void setRestrict(bool flag) {
1800953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask = (Mask & ~Restrict) | (flag ? Restrict : 0);
1810953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
1820953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void removeRestrict() { Mask &= ~Restrict; }
1830953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void addRestrict() { Mask |= Restrict; }
1840953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
1850953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool hasCVRQualifiers() const { return getCVRQualifiers(); }
1860953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  unsigned getCVRQualifiers() const { return Mask & CVRMask; }
1870953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void setCVRQualifiers(unsigned mask) {
1880953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(!(mask & ~CVRMask) && "bitmask contains non-CVR bits");
1890953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask = (Mask & ~CVRMask) | mask;
1900953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
1910953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void removeCVRQualifiers(unsigned mask) {
1920953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(!(mask & ~CVRMask) && "bitmask contains non-CVR bits");
1930953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask &= ~mask;
1940953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
1950953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void removeCVRQualifiers() {
1960953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    removeCVRQualifiers(CVRMask);
1970953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
1980953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void addCVRQualifiers(unsigned mask) {
1990953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(!(mask & ~CVRMask) && "bitmask contains non-CVR bits");
2000953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask |= mask;
2010953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2020953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
2030953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool hasObjCGCAttr() const { return Mask & GCAttrMask; }
2040953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  GC getObjCGCAttr() const { return GC((Mask & GCAttrMask) >> GCAttrShift); }
2050953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void setObjCGCAttr(GC type) {
2060953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask = (Mask & ~GCAttrMask) | (type << GCAttrShift);
2070953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2080953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void removeObjCGCAttr() { setObjCGCAttr(GCNone); }
2090953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void addObjCGCAttr(GC type) {
2100953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(type);
2110953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    setObjCGCAttr(type);
2120953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2130953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
2140953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool hasAddressSpace() const { return Mask & AddressSpaceMask; }
2150953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  unsigned getAddressSpace() const { return Mask >> AddressSpaceShift; }
2160953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void setAddressSpace(unsigned space) {
2170953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(space <= MaxAddressSpace);
2180953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask = (Mask & ~AddressSpaceMask)
2190953e767ff7817f97b3ab20896b229891eeff45bJohn McCall         | (((uint32_t) space) << AddressSpaceShift);
2200953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2210953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void removeAddressSpace() { setAddressSpace(0); }
2220953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void addAddressSpace(unsigned space) {
2230953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(space);
2240953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    setAddressSpace(space);
2250953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2260953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
2270953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Fast qualifiers are those that can be allocated directly
2280953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // on a QualType object.
2290953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool hasFastQualifiers() const { return getFastQualifiers(); }
2300953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  unsigned getFastQualifiers() const { return Mask & FastMask; }
2310953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void setFastQualifiers(unsigned mask) {
2320953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(!(mask & ~FastMask) && "bitmask contains non-fast qualifier bits");
2330953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask = (Mask & ~FastMask) | mask;
2340953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2350953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void removeFastQualifiers(unsigned mask) {
2360953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(!(mask & ~FastMask) && "bitmask contains non-fast qualifier bits");
2370953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask &= ~mask;
2380953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2390953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void removeFastQualifiers() {
2400953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    removeFastQualifiers(FastMask);
2410953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2420953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void addFastQualifiers(unsigned mask) {
2430953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(!(mask & ~FastMask) && "bitmask contains non-fast qualifier bits");
2440953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask |= mask;
2450953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2460953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
2470953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// hasNonFastQualifiers - Return true if the set contains any
2480953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// qualifiers which require an ExtQuals node to be allocated.
2490953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool hasNonFastQualifiers() const { return Mask & ~FastMask; }
2500953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  Qualifiers getNonFastQualifiers() const {
2510953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Qualifiers Quals = *this;
2520953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Quals.setFastQualifiers(0);
2530953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return Quals;
2540953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2550953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
2560953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// hasQualifiers - Return true if the set contains any qualifiers.
2570953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool hasQualifiers() const { return Mask; }
2580953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool empty() const { return !Mask; }
2590953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
2600953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// \brief Add the qualifiers from the given set to this set.
2610953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void addQualifiers(Qualifiers Q) {
2620953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    // If the other set doesn't have any non-boolean qualifiers, just
2630953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    // bit-or it in.
2640953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    if (!(Q.Mask & ~CVRMask))
2650953e767ff7817f97b3ab20896b229891eeff45bJohn McCall      Mask |= Q.Mask;
2660953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    else {
2670953e767ff7817f97b3ab20896b229891eeff45bJohn McCall      Mask |= (Q.Mask & CVRMask);
2680953e767ff7817f97b3ab20896b229891eeff45bJohn McCall      if (Q.hasAddressSpace())
2690953e767ff7817f97b3ab20896b229891eeff45bJohn McCall        addAddressSpace(Q.getAddressSpace());
2700953e767ff7817f97b3ab20896b229891eeff45bJohn McCall      if (Q.hasObjCGCAttr())
2710953e767ff7817f97b3ab20896b229891eeff45bJohn McCall        addObjCGCAttr(Q.getObjCGCAttr());
2720953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    }
2730953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2740953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
275b87786f045d798b070980c108c922e1475d27b15Douglas Gregor  bool isSupersetOf(Qualifiers Other) const;
276b87786f045d798b070980c108c922e1475d27b15Douglas Gregor
2770953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool operator==(Qualifiers Other) const { return Mask == Other.Mask; }
2780953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool operator!=(Qualifiers Other) const { return Mask != Other.Mask; }
2790953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
2800953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  operator bool() const { return hasQualifiers(); }
2810953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
2820953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  Qualifiers &operator+=(Qualifiers R) {
2830953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    addQualifiers(R);
2840953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return *this;
2850953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2860953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
2870953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Union two qualifier sets.  If an enumerated qualifier appears
2880953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // in both sets, use the one from the right.
2890953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  friend Qualifiers operator+(Qualifiers L, Qualifiers R) {
2900953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    L += R;
2910953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return L;
2920953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2933cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor
2943cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor  Qualifiers &operator-=(Qualifiers R) {
2953cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor    Mask = Mask & ~(R.Mask);
2963cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor    return *this;
2973cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor  }
2980953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
2993cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor  /// \brief Compute the difference between two qualifier sets.
3003cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor  friend Qualifiers operator-(Qualifiers L, Qualifiers R) {
3013cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor    L -= R;
3023cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor    return L;
3033cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor  }
3043cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor
3050953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  std::string getAsString() const;
3060953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  std::string getAsString(const PrintingPolicy &Policy) const {
3070953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    std::string Buffer;
3080953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    getAsStringInternal(Buffer, Policy);
3090953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return Buffer;
3100953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
3110953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void getAsStringInternal(std::string &S, const PrintingPolicy &Policy) const;
3120953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3130953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void Profile(llvm::FoldingSetNodeID &ID) const {
3140953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    ID.AddInteger(Mask);
3150953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
3160953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3170953e767ff7817f97b3ab20896b229891eeff45bJohn McCallprivate:
3180953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3190953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // bits:     |0 1 2|3 .. 4|5  ..  31|
3200953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  //           |C R V|GCAttr|AddrSpace|
3210953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  uint32_t Mask;
3220953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3230953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  static const uint32_t GCAttrMask = 0x18;
3240953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  static const uint32_t GCAttrShift = 3;
3250953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  static const uint32_t AddressSpaceMask = ~(CVRMask | GCAttrMask);
3260953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  static const uint32_t AddressSpaceShift = 5;
3270953e767ff7817f97b3ab20896b229891eeff45bJohn McCall};
3280953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3290953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
33055270e4bde91bd30d16086ae71f0f65caf3b8a51Douglas Gregor/// ExtQuals - We can encode up to four bits in the low bits of a
3310953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// type pointer, but there are many more type qualifiers that we want
3320953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// to be able to apply to an arbitrary type.  Therefore we have this
3330953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// struct, intended to be heap-allocated and used by QualType to
3340953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// store qualifiers.
3350953e767ff7817f97b3ab20896b229891eeff45bJohn McCall///
33655270e4bde91bd30d16086ae71f0f65caf3b8a51Douglas Gregor/// The current design tags the 'const', 'restrict', and 'volatile' qualifiers
33755270e4bde91bd30d16086ae71f0f65caf3b8a51Douglas Gregor/// in three low bits on the QualType pointer; a fourth bit records whether
33855270e4bde91bd30d16086ae71f0f65caf3b8a51Douglas Gregor/// the pointer is an ExtQuals node. The extended qualifiers (address spaces,
33955270e4bde91bd30d16086ae71f0f65caf3b8a51Douglas Gregor/// Objective-C GC attributes) are much more rare.
3400953e767ff7817f97b3ab20896b229891eeff45bJohn McCallclass ExtQuals : public llvm::FoldingSetNode {
3410953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // NOTE: changing the fast qualifiers should be straightforward as
3420953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // long as you don't make 'const' non-fast.
3430953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // 1. Qualifiers:
3440953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  //    a) Modify the bitmasks (Qualifiers::TQ and DeclSpec::TQ).
3450953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  //       Fast qualifiers must occupy the low-order bits.
3460953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  //    b) Update Qualifiers::FastWidth and FastMask.
3470953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // 2. QualType:
3480953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  //    a) Update is{Volatile,Restrict}Qualified(), defined inline.
3490953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  //    b) Update remove{Volatile,Restrict}, defined near the end of
3500953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  //       this header.
3510953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // 3. ASTContext:
3520953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  //    a) Update get{Volatile,Restrict}Type.
3530953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3540953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// BaseType - the underlying type that this qualifies
3550953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  const Type *BaseType;
3560953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3570953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// Quals - the immutable set of qualifiers applied by this
3580953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// node;  always contains extended qualifiers.
3590953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  Qualifiers Quals;
3600953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3610953e767ff7817f97b3ab20896b229891eeff45bJohn McCallpublic:
36249f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  ExtQuals(const Type *Base, Qualifiers Quals) : BaseType(Base), Quals(Quals)
3630953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  {
3640953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(Quals.hasNonFastQualifiers()
3650953e767ff7817f97b3ab20896b229891eeff45bJohn McCall           && "ExtQuals created with no fast qualifiers");
3660953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(!Quals.hasFastQualifiers()
3670953e767ff7817f97b3ab20896b229891eeff45bJohn McCall           && "ExtQuals created with fast qualifiers");
3680953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
3690953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3700953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  Qualifiers getQualifiers() const { return Quals; }
3710953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3720953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool hasObjCGCAttr() const { return Quals.hasObjCGCAttr(); }
3730953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  Qualifiers::GC getObjCGCAttr() const { return Quals.getObjCGCAttr(); }
3740953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3750953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool hasAddressSpace() const { return Quals.hasAddressSpace(); }
3760953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  unsigned getAddressSpace() const { return Quals.getAddressSpace(); }
3770953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3780953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  const Type *getBaseType() const { return BaseType; }
3791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3800953e767ff7817f97b3ab20896b229891eeff45bJohn McCallpublic:
3810953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void Profile(llvm::FoldingSetNodeID &ID) const {
3820953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Profile(ID, getBaseType(), Quals);
3830953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
3840953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  static void Profile(llvm::FoldingSetNodeID &ID,
3850953e767ff7817f97b3ab20896b229891eeff45bJohn McCall                      const Type *BaseType,
3860953e767ff7817f97b3ab20896b229891eeff45bJohn McCall                      Qualifiers Quals) {
3870953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(!Quals.hasFastQualifiers() && "fast qualifiers in ExtQuals hash!");
3880953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    ID.AddPointer(BaseType);
3890953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Quals.Profile(ID);
3900953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
3910953e767ff7817f97b3ab20896b229891eeff45bJohn McCall};
3920953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
393ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor/// CallingConv - Specifies the calling convention that a function uses.
394ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregorenum CallingConv {
395ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor  CC_Default,
396ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor  CC_C,           // __attribute__((cdecl))
397ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor  CC_X86StdCall,  // __attribute__((stdcall))
398f813a2c03fcb05381b3252010435f557eb6b3cdeDouglas Gregor  CC_X86FastCall, // __attribute__((fastcall))
39952fc314e1b5e1baee6305067cf831763d02bd243Dawn Perchik  CC_X86ThisCall, // __attribute__((thiscall))
40052fc314e1b5e1baee6305067cf831763d02bd243Dawn Perchik  CC_X86Pascal    // __attribute__((pascal))
401ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor};
402ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor
40349f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCalltypedef std::pair<const Type*, Qualifiers> SplitQualType;
4040953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
4050953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// QualType - For efficiency, we don't store CV-qualified types as nodes on
4060953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// their own: instead each reference to a type stores the qualifiers.  This
4070953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// greatly reduces the number of nodes we need to allocate for types (for
4080953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// example we only need one for 'int', 'const int', 'volatile int',
4090953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// 'const volatile int', etc).
4100953e767ff7817f97b3ab20896b229891eeff45bJohn McCall///
4110953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// As an added efficiency bonus, instead of making this a pair, we
4120953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// just store the two bits we care about in the low bits of the
4130953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// pointer.  To handle the packing/unpacking, we make QualType be a
4140953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// simple wrapper class that acts like a smart pointer.  A third bit
4150953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// indicates whether there are extended qualifiers present, in which
4160953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// case the pointer points to a special structure.
4170953e767ff7817f97b3ab20896b229891eeff45bJohn McCallclass QualType {
4180953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Thankfully, these are efficiently composable.
4190953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  llvm::PointerIntPair<llvm::PointerUnion<const Type*,const ExtQuals*>,
4200953e767ff7817f97b3ab20896b229891eeff45bJohn McCall                       Qualifiers::FastWidth> Value;
4210953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
4220953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  const ExtQuals *getExtQualsUnsafe() const {
4230953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return Value.getPointer().get<const ExtQuals*>();
4240953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
4250953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
4260953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  const Type *getTypePtrUnsafe() const {
4270953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return Value.getPointer().get<const Type*>();
4280953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
4290953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
430fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  QualType getUnqualifiedTypeSlow() const;
431fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor
4320953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  friend class QualifierCollector;
4330953e767ff7817f97b3ab20896b229891eeff45bJohn McCallpublic:
4345cf243a883872441d73ca49cea7e20de5802629bChris Lattner  QualType() {}
4351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4365cf243a883872441d73ca49cea7e20de5802629bChris Lattner  QualType(const Type *Ptr, unsigned Quals)
4370953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    : Value(Ptr, Quals) {}
4380953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  QualType(const ExtQuals *Ptr, unsigned Quals)
4390953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    : Value(Ptr, Quals) {}
4400953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
441a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  unsigned getLocalFastQualifiers() const { return Value.getInt(); }
442a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  void setLocalFastQualifiers(unsigned Quals) { Value.setInt(Quals); }
4435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4440953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// Retrieves a pointer to the underlying (unqualified) type.
4450953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// This should really return a const Type, but it's not worth
4460953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// changing all the users right now.
4470953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  Type *getTypePtr() const {
448a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor    if (hasLocalNonFastQualifiers())
4490953e767ff7817f97b3ab20896b229891eeff45bJohn McCall      return const_cast<Type*>(getExtQualsUnsafe()->getBaseType());
4500953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return const_cast<Type*>(getTypePtrUnsafe());
4510953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
4521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
45349f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  /// Divides a QualType into its unqualified type and a set of local
45449f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  /// qualifiers.
45549f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  SplitQualType split() const {
45649f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall    if (!hasLocalNonFastQualifiers())
45749f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall      return SplitQualType(getTypePtrUnsafe(),
45849f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall                           Qualifiers::fromFastMask(getLocalFastQualifiers()));
45949f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall
46049f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall    const ExtQuals *eq = getExtQualsUnsafe();
46149f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall    Qualifiers qs = eq->getQualifiers();
46249f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall    qs.addFastQualifiers(getLocalFastQualifiers());
46349f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall    return SplitQualType(eq->getBaseType(), qs);
46449f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  }
46549f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall
4665cf243a883872441d73ca49cea7e20de5802629bChris Lattner  void *getAsOpaquePtr() const { return Value.getOpaqueValue(); }
4675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static QualType getFromOpaquePtr(void *Ptr) {
4685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    QualType T;
4695cf243a883872441d73ca49cea7e20de5802629bChris Lattner    T.Value.setFromOpaqueValue(Ptr);
4705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T;
4715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
4721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Type &operator*() const {
4745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return *getTypePtr();
4755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
4765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Type *operator->() const {
4785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return getTypePtr();
4795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
4801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
481467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall  bool isCanonical() const;
48254e14c4db764c0636160d26c5bbf491637c83a76John McCall  bool isCanonicalAsParam() const;
483467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall
4845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isNull - Return true if this QualType doesn't point to a type yet.
4855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isNull() const {
4860953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return Value.getPointer().isNull();
4875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
4885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
489a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Determine whether this particular QualType instance has the
490a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// "const" qualifier set, without looking through typedefs that may have
491a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// added "const" at a different level.
492a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  bool isLocalConstQualified() const {
493a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor    return (getLocalFastQualifiers() & Qualifiers::Const);
4940953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
495a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor
496a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Determine whether this type is const-qualified.
497fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  bool isConstQualified() const;
498a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor
499a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Determine whether this particular QualType instance has the
500a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// "restrict" qualifier set, without looking through typedefs that may have
501a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// added "restrict" at a different level.
502a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  bool isLocalRestrictQualified() const {
503a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor    return (getLocalFastQualifiers() & Qualifiers::Restrict);
504a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  }
505a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor
506a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Determine whether this type is restrict-qualified.
507fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  bool isRestrictQualified() const;
508a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor
509a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Determine whether this particular QualType instance has the
510a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// "volatile" qualifier set, without looking through typedefs that may have
511a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// added "volatile" at a different level.
512a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  bool isLocalVolatileQualified() const {
513f7616b9067790757f4e12e834b216c53c8c04ebeDouglas Gregor    return (getLocalFastQualifiers() & Qualifiers::Volatile);
5145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
5150953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
516a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Determine whether this type is volatile-qualified.
517fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  bool isVolatileQualified() const;
518a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor
519a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Determine whether this particular QualType instance has any
520a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// qualifiers, without looking through any typedefs that might add
521a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// qualifiers at a different level.
522a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  bool hasLocalQualifiers() const {
523a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor    return getLocalFastQualifiers() || hasLocalNonFastQualifiers();
5240953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
5250953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
526a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Determine whether this type has any qualifiers.
527fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  bool hasQualifiers() const;
528a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor
529a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Determine whether this particular QualType instance has any
530a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// "non-fast" qualifiers, e.g., those that are stored in an ExtQualType
531a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// instance.
532a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  bool hasLocalNonFastQualifiers() const {
533a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor    return Value.getPointer().is<const ExtQuals*>();
5340953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
5350953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
536a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Retrieve the set of qualifiers local to this particular QualType
537a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// instance, not including any qualifiers acquired through typedefs or
538a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// other sugar.
539a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  Qualifiers getLocalQualifiers() const {
5400953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Qualifiers Quals;
541a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor    if (hasLocalNonFastQualifiers())
5420953e767ff7817f97b3ab20896b229891eeff45bJohn McCall      Quals = getExtQualsUnsafe()->getQualifiers();
543a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor    Quals.addFastQualifiers(getLocalFastQualifiers());
5440953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return Quals;
5450953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
5460953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
547a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Retrieve the set of qualifiers applied to this type.
548fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  Qualifiers getQualifiers() const;
549a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor
550a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Retrieve the set of CVR (const-volatile-restrict) qualifiers
551a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// local to this particular QualType instance, not including any qualifiers
552a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// acquired through typedefs or other sugar.
553a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  unsigned getLocalCVRQualifiers() const {
554f7616b9067790757f4e12e834b216c53c8c04ebeDouglas Gregor    return getLocalFastQualifiers();
5555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
556b381aac9bae6d608c72267dd0ed08ec6369e94e4Nuno Lopes
557a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Retrieve the set of CVR (const-volatile-restrict) qualifiers
558a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// applied to this type.
559fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  unsigned getCVRQualifiers() const;
560e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth
561e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth  /// \brief Retrieve the set of CVR (const-volatile-restrict) qualifiers
562e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth  /// applied to this type, looking through any number of unqualified array
563e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth  /// types to their element types' qualifiers.
564e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth  unsigned getCVRQualifiersThroughArrayTypes() const;
565e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth
566bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isConstant(ASTContext& Ctx) const {
567bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall    return QualType::isConstant(*this, Ctx);
568bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  }
5691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5700953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Don't promise in the API that anything besides 'const' can be
5710953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // easily added.
5720953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
5730953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// addConst - add the specified type qualifier to this QualType.
5740953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void addConst() {
5750953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    addFastQualifiers(Qualifiers::Const);
5760953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
5770953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  QualType withConst() const {
5780953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return withFastQualifiers(Qualifiers::Const);
5790953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
5800953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
5810953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void addFastQualifiers(unsigned TQs) {
5820953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(!(TQs & ~Qualifiers::FastMask)
5830953e767ff7817f97b3ab20896b229891eeff45bJohn McCall           && "non-fast qualifier bits set in mask!");
5840953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Value.setInt(Value.getInt() | TQs);
5850953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
5860953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
58749f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  void removeLocalConst();
58849f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  void removeLocalVolatile();
58949f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  void removeLocalRestrict();
59049f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  void removeLocalCVRQualifiers(unsigned Mask);
5910953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
59249f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  void removeLocalFastQualifiers() { Value.setInt(0); }
59349f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  void removeLocalFastQualifiers(unsigned Mask) {
5940953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(!(Mask & ~Qualifiers::FastMask) && "mask has non-fast qualifiers");
5950953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Value.setInt(Value.getInt() & ~Mask);
5960953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
5975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
5980953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Creates a type with the given qualifiers in addition to any
5990953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // qualifiers already on this type.
6000953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  QualType withFastQualifiers(unsigned TQs) const {
6010953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    QualType T = *this;
6020953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    T.addFastQualifiers(TQs);
6030953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return T;
6040953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
6051c6a38bcea17801e9a4738753aee845381af2b6cSanjiv Gupta
6060953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Creates a type with exactly the given fast qualifiers, removing
6070953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // any existing fast qualifiers.
60849f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  QualType withExactLocalFastQualifiers(unsigned TQs) const {
60949f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall    return withoutLocalFastQualifiers().withFastQualifiers(TQs);
6105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
6110953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
6120953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Removes fast qualifiers, but leaves any extended qualifiers in place.
61349f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  QualType withoutLocalFastQualifiers() const {
6140953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    QualType T = *this;
61549f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall    T.removeLocalFastQualifiers();
6160953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return T;
617c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  }
618971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis
619a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Return this type with all of the instance-specific qualifiers
620a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// removed, but without removing any qualifiers that may have been applied
621a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// through typedefs.
622a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  QualType getLocalUnqualifiedType() const { return QualType(getTypePtr(), 0); }
6231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
624a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Return the unqualified form of the given type, which might be
625a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// desugared to eliminate qualifiers introduced via typedefs.
626fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  QualType getUnqualifiedType() const {
627fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor    QualType T = getLocalUnqualifiedType();
628fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor    if (!T.hasQualifiers())
629fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor      return T;
630fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor
631fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor    return getUnqualifiedTypeSlow();
632a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  }
633a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor
634e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor  bool isMoreQualifiedThan(QualType Other) const;
635e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor  bool isAtLeastAsQualifiedAs(QualType Other) const;
636e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor  QualType getNonReferenceType() const;
6371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6386398235d7890a81b785ea5af3b6e66d86bf184ccDouglas Gregor  /// \brief Determine the type of a (typically non-lvalue) expression with the
6396398235d7890a81b785ea5af3b6e66d86bf184ccDouglas Gregor  /// specified result type.
6405291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor  ///
6416398235d7890a81b785ea5af3b6e66d86bf184ccDouglas Gregor  /// This routine should be used for expressions for which the return type is
6426398235d7890a81b785ea5af3b6e66d86bf184ccDouglas Gregor  /// explicitly specified (e.g., in a cast or call) and isn't necessarily
6436398235d7890a81b785ea5af3b6e66d86bf184ccDouglas Gregor  /// an lvalue. It removes a top-level reference (since there are no
6445291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor  /// expressions of reference type) and deletes top-level cvr-qualifiers
6455291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor  /// from non-class types (in C++) or all types (in C).
6466398235d7890a81b785ea5af3b6e66d86bf184ccDouglas Gregor  QualType getNonLValueExprType(ASTContext &Context) const;
6475291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor
6482fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner  /// getDesugaredType - Return the specified type with any "sugar" removed from
6492fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner  /// the type.  This takes off typedefs, typeof's etc.  If the outer level of
6502fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner  /// the type is already concrete, it returns it unmodified.  This is similar
6512fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner  /// to getting the canonical type, but it doesn't remove *all* typedefs.  For
6522fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner  /// example, it returns "T*" as "T*", (not as "int*"), because the pointer is
6532fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner  /// concrete.
6540953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  ///
6550953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// Qualifiers are left in place.
65649f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  QualType getDesugaredType(ASTContext &Context) const {
65749f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall    return getDesugaredType(*this, Context);
65849f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  }
65949f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall
66049f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  SplitQualType getSplitDesugaredType() const {
66149f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall    return getSplitDesugaredType(*this);
662bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  }
66398cd599ee8a9b259ed7388ee2921a20d97658864Douglas Gregor
664075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  /// IgnoreParens - Returns the specified type after dropping any
665075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  /// outer-level parentheses.
666075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  QualType IgnoreParens() const {
667075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara    return QualType::IgnoreParens(*this);
668075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  }
669075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
6705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// operator==/!= - Indicate whether the specified types and qualifiers are
6715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// identical.
67250d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor  friend bool operator==(const QualType &LHS, const QualType &RHS) {
67350d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor    return LHS.Value == RHS.Value;
6745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
67550d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor  friend bool operator!=(const QualType &LHS, const QualType &RHS) {
67650d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor    return LHS.Value != RHS.Value;
6775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
67849f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  std::string getAsString() const {
67949f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall    return getAsString(split());
68049f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  }
68149f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  static std::string getAsString(SplitQualType split) {
68249f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall    return getAsString(split.first, split.second);
68349f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  }
68449f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  static std::string getAsString(const Type *ty, Qualifiers qs);
685d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor
686d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor  std::string getAsString(const PrintingPolicy &Policy) const {
6875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    std::string S;
688d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor    getAsStringInternal(S, Policy);
6895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return S;
6905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
691e4f2142d00fa5fdb580c4e2413da91882d955381Chris Lattner  void getAsStringInternal(std::string &Str,
69249f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall                           const PrintingPolicy &Policy) const {
69349f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall    return getAsStringInternal(split(), Str, Policy);
69449f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  }
69549f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  static void getAsStringInternal(SplitQualType split, std::string &out,
69649f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall                                  const PrintingPolicy &policy) {
69749f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall    return getAsStringInternal(split.first, split.second, out, policy);
69849f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  }
69949f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  static void getAsStringInternal(const Type *ty, Qualifiers qs,
70049f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall                                  std::string &out,
70149f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall                                  const PrintingPolicy &policy);
7021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
703c36d405a02fab41f6c45cb2bc750d64949742903Chris Lattner  void dump(const char *s) const;
704c36d405a02fab41f6c45cb2bc750d64949742903Chris Lattner  void dump() const;
7051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7063f2dcb1ca8bd2d5d3ccc5c80f4ab06f949d88a89Ted Kremenek  void Profile(llvm::FoldingSetNodeID &ID) const {
7073f2dcb1ca8bd2d5d3ccc5c80f4ab06f949d88a89Ted Kremenek    ID.AddPointer(getAsOpaquePtr());
7083f2dcb1ca8bd2d5d3ccc5c80f4ab06f949d88a89Ted Kremenek  }
7095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
710ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb  /// getAddressSpace - Return the address space of this type.
711ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb  inline unsigned getAddressSpace() const;
7121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
713d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian  /// GCAttrTypesAttr - Returns gc attribute of this type.
7140953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  inline Qualifiers::GC getObjCGCAttr() const;
715f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian
716f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian  /// isObjCGCWeak true when Type is objc's weak.
717f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian  bool isObjCGCWeak() const {
7180953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return getObjCGCAttr() == Qualifiers::Weak;
719f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian  }
720f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian
721f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian  /// isObjCGCStrong true when Type is objc's strong.
722f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian  bool isObjCGCStrong() const {
7230953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return getObjCGCAttr() == Qualifiers::Strong;
724f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian  }
7252455636163fdd18581d7fdae816433f886d88213Mike Stump
726bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCallprivate:
727bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  // These methods are implemented in a separate translation unit;
728bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  // "static"-ize them to avoid creating temporary QualTypes in the
729bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  // caller.
730bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  static bool isConstant(QualType T, ASTContext& Ctx);
73149f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  static QualType getDesugaredType(QualType T, ASTContext &Context);
73249f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  static SplitQualType getSplitDesugaredType(QualType T);
733075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  static QualType IgnoreParens(QualType T);
7345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
7355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end clang.
7375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace llvm {
7395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Implement simplify_type for QualType, so that we can dyn_cast from QualType
7405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// to a specific Type class.
7415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencertemplate<> struct simplify_type<const ::clang::QualType> {
7425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  typedef ::clang::Type* SimpleType;
7435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static SimpleType getSimplifiedValue(const ::clang::QualType &Val) {
7445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return Val.getTypePtr();
7455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
7465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
7475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencertemplate<> struct simplify_type< ::clang::QualType>
7485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  : public simplify_type<const ::clang::QualType> {};
7491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7504e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner// Teach SmallPtrSet that QualType is "basically a pointer".
7514e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattnertemplate<>
752daae940507f2e93c6fa12e8062fa958e34cc2d1cChris Lattnerclass PointerLikeTypeTraits<clang::QualType> {
7534e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattnerpublic:
7544e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner  static inline void *getAsVoidPointer(clang::QualType P) {
7554e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner    return P.getAsOpaquePtr();
7564e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner  }
7574e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner  static inline clang::QualType getFromVoidPointer(void *P) {
7584e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner    return clang::QualType::getFromOpaquePtr(P);
7594e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner  }
7600953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Various qualifiers go in low bits.
7610eda3b31a672ea486fa92b9bc49a2c91be856b53Chris Lattner  enum { NumLowBitsAvailable = 0 };
7624e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner};
7631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
76473af669633e13c813f80cd15ecf3e6414778aee4Ted Kremenek} // end namespace llvm
7655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang {
7675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Type - This is the base class of the type hierarchy.  A central concept
7695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// with types is that each type always has a canonical type.  A canonical type
7705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// is the type with any typedef names stripped out of it or the types it
7715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// references.  For example, consider:
7725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
7735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///  typedef int  foo;
7745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///  typedef foo* bar;
7755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///    'int *'    'foo *'    'bar'
7765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
7775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// There will be a Type object created for 'int'.  Since int is canonical, its
7785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// canonicaltype pointer points to itself.  There is also a Type for 'foo' (a
77972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// TypedefType).  Its CanonicalType pointer points to the 'int' Type.  Next
7805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// there is a PointerType that represents 'int*', which, like 'int', is
7815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// canonical.  Finally, there is a PointerType type for 'foo*' whose canonical
78272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// type is 'int*', and there is a TypedefType for 'bar', whose canonical type
7835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// is also 'int*'.
7845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
7855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Non-canonical types are useful for emitting diagnostics, without losing
7865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// information about typedefs being used.  Canonical types are useful for type
7875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// comparisons (they allow by-pointer equality tests) and useful for reasoning
7885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// about whether something has a particular form (e.g. is a function type),
7895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// because they implicitly, recursively, strip all typedefs out of a type.
7905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
7915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Types, once created, are immutable.
7925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
7935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass Type {
7945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
7955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  enum TypeClass {
79672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#define TYPE(Class, Base) Class,
79727935ee59c30b0d8b610ab676aab8e65350af932John McCall#define LAST_TYPE(Class) TypeLast = Class,
79872564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#define ABSTRACT_TYPE(Class, Base)
79972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#include "clang/AST/TypeNodes.def"
80072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor    TagFirst = Record, TagLast = Enum
8015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
8021bb8a45f7386a23871598d05141a07af03067925Argyrios Kyrtzidis
8035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate:
804c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  Type(const Type&);           // DO NOT IMPLEMENT.
805c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  void operator=(const Type&); // DO NOT IMPLEMENT.
806c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
8075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType CanonicalType;
8085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
809b870b88df784c2940efce448ebfaf54dece14666John McCall  /// Bitfields required by the Type class.
810b870b88df784c2940efce448ebfaf54dece14666John McCall  class TypeBitfields {
811b870b88df784c2940efce448ebfaf54dece14666John McCall    friend class Type;
812b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall    template <class T> friend class TypePropertyCache;
81327935ee59c30b0d8b610ab676aab8e65350af932John McCall
814b870b88df784c2940efce448ebfaf54dece14666John McCall    /// TypeClass bitfield - Enum that specifies what subclass this belongs to.
815b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned TC : 8;
816b870b88df784c2940efce448ebfaf54dece14666John McCall
817b870b88df784c2940efce448ebfaf54dece14666John McCall    /// Dependent - Whether this type is a dependent type (C++ [temp.dep.type]).
818b870b88df784c2940efce448ebfaf54dece14666John McCall    /// Note that this should stay at the end of the ivars for Type so that
819b870b88df784c2940efce448ebfaf54dece14666John McCall    /// subclasses can pack their bitfields into the same word.
820bdb5b0e8ad8ed297ad01eb2ccd0d6d5ed6058033Francois Pichet    unsigned Dependent : 1;
82160e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
822b870b88df784c2940efce448ebfaf54dece14666John McCall    /// \brief Whether this type is a variably-modified type (C99 6.7.5).
823bdb5b0e8ad8ed297ad01eb2ccd0d6d5ed6058033Francois Pichet    unsigned VariablyModified : 1;
82435495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor
8251fb0caaa7bef765b85972274e3b434af2572c141John McCall    /// \brief Nonzero if the cache (i.e. the bitfields here starting
8261fb0caaa7bef765b85972274e3b434af2572c141John McCall    /// with 'Cache') is valid.  If so, then this is a
8271fb0caaa7bef765b85972274e3b434af2572c141John McCall    /// LangOptions::VisibilityMode+1.
8281fb0caaa7bef765b85972274e3b434af2572c141John McCall    mutable unsigned CacheValidAndVisibility : 2;
82960e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
830b870b88df784c2940efce448ebfaf54dece14666John McCall    /// \brief Linkage of this type.
831b870b88df784c2940efce448ebfaf54dece14666John McCall    mutable unsigned CachedLinkage : 2;
83207a353c2af3a3c557205466d4f4ed2513462ebfeSebastian Redl
833b870b88df784c2940efce448ebfaf54dece14666John McCall    /// \brief Whether this type involves and local or unnamed types.
834bdb5b0e8ad8ed297ad01eb2ccd0d6d5ed6058033Francois Pichet    mutable unsigned CachedLocalOrUnnamed : 1;
835db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor
836b870b88df784c2940efce448ebfaf54dece14666John McCall    /// \brief FromAST - Whether this type comes from an AST file.
837bdb5b0e8ad8ed297ad01eb2ccd0d6d5ed6058033Francois Pichet    mutable unsigned FromAST : 1;
838b870b88df784c2940efce448ebfaf54dece14666John McCall
8391fb0caaa7bef765b85972274e3b434af2572c141John McCall    bool isCacheValid() const {
8401fb0caaa7bef765b85972274e3b434af2572c141John McCall      return (CacheValidAndVisibility != 0);
8411fb0caaa7bef765b85972274e3b434af2572c141John McCall    }
8421fb0caaa7bef765b85972274e3b434af2572c141John McCall    Visibility getVisibility() const {
8431fb0caaa7bef765b85972274e3b434af2572c141John McCall      assert(isCacheValid() && "getting linkage from invalid cache");
8441fb0caaa7bef765b85972274e3b434af2572c141John McCall      return static_cast<Visibility>(CacheValidAndVisibility-1);
8451fb0caaa7bef765b85972274e3b434af2572c141John McCall    }
8461fb0caaa7bef765b85972274e3b434af2572c141John McCall    Linkage getLinkage() const {
8471fb0caaa7bef765b85972274e3b434af2572c141John McCall      assert(isCacheValid() && "getting linkage from invalid cache");
8481fb0caaa7bef765b85972274e3b434af2572c141John McCall      return static_cast<Linkage>(CachedLinkage);
8491fb0caaa7bef765b85972274e3b434af2572c141John McCall    }
8501fb0caaa7bef765b85972274e3b434af2572c141John McCall    bool hasLocalOrUnnamedType() const {
8511fb0caaa7bef765b85972274e3b434af2572c141John McCall      assert(isCacheValid() && "getting linkage from invalid cache");
8521fb0caaa7bef765b85972274e3b434af2572c141John McCall      return CachedLocalOrUnnamed;
8531fb0caaa7bef765b85972274e3b434af2572c141John McCall    }
854b870b88df784c2940efce448ebfaf54dece14666John McCall  };
855b870b88df784c2940efce448ebfaf54dece14666John McCall  enum { NumTypeBits = 16 };
856b870b88df784c2940efce448ebfaf54dece14666John McCall
857b870b88df784c2940efce448ebfaf54dece14666John McCallprotected:
858b870b88df784c2940efce448ebfaf54dece14666John McCall  // These classes allow subclasses to somewhat cleanly pack bitfields
859b870b88df784c2940efce448ebfaf54dece14666John McCall  // into Type.
860b870b88df784c2940efce448ebfaf54dece14666John McCall
861b870b88df784c2940efce448ebfaf54dece14666John McCall  class ArrayTypeBitfields {
862b870b88df784c2940efce448ebfaf54dece14666John McCall    friend class ArrayType;
863b870b88df784c2940efce448ebfaf54dece14666John McCall
864b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned : NumTypeBits;
865b870b88df784c2940efce448ebfaf54dece14666John McCall
866b870b88df784c2940efce448ebfaf54dece14666John McCall    /// IndexTypeQuals - CVR qualifiers from declarations like
867b870b88df784c2940efce448ebfaf54dece14666John McCall    /// 'int X[static restrict 4]'. For function parameters only.
868b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned IndexTypeQuals : 3;
869b870b88df784c2940efce448ebfaf54dece14666John McCall
870b870b88df784c2940efce448ebfaf54dece14666John McCall    /// SizeModifier - storage class qualifiers from declarations like
871b870b88df784c2940efce448ebfaf54dece14666John McCall    /// 'int X[static restrict 4]'. For function parameters only.
872b870b88df784c2940efce448ebfaf54dece14666John McCall    /// Actually an ArrayType::ArraySizeModifier.
873b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned SizeModifier : 3;
874b870b88df784c2940efce448ebfaf54dece14666John McCall  };
875b870b88df784c2940efce448ebfaf54dece14666John McCall
876b870b88df784c2940efce448ebfaf54dece14666John McCall  class BuiltinTypeBitfields {
877b870b88df784c2940efce448ebfaf54dece14666John McCall    friend class BuiltinType;
878b870b88df784c2940efce448ebfaf54dece14666John McCall
879b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned : NumTypeBits;
880b870b88df784c2940efce448ebfaf54dece14666John McCall
881b870b88df784c2940efce448ebfaf54dece14666John McCall    /// The kind (BuiltinType::Kind) of builtin type this is.
882b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned Kind : 8;
883b870b88df784c2940efce448ebfaf54dece14666John McCall  };
884b870b88df784c2940efce448ebfaf54dece14666John McCall
885b870b88df784c2940efce448ebfaf54dece14666John McCall  class FunctionTypeBitfields {
886b870b88df784c2940efce448ebfaf54dece14666John McCall    friend class FunctionType;
887b870b88df784c2940efce448ebfaf54dece14666John McCall
888b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned : NumTypeBits;
889b870b88df784c2940efce448ebfaf54dece14666John McCall
890b870b88df784c2940efce448ebfaf54dece14666John McCall    /// Extra information which affects how the function is called, like
891b870b88df784c2940efce448ebfaf54dece14666John McCall    /// regparm and the calling convention.
892b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned ExtInfo : 8;
893b870b88df784c2940efce448ebfaf54dece14666John McCall
894b870b88df784c2940efce448ebfaf54dece14666John McCall    /// A bit to be used by the subclass.
895bdb5b0e8ad8ed297ad01eb2ccd0d6d5ed6058033Francois Pichet    unsigned SubclassInfo : 1;
896b870b88df784c2940efce448ebfaf54dece14666John McCall
897b870b88df784c2940efce448ebfaf54dece14666John McCall    /// TypeQuals - Used only by FunctionProtoType, put here to pack with the
898b870b88df784c2940efce448ebfaf54dece14666John McCall    /// other bitfields.
899b870b88df784c2940efce448ebfaf54dece14666John McCall    /// The qualifiers are part of FunctionProtoType because...
900b870b88df784c2940efce448ebfaf54dece14666John McCall    ///
901b870b88df784c2940efce448ebfaf54dece14666John McCall    /// C++ 8.3.5p4: The return type, the parameter type list and the
902b870b88df784c2940efce448ebfaf54dece14666John McCall    /// cv-qualifier-seq, [...], are part of the function type.
903b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned TypeQuals : 3;
904b870b88df784c2940efce448ebfaf54dece14666John McCall  };
905b870b88df784c2940efce448ebfaf54dece14666John McCall
906b870b88df784c2940efce448ebfaf54dece14666John McCall  class ObjCObjectTypeBitfields {
907b870b88df784c2940efce448ebfaf54dece14666John McCall    friend class ObjCObjectType;
908b870b88df784c2940efce448ebfaf54dece14666John McCall
909b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned : NumTypeBits;
910b870b88df784c2940efce448ebfaf54dece14666John McCall
911b870b88df784c2940efce448ebfaf54dece14666John McCall    /// NumProtocols - The number of protocols stored directly on this
912b870b88df784c2940efce448ebfaf54dece14666John McCall    /// object type.
913b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned NumProtocols : 32 - NumTypeBits;
914b870b88df784c2940efce448ebfaf54dece14666John McCall  };
915b870b88df784c2940efce448ebfaf54dece14666John McCall
916b870b88df784c2940efce448ebfaf54dece14666John McCall  class ReferenceTypeBitfields {
917b870b88df784c2940efce448ebfaf54dece14666John McCall    friend class ReferenceType;
918b870b88df784c2940efce448ebfaf54dece14666John McCall
919b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned : NumTypeBits;
920b870b88df784c2940efce448ebfaf54dece14666John McCall
921b870b88df784c2940efce448ebfaf54dece14666John McCall    /// True if the type was originally spelled with an lvalue sigil.
922b870b88df784c2940efce448ebfaf54dece14666John McCall    /// This is never true of rvalue references but can also be false
923b870b88df784c2940efce448ebfaf54dece14666John McCall    /// on lvalue references because of C++0x [dcl.typedef]p9,
924b870b88df784c2940efce448ebfaf54dece14666John McCall    /// as follows:
925b870b88df784c2940efce448ebfaf54dece14666John McCall    ///
926b870b88df784c2940efce448ebfaf54dece14666John McCall    ///   typedef int &ref;    // lvalue, spelled lvalue
927b870b88df784c2940efce448ebfaf54dece14666John McCall    ///   typedef int &&rvref; // rvalue
928b870b88df784c2940efce448ebfaf54dece14666John McCall    ///   ref &a;              // lvalue, inner ref, spelled lvalue
929b870b88df784c2940efce448ebfaf54dece14666John McCall    ///   ref &&a;             // lvalue, inner ref
930b870b88df784c2940efce448ebfaf54dece14666John McCall    ///   rvref &a;            // lvalue, inner ref, spelled lvalue
931b870b88df784c2940efce448ebfaf54dece14666John McCall    ///   rvref &&a;           // rvalue, inner ref
932bdb5b0e8ad8ed297ad01eb2ccd0d6d5ed6058033Francois Pichet    unsigned SpelledAsLValue : 1;
933b870b88df784c2940efce448ebfaf54dece14666John McCall
934b870b88df784c2940efce448ebfaf54dece14666John McCall    /// True if the inner type is a reference type.  This only happens
935b870b88df784c2940efce448ebfaf54dece14666John McCall    /// in non-canonical forms.
936bdb5b0e8ad8ed297ad01eb2ccd0d6d5ed6058033Francois Pichet    unsigned InnerRef : 1;
937b870b88df784c2940efce448ebfaf54dece14666John McCall  };
938b870b88df784c2940efce448ebfaf54dece14666John McCall
93977be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall  class TypeWithKeywordBitfields {
94077be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall    friend class TypeWithKeyword;
94177be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall
94277be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall    unsigned : NumTypeBits;
94377be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall
94477be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall    /// An ElaboratedTypeKeyword.  8 bits for efficient access.
94577be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall    unsigned Keyword : 8;
94677be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall  };
94777be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall
948b870b88df784c2940efce448ebfaf54dece14666John McCall  class VectorTypeBitfields {
949b870b88df784c2940efce448ebfaf54dece14666John McCall    friend class VectorType;
95007a353c2af3a3c557205466d4f4ed2513462ebfeSebastian Redl
951b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned : NumTypeBits;
95271c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall
953e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson    /// VecKind - The kind of vector, either a generic vector type or some
954e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson    /// target-specific vector type such as for AltiVec or Neon.
955cc3b946c35c4372272034e6f0663089477a9a5bdBob Wilson    unsigned VecKind : 3;
956b870b88df784c2940efce448ebfaf54dece14666John McCall
957b870b88df784c2940efce448ebfaf54dece14666John McCall    /// NumElements - The number of elements in the vector.
958cc3b946c35c4372272034e6f0663089477a9a5bdBob Wilson    unsigned NumElements : 29 - NumTypeBits;
959b870b88df784c2940efce448ebfaf54dece14666John McCall  };
960b870b88df784c2940efce448ebfaf54dece14666John McCall
961b870b88df784c2940efce448ebfaf54dece14666John McCall  union {
962b870b88df784c2940efce448ebfaf54dece14666John McCall    TypeBitfields TypeBits;
963b870b88df784c2940efce448ebfaf54dece14666John McCall    ArrayTypeBitfields ArrayTypeBits;
964b870b88df784c2940efce448ebfaf54dece14666John McCall    BuiltinTypeBitfields BuiltinTypeBits;
965b870b88df784c2940efce448ebfaf54dece14666John McCall    FunctionTypeBitfields FunctionTypeBits;
966b870b88df784c2940efce448ebfaf54dece14666John McCall    ObjCObjectTypeBitfields ObjCObjectTypeBits;
967b870b88df784c2940efce448ebfaf54dece14666John McCall    ReferenceTypeBitfields ReferenceTypeBits;
96877be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall    TypeWithKeywordBitfields TypeWithKeywordBits;
969b870b88df784c2940efce448ebfaf54dece14666John McCall    VectorTypeBitfields VectorTypeBits;
970b870b88df784c2940efce448ebfaf54dece14666John McCall  };
971b870b88df784c2940efce448ebfaf54dece14666John McCall
972b870b88df784c2940efce448ebfaf54dece14666John McCallprivate:
9733c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief Set whether this type comes from an AST file.
9743c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  void setFromAST(bool V = true) const {
975b870b88df784c2940efce448ebfaf54dece14666John McCall    TypeBits.FromAST = V;
97607a353c2af3a3c557205466d4f4ed2513462ebfeSebastian Redl  }
97707a353c2af3a3c557205466d4f4ed2513462ebfeSebastian Redl
978b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall  template <class T> friend class TypePropertyCache;
9791fb0caaa7bef765b85972274e3b434af2572c141John McCall
9805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprotected:
981124dd7b5777e29ecac006822bd4d4623f0dc4264Hartmut Kaiser  // silence VC++ warning C4355: 'this' : used in base member initializer list
982124dd7b5777e29ecac006822bd4d4623f0dc4264Hartmut Kaiser  Type *this_() { return this; }
98335495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor  Type(TypeClass tc, QualType Canonical, bool Dependent, bool VariablyModified)
984b870b88df784c2940efce448ebfaf54dece14666John McCall    : CanonicalType(Canonical.isNull() ? QualType(this_(), 0) : Canonical) {
985b870b88df784c2940efce448ebfaf54dece14666John McCall    TypeBits.TC = tc;
986b870b88df784c2940efce448ebfaf54dece14666John McCall    TypeBits.Dependent = Dependent;
987b870b88df784c2940efce448ebfaf54dece14666John McCall    TypeBits.VariablyModified = VariablyModified;
9881fb0caaa7bef765b85972274e3b434af2572c141John McCall    TypeBits.CacheValidAndVisibility = 0;
989b870b88df784c2940efce448ebfaf54dece14666John McCall    TypeBits.CachedLocalOrUnnamed = false;
990b870b88df784c2940efce448ebfaf54dece14666John McCall    TypeBits.CachedLinkage = NoLinkage;
991b870b88df784c2940efce448ebfaf54dece14666John McCall    TypeBits.FromAST = false;
992b870b88df784c2940efce448ebfaf54dece14666John McCall  }
9935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;
9941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
995b870b88df784c2940efce448ebfaf54dece14666John McCall  void setDependent(bool D = true) { TypeBits.Dependent = D; }
996b870b88df784c2940efce448ebfaf54dece14666John McCall  void setVariablyModified(bool VM = true) { TypeBits.VariablyModified = VM; }
99735495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor
9988b9023ba35a86838789e2c9034a6128728c547aaChris Lattnerpublic:
999b870b88df784c2940efce448ebfaf54dece14666John McCall  TypeClass getTypeClass() const { return static_cast<TypeClass>(TypeBits.TC); }
10001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
10013c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief Whether this type comes from an AST file.
1002b870b88df784c2940efce448ebfaf54dece14666John McCall  bool isFromAST() const { return TypeBits.FromAST; }
100307a353c2af3a3c557205466d4f4ed2513462ebfeSebastian Redl
1004467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall  bool isCanonicalUnqualified() const {
1005467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall    return CanonicalType.getTypePtr() == this;
1006467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall  }
10075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
10081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// Types are partitioned into 3 broad categories (C99 6.2.5p1):
10095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// object types, function types, and incomplete types.
10101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
10115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isIncompleteType - Return true if this is an incomplete type.
10125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// A type that can describe objects, but which lacks information needed to
10135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// determine its size (e.g. void, or a fwd declared struct). Clients of this
10141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// routine will need to determine if the size is actually required.
10155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isIncompleteType() const;
1016d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner
1017d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner  /// isIncompleteOrObjectType - Return true if this is an incomplete or object
1018d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner  /// type, in other words, not a function type.
1019d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner  bool isIncompleteOrObjectType() const {
1020d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner    return !isFunctionType();
1021d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner  }
102264b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
102364b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  /// isPODType - Return true if this is a plain-old-data type (C++ 3.9p10).
102464b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  bool isPODType() const;
102564b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
1026ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl  /// isLiteralType - Return true if this is a literal type
1027ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl  /// (C++0x [basic.types]p10)
1028ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl  bool isLiteralType() const;
1029ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl
10305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// Helper methods to distinguish type categories. All type predicates
1031ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb  /// operate on the canonical type, ignoring typedefs and qualifiers.
1032e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar
10339b065ddabf572772991a4aadad5bf4921fac5069Tom Care  /// isBuiltinType - returns true if the type is a builtin type.
10349b065ddabf572772991a4aadad5bf4921fac5069Tom Care  bool isBuiltinType() const;
10359b065ddabf572772991a4aadad5bf4921fac5069Tom Care
1036e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar  /// isSpecificBuiltinType - Test for a particular builtin type.
1037e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar  bool isSpecificBuiltinType(unsigned K) const;
10381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
10392a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  /// isPlaceholderType - Test for a type which does not represent an
10402a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  /// actual type-system type but is instead used as a placeholder for
10412a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  /// various convenient purposes within Clang.  All such types are
10422a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  /// BuiltinTypes.
10432a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  bool isPlaceholderType() const;
10442a984cad5ac3fdceeff2bd99daa7b90979313475John McCall
104596d2c438f5c9ada8229f7f2ac049d2e9957bc954Steve Naroff  /// isIntegerType() does *not* include complex integers (a GCC extension).
104696d2c438f5c9ada8229f7f2ac049d2e9957bc954Steve Naroff  /// isComplexIntegerType() can be used to test for complex integers.
10475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isIntegerType() const;     // C99 6.2.5p17 (int, char, bool, enum)
104813b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff  bool isEnumeralType() const;
104913b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff  bool isBooleanType() const;
105013b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff  bool isCharType() const;
105177a52233f7c0f162672652051bfe78b65ad4f789Douglas Gregor  bool isWideCharType() const;
105220093b4bf698f292c664676987541d5103b65b15Douglas Gregor  bool isAnyCharacterType() const;
10539d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor  bool isIntegralType(ASTContext &Ctx) const;
105420093b4bf698f292c664676987541d5103b65b15Douglas Gregor
10552ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor  /// \brief Determine whether this type is an integral or enumeration type.
10562ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor  bool isIntegralOrEnumerationType() const;
10571274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor  /// \brief Determine whether this type is an integral or unscoped enumeration
10581274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor  /// type.
10591274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor  bool isIntegralOrUnscopedEnumerationType() const;
10602ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor
10615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// Floating point categories.
10625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isRealFloatingType() const; // C99 6.2.5p10 (float, double, long double)
106302f62a9fedbc370fba081303399410a3afdde29fSteve Naroff  /// isComplexType() does *not* include complex integers (a GCC extension).
106402f62a9fedbc370fba081303399410a3afdde29fSteve Naroff  /// isComplexIntegerType() can be used to test for complex integers.
10655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isComplexType() const;      // C99 6.2.5p11 (complex)
1066f23d364084d1aabea688222780d6fc1dd8c7f78cChris Lattner  bool isAnyComplexType() const;   // C99 6.2.5p11 (complex) + Complex Int.
10675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isFloatingType() const;     // C99 6.2.5p11 (real floating + complex)
10685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isRealType() const;         // C99 6.2.5p17 (real floating + integer)
10695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isArithmeticType() const;   // C99 6.2.5p18 (integer + floating)
1070c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  bool isVoidType() const;         // C99 6.2.5p19
1071c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  bool isDerivedType() const;      // C99 6.2.5p20
1072c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  bool isScalarType() const;       // C99 6.2.5p21 (arithmetic + pointers)
1073d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor  bool isAggregateType() const;
10741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1075c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  // Type Predicates: Check to see if this type is structurally the specified
1076ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb  // type, ignoring typedefs and qualifiers.
1077c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  bool isFunctionType() const;
1078183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  bool isFunctionNoProtoType() const { return getAs<FunctionNoProtoType>(); }
1079183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  bool isFunctionProtoType() const { return getAs<FunctionProtoType>(); }
1080befee48ff2a1dab236c5700f00ecca1cfdcd5837Chris Lattner  bool isPointerType() const;
108158f9f2c884af6b72d036b746a016d8031d31cb7aSteve Naroff  bool isAnyPointerType() const;   // Any C pointer or ObjC object pointer
10825618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  bool isBlockPointerType() const;
10837154a77e7c1f23418342d3b72836ab504aa7821eSteve Naroff  bool isVoidPointerType() const;
1084a1d9fdea79ba7bbd71862b9f9f78f5f117331fc7Chris Lattner  bool isReferenceType() const;
10857c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  bool isLValueReferenceType() const;
10867c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  bool isRValueReferenceType() const;
1087bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner  bool isFunctionPointerType() const;
1088f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  bool isMemberPointerType() const;
1089f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  bool isMemberFunctionPointerType() const;
1090db68e28c05a67735211e688009890cf834c22e75Douglas Gregor  bool isMemberDataPointerType() const;
1091c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  bool isArrayType() const;
1092c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  bool isConstantArrayType() const;
1093c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  bool isIncompleteArrayType() const;
1094c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  bool isVariableArrayType() const;
1095898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  bool isDependentSizedArrayType() const;
1096c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  bool isRecordType() const;
10971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  bool isClassType() const;
10981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  bool isStructureType() const;
1099fb87b89fc9eb103e19fb8e4b925c23f0bd091b99Douglas Gregor  bool isStructureOrClassType() const;
11004cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroff  bool isUnionType() const;
1101368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner  bool isComplexIntegerType() const;            // GCC _Complex integer type.
1102368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner  bool isVectorType() const;                    // GCC vector type.
1103213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman  bool isExtVectorType() const;                 // Extended vector type.
1104d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff  bool isObjCObjectPointerType() const;         // Pointer to *any* ObjC object.
110514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  // FIXME: change this to 'raw' interface type, so we can used 'interface' type
110614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  // for the common case.
1107c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool isObjCObjectType() const;                // NSString or typeof(*(id)0)
1108368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner  bool isObjCQualifiedInterfaceType() const;    // NSString<foo>
1109368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner  bool isObjCQualifiedIdType() const;           // id<foo>
1110470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroff  bool isObjCQualifiedClassType() const;        // Class<foo>
1111569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor  bool isObjCObjectOrInterfaceType() const;
111214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  bool isObjCIdType() const;                    // id
111314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  bool isObjCClassType() const;                 // Class
111413dcd00615de5c4279d97bdf63cd5f0a14fd9dccFariborz Jahanian  bool isObjCSelType() const;                 // Class
1115de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff  bool isObjCBuiltinType() const;               // 'id' or 'Class'
111672c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor  bool isTemplateTypeParmType() const;          // C++ template type parameter
11176e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl  bool isNullPtrType() const;                   // C++0x nullptr_t
1118898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
1119daa8e4e888758d55a7a759dd4a91b83921cef222John McCall  enum ScalarTypeKind {
1120daa8e4e888758d55a7a759dd4a91b83921cef222John McCall    STK_Pointer,
1121daa8e4e888758d55a7a759dd4a91b83921cef222John McCall    STK_MemberPointer,
1122daa8e4e888758d55a7a759dd4a91b83921cef222John McCall    STK_Bool,
1123daa8e4e888758d55a7a759dd4a91b83921cef222John McCall    STK_Integral,
1124daa8e4e888758d55a7a759dd4a91b83921cef222John McCall    STK_Floating,
1125daa8e4e888758d55a7a759dd4a91b83921cef222John McCall    STK_IntegralComplex,
1126daa8e4e888758d55a7a759dd4a91b83921cef222John McCall    STK_FloatingComplex
1127daa8e4e888758d55a7a759dd4a91b83921cef222John McCall  };
1128daa8e4e888758d55a7a759dd4a91b83921cef222John McCall  /// getScalarTypeKind - Given that this is a scalar type, classify it.
1129daa8e4e888758d55a7a759dd4a91b83921cef222John McCall  ScalarTypeKind getScalarTypeKind() const;
1130daa8e4e888758d55a7a759dd4a91b83921cef222John McCall
1131898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// isDependentType - Whether this type is a dependent type, meaning
11321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// that its definition somehow depends on a template parameter
1133898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// (C++ [temp.dep.type]).
1134b870b88df784c2940efce448ebfaf54dece14666John McCall  bool isDependentType() const { return TypeBits.Dependent; }
113535495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor
113635495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor  /// \brief Whether this type is a variably-modified type (C99 6.7.5).
1137b870b88df784c2940efce448ebfaf54dece14666John McCall  bool isVariablyModifiedType() const { return TypeBits.VariablyModified; }
113835495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor
1139db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor  /// \brief Whether this type is or contains a local or unnamed type.
1140db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor  bool hasUnnamedOrLocalType() const;
1141db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor
1142063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  bool isOverloadableType() const;
114372c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor
11444033642464e8ba0982f88f34cffad808d247b393Douglas Gregor  /// \brief Determine wither this type is a C++ elaborated-type-specifier.
11454033642464e8ba0982f88f34cffad808d247b393Douglas Gregor  bool isElaboratedTypeSpecifier() const;
11464033642464e8ba0982f88f34cffad808d247b393Douglas Gregor
11478958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar  /// hasPointerRepresentation - Whether this type is represented
11488958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar  /// natively as a pointer; this includes pointers, references, block
11498958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar  /// pointers, and Objective-C interface, qualified id, and qualified
11506e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl  /// interface types, as well as nullptr_t.
11518958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar  bool hasPointerRepresentation() const;
11528958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar
1153820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian  /// hasObjCPointerRepresentation - Whether this type can represent
1154820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian  /// an objective pointer type for the purpose of GC'ability
11551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  bool hasObjCPointerRepresentation() const;
1156820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian
1157f60946222721d9ba3c059563935c17b84703187aDouglas Gregor  /// \brief Determine whether this type has an integer representation
1158f60946222721d9ba3c059563935c17b84703187aDouglas Gregor  /// of some sort, e.g., it is an integer type or a vector.
1159f60946222721d9ba3c059563935c17b84703187aDouglas Gregor  bool hasIntegerRepresentation() const;
1160f60946222721d9ba3c059563935c17b84703187aDouglas Gregor
1161f60946222721d9ba3c059563935c17b84703187aDouglas Gregor  /// \brief Determine whether this type has an signed integer representation
1162f60946222721d9ba3c059563935c17b84703187aDouglas Gregor  /// of some sort, e.g., it is an signed integer type or a vector.
1163f60946222721d9ba3c059563935c17b84703187aDouglas Gregor  bool hasSignedIntegerRepresentation() const;
1164f60946222721d9ba3c059563935c17b84703187aDouglas Gregor
1165f60946222721d9ba3c059563935c17b84703187aDouglas Gregor  /// \brief Determine whether this type has an unsigned integer representation
1166f60946222721d9ba3c059563935c17b84703187aDouglas Gregor  /// of some sort, e.g., it is an unsigned integer type or a vector.
1167f60946222721d9ba3c059563935c17b84703187aDouglas Gregor  bool hasUnsignedIntegerRepresentation() const;
1168f60946222721d9ba3c059563935c17b84703187aDouglas Gregor
11698eee119bf4f1693dde17b8552c1f9f81bf2b681eDouglas Gregor  /// \brief Determine whether this type has a floating-point representation
11708eee119bf4f1693dde17b8552c1f9f81bf2b681eDouglas Gregor  /// of some sort, e.g., it is a floating-point type or a vector thereof.
11718eee119bf4f1693dde17b8552c1f9f81bf2b681eDouglas Gregor  bool hasFloatingRepresentation() const;
1172f60946222721d9ba3c059563935c17b84703187aDouglas Gregor
1173c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  // Type Checking Functions: Check to see if this type is structurally the
1174f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner  // specified type, ignoring typedefs and qualifiers, and return a pointer to
1175f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner  // the best type we can.
1176769c9cfc6e06bd9d8ffe7a4397b939f19b0e4dc3Ted Kremenek  const RecordType *getAsStructureType() const;
1177898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// NOTE: getAs*ArrayType are methods on ASTContext.
1178c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  const RecordType *getAsUnionType() const;
11794cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroff  const ComplexType *getAsComplexIntegerType() const; // GCC complex int type.
118014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  // The following is a convenience method that returns an ObjCObjectPointerType
118114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  // for object declared using an interface.
118214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  const ObjCObjectPointerType *getAsObjCInterfacePointerType() const;
118314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  const ObjCObjectPointerType *getAsObjCQualifiedIdType() const;
1184c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  const ObjCObjectType *getAsObjCQualifiedInterfaceType() const;
1185a91d6a6619a91d0ca7102d8ab5678d855f04d850Fariborz Jahanian  const CXXRecordDecl *getCXXRecordDeclForPointerType() const;
11861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1187c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor  /// \brief Retrieves the CXXRecordDecl that this type refers to, either
1188c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor  /// because the type is a RecordType or because it is the injected-class-name
1189c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor  /// type of a class template or class template partial specialization.
1190c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor  CXXRecordDecl *getAsCXXRecordDecl() const;
1191c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor
1192fa78c91c54dd99ec61a9e27e6b74a549f5c9fa9cDan Gohman  // Member-template getAs<specific type>'.  Look through sugar for
1193fa78c91c54dd99ec61a9e27e6b74a549f5c9fa9cDan Gohman  // an instance of <specific type>.   This scheme will eventually
11941a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek  // replace the specific getAsXXXX methods above.
1195183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  //
1196183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  // There are some specializations of this member template listed
1197183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  // immediately following this class.
11981a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek  template <typename T> const T *getAs() const;
11991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1200c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  /// getArrayElementTypeNoTypeQual - If this is an array type, return the
1201c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  /// element type of the array, potentially with type qualifiers missing.
1202c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  /// This method should never be used when type qualifiers are meaningful.
1203c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  const Type *getArrayElementTypeNoTypeQual() const;
12041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1205f8910df57799256c1897a8610dc52685729ae90eSteve Naroff  /// getPointeeType - If this is a pointer, ObjC object pointer, or block
1206f8910df57799256c1897a8610dc52685729ae90eSteve Naroff  /// pointer, this returns the respective pointee.
120714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  QualType getPointeeType() const;
12081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1209bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// getUnqualifiedDesugaredType() - Return the specified type with
1210bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// any "sugar" removed from the type, removing any typedefs,
1211bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// typeofs, etc., as well as any qualifiers.
1212bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  const Type *getUnqualifiedDesugaredType() const;
12131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// More type predicates useful for type checking/promotion
12155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isPromotableIntegerType() const; // C99 6.3.1.1p2
12165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
12175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isSignedIntegerType - Return true if this is an integer type that is
1218d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner  /// signed, according to C99 6.2.5p4 [char, signed char, short, int, long..],
1219d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner  /// an enum decl which has a signed representation, or a vector of signed
1220d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner  /// integer element type.
12215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isSignedIntegerType() const;
12225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
12235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isUnsignedIntegerType - Return true if this is an integer type that is
1224d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner  /// unsigned, according to C99 6.2.5p6 [which returns true for _Bool], an enum
1225d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner  /// decl which has an unsigned representation, or a vector of unsigned integer
1226d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner  /// element type.
12275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isUnsignedIntegerType() const;
1228d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner
12295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isConstantSizeType - Return true if this is not a variable sized type,
12309bfa73c5ab7bf4b0e749d04f29da6884e8d5bd9fChris Lattner  /// according to the rules of C99 6.7.5p3.  It is not legal to call this on
12319bfa73c5ab7bf4b0e749d04f29da6884e8d5bd9fChris Lattner  /// incomplete types.
12323c2b3170041f69a92904e3bab9b6d654eaf260acEli Friedman  bool isConstantSizeType() const;
1233c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner
123422b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman  /// isSpecifierType - Returns true if this type can be represented by some
123522b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman  /// set of type specifiers.
123622b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman  bool isSpecifierType() const;
123722b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman
12380b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor  /// \brief Determine the linkage of this type.
123960e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor  Linkage getLinkage() const;
12401fb0caaa7bef765b85972274e3b434af2572c141John McCall
12411fb0caaa7bef765b85972274e3b434af2572c141John McCall  /// \brief Determine the visibility of this type.
12421fb0caaa7bef765b85972274e3b434af2572c141John McCall  Visibility getVisibility() const;
12431fb0caaa7bef765b85972274e3b434af2572c141John McCall
12441fb0caaa7bef765b85972274e3b434af2572c141John McCall  /// \brief Determine the linkage and visibility of this type.
12451fb0caaa7bef765b85972274e3b434af2572c141John McCall  std::pair<Linkage,Visibility> getLinkageAndVisibility() const;
124660e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
124760e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor  /// \brief Note that the linkage is no longer known.
124860e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor  void ClearLinkageCache();
124960e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
125060e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor  const char *getTypeClassName() const;
12510b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor
1252ead608af31b6c9abeae1ca6d0b75094dac4641c0John McCall  QualType getCanonicalTypeInternal() const {
1253ead608af31b6c9abeae1ca6d0b75094dac4641c0John McCall    return CanonicalType;
1254ead608af31b6c9abeae1ca6d0b75094dac4641c0John McCall  }
1255ead608af31b6c9abeae1ca6d0b75094dac4641c0John McCall  CanQualType getCanonicalTypeUnqualified() const; // in CanonicalType.h
1256c36d405a02fab41f6c45cb2bc750d64949742903Chris Lattner  void dump() const;
12575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *) { return true; }
1258be191100e034b23a3e13053757a57b7f5068c24aArgyrios Kyrtzidis
1259c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl  friend class ASTReader;
1260a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian Redl  friend class ASTWriter;
12615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
12625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1263183700f494ec9b6701b6efe82bcb25f4c79ba561John McCalltemplate <> inline const TypedefType *Type::getAs() const {
1264183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  return dyn_cast<TypedefType>(this);
1265183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall}
1266183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall
1267183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall// We can do canonical leaf types faster, because we don't have to
1268183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall// worry about preserving child type decoration.
1269183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall#define TYPE(Class, Base)
1270183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall#define LEAF_TYPE(Class) \
1271183700f494ec9b6701b6efe82bcb25f4c79ba561John McCalltemplate <> inline const Class##Type *Type::getAs() const { \
12720953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  return dyn_cast<Class##Type>(CanonicalType); \
1273183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall}
1274183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall#include "clang/AST/TypeNodes.def"
1275183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall
1276183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall
12775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// BuiltinType - This class is used for builtin types like 'int'.  Builtin
12785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// types are always canonical and have a literal name field.
12795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass BuiltinType : public Type {
12805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
12815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  enum Kind {
12825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Void,
12831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Bool,     // This is bool and/or _Bool.
12855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Char_U,   // This is 'char' for targets where char is unsigned.
12865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    UChar,    // This is explicitly qualified unsigned char.
1287f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith    Char16,   // This is 'char16_t' for C++.
1288f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith    Char32,   // This is 'char32_t' for C++.
12895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    UShort,
12905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    UInt,
12915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ULong,
12925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ULongLong,
12932df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner    UInt128,  // __uint128_t
12941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Char_S,   // This is 'char' for targets where char is signed.
12965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    SChar,    // This is explicitly qualified signed char.
12972ff9b4c7c8fed9233a0b8de2e9507368c451aab6Argyrios Kyrtzidis    WChar,    // This is 'wchar_t' for C++.
12985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Short,
12995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Int,
13005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Long,
13015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    LongLong,
13022df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner    Int128,   // __int128_t
13031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
13048e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor    Float, Double, LongDouble,
13058e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor
13066e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl    NullPtr,  // This is the type of C++0x 'nullptr'.
13076e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl
13082a984cad5ac3fdceeff2bd99daa7b90979313475John McCall    /// This represents the type of an expression whose type is
13092a984cad5ac3fdceeff2bd99daa7b90979313475John McCall    /// totally unknown, e.g. 'T::foo'.  It is permitted for this to
13102a984cad5ac3fdceeff2bd99daa7b90979313475John McCall    /// appear in situations where the structure of the type is
13112a984cad5ac3fdceeff2bd99daa7b90979313475John McCall    /// theoretically deducible.
13122a984cad5ac3fdceeff2bd99daa7b90979313475John McCall    Dependent,
13132a984cad5ac3fdceeff2bd99daa7b90979313475John McCall
1314898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    Overload,  // This represents the type of an overloaded function declaration.
13151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1316de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff    UndeducedAuto, // In C++0x, this represents the type of an auto variable
1317e89d15944dd3be750a09805ad21222d2fa9321faAnders Carlsson                   // that has not been deduced yet.
1318e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall
1319e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall    /// The primitive Objective C 'id' type.  The type pointed to by the
1320e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall    /// user-visible 'id' type.  Only ever shows up in an AST as the base
1321e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall    /// type of an ObjCObjectType.
1322e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall    ObjCId,
1323e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall
1324e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall    /// The primitive Objective C 'Class' type.  The type pointed to by the
1325e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall    /// user-visible 'Class' type.  Only ever shows up in an AST as the
1326e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall    /// base type of an ObjCObjectType.
1327e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall    ObjCClass,
1328e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall
132913dcd00615de5c4279d97bdf63cd5f0a14fd9dccFariborz Jahanian    ObjCSel    // This represents the ObjC 'SEL' type.
13305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
133171c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall
13325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
13331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  BuiltinType(Kind K)
133435495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    : Type(Builtin, QualType(), /*Dependent=*/(K == Dependent),
133571c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall           /*VariablyModified=*/false) {
1336b870b88df784c2940efce448ebfaf54dece14666John McCall    BuiltinTypeBits.Kind = K;
133771c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  }
13381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1339b870b88df784c2940efce448ebfaf54dece14666John McCall  Kind getKind() const { return static_cast<Kind>(BuiltinTypeBits.Kind); }
1340e4f2142d00fa5fdb580c4e2413da91882d955381Chris Lattner  const char *getName(const LangOptions &LO) const;
13411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1342bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1343bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1344bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
1345680523a91dd3351389667c8de17121ba7ae82673John McCall  bool isInteger() const {
134671c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    return getKind() >= Bool && getKind() <= Int128;
1347680523a91dd3351389667c8de17121ba7ae82673John McCall  }
1348680523a91dd3351389667c8de17121ba7ae82673John McCall
1349680523a91dd3351389667c8de17121ba7ae82673John McCall  bool isSignedInteger() const {
135071c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    return getKind() >= Char_S && getKind() <= Int128;
1351680523a91dd3351389667c8de17121ba7ae82673John McCall  }
1352680523a91dd3351389667c8de17121ba7ae82673John McCall
1353680523a91dd3351389667c8de17121ba7ae82673John McCall  bool isUnsignedInteger() const {
135471c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    return getKind() >= Bool && getKind() <= UInt128;
1355680523a91dd3351389667c8de17121ba7ae82673John McCall  }
1356680523a91dd3351389667c8de17121ba7ae82673John McCall
1357680523a91dd3351389667c8de17121ba7ae82673John McCall  bool isFloatingPoint() const {
135871c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    return getKind() >= Float && getKind() <= LongDouble;
1359680523a91dd3351389667c8de17121ba7ae82673John McCall  }
1360680523a91dd3351389667c8de17121ba7ae82673John McCall
13612a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  /// Determines whether this type is a "forbidden" placeholder type,
13622a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  /// i.e. a type which cannot appear in arbitrary positions in a
13632a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  /// fully-formed expression.
13642a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  bool isPlaceholderType() const {
136571c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    return getKind() == Overload ||
136671c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall           getKind() == UndeducedAuto;
13672a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  }
13682a984cad5ac3fdceeff2bd99daa7b90979313475John McCall
13695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T) { return T->getTypeClass() == Builtin; }
13705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const BuiltinType *) { return true; }
13715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
13725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
13735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ComplexType - C99 6.2.5p11 - Complex values.  This supports the C99 complex
13745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// types (_Complex float etc) as well as the GCC integer complex extensions.
13755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
13765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ComplexType : public Type, public llvm::FoldingSetNode {
13775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType ElementType;
13785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ComplexType(QualType Element, QualType CanonicalPtr) :
137935495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    Type(Complex, CanonicalPtr, Element->isDependentType(),
138035495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor         Element->isVariablyModifiedType()),
1381898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    ElementType(Element) {
13825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
13835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
138460e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
13855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
13865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType getElementType() const { return ElementType; }
13871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1388bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1389bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1390bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
13915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void Profile(llvm::FoldingSetNodeID &ID) {
13925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Profile(ID, getElementType());
13935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
13945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static void Profile(llvm::FoldingSetNodeID &ID, QualType Element) {
13955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ID.AddPointer(Element.getAsOpaquePtr());
13965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
13971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
13985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T) { return T->getTypeClass() == Complex; }
13995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const ComplexType *) { return true; }
14005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
14015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1402075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara/// ParenType - Sugar for parentheses used when specifying types.
1403075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara///
1404075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnaraclass ParenType : public Type, public llvm::FoldingSetNode {
1405075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  QualType Inner;
1406075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
1407075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  ParenType(QualType InnerType, QualType CanonType) :
1408075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara    Type(Paren, CanonType, InnerType->isDependentType(),
1409075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara         InnerType->isVariablyModifiedType()),
1410075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara    Inner(InnerType) {
1411075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  }
1412075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  friend class ASTContext;  // ASTContext creates these.
1413075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
1414075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnarapublic:
1415075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
1416075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  QualType getInnerType() const { return Inner; }
1417075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
1418075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  bool isSugared() const { return true; }
1419075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  QualType desugar() const { return getInnerType(); }
1420075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
1421075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  void Profile(llvm::FoldingSetNodeID &ID) {
1422075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara    Profile(ID, getInnerType());
1423075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  }
1424075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  static void Profile(llvm::FoldingSetNodeID &ID, QualType Inner) {
1425075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara    Inner.Profile(ID);
1426075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  }
1427075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
1428075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  static bool classof(const Type *T) { return T->getTypeClass() == Paren; }
1429075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  static bool classof(const ParenType *) { return true; }
1430075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara};
1431075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
143268694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar/// PointerType - C99 6.7.5.1 - Pointer Declarators.
1433bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner///
143468694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbarclass PointerType : public Type, public llvm::FoldingSetNode {
1435bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner  QualType PointeeType;
14365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
14375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  PointerType(QualType Pointee, QualType CanonicalPtr) :
143835495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    Type(Pointer, CanonicalPtr, Pointee->isDependentType(),
143935495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor         Pointee->isVariablyModifiedType()),
144035495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    PointeeType(Pointee) {
14415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
14425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
144360e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
14445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
14451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
144668694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar  QualType getPointeeType() const { return PointeeType; }
144768694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar
1448bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1449bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1450bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
14515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void Profile(llvm::FoldingSetNodeID &ID) {
14525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Profile(ID, getPointeeType());
14535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
14545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) {
14555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ID.AddPointer(Pointee.getAsOpaquePtr());
14565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
14571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
14585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T) { return T->getTypeClass() == Pointer; }
14595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const PointerType *) { return true; }
14605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
14615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
14625618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff/// BlockPointerType - pointer to a block type.
14635618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff/// This type is to represent types syntactically represented as
14645618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff/// "void (^)(int)", etc. Pointee is required to always be a function type.
14655618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff///
14665618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroffclass BlockPointerType : public Type, public llvm::FoldingSetNode {
14675618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  QualType PointeeType;  // Block is some kind of pointer type
14685618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  BlockPointerType(QualType Pointee, QualType CanonicalCls) :
146935495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    Type(BlockPointer, CanonicalCls, Pointee->isDependentType(),
147035495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor         Pointee->isVariablyModifiedType()),
1471898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    PointeeType(Pointee) {
14725618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  }
14735618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  friend class ASTContext;  // ASTContext creates these.
147460e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
14755618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroffpublic:
14761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
14775618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  // Get the pointee type. Pointee is required to always be a function type.
14785618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  QualType getPointeeType() const { return PointeeType; }
14795618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff
1480bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1481bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1482bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
14835618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  void Profile(llvm::FoldingSetNodeID &ID) {
14845618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff      Profile(ID, getPointeeType());
14855618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  }
14865618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) {
14875618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff      ID.AddPointer(Pointee.getAsOpaquePtr());
14885618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  }
14891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
14901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
14911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == BlockPointer;
14925618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  }
14935618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  static bool classof(const BlockPointerType *) { return true; }
14945618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff};
14955618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff
14967c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// ReferenceType - Base for LValueReferenceType and RValueReferenceType
14975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
149868694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbarclass ReferenceType : public Type, public llvm::FoldingSetNode {
149968694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar  QualType PointeeType;
150068694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar
15017c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlprotected:
150254e14c4db764c0636160d26c5bbf491637c83a76John McCall  ReferenceType(TypeClass tc, QualType Referencee, QualType CanonicalRef,
150354e14c4db764c0636160d26c5bbf491637c83a76John McCall                bool SpelledAsLValue) :
150435495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    Type(tc, CanonicalRef, Referencee->isDependentType(),
150571c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall         Referencee->isVariablyModifiedType()), PointeeType(Referencee) {
1506b870b88df784c2940efce448ebfaf54dece14666John McCall    ReferenceTypeBits.SpelledAsLValue = SpelledAsLValue;
1507b870b88df784c2940efce448ebfaf54dece14666John McCall    ReferenceTypeBits.InnerRef = Referencee->isReferenceType();
15085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
150960e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
15105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
1511b870b88df784c2940efce448ebfaf54dece14666John McCall  bool isSpelledAsLValue() const { return ReferenceTypeBits.SpelledAsLValue; }
1512b870b88df784c2940efce448ebfaf54dece14666John McCall  bool isInnerRef() const { return ReferenceTypeBits.InnerRef; }
151373dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor
151454e14c4db764c0636160d26c5bbf491637c83a76John McCall  QualType getPointeeTypeAsWritten() const { return PointeeType; }
151554e14c4db764c0636160d26c5bbf491637c83a76John McCall  QualType getPointeeType() const {
151654e14c4db764c0636160d26c5bbf491637c83a76John McCall    // FIXME: this might strip inner qualifiers; okay?
151754e14c4db764c0636160d26c5bbf491637c83a76John McCall    const ReferenceType *T = this;
151871c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    while (T->isInnerRef())
151954e14c4db764c0636160d26c5bbf491637c83a76John McCall      T = T->PointeeType->getAs<ReferenceType>();
152054e14c4db764c0636160d26c5bbf491637c83a76John McCall    return T->PointeeType;
152154e14c4db764c0636160d26c5bbf491637c83a76John McCall  }
152268694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar
15235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void Profile(llvm::FoldingSetNodeID &ID) {
152471c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    Profile(ID, PointeeType, isSpelledAsLValue());
15255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
152654e14c4db764c0636160d26c5bbf491637c83a76John McCall  static void Profile(llvm::FoldingSetNodeID &ID,
152754e14c4db764c0636160d26c5bbf491637c83a76John McCall                      QualType Referencee,
152854e14c4db764c0636160d26c5bbf491637c83a76John McCall                      bool SpelledAsLValue) {
15295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ID.AddPointer(Referencee.getAsOpaquePtr());
153054e14c4db764c0636160d26c5bbf491637c83a76John McCall    ID.AddBoolean(SpelledAsLValue);
15315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
15325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
15337c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  static bool classof(const Type *T) {
15347c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl    return T->getTypeClass() == LValueReference ||
15357c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl           T->getTypeClass() == RValueReference;
15367c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  }
15375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const ReferenceType *) { return true; }
15387c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl};
15397c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl
15407c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// LValueReferenceType - C++ [dcl.ref] - Lvalue reference
15417c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl///
15427c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlclass LValueReferenceType : public ReferenceType {
154354e14c4db764c0636160d26c5bbf491637c83a76John McCall  LValueReferenceType(QualType Referencee, QualType CanonicalRef,
154454e14c4db764c0636160d26c5bbf491637c83a76John McCall                      bool SpelledAsLValue) :
154554e14c4db764c0636160d26c5bbf491637c83a76John McCall    ReferenceType(LValueReference, Referencee, CanonicalRef, SpelledAsLValue)
154654e14c4db764c0636160d26c5bbf491637c83a76John McCall  {}
15477c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  friend class ASTContext; // ASTContext creates these
15487c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlpublic:
1549bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1550bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1551bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
15527c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  static bool classof(const Type *T) {
15537c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl    return T->getTypeClass() == LValueReference;
15547c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  }
15557c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  static bool classof(const LValueReferenceType *) { return true; }
15567c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl};
15577c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl
15587c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// RValueReferenceType - C++0x [dcl.ref] - Rvalue reference
15597c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl///
15607c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlclass RValueReferenceType : public ReferenceType {
15617c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  RValueReferenceType(QualType Referencee, QualType CanonicalRef) :
156254e14c4db764c0636160d26c5bbf491637c83a76John McCall    ReferenceType(RValueReference, Referencee, CanonicalRef, false) {
15637c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  }
15647c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  friend class ASTContext; // ASTContext creates these
15657c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlpublic:
1566bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1567bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1568bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
15697c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  static bool classof(const Type *T) {
15707c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl    return T->getTypeClass() == RValueReference;
15717c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  }
15727c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  static bool classof(const RValueReferenceType *) { return true; }
1573f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl};
1574f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl
1575f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl/// MemberPointerType - C++ 8.3.3 - Pointers to members
1576f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl///
1577f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlclass MemberPointerType : public Type, public llvm::FoldingSetNode {
1578f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  QualType PointeeType;
1579f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  /// The class of which the pointee is a member. Must ultimately be a
1580f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  /// RecordType, but could be a typedef or a template parameter too.
1581f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  const Type *Class;
1582f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl
1583f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  MemberPointerType(QualType Pointee, const Type *Cls, QualType CanonicalPtr) :
1584f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    Type(MemberPointer, CanonicalPtr,
158535495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor         Cls->isDependentType() || Pointee->isDependentType(),
158635495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor         Pointee->isVariablyModifiedType()),
1587f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    PointeeType(Pointee), Class(Cls) {
1588f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  }
1589f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  friend class ASTContext; // ASTContext creates these.
159060e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
1591f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlpublic:
1592f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  QualType getPointeeType() const { return PointeeType; }
1593f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl
15940bab0cdab751248ca389a5592bcb70eac5d39260John McCall  /// Returns true if the member type (i.e. the pointee type) is a
15950bab0cdab751248ca389a5592bcb70eac5d39260John McCall  /// function type rather than a data-member type.
15960bab0cdab751248ca389a5592bcb70eac5d39260John McCall  bool isMemberFunctionPointer() const {
15970bab0cdab751248ca389a5592bcb70eac5d39260John McCall    return PointeeType->isFunctionProtoType();
15980bab0cdab751248ca389a5592bcb70eac5d39260John McCall  }
15990bab0cdab751248ca389a5592bcb70eac5d39260John McCall
16000bab0cdab751248ca389a5592bcb70eac5d39260John McCall  /// Returns true if the member type (i.e. the pointee type) is a
16010bab0cdab751248ca389a5592bcb70eac5d39260John McCall  /// data type rather than a function type.
16020bab0cdab751248ca389a5592bcb70eac5d39260John McCall  bool isMemberDataPointer() const {
16030bab0cdab751248ca389a5592bcb70eac5d39260John McCall    return !PointeeType->isFunctionProtoType();
16040bab0cdab751248ca389a5592bcb70eac5d39260John McCall  }
16050bab0cdab751248ca389a5592bcb70eac5d39260John McCall
1606f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  const Type *getClass() const { return Class; }
1607f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl
1608bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1609bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1610bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
1611f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  void Profile(llvm::FoldingSetNodeID &ID) {
1612f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    Profile(ID, getPointeeType(), getClass());
1613f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  }
1614f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee,
1615f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl                      const Type *Class) {
1616f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    ID.AddPointer(Pointee.getAsOpaquePtr());
1617f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    ID.AddPointer(Class);
1618f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  }
1619f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl
1620f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  static bool classof(const Type *T) {
1621f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    return T->getTypeClass() == MemberPointer;
1622f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  }
1623f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  static bool classof(const MemberPointerType *) { return true; }
16245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
16255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
16265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ArrayType - C99 6.7.5.2 - Array Declarators.
16275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
16282e7d352dbec06755105237afba183492d31d03cbTed Kremenekclass ArrayType : public Type, public llvm::FoldingSetNode {
16295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
16305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// ArraySizeModifier - Capture whether this is a normal array (e.g. int X[4])
1631898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// an array with a static size (e.g. int X[static 4]), or an array
1632898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// with a star size (e.g. int X[*]).
1633898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// 'static' is only allowed on function parameters.
16345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  enum ArraySizeModifier {
16355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Normal, Static, Star
16365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
16375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate:
1638fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  /// ElementType - The element type of the array.
1639fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  QualType ElementType;
16401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1641fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroffprotected:
1642898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  // C++ [temp.dep.type]p1:
1643898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  //   A type is dependent if it is...
1644898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  //     - an array type constructed from any dependent type or whose
1645898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  //       size is specified by a constant expression that is
1646898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  //       value-dependent,
1647c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff  ArrayType(TypeClass tc, QualType et, QualType can,
1648c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff            ArraySizeModifier sm, unsigned tq)
164935495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    : Type(tc, can, et->isDependentType() || tc == DependentSizedArray,
165035495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor           (tc == VariableArray || et->isVariablyModifiedType())),
165171c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall      ElementType(et) {
1652b870b88df784c2940efce448ebfaf54dece14666John McCall    ArrayTypeBits.IndexTypeQuals = tq;
1653b870b88df784c2940efce448ebfaf54dece14666John McCall    ArrayTypeBits.SizeModifier = sm;
165471c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  }
1655898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
1656fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  friend class ASTContext;  // ASTContext creates these.
165760e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
1658fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroffpublic:
1659fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  QualType getElementType() const { return ElementType; }
1660ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek  ArraySizeModifier getSizeModifier() const {
1661b870b88df784c2940efce448ebfaf54dece14666John McCall    return ArraySizeModifier(ArrayTypeBits.SizeModifier);
1662ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek  }
16630953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  Qualifiers getIndexTypeQualifiers() const {
166471c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    return Qualifiers::fromCVRMask(getIndexTypeCVRQualifiers());
166571c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  }
166671c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  unsigned getIndexTypeCVRQualifiers() const {
1667b870b88df784c2940efce448ebfaf54dece14666John McCall    return ArrayTypeBits.IndexTypeQuals;
16680953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
16691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1670fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  static bool classof(const Type *T) {
1671fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff    return T->getTypeClass() == ConstantArray ||
1672c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman           T->getTypeClass() == VariableArray ||
1673898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor           T->getTypeClass() == IncompleteArray ||
1674898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor           T->getTypeClass() == DependentSizedArray;
1675fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  }
1676fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  static bool classof(const ArrayType *) { return true; }
1677fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff};
1678fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff
16797e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// ConstantArrayType - This class represents the canonical version of
16807e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// C arrays with a specified constant size.  For example, the canonical
16817e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// type for 'int A[4 + 4*100]' is a ConstantArrayType where the element
16827e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// type is 'int' and the size is 404.
16832e7d352dbec06755105237afba183492d31d03cbTed Kremenekclass ConstantArrayType : public ArrayType {
1684fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  llvm::APInt Size; // Allows us to unique the type.
16851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
16860be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner  ConstantArrayType(QualType et, QualType can, const llvm::APInt &size,
1687c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff                    ArraySizeModifier sm, unsigned tq)
16887e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor    : ArrayType(ConstantArray, et, can, sm, tq),
16897e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor      Size(size) {}
16907e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregorprotected:
16917e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  ConstantArrayType(TypeClass tc, QualType et, QualType can,
16927e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor                    const llvm::APInt &size, ArraySizeModifier sm, unsigned tq)
16937e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor    : ArrayType(tc, et, can, sm, tq), Size(size) {}
1694fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  friend class ASTContext;  // ASTContext creates these.
1695fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroffpublic:
1696c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  const llvm::APInt &getSize() const { return Size; }
1697bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1698bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1699bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
17002767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor
17012767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor  /// \brief Determine the number of bits required to address a member of
17022767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor  // an array with the given element type and number of elements.
17032767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor  static unsigned getNumAddressingBits(ASTContext &Context,
17042767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor                                       QualType ElementType,
17052767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor                                       const llvm::APInt &NumElements);
17062767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor
17072767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor  /// \brief Determine the maximum number of active bits that an array's size
17082767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor  /// can require, which limits the maximum size of the array.
17092767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor  static unsigned getMaxSizeBits(ASTContext &Context);
17102767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor
1711fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  void Profile(llvm::FoldingSetNodeID &ID) {
17121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    Profile(ID, getElementType(), getSize(),
17130953e767ff7817f97b3ab20896b229891eeff45bJohn McCall            getSizeModifier(), getIndexTypeCVRQualifiers());
1714fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  }
1715fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  static void Profile(llvm::FoldingSetNodeID &ID, QualType ET,
17160be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner                      const llvm::APInt &ArraySize, ArraySizeModifier SizeMod,
17170be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner                      unsigned TypeQuals) {
1718fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff    ID.AddPointer(ET.getAsOpaquePtr());
1719fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff    ID.AddInteger(ArraySize.getZExtValue());
17200be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner    ID.AddInteger(SizeMod);
17210be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner    ID.AddInteger(TypeQuals);
1722fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  }
17237e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  static bool classof(const Type *T) {
172446a617a792bfab0d9b1e057371ea3b9540802226John McCall    return T->getTypeClass() == ConstantArray;
1725fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  }
1726fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  static bool classof(const ConstantArrayType *) { return true; }
1727fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff};
1728fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff
1729da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// IncompleteArrayType - This class represents C arrays with an unspecified
1730da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// size.  For example 'int A[]' has an IncompleteArrayType where the element
1731da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// type is 'int' and the size is unspecified.
1732c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedmanclass IncompleteArrayType : public ArrayType {
17337e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor
1734c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman  IncompleteArrayType(QualType et, QualType can,
17357e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor                      ArraySizeModifier sm, unsigned tq)
1736c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman    : ArrayType(IncompleteArray, et, can, sm, tq) {}
1737c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman  friend class ASTContext;  // ASTContext creates these.
1738c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedmanpublic:
1739bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1740bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1741bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
17421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
17431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == IncompleteArray;
1744c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman  }
1745c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman  static bool classof(const IncompleteArrayType *) { return true; }
17461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1747c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman  friend class StmtIteratorBase;
17481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1749c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman  void Profile(llvm::FoldingSetNodeID &ID) {
17500953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Profile(ID, getElementType(), getSizeModifier(),
17510953e767ff7817f97b3ab20896b229891eeff45bJohn McCall            getIndexTypeCVRQualifiers());
1752c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman  }
17531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
17540be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner  static void Profile(llvm::FoldingSetNodeID &ID, QualType ET,
17550be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner                      ArraySizeModifier SizeMod, unsigned TypeQuals) {
1756c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman    ID.AddPointer(ET.getAsOpaquePtr());
17570be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner    ID.AddInteger(SizeMod);
17580be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner    ID.AddInteger(TypeQuals);
1759c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman  }
1760c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman};
1761c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman
1762da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// VariableArrayType - This class represents C arrays with a specified size
1763da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// which is not an integer-constant-expression.  For example, 'int s[x+foo()]'.
1764da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// Since the size expression is an arbitrary expression, we store it as such.
1765da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner///
1766da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// Note: VariableArrayType's aren't uniqued (since the expressions aren't) and
1767da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// should not be: two lexically equivalent variable array types could mean
1768da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// different things, for example, these variables do not have the same type
1769da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// dynamically:
1770da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner///
1771da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// void foo(int x) {
1772da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner///   int Y[x];
1773da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner///   ++x;
1774da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner///   int Z[x];
1775da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// }
1776da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner///
17772e7d352dbec06755105237afba183492d31d03cbTed Kremenekclass VariableArrayType : public ArrayType {
17781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// SizeExpr - An assignment expression. VLA's are only permitted within
17791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// a function block.
1780b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek  Stmt *SizeExpr;
17817e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  /// Brackets - The left and right array brackets.
17827e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  SourceRange Brackets;
17837e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor
1784c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff  VariableArrayType(QualType et, QualType can, Expr *e,
17857e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor                    ArraySizeModifier sm, unsigned tq,
17867e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor                    SourceRange brackets)
17877e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor    : ArrayType(VariableArray, et, can, sm, tq),
17887e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor      SizeExpr((Stmt*) e), Brackets(brackets) {}
17895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
17904b05b1dee6cc65ae61d93dab7edff72710f24589Ted Kremenek
17915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
17921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Expr *getSizeExpr() const {
1793b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek    // We use C-style casts instead of cast<> here because we do not wish
1794b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek    // to have a dependency of Type.h on Stmt.h/Expr.h.
1795b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek    return (Expr*) SizeExpr;
1796b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek  }
17977e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  SourceRange getBracketsRange() const { return Brackets; }
17987e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  SourceLocation getLBracketLoc() const { return Brackets.getBegin(); }
17997e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  SourceLocation getRBracketLoc() const { return Brackets.getEnd(); }
18001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1801bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1802bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1803bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
18041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
18051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == VariableArray;
18065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
1807fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  static bool classof(const VariableArrayType *) { return true; }
18081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
180992866e2e90f6d93fb95e25a7ac4438e239d89ce6Ted Kremenek  friend class StmtIteratorBase;
18101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
18112bd24ba6d10f8c811c8e2a57c8397e07082ba497Ted Kremenek  void Profile(llvm::FoldingSetNodeID &ID) {
1812bc5e150b6d94cf131f7d01bc715571b741c5b408Chris Lattner    assert(0 && "Cannnot unique VariableArrayTypes.");
18132bd24ba6d10f8c811c8e2a57c8397e07082ba497Ted Kremenek  }
18145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
18155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1816898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// DependentSizedArrayType - This type represents an array type in
1817898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// C++ whose size is a value-dependent expression. For example:
1818cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor///
1819cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor/// \code
18201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// template<typename T, int Size>
1821898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// class array {
1822898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor///   T data[Size];
1823898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// };
1824cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor/// \endcode
1825cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor///
1826898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// For these types, we won't actually know what the array bound is
1827898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// until template instantiation occurs, at which point this will
1828898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// become either a ConstantArrayType or a VariableArrayType.
1829898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorclass DependentSizedArrayType : public ArrayType {
183004d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor  ASTContext &Context;
18311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1832cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor  /// \brief An assignment expression that will instantiate to the
1833898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// size of the array.
1834cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor  ///
1835cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor  /// The expression itself might be NULL, in which case the array
1836cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor  /// type will have its size deduced from an initializer.
1837898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  Stmt *SizeExpr;
1838cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor
18397e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  /// Brackets - The left and right array brackets.
18407e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  SourceRange Brackets;
18411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
18421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  DependentSizedArrayType(ASTContext &Context, QualType et, QualType can,
184304d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor                          Expr *e, ArraySizeModifier sm, unsigned tq,
18447e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor                          SourceRange brackets)
18457e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor    : ArrayType(DependentSizedArray, et, can, sm, tq),
184604d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor      Context(Context), SizeExpr((Stmt*) e), Brackets(brackets) {}
1847898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  friend class ASTContext;  // ASTContext creates these.
1848898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
1849898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorpublic:
18501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Expr *getSizeExpr() const {
1851898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    // We use C-style casts instead of cast<> here because we do not wish
1852898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    // to have a dependency of Type.h on Stmt.h/Expr.h.
1853898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    return (Expr*) SizeExpr;
1854898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  }
18557e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  SourceRange getBracketsRange() const { return Brackets; }
18567e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  SourceLocation getLBracketLoc() const { return Brackets.getBegin(); }
18577e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  SourceLocation getRBracketLoc() const { return Brackets.getEnd(); }
18581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1859bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1860bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1861bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
18621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
18631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == DependentSizedArray;
1864898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  }
1865898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  static bool classof(const DependentSizedArrayType *) { return true; }
18661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1867898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  friend class StmtIteratorBase;
18681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
18691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1870898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  void Profile(llvm::FoldingSetNodeID &ID) {
18711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    Profile(ID, Context, getElementType(),
18720953e767ff7817f97b3ab20896b229891eeff45bJohn McCall            getSizeModifier(), getIndexTypeCVRQualifiers(), getSizeExpr());
1873898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  }
18741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
18751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static void Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context,
18761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                      QualType ET, ArraySizeModifier SizeMod,
187704d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor                      unsigned TypeQuals, Expr *E);
1878898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor};
1879898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
1880f6ddb737cb882ffbf0b75a9abd50b930cc2b9068Douglas Gregor/// DependentSizedExtVectorType - This type represent an extended vector type
18819cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// where either the type or size is dependent. For example:
18829cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// @code
18839cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// template<typename T, int Size>
18849cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// class vector {
18859cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor///   typedef T __attribute__((ext_vector_type(Size))) type;
18869cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// }
18879cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// @endcode
18882ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregorclass DependentSizedExtVectorType : public Type, public llvm::FoldingSetNode {
18892ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor  ASTContext &Context;
18909cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor  Expr *SizeExpr;
18919cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor  /// ElementType - The element type of the array.
18929cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor  QualType ElementType;
18939cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor  SourceLocation loc;
18941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
18951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  DependentSizedExtVectorType(ASTContext &Context, QualType ElementType,
18962ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor                              QualType can, Expr *SizeExpr, SourceLocation loc)
189735495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    : Type(DependentSizedExtVector, can, /*Dependent=*/true,
189835495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor           ElementType->isVariablyModifiedType()),
18991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      Context(Context), SizeExpr(SizeExpr), ElementType(ElementType),
19002ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor      loc(loc) {}
19019cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor  friend class ASTContext;
19029cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor
19039cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregorpublic:
19042ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor  Expr *getSizeExpr() const { return SizeExpr; }
19059cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor  QualType getElementType() const { return ElementType; }
19069cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor  SourceLocation getAttributeLoc() const { return loc; }
19079cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor
1908bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1909bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1910bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
19111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
19121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == DependentSizedExtVector;
19139cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor  }
19141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const DependentSizedExtVectorType *) { return true; }
19152ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor
19162ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor  void Profile(llvm::FoldingSetNodeID &ID) {
19172ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor    Profile(ID, Context, getElementType(), getSizeExpr());
19182ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor  }
19191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
19202ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor  static void Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context,
19212ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor                      QualType ElementType, Expr *SizeExpr);
19229cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor};
19231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
19249cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor
192573322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// VectorType - GCC generic vector type. This type is created using
19261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// __attribute__((vector_size(n)), where "n" specifies the vector size in
192782287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson/// bytes; or from an Altivec __vector or vector declaration.
192882287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson/// Since the constructor takes the number of vector elements, the
192973322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// client is responsible for converting the size into the number of elements.
19305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass VectorType : public Type, public llvm::FoldingSetNode {
1931788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattnerpublic:
1932e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson  enum VectorKind {
1933e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson    GenericVector,  // not a target-specific vector type
1934e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson    AltiVecVector,  // is AltiVec vector
1935e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson    AltiVecPixel,   // is AltiVec 'vector Pixel'
1936e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson    AltiVecBool,    // is AltiVec 'vector bool ...'
1937491328c90c00ecad6ad27fa0ab3cdf9195a4a820Bob Wilson    NeonVector,     // is ARM Neon vector
1938491328c90c00ecad6ad27fa0ab3cdf9195a4a820Bob Wilson    NeonPolyVector  // is ARM Neon polynomial vector
1939788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner  };
194073322924127c873c13101b705dd823f5539ffa5fSteve Naroffprotected:
19415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// ElementType - The element type of the vector.
19425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType ElementType;
19431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
194482287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson  VectorType(QualType vecType, unsigned nElements, QualType canonType,
1945e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson             VectorKind vecKind) :
194635495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    Type(Vector, canonType, vecType->isDependentType(),
194771c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall         vecType->isVariablyModifiedType()), ElementType(vecType) {
1948e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson    VectorTypeBits.VecKind = vecKind;
1949b870b88df784c2940efce448ebfaf54dece14666John McCall    VectorTypeBits.NumElements = nElements;
195071c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  }
195135495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor
19521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  VectorType(TypeClass tc, QualType vecType, unsigned nElements,
1953e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson             QualType canonType, VectorKind vecKind)
195435495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    : Type(tc, canonType, vecType->isDependentType(),
195571c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall           vecType->isVariablyModifiedType()), ElementType(vecType) {
1956e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson    VectorTypeBits.VecKind = vecKind;
1957b870b88df784c2940efce448ebfaf54dece14666John McCall    VectorTypeBits.NumElements = nElements;
195871c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  }
19595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
196060e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
19615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
19621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
19635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType getElementType() const { return ElementType; }
1964b870b88df784c2940efce448ebfaf54dece14666John McCall  unsigned getNumElements() const { return VectorTypeBits.NumElements; }
19655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1966bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1967bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1968bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
1969e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson  VectorKind getVectorKind() const {
1970e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson    return VectorKind(VectorTypeBits.VecKind);
197171c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  }
1972788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner
19735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void Profile(llvm::FoldingSetNodeID &ID) {
197471c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    Profile(ID, getElementType(), getNumElements(),
1975e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson            getTypeClass(), getVectorKind());
19765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
19771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static void Profile(llvm::FoldingSetNodeID &ID, QualType ElementType,
197882287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson                      unsigned NumElements, TypeClass TypeClass,
1979e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson                      VectorKind VecKind) {
19805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ID.AddPointer(ElementType.getAsOpaquePtr());
19815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ID.AddInteger(NumElements);
198273322924127c873c13101b705dd823f5539ffa5fSteve Naroff    ID.AddInteger(TypeClass);
1983e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson    ID.AddInteger(VecKind);
198473322924127c873c13101b705dd823f5539ffa5fSteve Naroff  }
19850b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor
19861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
19871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == Vector || T->getTypeClass() == ExtVector;
19885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
19895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const VectorType *) { return true; }
19905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
19915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1992213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman/// ExtVectorType - Extended vector type. This type is created using
1993213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman/// __attribute__((ext_vector_type(n)), where "n" is the number of elements.
1994213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman/// Unlike vector_size, ext_vector_type is only allowed on typedef's. This
1995fcac0fff877a461bc5d5a57e6c6727a4c819d95aSteve Naroff/// class enables syntactic extensions, like Vector Components for accessing
1996fcac0fff877a461bc5d5a57e6c6727a4c819d95aSteve Naroff/// points, colors, and textures (modeled after OpenGL Shading Language).
1997213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begemanclass ExtVectorType : public VectorType {
1998213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman  ExtVectorType(QualType vecType, unsigned nElements, QualType canonType) :
1999e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson    VectorType(ExtVector, vecType, nElements, canonType, GenericVector) {}
200073322924127c873c13101b705dd823f5539ffa5fSteve Naroff  friend class ASTContext;  // ASTContext creates these.
200173322924127c873c13101b705dd823f5539ffa5fSteve Naroffpublic:
200288dca0464804b8b26ae605f89784c927e8493dddChris Lattner  static int getPointAccessorIdx(char c) {
200388dca0464804b8b26ae605f89784c927e8493dddChris Lattner    switch (c) {
200488dca0464804b8b26ae605f89784c927e8493dddChris Lattner    default: return -1;
200588dca0464804b8b26ae605f89784c927e8493dddChris Lattner    case 'x': return 0;
200688dca0464804b8b26ae605f89784c927e8493dddChris Lattner    case 'y': return 1;
200788dca0464804b8b26ae605f89784c927e8493dddChris Lattner    case 'z': return 2;
200888dca0464804b8b26ae605f89784c927e8493dddChris Lattner    case 'w': return 3;
200988dca0464804b8b26ae605f89784c927e8493dddChris Lattner    }
2010e1b31fedbc006e6e4071bbb4f74c6116b56cfa9fSteve Naroff  }
2011353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman  static int getNumericAccessorIdx(char c) {
201288dca0464804b8b26ae605f89784c927e8493dddChris Lattner    switch (c) {
2013353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      default: return -1;
2014353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '0': return 0;
2015353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '1': return 1;
2016353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '2': return 2;
2017353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '3': return 3;
2018353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '4': return 4;
2019353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '5': return 5;
2020353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '6': return 6;
2021353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '7': return 7;
2022353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '8': return 8;
2023353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '9': return 9;
2024131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman      case 'A':
2025353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case 'a': return 10;
2026131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman      case 'B':
2027353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case 'b': return 11;
2028131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman      case 'C':
2029353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case 'c': return 12;
2030131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman      case 'D':
2031353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case 'd': return 13;
2032131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman      case 'E':
2033353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case 'e': return 14;
2034131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman      case 'F':
2035353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case 'f': return 15;
203688dca0464804b8b26ae605f89784c927e8493dddChris Lattner    }
2037e1b31fedbc006e6e4071bbb4f74c6116b56cfa9fSteve Naroff  }
20381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2039b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner  static int getAccessorIdx(char c) {
2040b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner    if (int idx = getPointAccessorIdx(c)+1) return idx-1;
2041353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman    return getNumericAccessorIdx(c);
2042b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner  }
20431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
204488dca0464804b8b26ae605f89784c927e8493dddChris Lattner  bool isAccessorWithinNumElements(char c) const {
2045b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner    if (int idx = getAccessorIdx(c)+1)
204671c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall      return unsigned(idx-1) < getNumElements();
204788dca0464804b8b26ae605f89784c927e8493dddChris Lattner    return false;
2048e1b31fedbc006e6e4071bbb4f74c6116b56cfa9fSteve Naroff  }
2049bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2050bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2051bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
20521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
20531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == ExtVector;
205473322924127c873c13101b705dd823f5539ffa5fSteve Naroff  }
2055213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman  static bool classof(const ExtVectorType *) { return true; }
205673322924127c873c13101b705dd823f5539ffa5fSteve Naroff};
205773322924127c873c13101b705dd823f5539ffa5fSteve Naroff
20585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// FunctionType - C99 6.7.5.3 - Function Declarators.  This is the common base
205972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// class of FunctionNoProtoType and FunctionProtoType.
20605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
20615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass FunctionType : public Type {
20625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // The type returned by the function.
20635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType ResultType;
2064264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola
2065264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola public:
2066075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  // This class is used for passing around the information needed to
2067264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola  // construct a call. It is not actually used for storage, just for
2068264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola  // factoring together common arguments.
2069075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  // If you add a field (say Foo), other than the obvious places (both,
2070075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  // constructors, compile failures), what you need to update is
2071075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  // * Operator==
2072425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola  // * getFoo
2073425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola  // * withFoo
2074425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola  // * functionType. Add Foo, getFoo.
2075425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola  // * ASTContext::getFooType
2076425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola  // * ASTContext::mergeFunctionTypes
2077425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola  // * FunctionNoProtoType::Profile
2078425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola  // * FunctionProtoType::Profile
2079425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola  // * TypePrinter::PrintFunctionProto
20803c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  // * AST read and write
2081425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola  // * Codegen
2082425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola
2083264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola  class ExtInfo {
2084b870b88df784c2940efce448ebfaf54dece14666John McCall    enum { CallConvMask = 0x7 };
2085b870b88df784c2940efce448ebfaf54dece14666John McCall    enum { NoReturnMask = 0x8 };
2086b870b88df784c2940efce448ebfaf54dece14666John McCall    enum { RegParmMask = ~(CallConvMask | NoReturnMask),
2087b870b88df784c2940efce448ebfaf54dece14666John McCall           RegParmOffset = 4 };
2088b870b88df784c2940efce448ebfaf54dece14666John McCall
208971c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    unsigned Bits;
209071c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall
209171c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    ExtInfo(unsigned Bits) : Bits(Bits) {}
209271c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall
209371c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    friend class FunctionType;
209471c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall
2095264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola   public:
2096264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    // Constructor with no defaults. Use this when you know that you
20973c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl    // have all the elements (when reading an AST file for example).
209871c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    ExtInfo(bool noReturn, unsigned regParm, CallingConv cc) {
2099b870b88df784c2940efce448ebfaf54dece14666John McCall      Bits = ((unsigned) cc) |
2100b870b88df784c2940efce448ebfaf54dece14666John McCall             (noReturn ? NoReturnMask : 0) |
2101b870b88df784c2940efce448ebfaf54dece14666John McCall             (regParm << RegParmOffset);
210271c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    }
2103264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola
2104264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    // Constructor with all defaults. Use when for example creating a
2105264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    // function know to use defaults.
210671c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    ExtInfo() : Bits(0) {}
2107264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola
2108b870b88df784c2940efce448ebfaf54dece14666John McCall    bool getNoReturn() const { return Bits & NoReturnMask; }
2109b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned getRegParm() const { return Bits >> RegParmOffset; }
2110b870b88df784c2940efce448ebfaf54dece14666John McCall    CallingConv getCC() const { return CallingConv(Bits & CallConvMask); }
2111264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola
211271c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    bool operator==(ExtInfo Other) const {
211371c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall      return Bits == Other.Bits;
2114264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    }
211571c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    bool operator!=(ExtInfo Other) const {
211671c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall      return Bits != Other.Bits;
2117264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    }
2118264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola
2119264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    // Note that we don't have setters. That is by design, use
2120264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    // the following with methods instead of mutating these objects.
2121264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola
2122264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    ExtInfo withNoReturn(bool noReturn) const {
212371c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall      if (noReturn)
212471c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall        return ExtInfo(Bits | NoReturnMask);
212571c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall      else
212671c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall        return ExtInfo(Bits & ~NoReturnMask);
2127425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola    }
2128425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola
2129425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola    ExtInfo withRegParm(unsigned RegParm) const {
2130b870b88df784c2940efce448ebfaf54dece14666John McCall      return ExtInfo((Bits & ~RegParmMask) | (RegParm << RegParmOffset));
2131264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    }
2132264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola
2133264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    ExtInfo withCallingConv(CallingConv cc) const {
2134b870b88df784c2940efce448ebfaf54dece14666John McCall      return ExtInfo((Bits & ~CallConvMask) | (unsigned) cc);
2135264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    }
2136264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola
213771c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    void Profile(llvm::FoldingSetNodeID &ID) {
213871c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall      ID.AddInteger(Bits);
213971c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    }
2140264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola  };
2141264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola
21425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprotected:
2143971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis  FunctionType(TypeClass tc, QualType res, bool SubclassInfo,
21442455636163fdd18581d7fdae816433f886d88213Mike Stump               unsigned typeQuals, QualType Canonical, bool Dependent,
214571c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall               bool VariablyModified, ExtInfo Info)
214671c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    : Type(tc, Canonical, Dependent, VariablyModified), ResultType(res) {
2147b870b88df784c2940efce448ebfaf54dece14666John McCall    FunctionTypeBits.ExtInfo = Info.Bits;
2148b870b88df784c2940efce448ebfaf54dece14666John McCall    FunctionTypeBits.SubclassInfo = SubclassInfo;
2149b870b88df784c2940efce448ebfaf54dece14666John McCall    FunctionTypeBits.TypeQuals = typeQuals;
215071c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  }
2151b870b88df784c2940efce448ebfaf54dece14666John McCall  bool getSubClassData() const { return FunctionTypeBits.SubclassInfo; }
2152b870b88df784c2940efce448ebfaf54dece14666John McCall  unsigned getTypeQuals() const { return FunctionTypeBits.TypeQuals; }
21535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
21541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
21555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType getResultType() const { return ResultType; }
21565291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor
2157b870b88df784c2940efce448ebfaf54dece14666John McCall  unsigned getRegParmType() const { return getExtInfo().getRegParm(); }
2158b870b88df784c2940efce448ebfaf54dece14666John McCall  bool getNoReturnAttr() const { return getExtInfo().getNoReturn(); }
2159b870b88df784c2940efce448ebfaf54dece14666John McCall  CallingConv getCallConv() const { return getExtInfo().getCC(); }
2160b870b88df784c2940efce448ebfaf54dece14666John McCall  ExtInfo getExtInfo() const { return ExtInfo(FunctionTypeBits.ExtInfo); }
21615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
21625291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor  /// \brief Determine the type of an expression that calls a function of
21635291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor  /// this type.
21645291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor  QualType getCallResultType(ASTContext &Context) const {
21656398235d7890a81b785ea5af3b6e66d86bf184ccDouglas Gregor    return getResultType().getNonLValueExprType(Context);
21665291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor  }
21675291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor
216804a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall  static llvm::StringRef getNameForCallConv(CallingConv CC);
216904a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall
21705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T) {
21715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T->getTypeClass() == FunctionNoProto ||
21725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer           T->getTypeClass() == FunctionProto;
21735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
21745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const FunctionType *) { return true; }
21755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
21765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
217772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// FunctionNoProtoType - Represents a K&R-style 'int foo()' function, which has
21785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// no information available about its arguments.
217972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregorclass FunctionNoProtoType : public FunctionType, public llvm::FoldingSetNode {
218071c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  FunctionNoProtoType(QualType Result, QualType Canonical, ExtInfo Info)
21811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    : FunctionType(FunctionNoProto, Result, false, 0, Canonical,
218235495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor                   /*Dependent=*/false, Result->isVariablyModifiedType(),
218335495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor                   Info) {}
21845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
218560e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
21865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
21875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // No additional state past what FunctionType provides.
21881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2189bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2190bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2191bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
21925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void Profile(llvm::FoldingSetNodeID &ID) {
2193264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    Profile(ID, getResultType(), getExtInfo());
21945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
21952455636163fdd18581d7fdae816433f886d88213Mike Stump  static void Profile(llvm::FoldingSetNodeID &ID, QualType ResultType,
219671c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall                      ExtInfo Info) {
219771c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    Info.Profile(ID);
21985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ID.AddPointer(ResultType.getAsOpaquePtr());
21995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
22001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
22015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T) {
22025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T->getTypeClass() == FunctionNoProto;
22035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
220472564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  static bool classof(const FunctionNoProtoType *) { return true; }
22055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
22065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
220772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// FunctionProtoType - Represents a prototype with argument type info, e.g.
22085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 'int foo(int)' or 'int foo(void)'.  'void' is represented as having no
2209465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl/// arguments, not as having a single void argument. Such a type can have an
2210465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl/// exception specification, but this specification is not part of the canonical
2211465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl/// type.
221272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregorclass FunctionProtoType : public FunctionType, public llvm::FoldingSetNode {
221372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  FunctionProtoType(QualType Result, const QualType *ArgArray, unsigned numArgs,
2214465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl                    bool isVariadic, unsigned typeQuals, bool hasExs,
2215465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl                    bool hasAnyExs, const QualType *ExArray,
2216264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola                    unsigned numExs, QualType Canonical,
221735495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor                    const ExtInfo &Info);
2218465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
22195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// NumArgs - The number of arguments this function has, not counting '...'.
2220465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  unsigned NumArgs : 20;
2221465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
2222465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  /// NumExceptions - The number of types in the exception spec, if any.
2223465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  unsigned NumExceptions : 10;
2224465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
2225465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  /// HasExceptionSpec - Whether this function has an exception spec at all.
222634e80e94a21eb1ac2a9405d918e711e8b12256a9John McCall  unsigned HasExceptionSpec : 1;
2227465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
2228465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  /// AnyExceptionSpec - Whether this function has a throw(...) spec.
222934e80e94a21eb1ac2a9405d918e711e8b12256a9John McCall  unsigned AnyExceptionSpec : 1;
2230465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
2231942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner  /// ArgInfo - There is an variable size array after the class in memory that
2232942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner  /// holds the argument types.
2233465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
2234465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  /// Exceptions - There is another variable size array after ArgInfo that
2235465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  /// holds the exception types.
2236465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
22375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
22384b05b1dee6cc65ae61d93dab7edff72710f24589Ted Kremenek
22395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
22405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned getNumArgs() const { return NumArgs; }
22415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType getArgType(unsigned i) const {
22425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    assert(i < NumArgs && "Invalid argument number!");
2243942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner    return arg_type_begin()[i];
22445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
2245465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
2246465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  bool hasExceptionSpec() const { return HasExceptionSpec; }
2247465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  bool hasAnyExceptionSpec() const { return AnyExceptionSpec; }
2248465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  unsigned getNumExceptions() const { return NumExceptions; }
2249465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  QualType getExceptionType(unsigned i) const {
2250465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl    assert(i < NumExceptions && "Invalid exception number!");
2251465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl    return exception_begin()[i];
2252465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  }
22531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  bool hasEmptyExceptionSpec() const {
22541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return hasExceptionSpec() && !hasAnyExceptionSpec() &&
2255a12823f6c0ec9e0e644a9d0ee153e973f49c63fcAnders Carlsson      getNumExceptions() == 0;
2256d3fd6bad1249d3f34d71b73e2333fab0db51cce4Anders Carlsson  }
2257465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
22585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isVariadic() const { return getSubClassData(); }
2259971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis  unsigned getTypeQuals() const { return FunctionType::getTypeQuals(); }
22601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
22615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  typedef const QualType *arg_type_iterator;
2262942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner  arg_type_iterator arg_type_begin() const {
2263942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner    return reinterpret_cast<const QualType *>(this+1);
2264942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner  }
2265942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner  arg_type_iterator arg_type_end() const { return arg_type_begin()+NumArgs; }
2266465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
2267465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  typedef const QualType *exception_iterator;
2268465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  exception_iterator exception_begin() const {
2269465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl    // exceptions begin where arguments end
2270465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl    return arg_type_end();
2271465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  }
2272465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  exception_iterator exception_end() const {
2273465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl    return exception_begin() + NumExceptions;
2274465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  }
2275465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
2276bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2277bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2278bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
22795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T) {
22805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T->getTypeClass() == FunctionProto;
22815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
228272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  static bool classof(const FunctionProtoType *) { return true; }
2283465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
22845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void Profile(llvm::FoldingSetNodeID &ID);
22855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static void Profile(llvm::FoldingSetNodeID &ID, QualType Result,
2286942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner                      arg_type_iterator ArgTys, unsigned NumArgs,
2287465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl                      bool isVariadic, unsigned TypeQuals,
2288465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl                      bool hasExceptionSpec, bool anyExceptionSpec,
22892455636163fdd18581d7fdae816433f886d88213Mike Stump                      unsigned NumExceptions, exception_iterator Exs,
229071c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall                      ExtInfo ExtInfo);
22915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
22925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
22935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2294ed97649e9574b9d854fa4d6109c9333ae0993554John McCall/// \brief Represents the dependent type named by a dependently-scoped
2295ed97649e9574b9d854fa4d6109c9333ae0993554John McCall/// typename using declaration, e.g.
2296ed97649e9574b9d854fa4d6109c9333ae0993554John McCall///   using typename Base<T>::foo;
2297ed97649e9574b9d854fa4d6109c9333ae0993554John McCall/// Template instantiation turns these into the underlying type.
2298ed97649e9574b9d854fa4d6109c9333ae0993554John McCallclass UnresolvedUsingType : public Type {
2299ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  UnresolvedUsingTypenameDecl *Decl;
2300ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
230119c8576b7328f4dc2d07682f5da552875c1912efJohn McCall  UnresolvedUsingType(const UnresolvedUsingTypenameDecl *D)
230235495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    : Type(UnresolvedUsing, QualType(), true, false),
230319c8576b7328f4dc2d07682f5da552875c1912efJohn McCall      Decl(const_cast<UnresolvedUsingTypenameDecl*>(D)) {}
2304ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  friend class ASTContext; // ASTContext creates these.
2305ed97649e9574b9d854fa4d6109c9333ae0993554John McCallpublic:
2306ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
2307ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  UnresolvedUsingTypenameDecl *getDecl() const { return Decl; }
2308ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
2309ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  bool isSugared() const { return false; }
2310ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  QualType desugar() const { return QualType(this, 0); }
2311ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
2312ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  static bool classof(const Type *T) {
2313ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    return T->getTypeClass() == UnresolvedUsing;
2314ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  }
2315ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  static bool classof(const UnresolvedUsingType *) { return true; }
2316ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
2317ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  void Profile(llvm::FoldingSetNodeID &ID) {
2318ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    return Profile(ID, Decl);
2319ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  }
2320ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  static void Profile(llvm::FoldingSetNodeID &ID,
2321ed97649e9574b9d854fa4d6109c9333ae0993554John McCall                      UnresolvedUsingTypenameDecl *D) {
2322ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    ID.AddPointer(D);
2323ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  }
2324ed97649e9574b9d854fa4d6109c9333ae0993554John McCall};
2325ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
2326ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
23275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass TypedefType : public Type {
23285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  TypedefDecl *Decl;
2329c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanianprotected:
233019c8576b7328f4dc2d07682f5da552875c1912efJohn McCall  TypedefType(TypeClass tc, const TypedefDecl *D, QualType can)
233135495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    : Type(tc, can, can->isDependentType(), can->isVariablyModifiedType()),
233219c8576b7328f4dc2d07682f5da552875c1912efJohn McCall      Decl(const_cast<TypedefDecl*>(D)) {
23335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    assert(!isa<TypedefType>(can) && "Invalid canonical type");
23345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
23355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
23365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
23371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
23385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  TypedefDecl *getDecl() const { return Decl; }
23391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2340bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return true; }
2341bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const;
2342bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
234372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  static bool classof(const Type *T) { return T->getTypeClass() == Typedef; }
23445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const TypedefType *) { return true; }
23455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
23465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
234772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// TypeOfExprType (GCC extension).
234872564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregorclass TypeOfExprType : public Type {
2349d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  Expr *TOExpr;
23501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2351b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregorprotected:
2352dd0257c77719a13d4acd513df40b04300cbfc871Douglas Gregor  TypeOfExprType(Expr *E, QualType can = QualType());
2353d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  friend class ASTContext;  // ASTContext creates these.
2354d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroffpublic:
2355d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  Expr *getUnderlyingExpr() const { return TOExpr; }
23561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2357bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// \brief Remove a single level of sugar.
2358bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const;
2359bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
2360bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// \brief Returns whether this type directly provides sugar.
2361bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return true; }
2362bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
236372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  static bool classof(const Type *T) { return T->getTypeClass() == TypeOfExpr; }
236472564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  static bool classof(const TypeOfExprType *) { return true; }
2365d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff};
2366d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff
2367c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// \brief Internal representation of canonical, dependent
23681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// typeof(expr) types.
2369c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor///
2370c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// This class is used internally by the ASTContext to manage
2371c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// canonical, dependent types, only. Clients will only see instances
2372c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// of this class via TypeOfExprType nodes.
23731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpclass DependentTypeOfExprType
2374b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor  : public TypeOfExprType, public llvm::FoldingSetNode {
2375b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor  ASTContext &Context;
23761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2377b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregorpublic:
23781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  DependentTypeOfExprType(ASTContext &Context, Expr *E)
2379b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor    : TypeOfExprType(E), Context(Context) { }
23801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2381bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2382bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2383bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
2384b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor  void Profile(llvm::FoldingSetNodeID &ID) {
2385b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor    Profile(ID, Context, getUnderlyingExpr());
2386b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor  }
23871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2388b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor  static void Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context,
2389b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor                      Expr *E);
2390b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor};
23911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2392d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff/// TypeOfType (GCC extension).
2393d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroffclass TypeOfType : public Type {
2394d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  QualType TOType;
23951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  TypeOfType(QualType T, QualType can)
239635495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    : Type(TypeOf, can, T->isDependentType(), T->isVariablyModifiedType()),
239735495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor      TOType(T) {
2398d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff    assert(!isa<TypedefType>(can) && "Invalid canonical type");
2399d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  }
2400d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  friend class ASTContext;  // ASTContext creates these.
2401d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroffpublic:
2402d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  QualType getUnderlyingType() const { return TOType; }
24031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2404bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// \brief Remove a single level of sugar.
2405bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return getUnderlyingType(); }
2406bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
2407bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// \brief Returns whether this type directly provides sugar.
2408bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return true; }
2409bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
241072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  static bool classof(const Type *T) { return T->getTypeClass() == TypeOf; }
2411d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  static bool classof(const TypeOfType *) { return true; }
2412d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff};
24135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2414395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson/// DecltypeType (C++0x)
2415395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlssonclass DecltypeType : public Type {
2416395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson  Expr *E;
24171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2418563a03b1338d31c2462def43253a722bc885d384Anders Carlsson  // FIXME: We could get rid of UnderlyingType if we wanted to: We would have to
2419563a03b1338d31c2462def43253a722bc885d384Anders Carlsson  // Move getDesugaredType to ASTContext so that it can call getDecltypeForExpr
2420563a03b1338d31c2462def43253a722bc885d384Anders Carlsson  // from it.
2421563a03b1338d31c2462def43253a722bc885d384Anders Carlsson  QualType UnderlyingType;
24221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
24239d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregorprotected:
2424563a03b1338d31c2462def43253a722bc885d384Anders Carlsson  DecltypeType(Expr *E, QualType underlyingType, QualType can = QualType());
2425395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson  friend class ASTContext;  // ASTContext creates these.
2426395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlssonpublic:
2427395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson  Expr *getUnderlyingExpr() const { return E; }
2428563a03b1338d31c2462def43253a722bc885d384Anders Carlsson  QualType getUnderlyingType() const { return UnderlyingType; }
2429563a03b1338d31c2462def43253a722bc885d384Anders Carlsson
2430bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// \brief Remove a single level of sugar.
2431bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return getUnderlyingType(); }
2432bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
2433bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// \brief Returns whether this type directly provides sugar.
2434bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return !isDependentType(); }
2435bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
2436395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson  static bool classof(const Type *T) { return T->getTypeClass() == Decltype; }
2437395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson  static bool classof(const DecltypeType *) { return true; }
2438395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson};
24391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2440c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// \brief Internal representation of canonical, dependent
2441c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// decltype(expr) types.
2442c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor///
2443c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// This class is used internally by the ASTContext to manage
2444c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// canonical, dependent types, only. Clients will only see instances
2445c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// of this class via DecltypeType nodes.
24469d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregorclass DependentDecltypeType : public DecltypeType, public llvm::FoldingSetNode {
24479d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor  ASTContext &Context;
24481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
24499d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregorpublic:
24509d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor  DependentDecltypeType(ASTContext &Context, Expr *E);
24511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2452bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2453bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2454bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
24559d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor  void Profile(llvm::FoldingSetNodeID &ID) {
24569d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor    Profile(ID, Context, getUnderlyingExpr());
24579d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor  }
24581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
24599d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor  static void Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context,
24601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                      Expr *E);
24619d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor};
24621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
24635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass TagType : public Type {
2464ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl  /// Stores the TagDecl associated with this type. The decl may point to any
2465ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl  /// TagDecl that declares the entity.
2466ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl  TagDecl * decl;
24672ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor
24682ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregorprotected:
246919c8576b7328f4dc2d07682f5da552875c1912efJohn McCall  TagType(TypeClass TC, const TagDecl *D, QualType can);
24702ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor
24711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic:
2472ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl  TagDecl *getDecl() const;
24731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
24740b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor  /// @brief Determines whether this type is in the process of being
24751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// defined.
2476ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl  bool isBeingDefined() const;
24770b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor
24781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
247972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor    return T->getTypeClass() >= TagFirst && T->getTypeClass() <= TagLast;
248072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  }
24815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const TagType *) { return true; }
248272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  static bool classof(const RecordType *) { return true; }
248372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  static bool classof(const EnumType *) { return true; }
24845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
24855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
24865edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner/// RecordType - This is a helper class that allows the use of isa/cast/dyncast
24875edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner/// to detect TagType objects of structs/unions/classes.
24885edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattnerclass RecordType : public TagType {
248949aa7ff1245abd03e6e998e01302df31e4c6f8f6Argyrios Kyrtzidisprotected:
249019c8576b7328f4dc2d07682f5da552875c1912efJohn McCall  explicit RecordType(const RecordDecl *D)
249119c8576b7328f4dc2d07682f5da552875c1912efJohn McCall    : TagType(Record, reinterpret_cast<const TagDecl*>(D), QualType()) { }
249272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  explicit RecordType(TypeClass TC, RecordDecl *D)
249319c8576b7328f4dc2d07682f5da552875c1912efJohn McCall    : TagType(TC, reinterpret_cast<const TagDecl*>(D), QualType()) { }
24942ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor  friend class ASTContext;   // ASTContext creates these.
24955edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattnerpublic:
24961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
24975edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner  RecordDecl *getDecl() const {
24985edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner    return reinterpret_cast<RecordDecl*>(TagType::getDecl());
24995edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner  }
25001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
25011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  // FIXME: This predicate is a helper to QualType/Type. It needs to
25025edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner  // recursively check all fields for const-ness. If any field is declared
25031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  // const, it needs to return false.
25045edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner  bool hasConstFields() const { return false; }
25055edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner
25065edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner  // FIXME: RecordType needs to check when it is created that all fields are in
25075edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner  // the same address space, and return that.
25085edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner  unsigned getAddressSpace() const { return 0; }
25091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2510bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2511bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2512bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
25132daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner  static bool classof(const TagType *T);
25142daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner  static bool classof(const Type *T) {
25152daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner    return isa<TagType>(T) && classof(cast<TagType>(T));
25162daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner  }
25175edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner  static bool classof(const RecordType *) { return true; }
25185edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner};
25195edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner
25205edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner/// EnumType - This is a helper class that allows the use of isa/cast/dyncast
25215edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner/// to detect TagType objects of enums.
25225edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattnerclass EnumType : public TagType {
252319c8576b7328f4dc2d07682f5da552875c1912efJohn McCall  explicit EnumType(const EnumDecl *D)
252419c8576b7328f4dc2d07682f5da552875c1912efJohn McCall    : TagType(Enum, reinterpret_cast<const TagDecl*>(D), QualType()) { }
25252ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor  friend class ASTContext;   // ASTContext creates these.
25265edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattnerpublic:
25271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
25285edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner  EnumDecl *getDecl() const {
25295edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner    return reinterpret_cast<EnumDecl*>(TagType::getDecl());
25305edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner  }
25311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2532bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2533bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2534bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
25352daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner  static bool classof(const TagType *T);
25362daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner  static bool classof(const Type *T) {
25372daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner    return isa<TagType>(T) && classof(cast<TagType>(T));
25382daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner  }
25395edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner  static bool classof(const EnumType *) { return true; }
25405edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner};
25415edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner
2542fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregorclass TemplateTypeParmType : public Type, public llvm::FoldingSetNode {
2543efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor  unsigned Depth : 15;
2544efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor  unsigned ParameterPack : 1;
254577be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall  unsigned Index : 16;
2546efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor  IdentifierInfo *Name;
254772c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor
2548efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor  TemplateTypeParmType(unsigned D, unsigned I, bool PP, IdentifierInfo *N,
2549efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor                       QualType Canon)
255035495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    : Type(TemplateTypeParm, Canon, /*Dependent=*/true,
255135495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor           /*VariablyModified=*/false),
255277be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall      Depth(D), ParameterPack(PP), Index(I), Name(N) { }
255372c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor
25541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  TemplateTypeParmType(unsigned D, unsigned I, bool PP)
255535495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    : Type(TemplateTypeParm, QualType(this, 0), /*Dependent=*/true,
255635495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor           /*VariablyModified=*/false),
255777be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall      Depth(D), ParameterPack(PP), Index(I), Name(0) { }
255872c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor
2559fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor  friend class ASTContext;  // ASTContext creates these
256072c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor
2561fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregorpublic:
2562efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor  unsigned getDepth() const { return Depth; }
2563efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor  unsigned getIndex() const { return Index; }
2564efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor  bool isParameterPack() const { return ParameterPack; }
2565efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor  IdentifierInfo *getName() const { return Name; }
25661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2567bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2568bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2569bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
2570fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor  void Profile(llvm::FoldingSetNodeID &ID) {
2571efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor    Profile(ID, Depth, Index, ParameterPack, Name);
2572fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor  }
2573fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor
25741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static void Profile(llvm::FoldingSetNodeID &ID, unsigned Depth,
25751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                      unsigned Index, bool ParameterPack,
2576efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor                      IdentifierInfo *Name) {
2577fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor    ID.AddInteger(Depth);
2578fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor    ID.AddInteger(Index);
257976e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson    ID.AddBoolean(ParameterPack);
2580efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor    ID.AddPointer(Name);
2581fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor  }
2582fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor
25831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
25841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == TemplateTypeParm;
258572c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor  }
258672c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor  static bool classof(const TemplateTypeParmType *T) { return true; }
258772c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor};
2588fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor
258949a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// \brief Represents the result of substituting a type for a template
259049a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// type parameter.
259149a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall///
259249a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// Within an instantiated template, all template type parameters have
259349a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// been replaced with these.  They are used solely to record that a
259449a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// type was originally written as a template type parameter;
259549a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// therefore they are never canonical.
259649a832bd499d6f61c23655f1fac99f0dd229756eJohn McCallclass SubstTemplateTypeParmType : public Type, public llvm::FoldingSetNode {
259749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  // The original type parameter.
259849a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  const TemplateTypeParmType *Replaced;
259949a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall
260049a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  SubstTemplateTypeParmType(const TemplateTypeParmType *Param, QualType Canon)
260135495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    : Type(SubstTemplateTypeParm, Canon, Canon->isDependentType(),
260235495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor           Canon->isVariablyModifiedType()),
260349a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall      Replaced(Param) { }
260449a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall
260549a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  friend class ASTContext;
260649a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall
260749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCallpublic:
2608efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor  IdentifierInfo *getName() const { return Replaced->getName(); }
2609efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor
261049a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  /// Gets the template parameter that was substituted for.
261149a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  const TemplateTypeParmType *getReplacedParameter() const {
261249a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall    return Replaced;
261349a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  }
261449a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall
261549a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  /// Gets the type that was substituted for the template
261649a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  /// parameter.
261749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  QualType getReplacementType() const {
261849a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall    return getCanonicalTypeInternal();
261949a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  }
262049a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall
262149a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  bool isSugared() const { return true; }
262249a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  QualType desugar() const { return getReplacementType(); }
262349a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall
262449a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  void Profile(llvm::FoldingSetNodeID &ID) {
262549a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall    Profile(ID, getReplacedParameter(), getReplacementType());
262649a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  }
262749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  static void Profile(llvm::FoldingSetNodeID &ID,
262849a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall                      const TemplateTypeParmType *Replaced,
262949a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall                      QualType Replacement) {
263049a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall    ID.AddPointer(Replaced);
263149a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall    ID.AddPointer(Replacement.getAsOpaquePtr());
263249a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  }
263349a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall
263449a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  static bool classof(const Type *T) {
263549a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall    return T->getTypeClass() == SubstTemplateTypeParm;
263649a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  }
263749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  static bool classof(const SubstTemplateTypeParmType *T) { return true; }
263849a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall};
263949a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall
26407532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// \brief Represents the type of a template specialization as written
26417532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// in the source code.
264255f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor///
26437532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// Template specialization types represent the syntactic form of a
26447532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// template-id that refers to a type, e.g., @c vector<int>. Some
26457532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// template specialization types are syntactic sugar, whose canonical
26467532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// type will point to some other type node that represents the
26477532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// instantiation or class template specialization. For example, a
264855f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor/// class template specialization type of @c vector<int> will refer to
26491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// a tag type for the instantiation
265055f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor/// @c std::vector<int, std::allocator<int>>.
26517532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor///
26527532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// Other template specialization types, for which the template name
26537532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// is dependent, may be canonical types. These types are always
26547532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// dependent.
26551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpclass TemplateSpecializationType
265655f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  : public Type, public llvm::FoldingSetNode {
265733500955d731c73717af52088b7fc0e7a85681e7John McCall  /// \brief The name of the template being specialized.
26587532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor  TemplateName Template;
265955f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
266040808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  /// \brief - The number of template arguments named in this class
266140808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  /// template specialization.
266255f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  unsigned NumArgs;
266355f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
2664ef99001908e799c388f1363b1e607dad5f5b57d3John McCall  TemplateSpecializationType(TemplateName T,
26657532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor                             const TemplateArgument *Args,
26667532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor                             unsigned NumArgs, QualType Canon);
266755f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
266855f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  friend class ASTContext;  // ASTContext creates these
266955f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
267055f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregorpublic:
267140808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  /// \brief Determine whether any of the given template arguments are
267240808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  /// dependent.
267340808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  static bool anyDependentTemplateArguments(const TemplateArgument *Args,
26741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                            unsigned NumArgs);
267540808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor
2676833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  static bool anyDependentTemplateArguments(const TemplateArgumentLoc *Args,
2677833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                            unsigned NumArgs);
2678833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
2679d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  static bool anyDependentTemplateArguments(const TemplateArgumentListInfo &);
2680d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall
2681df667e71b1daadeacb230cf94fc717843f1a138aDouglas Gregor  /// \brief Print a template argument list, including the '<' and '>'
2682df667e71b1daadeacb230cf94fc717843f1a138aDouglas Gregor  /// enclosing the template arguments.
2683df667e71b1daadeacb230cf94fc717843f1a138aDouglas Gregor  static std::string PrintTemplateArgumentList(const TemplateArgument *Args,
2684d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor                                               unsigned NumArgs,
2685d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor                                               const PrintingPolicy &Policy);
2686df667e71b1daadeacb230cf94fc717843f1a138aDouglas Gregor
2687833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  static std::string PrintTemplateArgumentList(const TemplateArgumentLoc *Args,
2688833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                               unsigned NumArgs,
2689833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                               const PrintingPolicy &Policy);
2690833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
2691d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  static std::string PrintTemplateArgumentList(const TemplateArgumentListInfo &,
2692d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall                                               const PrintingPolicy &Policy);
2693d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall
269431f17ecbef57b5679c017c375db330546b7b5145John McCall  /// True if this template specialization type matches a current
269531f17ecbef57b5679c017c375db330546b7b5145John McCall  /// instantiation in the context in which it is found.
269631f17ecbef57b5679c017c375db330546b7b5145John McCall  bool isCurrentInstantiation() const {
269771d74bc0d6e522ce7c21a599db8e19d3883b518fJohn McCall    return isa<InjectedClassNameType>(getCanonicalTypeInternal());
269831f17ecbef57b5679c017c375db330546b7b5145John McCall  }
269931f17ecbef57b5679c017c375db330546b7b5145John McCall
270040808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  typedef const TemplateArgument * iterator;
270140808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor
270240808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  iterator begin() const { return getArgs(); }
270333500955d731c73717af52088b7fc0e7a85681e7John McCall  iterator end() const; // defined inline in TemplateBase.h
270440808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor
27057532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor  /// \brief Retrieve the name of the template that we are specializing.
27067532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor  TemplateName getTemplateName() const { return Template; }
270755f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
270840808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  /// \brief Retrieve the template arguments.
27091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  const TemplateArgument *getArgs() const {
271040808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor    return reinterpret_cast<const TemplateArgument *>(this + 1);
271140808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  }
271240808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor
271340808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  /// \brief Retrieve the number of template arguments.
271455f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  unsigned getNumArgs() const { return NumArgs; }
271555f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
271655f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  /// \brief Retrieve a specific template argument as a type.
271755f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  /// \precondition @c isArgType(Arg)
271833500955d731c73717af52088b7fc0e7a85681e7John McCall  const TemplateArgument &getArg(unsigned Idx) const; // in TemplateBase.h
271955f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
272031f17ecbef57b5679c017c375db330546b7b5145John McCall  bool isSugared() const {
272131f17ecbef57b5679c017c375db330546b7b5145John McCall    return !isDependentType() || isCurrentInstantiation();
272231f17ecbef57b5679c017c375db330546b7b5145John McCall  }
2723bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return getCanonicalTypeInternal(); }
2724bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
2725ef99001908e799c388f1363b1e607dad5f5b57d3John McCall  void Profile(llvm::FoldingSetNodeID &ID, ASTContext &Ctx) {
272671d74bc0d6e522ce7c21a599db8e19d3883b518fJohn McCall    Profile(ID, Template, getArgs(), NumArgs, Ctx);
272755f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  }
272855f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
27297532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor  static void Profile(llvm::FoldingSetNodeID &ID, TemplateName T,
273031f17ecbef57b5679c017c375db330546b7b5145John McCall                      const TemplateArgument *Args,
273131f17ecbef57b5679c017c375db330546b7b5145John McCall                      unsigned NumArgs,
2732828e226ab7ed08b3eb766549e9d3306432137460Douglas Gregor                      ASTContext &Context);
273355f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
27341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
27351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == TemplateSpecialization;
273655f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  }
27377532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor  static bool classof(const TemplateSpecializationType *T) { return true; }
273855f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor};
273955f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
274031f17ecbef57b5679c017c375db330546b7b5145John McCall/// \brief The injected class name of a C++ class template or class
274131f17ecbef57b5679c017c375db330546b7b5145John McCall/// template partial specialization.  Used to record that a type was
274231f17ecbef57b5679c017c375db330546b7b5145John McCall/// spelled with a bare identifier rather than as a template-id; the
274331f17ecbef57b5679c017c375db330546b7b5145John McCall/// equivalent for non-templated classes is just RecordType.
27443cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall///
274531f17ecbef57b5679c017c375db330546b7b5145John McCall/// Injected class name types are always dependent.  Template
274631f17ecbef57b5679c017c375db330546b7b5145John McCall/// instantiation turns these into RecordTypes.
27473cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall///
274831f17ecbef57b5679c017c375db330546b7b5145John McCall/// Injected class name types are always canonical.  This works
274931f17ecbef57b5679c017c375db330546b7b5145John McCall/// because it is impossible to compare an injected class name type
275031f17ecbef57b5679c017c375db330546b7b5145John McCall/// with the corresponding non-injected template type, for the same
275131f17ecbef57b5679c017c375db330546b7b5145John McCall/// reason that it is impossible to directly compare template
275231f17ecbef57b5679c017c375db330546b7b5145John McCall/// parameters from different dependent contexts: injected class name
275331f17ecbef57b5679c017c375db330546b7b5145John McCall/// types can only occur within the scope of a particular templated
275431f17ecbef57b5679c017c375db330546b7b5145John McCall/// declaration, and within that scope every template specialization
275531f17ecbef57b5679c017c375db330546b7b5145John McCall/// will canonicalize to the injected class name (when appropriate
275631f17ecbef57b5679c017c375db330546b7b5145John McCall/// according to the rules of the language).
27573cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCallclass InjectedClassNameType : public Type {
27583cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  CXXRecordDecl *Decl;
27593cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall
276031f17ecbef57b5679c017c375db330546b7b5145John McCall  /// The template specialization which this type represents.
276131f17ecbef57b5679c017c375db330546b7b5145John McCall  /// For example, in
276231f17ecbef57b5679c017c375db330546b7b5145John McCall  ///   template <class T> class A { ... };
276331f17ecbef57b5679c017c375db330546b7b5145John McCall  /// this is A<T>, whereas in
276431f17ecbef57b5679c017c375db330546b7b5145John McCall  ///   template <class X, class Y> class A<B<X,Y> > { ... };
276531f17ecbef57b5679c017c375db330546b7b5145John McCall  /// this is A<B<X,Y> >.
276631f17ecbef57b5679c017c375db330546b7b5145John McCall  ///
276731f17ecbef57b5679c017c375db330546b7b5145John McCall  /// It is always unqualified, always a template specialization type,
276831f17ecbef57b5679c017c375db330546b7b5145John McCall  /// and always dependent.
276931f17ecbef57b5679c017c375db330546b7b5145John McCall  QualType InjectedType;
27703cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall
27713cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  friend class ASTContext; // ASTContext creates these.
2772c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl  friend class ASTReader; // FIXME: ASTContext::getInjectedClassNameType is not
2773c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl                          // currently suitable for AST reading, too much
277443921b53b582145f0d1b7c48223bd4d9f0a9d1beArgyrios Kyrtzidis                          // interdependencies.
277531f17ecbef57b5679c017c375db330546b7b5145John McCall  InjectedClassNameType(CXXRecordDecl *D, QualType TST)
277635495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    : Type(InjectedClassName, QualType(), /*Dependent=*/true,
277735495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor           /*VariablyModified=*/false),
277831f17ecbef57b5679c017c375db330546b7b5145John McCall      Decl(D), InjectedType(TST) {
27793cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall    assert(isa<TemplateSpecializationType>(TST));
27803cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall    assert(!TST.hasQualifiers());
278131f17ecbef57b5679c017c375db330546b7b5145John McCall    assert(TST->isDependentType());
27823cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  }
27833cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall
27843cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCallpublic:
278531f17ecbef57b5679c017c375db330546b7b5145John McCall  QualType getInjectedSpecializationType() const { return InjectedType; }
278631f17ecbef57b5679c017c375db330546b7b5145John McCall  const TemplateSpecializationType *getInjectedTST() const {
278731f17ecbef57b5679c017c375db330546b7b5145John McCall    return cast<TemplateSpecializationType>(InjectedType.getTypePtr());
27883cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  }
27893cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall
2790ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl  CXXRecordDecl *getDecl() const;
27913cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall
279231f17ecbef57b5679c017c375db330546b7b5145John McCall  bool isSugared() const { return false; }
279331f17ecbef57b5679c017c375db330546b7b5145John McCall  QualType desugar() const { return QualType(this, 0); }
27943cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall
27953cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  static bool classof(const Type *T) {
27963cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall    return T->getTypeClass() == InjectedClassName;
27973cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  }
27983cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  static bool classof(const InjectedClassNameType *T) { return true; }
27993cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall};
28003cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall
2801465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// \brief The kind of a tag type.
2802465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnaraenum TagTypeKind {
2803465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// \brief The "struct" keyword.
2804465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  TTK_Struct,
2805465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// \brief The "union" keyword.
2806465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  TTK_Union,
2807465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// \brief The "class" keyword.
2808465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  TTK_Class,
2809465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// \brief The "enum" keyword.
2810465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  TTK_Enum
2811465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara};
2812465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
28134a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// \brief The elaboration keyword that precedes a qualified type name or
28144a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// introduces an elaborated-type-specifier.
28154a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregorenum ElaboratedTypeKeyword {
28164a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor  /// \brief The "struct" keyword introduces the elaborated-type-specifier.
28174a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor  ETK_Struct,
28184a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor  /// \brief The "union" keyword introduces the elaborated-type-specifier.
28194a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor  ETK_Union,
2820465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// \brief The "class" keyword introduces the elaborated-type-specifier.
2821465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  ETK_Class,
28224a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor  /// \brief The "enum" keyword introduces the elaborated-type-specifier.
2823465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  ETK_Enum,
2824465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// \brief The "typename" keyword precedes the qualified type name, e.g.,
2825465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// \c typename T::type.
2826465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  ETK_Typename,
2827465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// \brief No keyword precedes the qualified type name.
2828465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  ETK_None
28294a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor};
2830465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
2831465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// A helper class for Type nodes having an ElaboratedTypeKeyword.
2832465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// The keyword in stored in the free bits of the base class.
2833465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// Also provides a few static helpers for converting and printing
2834465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// elaborated type keyword and tag type kind enumerations.
2835465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnaraclass TypeWithKeyword : public Type {
2836465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnaraprotected:
2837465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  TypeWithKeyword(ElaboratedTypeKeyword Keyword, TypeClass tc,
283835495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor                  QualType Canonical, bool Dependent, bool VariablyModified)
283977be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall    : Type(tc, Canonical, Dependent, VariablyModified) {
284077be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall    TypeWithKeywordBits.Keyword = Keyword;
284177be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall  }
2842465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
2843465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnarapublic:
2844465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  ElaboratedTypeKeyword getKeyword() const {
284577be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall    return static_cast<ElaboratedTypeKeyword>(TypeWithKeywordBits.Keyword);
2846465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  }
2847465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
2848465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// getKeywordForTypeSpec - Converts a type specifier (DeclSpec::TST)
2849465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// into an elaborated type keyword.
2850465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  static ElaboratedTypeKeyword getKeywordForTypeSpec(unsigned TypeSpec);
2851465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
2852465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// getTagTypeKindForTypeSpec - Converts a type specifier (DeclSpec::TST)
2853465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// into a tag type kind.  It is an error to provide a type specifier
2854465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// which *isn't* a tag kind here.
2855465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  static TagTypeKind getTagTypeKindForTypeSpec(unsigned TypeSpec);
2856465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
2857465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// getKeywordForTagDeclKind - Converts a TagTypeKind into an
2858465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// elaborated type keyword.
2859465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  static ElaboratedTypeKeyword getKeywordForTagTypeKind(TagTypeKind Tag);
2860465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
2861465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// getTagTypeKindForKeyword - Converts an elaborated type keyword into
2862465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  // a TagTypeKind. It is an error to provide an elaborated type keyword
2863465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// which *isn't* a tag kind here.
2864465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  static TagTypeKind getTagTypeKindForKeyword(ElaboratedTypeKeyword Keyword);
2865465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
2866465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  static bool KeywordIsTagTypeKind(ElaboratedTypeKeyword Keyword);
2867465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
2868465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  static const char *getKeywordName(ElaboratedTypeKeyword Keyword);
2869465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
2870465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  static const char *getTagTypeKindName(TagTypeKind Kind) {
2871465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    return getKeywordName(getKeywordForTagTypeKind(Kind));
2872465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  }
2873465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
2874465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  class CannotCastToThisType {};
2875465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  static CannotCastToThisType classof(const Type *);
2876465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara};
2877465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
2878465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// \brief Represents a type that was referred to using an elaborated type
2879465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// keyword, e.g., struct S, or via a qualified name, e.g., N::M::type,
2880465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// or both.
2881e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor///
2882e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor/// This type is used to keep track of a type name as written in the
2883465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// source code, including tag keywords and any nested-name-specifiers.
2884465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// The type itself is always "sugar", used to express what was written
2885465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// in the source code but containing no additional semantic information.
2886465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnaraclass ElaboratedType : public TypeWithKeyword, public llvm::FoldingSetNode {
2887465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
2888ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor  /// \brief The nested name specifier containing the qualifier.
2889ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor  NestedNameSpecifier *NNS;
2890e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor
2891e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor  /// \brief The type that this qualified name refers to.
2892e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor  QualType NamedType;
2893e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor
2894465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  ElaboratedType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS,
2895465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara                 QualType NamedType, QualType CanonType)
2896465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    : TypeWithKeyword(Keyword, Elaborated, CanonType,
289735495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor                      NamedType->isDependentType(),
289835495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor                      NamedType->isVariablyModifiedType()),
2899465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara      NNS(NNS), NamedType(NamedType) {
2900465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    assert(!(Keyword == ETK_None && NNS == 0) &&
2901465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara           "ElaboratedType cannot have elaborated type keyword "
2902465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara           "and name qualifier both null.");
2903465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  }
2904e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor
2905e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor  friend class ASTContext;  // ASTContext creates these
2906e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor
2907e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregorpublic:
290833500955d731c73717af52088b7fc0e7a85681e7John McCall  ~ElaboratedType();
2909465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
2910ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor  /// \brief Retrieve the qualification on this type.
2911ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor  NestedNameSpecifier *getQualifier() const { return NNS; }
2912e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor
2913e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor  /// \brief Retrieve the type named by the qualified-id.
2914e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor  QualType getNamedType() const { return NamedType; }
2915e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor
2916bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// \brief Remove a single level of sugar.
2917bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return getNamedType(); }
2918bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
2919bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// \brief Returns whether this type directly provides sugar.
2920bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return true; }
2921bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
2922e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor  void Profile(llvm::FoldingSetNodeID &ID) {
2923465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    Profile(ID, getKeyword(), NNS, NamedType);
2924e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor  }
2925e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor
2926465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  static void Profile(llvm::FoldingSetNodeID &ID, ElaboratedTypeKeyword Keyword,
2927465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara                      NestedNameSpecifier *NNS, QualType NamedType) {
2928465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    ID.AddInteger(Keyword);
2929ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor    ID.AddPointer(NNS);
2930ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor    NamedType.Profile(ID);
2931ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor  }
2932e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor
29331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
2934465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    return T->getTypeClass() == Elaborated;
2935e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor  }
2936465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  static bool classof(const ElaboratedType *T) { return true; }
2937e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor};
2938e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor
29394a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// \brief Represents a qualified type name for which the type name is
29404a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// dependent.
2941d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor///
29424a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// DependentNameType represents a class of dependent types that involve a
29434a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// dependent nested-name-specifier (e.g., "T::") followed by a (dependent)
29444a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// name of a type. The DependentNameType may start with a "typename" (for a
29454a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// typename-specifier), "class", "struct", "union", or "enum" (for a
29464a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// dependent elaborated-type-specifier), or nothing (in contexts where we
29474a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// know that we must be referring to a type, e.g., in a base class specifier).
2948465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnaraclass DependentNameType : public TypeWithKeyword, public llvm::FoldingSetNode {
2949465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
2950d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  /// \brief The nested name specifier containing the qualifier.
2951d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  NestedNameSpecifier *NNS;
2952d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor
2953d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  /// \brief The type that this typename specifier refers to.
295433500955d731c73717af52088b7fc0e7a85681e7John McCall  const IdentifierInfo *Name;
2955d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor
29564a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor  DependentNameType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS,
29574a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor                    const IdentifierInfo *Name, QualType CanonType)
295835495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    : TypeWithKeyword(Keyword, DependentName, CanonType, /*Dependent=*/true,
295935495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor                      /*VariablyModified=*/false),
2960465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara      NNS(NNS), Name(Name) {
29611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    assert(NNS->isDependent() &&
29624714c12a1ab759156b78be8f109ea4c12213af57Douglas Gregor           "DependentNameType requires a dependent nested-name-specifier");
2963d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  }
2964d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor
2965d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  friend class ASTContext;  // ASTContext creates these
2966d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor
2967d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregorpublic:
2968d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  /// \brief Retrieve the qualification on this type.
2969d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  NestedNameSpecifier *getQualifier() const { return NNS; }
2970d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor
29711734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor  /// \brief Retrieve the type named by the typename specifier as an
29721734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor  /// identifier.
29731734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor  ///
29741734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor  /// This routine will return a non-NULL identifier pointer when the
29751734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor  /// form of the original typename was terminated by an identifier,
29761734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor  /// e.g., "typename T::type".
29771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  const IdentifierInfo *getIdentifier() const {
297833500955d731c73717af52088b7fc0e7a85681e7John McCall    return Name;
29791734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor  }
2980d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor
2981bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2982bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2983bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
2984d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  void Profile(llvm::FoldingSetNodeID &ID) {
2985465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    Profile(ID, getKeyword(), NNS, Name);
2986d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  }
2987d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor
29884a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor  static void Profile(llvm::FoldingSetNodeID &ID, ElaboratedTypeKeyword Keyword,
298933500955d731c73717af52088b7fc0e7a85681e7John McCall                      NestedNameSpecifier *NNS, const IdentifierInfo *Name) {
29904a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor    ID.AddInteger(Keyword);
2991d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor    ID.AddPointer(NNS);
299233500955d731c73717af52088b7fc0e7a85681e7John McCall    ID.AddPointer(Name);
2993d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  }
2994d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor
29951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
29964714c12a1ab759156b78be8f109ea4c12213af57Douglas Gregor    return T->getTypeClass() == DependentName;
2997d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  }
29984714c12a1ab759156b78be8f109ea4c12213af57Douglas Gregor  static bool classof(const DependentNameType *T) { return true; }
2999d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor};
3000d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor
300133500955d731c73717af52088b7fc0e7a85681e7John McCall/// DependentTemplateSpecializationType - Represents a template
300233500955d731c73717af52088b7fc0e7a85681e7John McCall/// specialization type whose template cannot be resolved, e.g.
300333500955d731c73717af52088b7fc0e7a85681e7John McCall///   A<T>::template B<T>
300433500955d731c73717af52088b7fc0e7a85681e7John McCallclass DependentTemplateSpecializationType :
300533500955d731c73717af52088b7fc0e7a85681e7John McCall  public TypeWithKeyword, public llvm::FoldingSetNode {
300633500955d731c73717af52088b7fc0e7a85681e7John McCall
300733500955d731c73717af52088b7fc0e7a85681e7John McCall  /// \brief The nested name specifier containing the qualifier.
300833500955d731c73717af52088b7fc0e7a85681e7John McCall  NestedNameSpecifier *NNS;
300933500955d731c73717af52088b7fc0e7a85681e7John McCall
301033500955d731c73717af52088b7fc0e7a85681e7John McCall  /// \brief The identifier of the template.
301133500955d731c73717af52088b7fc0e7a85681e7John McCall  const IdentifierInfo *Name;
301233500955d731c73717af52088b7fc0e7a85681e7John McCall
301333500955d731c73717af52088b7fc0e7a85681e7John McCall  /// \brief - The number of template arguments named in this class
301433500955d731c73717af52088b7fc0e7a85681e7John McCall  /// template specialization.
301533500955d731c73717af52088b7fc0e7a85681e7John McCall  unsigned NumArgs;
301633500955d731c73717af52088b7fc0e7a85681e7John McCall
301733500955d731c73717af52088b7fc0e7a85681e7John McCall  const TemplateArgument *getArgBuffer() const {
301833500955d731c73717af52088b7fc0e7a85681e7John McCall    return reinterpret_cast<const TemplateArgument*>(this+1);
301933500955d731c73717af52088b7fc0e7a85681e7John McCall  }
302033500955d731c73717af52088b7fc0e7a85681e7John McCall  TemplateArgument *getArgBuffer() {
302133500955d731c73717af52088b7fc0e7a85681e7John McCall    return reinterpret_cast<TemplateArgument*>(this+1);
302233500955d731c73717af52088b7fc0e7a85681e7John McCall  }
302333500955d731c73717af52088b7fc0e7a85681e7John McCall
3024ef99001908e799c388f1363b1e607dad5f5b57d3John McCall  DependentTemplateSpecializationType(ElaboratedTypeKeyword Keyword,
302533500955d731c73717af52088b7fc0e7a85681e7John McCall                                      NestedNameSpecifier *NNS,
302633500955d731c73717af52088b7fc0e7a85681e7John McCall                                      const IdentifierInfo *Name,
302733500955d731c73717af52088b7fc0e7a85681e7John McCall                                      unsigned NumArgs,
302833500955d731c73717af52088b7fc0e7a85681e7John McCall                                      const TemplateArgument *Args,
302933500955d731c73717af52088b7fc0e7a85681e7John McCall                                      QualType Canon);
303033500955d731c73717af52088b7fc0e7a85681e7John McCall
303133500955d731c73717af52088b7fc0e7a85681e7John McCall  friend class ASTContext;  // ASTContext creates these
303233500955d731c73717af52088b7fc0e7a85681e7John McCall
303333500955d731c73717af52088b7fc0e7a85681e7John McCallpublic:
303433500955d731c73717af52088b7fc0e7a85681e7John McCall  NestedNameSpecifier *getQualifier() const { return NNS; }
303533500955d731c73717af52088b7fc0e7a85681e7John McCall  const IdentifierInfo *getIdentifier() const { return Name; }
303633500955d731c73717af52088b7fc0e7a85681e7John McCall
303733500955d731c73717af52088b7fc0e7a85681e7John McCall  /// \brief Retrieve the template arguments.
303833500955d731c73717af52088b7fc0e7a85681e7John McCall  const TemplateArgument *getArgs() const {
303933500955d731c73717af52088b7fc0e7a85681e7John McCall    return getArgBuffer();
304033500955d731c73717af52088b7fc0e7a85681e7John McCall  }
304133500955d731c73717af52088b7fc0e7a85681e7John McCall
304233500955d731c73717af52088b7fc0e7a85681e7John McCall  /// \brief Retrieve the number of template arguments.
304333500955d731c73717af52088b7fc0e7a85681e7John McCall  unsigned getNumArgs() const { return NumArgs; }
304433500955d731c73717af52088b7fc0e7a85681e7John McCall
304533500955d731c73717af52088b7fc0e7a85681e7John McCall  const TemplateArgument &getArg(unsigned Idx) const; // in TemplateBase.h
304633500955d731c73717af52088b7fc0e7a85681e7John McCall
304733500955d731c73717af52088b7fc0e7a85681e7John McCall  typedef const TemplateArgument * iterator;
304833500955d731c73717af52088b7fc0e7a85681e7John McCall  iterator begin() const { return getArgs(); }
304933500955d731c73717af52088b7fc0e7a85681e7John McCall  iterator end() const; // inline in TemplateBase.h
305033500955d731c73717af52088b7fc0e7a85681e7John McCall
305133500955d731c73717af52088b7fc0e7a85681e7John McCall  bool isSugared() const { return false; }
305233500955d731c73717af52088b7fc0e7a85681e7John McCall  QualType desugar() const { return QualType(this, 0); }
305333500955d731c73717af52088b7fc0e7a85681e7John McCall
3054ef99001908e799c388f1363b1e607dad5f5b57d3John McCall  void Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context) {
305533500955d731c73717af52088b7fc0e7a85681e7John McCall    Profile(ID, Context, getKeyword(), NNS, Name, NumArgs, getArgs());
305633500955d731c73717af52088b7fc0e7a85681e7John McCall  }
305733500955d731c73717af52088b7fc0e7a85681e7John McCall
305833500955d731c73717af52088b7fc0e7a85681e7John McCall  static void Profile(llvm::FoldingSetNodeID &ID,
305933500955d731c73717af52088b7fc0e7a85681e7John McCall                      ASTContext &Context,
306033500955d731c73717af52088b7fc0e7a85681e7John McCall                      ElaboratedTypeKeyword Keyword,
306133500955d731c73717af52088b7fc0e7a85681e7John McCall                      NestedNameSpecifier *Qualifier,
306233500955d731c73717af52088b7fc0e7a85681e7John McCall                      const IdentifierInfo *Name,
306333500955d731c73717af52088b7fc0e7a85681e7John McCall                      unsigned NumArgs,
306433500955d731c73717af52088b7fc0e7a85681e7John McCall                      const TemplateArgument *Args);
306533500955d731c73717af52088b7fc0e7a85681e7John McCall
306633500955d731c73717af52088b7fc0e7a85681e7John McCall  static bool classof(const Type *T) {
306733500955d731c73717af52088b7fc0e7a85681e7John McCall    return T->getTypeClass() == DependentTemplateSpecialization;
306833500955d731c73717af52088b7fc0e7a85681e7John McCall  }
306933500955d731c73717af52088b7fc0e7a85681e7John McCall  static bool classof(const DependentTemplateSpecializationType *T) {
307033500955d731c73717af52088b7fc0e7a85681e7John McCall    return true;
307133500955d731c73717af52088b7fc0e7a85681e7John McCall  }
307233500955d731c73717af52088b7fc0e7a85681e7John McCall};
307333500955d731c73717af52088b7fc0e7a85681e7John McCall
3074c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// ObjCObjectType - Represents a class type in Objective C.
3075c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// Every Objective C type is a combination of a base type and a
3076c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// list of protocols.
3077c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall///
3078c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// Given the following declarations:
3079c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall///   @class C;
3080c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall///   @protocol P;
3081c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall///
3082c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// 'C' is an ObjCInterfaceType C.  It is sugar for an ObjCObjectType
3083c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// with base C and no protocols.
3084c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall///
3085c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// 'C<P>' is an ObjCObjectType with base C and protocol list [P].
3086c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall///
3087e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// 'id' is a TypedefType which is sugar for an ObjCPointerType whose
3088e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// pointee is an ObjCObjectType with base BuiltinType::ObjCIdType
3089e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// and no protocols.
3090c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall///
3091e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// 'id<P>' is an ObjCPointerType whose pointee is an ObjCObjecType
3092e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// with base BuiltinType::ObjCIdType and protocol list [P].  Eventually
3093e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// this should get its own sugar class to better represent the source.
3094c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallclass ObjCObjectType : public Type {
3095b870b88df784c2940efce448ebfaf54dece14666John McCall  // ObjCObjectType.NumProtocols - the number of protocols stored
3096b870b88df784c2940efce448ebfaf54dece14666John McCall  // after the ObjCObjectPointerType node.
309771c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  //
309871c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  // These protocols are those written directly on the type.  If
309971c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  // protocol qualifiers ever become additive, the iterators will need
310071c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  // to get kindof complicated.
310171c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  //
310271c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  // In the canonical object type, these are sorted alphabetically
310371c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  // and uniqued.
3104c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff
3105c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  /// Either a BuiltinType or an InterfaceType or sugar for either.
3106c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  QualType BaseType;
3107c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3108c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  ObjCProtocolDecl * const *getProtocolStorage() const {
3109c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return const_cast<ObjCObjectType*>(this)->getProtocolStorage();
3110c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  }
3111c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3112c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  ObjCProtocolDecl **getProtocolStorage();
3113c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3114c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallprotected:
3115c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  ObjCObjectType(QualType Canonical, QualType Base,
3116c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall                 ObjCProtocolDecl * const *Protocols, unsigned NumProtocols);
3117c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3118c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  enum Nonce_ObjCInterface { Nonce_ObjCInterface };
3119c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  ObjCObjectType(enum Nonce_ObjCInterface)
312035495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    : Type(ObjCInterface, QualType(), false, false),
312171c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall      BaseType(QualType(this_(), 0)) {
3122b870b88df784c2940efce448ebfaf54dece14666John McCall    ObjCObjectTypeBits.NumProtocols = 0;
312371c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  }
3124c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff
31253536b443bc50d58a79f14fca9b6842541a434854Steve Naroffpublic:
3126e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// getBaseType - Gets the base type of this object type.  This is
3127e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// always (possibly sugar for) one of:
3128e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///  - the 'id' builtin type (as opposed to the 'id' type visible to the
3129e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///    user, which is a typedef for an ObjCPointerType)
3130e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///  - the 'Class' builtin type (same caveat)
3131e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///  - an ObjCObjectType (currently always an ObjCInterfaceType)
3132c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  QualType getBaseType() const { return BaseType; }
313371842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek
3134c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool isObjCId() const {
3135c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getBaseType()->isSpecificBuiltinType(BuiltinType::ObjCId);
3136c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  }
3137c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool isObjCClass() const {
3138c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getBaseType()->isSpecificBuiltinType(BuiltinType::ObjCClass);
3139c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  }
3140c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool isObjCUnqualifiedId() const { return qual_empty() && isObjCId(); }
3141c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool isObjCUnqualifiedClass() const { return qual_empty() && isObjCClass(); }
3142c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool isObjCUnqualifiedIdOrClass() const {
3143c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    if (!qual_empty()) return false;
3144c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    if (const BuiltinType *T = getBaseType()->getAs<BuiltinType>())
3145c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall      return T->getKind() == BuiltinType::ObjCId ||
3146c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall             T->getKind() == BuiltinType::ObjCClass;
3147c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return false;
3148c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  }
3149c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool isObjCQualifiedId() const { return !qual_empty() && isObjCId(); }
3150c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool isObjCQualifiedClass() const { return !qual_empty() && isObjCClass(); }
3151c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3152c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  /// Gets the interface declaration for this object type, if the base type
3153c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  /// really is an interface.
3154c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  ObjCInterfaceDecl *getInterface() const;
3155c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3156c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  typedef ObjCProtocolDecl * const *qual_iterator;
3157c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3158c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  qual_iterator qual_begin() const { return getProtocolStorage(); }
3159c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  qual_iterator qual_end() const { return qual_begin() + getNumProtocols(); }
3160c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3161c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool qual_empty() const { return getNumProtocols() == 0; }
31621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3163c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff  /// getNumProtocols - Return the number of qualifying protocols in this
3164c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff  /// interface type, or 0 if there are none.
3165b870b88df784c2940efce448ebfaf54dece14666John McCall  unsigned getNumProtocols() const { return ObjCObjectTypeBits.NumProtocols; }
316614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff
3167c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  /// \brief Fetch a protocol by index.
316873dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor  ObjCProtocolDecl *getProtocol(unsigned I) const {
316973dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor    assert(I < getNumProtocols() && "Out-of-range protocol access");
317073dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor    return qual_begin()[I];
317173dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor  }
317273dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor
3173bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
3174bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
3175bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
3176c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  static bool classof(const Type *T) {
3177c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return T->getTypeClass() == ObjCObject ||
3178c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall           T->getTypeClass() == ObjCInterface;
3179c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  }
3180c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  static bool classof(const ObjCObjectType *) { return true; }
3181c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall};
3182c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3183c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// ObjCObjectTypeImpl - A class providing a concrete implementation
3184c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// of ObjCObjectType, so as to not increase the footprint of
3185c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// ObjCInterfaceType.  Code outside of ASTContext and the core type
3186c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// system should not reference this type.
3187c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallclass ObjCObjectTypeImpl : public ObjCObjectType, public llvm::FoldingSetNode {
3188c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  friend class ASTContext;
3189c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3190c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  // If anyone adds fields here, ObjCObjectType::getProtocolStorage()
3191c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  // will need to be modified.
3192c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3193c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  ObjCObjectTypeImpl(QualType Canonical, QualType Base,
3194c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall                     ObjCProtocolDecl * const *Protocols,
3195c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall                     unsigned NumProtocols)
3196c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    : ObjCObjectType(Canonical, Base, Protocols, NumProtocols) {}
3197c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3198c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallpublic:
3199c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff  void Profile(llvm::FoldingSetNodeID &ID);
32001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static void Profile(llvm::FoldingSetNodeID &ID,
3201c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall                      QualType Base,
3202c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall                      ObjCProtocolDecl *const *protocols,
3203c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall                      unsigned NumProtocols);
3204c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall};
32051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3206c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallinline ObjCProtocolDecl **ObjCObjectType::getProtocolStorage() {
3207c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  return reinterpret_cast<ObjCProtocolDecl**>(
3208c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall            static_cast<ObjCObjectTypeImpl*>(this) + 1);
3209c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall}
3210c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3211c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// ObjCInterfaceType - Interfaces are the core concept in Objective-C for
3212c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// object oriented design.  They basically correspond to C++ classes.  There
3213c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// are two kinds of interface types, normal interfaces like "NSString" and
3214c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// qualified interfaces, which are qualified with a protocol list like
3215c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// "NSString<NSCopyable, NSAmazing>".
3216e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall///
3217e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// ObjCInterfaceType guarantees the following properties when considered
3218e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// as a subtype of its superclass, ObjCObjectType:
3219e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall///   - There are no protocol qualifiers.  To reinforce this, code which
3220e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall///     tries to invoke the protocol methods via an ObjCInterfaceType will
3221e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall///     fail to compile.
3222e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall///   - It is its own base type.  That is, if T is an ObjCInterfaceType*,
3223e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall///     T->getBaseType() == QualType(T, 0).
3224c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallclass ObjCInterfaceType : public ObjCObjectType {
3225c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  ObjCInterfaceDecl *Decl;
3226c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3227c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  ObjCInterfaceType(const ObjCInterfaceDecl *D)
3228c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    : ObjCObjectType(Nonce_ObjCInterface),
3229c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall      Decl(const_cast<ObjCInterfaceDecl*>(D)) {}
3230c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  friend class ASTContext;  // ASTContext creates these.
32311fb0caaa7bef765b85972274e3b434af2572c141John McCall
3232c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallpublic:
3233e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// getDecl - Get the declaration of this interface.
3234deacbdca554298ccdf636f19c6094a8825ec6b34Douglas Gregor  ObjCInterfaceDecl *getDecl() const { return Decl; }
3235c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3236c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool isSugared() const { return false; }
3237c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  QualType desugar() const { return QualType(this, 0); }
32380b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor
32391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
32401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == ObjCInterface;
32413536b443bc50d58a79f14fca9b6842541a434854Steve Naroff  }
3242a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const ObjCInterfaceType *) { return true; }
3243c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3244c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  // Nonsense to "hide" certain members of ObjCObjectType within this
3245c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  // class.  People asking for protocols on an ObjCInterfaceType are
3246c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  // not going to get what they want: ObjCInterfaceTypes are
3247c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  // guaranteed to have no protocols.
3248c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  enum {
3249c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    qual_iterator,
3250c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    qual_begin,
3251c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    qual_end,
3252c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    getNumProtocols,
3253c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    getProtocol
3254c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  };
32553536b443bc50d58a79f14fca9b6842541a434854Steve Naroff};
32563536b443bc50d58a79f14fca9b6842541a434854Steve Naroff
3257c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallinline ObjCInterfaceDecl *ObjCObjectType::getInterface() const {
3258c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  if (const ObjCInterfaceType *T =
3259c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall        getBaseType()->getAs<ObjCInterfaceType>())
3260c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return T->getDecl();
3261c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  return 0;
3262c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall}
3263c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3264e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// ObjCObjectPointerType - Used to represent a pointer to an
3265e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// Objective C object.  These are constructed from pointer
3266e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// declarators when the pointee type is an ObjCObjectType (or sugar
3267e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// for one).  In addition, the 'id' and 'Class' types are typedefs
3268e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// for these, and the protocol-qualified types 'id<P>' and 'Class<P>'
3269e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// are translated into these.
327014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff///
3271e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// Pointers to pointers to Objective C objects are still PointerTypes;
3272e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// only the first level of pointer gets it own type implementation.
327314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroffclass ObjCObjectPointerType : public Type, public llvm::FoldingSetNode {
3274e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  QualType PointeeType;
32751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3276c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  ObjCObjectPointerType(QualType Canonical, QualType Pointee)
327735495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    : Type(ObjCObjectPointer, Canonical, false, false),
3278c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall      PointeeType(Pointee) {}
327914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  friend class ASTContext;  // ASTContext creates these.
32801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
328114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroffpublic:
3282e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// getPointeeType - Gets the type pointed to by this ObjC pointer.
3283e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// The result will always be an ObjCObjectType or sugar thereof.
328414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  QualType getPointeeType() const { return PointeeType; }
328514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff
3286e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// getObjCObjectType - Gets the type pointed to by this ObjC
3287e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// pointer.  This method always returns non-null.
3288e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///
3289e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// This method is equivalent to getPointeeType() except that
3290e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// it discards any typedefs (or other sugar) between this
3291e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// type and the "outermost" object type.  So for:
3292e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///   @class A; @protocol P; @protocol Q;
3293e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///   typedef A<P> AP;
3294e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///   typedef A A1;
3295e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///   typedef A1<P> A1P;
3296e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///   typedef A1P<Q> A1PQ;
3297e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// For 'A*', getObjectType() will return 'A'.
3298e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// For 'A<P>*', getObjectType() will return 'A<P>'.
3299e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// For 'AP*', getObjectType() will return 'A<P>'.
3300e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// For 'A1*', getObjectType() will return 'A'.
3301e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// For 'A1<P>*', getObjectType() will return 'A1<P>'.
3302e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// For 'A1P*', getObjectType() will return 'A1<P>'.
3303e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// For 'A1PQ*', getObjectType() will return 'A1<Q>', because
3304e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///   adding protocols to a protocol-qualified base discards the
3305e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///   old qualifiers (for now).  But if it didn't, getObjectType()
3306e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///   would return 'A1P<Q>' (and we'd have to make iterating over
3307e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///   qualifiers more complicated).
3308c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  const ObjCObjectType *getObjectType() const {
3309c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return PointeeType->getAs<ObjCObjectType>();
3310c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  }
3311c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3312e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// getInterfaceType - If this pointer points to an Objective C
3313e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// @interface type, gets the type for that interface.  Any protocol
3314e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// qualifiers on the interface are ignored.
3315e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///
3316e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// \return null if the base type for this pointer is 'id' or 'Class'
33171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  const ObjCInterfaceType *getInterfaceType() const {
3318c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getObjectType()->getBaseType()->getAs<ObjCInterfaceType>();
331914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  }
3320e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall
3321e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// getInterfaceDecl - If this pointer points to an Objective @interface
3322e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// type, gets the declaration for that interface.
3323e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///
3324e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// \return null if the base type for this pointer is 'id' or 'Class'
332514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  ObjCInterfaceDecl *getInterfaceDecl() const {
3326e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall    return getObjectType()->getInterface();
332714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  }
3328e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall
3329e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// isObjCIdType - True if this is equivalent to the 'id' type, i.e. if
3330e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// its object type is the primitive 'id' type with no protocols.
333114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  bool isObjCIdType() const {
3332c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getObjectType()->isObjCUnqualifiedId();
333314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  }
3334e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall
3335e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// isObjCClassType - True if this is equivalent to the 'Class' type,
3336e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// i.e. if its object tive is the primitive 'Class' type with no protocols.
333714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  bool isObjCClassType() const {
3338c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getObjectType()->isObjCUnqualifiedClass();
3339de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff  }
33408d2c0a9814e56c2b22e22d1045181c735aef62fdFariborz Jahanian
3341e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// isObjCQualifiedIdType - True if this is equivalent to 'id<P>' for some
3342e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// non-empty set of protocols.
33431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  bool isObjCQualifiedIdType() const {
3344c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getObjectType()->isObjCQualifiedId();
3345de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff  }
3346e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall
3347e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// isObjCQualifiedClassType - True if this is equivalent to 'Class<P>' for
3348e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// some non-empty set of protocols.
3349470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroff  bool isObjCQualifiedClassType() const {
3350c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getObjectType()->isObjCQualifiedClass();
335114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  }
3352e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall
3353e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// An iterator over the qualifiers on the object type.  Provided
3354e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// for convenience.  This will always iterate over the full set of
3355e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// protocols on a type, not just those provided directly.
3356c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  typedef ObjCObjectType::qual_iterator qual_iterator;
335714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff
335871842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek  qual_iterator qual_begin() const {
3359c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getObjectType()->qual_begin();
336071842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek  }
3361c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  qual_iterator qual_end() const {
3362c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getObjectType()->qual_end();
336371842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek  }
3364c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool qual_empty() const { return getObjectType()->qual_empty(); }
336514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff
3366e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// getNumProtocols - Return the number of qualifying protocols on
3367e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// the object type.
3368c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  unsigned getNumProtocols() const {
3369c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getObjectType()->getNumProtocols();
3370c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  }
337114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff
3372e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// \brief Retrieve a qualifying protocol by index on the object
3373e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// type.
337473dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor  ObjCProtocolDecl *getProtocol(unsigned I) const {
3375c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getObjectType()->getProtocol(I);
337673dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor  }
337773dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor
3378bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
3379bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
3380bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
3381e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  void Profile(llvm::FoldingSetNodeID &ID) {
3382e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall    Profile(ID, getPointeeType());
3383e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  }
3384c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  static void Profile(llvm::FoldingSetNodeID &ID, QualType T) {
3385c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    ID.AddPointer(T.getAsOpaquePtr());
3386c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  }
33871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
33881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == ObjCObjectPointer;
338914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  }
339014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  static bool classof(const ObjCObjectPointerType *) { return true; }
339114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff};
33921bb8a45f7386a23871598d05141a07af03067925Argyrios Kyrtzidis
33930953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// A qualifier set is used to build a set of qualifiers.
33940953e767ff7817f97b3ab20896b229891eeff45bJohn McCallclass QualifierCollector : public Qualifiers {
33950953e767ff7817f97b3ab20896b229891eeff45bJohn McCallpublic:
339649f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  QualifierCollector(Qualifiers Qs = Qualifiers()) : Qualifiers(Qs) {}
33970953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
33980953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// Collect any qualifiers on the given type and return an
33990953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// unqualified type.
34000953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  const Type *strip(QualType QT) {
3401a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor    addFastQualifiers(QT.getLocalFastQualifiers());
3402a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor    if (QT.hasLocalNonFastQualifiers()) {
34030953e767ff7817f97b3ab20896b229891eeff45bJohn McCall      const ExtQuals *EQ = QT.getExtQualsUnsafe();
34040953e767ff7817f97b3ab20896b229891eeff45bJohn McCall      addQualifiers(EQ->getQualifiers());
34050953e767ff7817f97b3ab20896b229891eeff45bJohn McCall      return EQ->getBaseType();
34060953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    }
34070953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return QT.getTypePtrUnsafe();
34080953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
34090953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
34100953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// Apply the collected qualifiers to the given type.
341149f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  QualType apply(ASTContext &Context, QualType QT) const;
34120953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
34130953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// Apply the collected qualifiers to the given type.
341449f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  QualType apply(ASTContext &Context, const Type* T) const;
34150953e767ff7817f97b3ab20896b229891eeff45bJohn McCall};
34160953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
34170953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3418611c1fff195d32df97706e0920c92468b2509900Chris Lattner// Inline function definitions.
34195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3420467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCallinline bool QualType::isCanonical() const {
3421467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall  const Type *T = getTypePtr();
3422a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  if (hasLocalQualifiers())
3423467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall    return T->isCanonicalUnqualified() && !isa<ArrayType>(T);
3424467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall  return T->isCanonicalUnqualified();
3425467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall}
3426467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall
342754e14c4db764c0636160d26c5bbf491637c83a76John McCallinline bool QualType::isCanonicalAsParam() const {
3428a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  if (hasLocalQualifiers()) return false;
3429745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian
343054e14c4db764c0636160d26c5bbf491637c83a76John McCall  const Type *T = getTypePtr();
3431745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian  if ((*this)->isPointerType()) {
3432745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian    QualType BaseType = (*this)->getAs<PointerType>()->getPointeeType();
3433745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian    if (isa<VariableArrayType>(BaseType)) {
3434745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian      ArrayType *AT = dyn_cast<ArrayType>(BaseType);
3435745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian      VariableArrayType *VAT = cast<VariableArrayType>(AT);
3436745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian      if (VAT->getSizeExpr())
3437745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian        T = BaseType.getTypePtr();
3438745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian    }
3439745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian  }
344054e14c4db764c0636160d26c5bbf491637c83a76John McCall  return T->isCanonicalUnqualified() &&
344154e14c4db764c0636160d26c5bbf491637c83a76John McCall           !isa<FunctionType>(T) && !isa<ArrayType>(T);
344254e14c4db764c0636160d26c5bbf491637c83a76John McCall}
344354e14c4db764c0636160d26c5bbf491637c83a76John McCall
3444fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregorinline bool QualType::isConstQualified() const {
3445fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  return isLocalConstQualified() ||
3446fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor              getTypePtr()->getCanonicalTypeInternal().isLocalConstQualified();
3447fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor}
3448fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor
3449fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregorinline bool QualType::isRestrictQualified() const {
3450fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  return isLocalRestrictQualified() ||
3451fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor            getTypePtr()->getCanonicalTypeInternal().isLocalRestrictQualified();
3452fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor}
3453fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor
3454fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor
3455fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregorinline bool QualType::isVolatileQualified() const {
3456fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  return isLocalVolatileQualified() ||
3457fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  getTypePtr()->getCanonicalTypeInternal().isLocalVolatileQualified();
3458fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor}
3459fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor
3460fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregorinline bool QualType::hasQualifiers() const {
3461fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  return hasLocalQualifiers() ||
3462fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor                  getTypePtr()->getCanonicalTypeInternal().hasLocalQualifiers();
3463fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor}
3464fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor
3465fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregorinline Qualifiers QualType::getQualifiers() const {
3466fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  Qualifiers Quals = getLocalQualifiers();
3467fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  Quals.addQualifiers(
3468fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor                 getTypePtr()->getCanonicalTypeInternal().getLocalQualifiers());
3469fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  return Quals;
3470fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor}
3471fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor
3472fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregorinline unsigned QualType::getCVRQualifiers() const {
3473fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  return getLocalCVRQualifiers() |
3474fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor              getTypePtr()->getCanonicalTypeInternal().getLocalCVRQualifiers();
3475fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor}
3476e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth
3477e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth/// getCVRQualifiersThroughArrayTypes - If there are CVR qualifiers for this
3478e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth/// type, returns them. Otherwise, if this is an array type, recurses
3479e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth/// on the element type until some qualifiers have been found or a non-array
3480e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth/// type reached.
3481e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruthinline unsigned QualType::getCVRQualifiersThroughArrayTypes() const {
3482e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth  if (unsigned Quals = getCVRQualifiers())
3483e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth    return Quals;
3484e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth  QualType CT = getTypePtr()->getCanonicalTypeInternal();
3485e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth  if (const ArrayType *AT = dyn_cast<ArrayType>(CT))
3486e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth    return AT->getElementType().getCVRQualifiersThroughArrayTypes();
3487e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth  return 0;
3488e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth}
3489e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth
349049f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCallinline void QualType::removeLocalConst() {
349149f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  removeLocalFastQualifiers(Qualifiers::Const);
34920953e767ff7817f97b3ab20896b229891eeff45bJohn McCall}
34930953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
349449f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCallinline void QualType::removeLocalRestrict() {
349549f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  removeLocalFastQualifiers(Qualifiers::Restrict);
34960953e767ff7817f97b3ab20896b229891eeff45bJohn McCall}
34970953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
349849f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCallinline void QualType::removeLocalVolatile() {
349949f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  removeLocalFastQualifiers(Qualifiers::Volatile);
35000953e767ff7817f97b3ab20896b229891eeff45bJohn McCall}
35010953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
350249f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCallinline void QualType::removeLocalCVRQualifiers(unsigned Mask) {
35036b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall  assert(!(Mask & ~Qualifiers::CVRMask) && "mask has non-CVR bits");
3504c3c0af36bac3d71f61dd758585ab307892545de4Douglas Gregor  assert((int)Qualifiers::CVRMask == (int)Qualifiers::FastMask);
35050953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
35060953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Fast path: we don't need to touch the slow qualifiers.
350749f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  removeLocalFastQualifiers(Mask);
3508ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb}
3509ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb
3510ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb/// getAddressSpace - Return the address space of this type.
3511ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lambinline unsigned QualType::getAddressSpace() const {
3512a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  if (hasLocalNonFastQualifiers()) {
35130953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    const ExtQuals *EQ = getExtQualsUnsafe();
35140953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    if (EQ->hasAddressSpace())
35150953e767ff7817f97b3ab20896b229891eeff45bJohn McCall      return EQ->getAddressSpace();
35160953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
35170953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
35184243a94b43ef6207938f3023dfcfb804dd545363Chris Lattner  QualType CT = getTypePtr()->getCanonicalTypeInternal();
3519a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  if (CT.hasLocalNonFastQualifiers()) {
35200953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    const ExtQuals *EQ = CT.getExtQualsUnsafe();
35210953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    if (EQ->hasAddressSpace())
35220953e767ff7817f97b3ab20896b229891eeff45bJohn McCall      return EQ->getAddressSpace();
35230953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
35240953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
35254243a94b43ef6207938f3023dfcfb804dd545363Chris Lattner  if (const ArrayType *AT = dyn_cast<ArrayType>(CT))
3526c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner    return AT->getElementType().getAddressSpace();
35274243a94b43ef6207938f3023dfcfb804dd545363Chris Lattner  if (const RecordType *RT = dyn_cast<RecordType>(CT))
35288e7dafec4b70303dfaff95151cd06bfc5532720cNate Begeman    return RT->getAddressSpace();
3529ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb  return 0;
3530ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb}
3531611c1fff195d32df97706e0920c92468b2509900Chris Lattner
3532d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian/// getObjCGCAttr - Return the gc attribute of this type.
35330953e767ff7817f97b3ab20896b229891eeff45bJohn McCallinline Qualifiers::GC QualType::getObjCGCAttr() const {
3534a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  if (hasLocalNonFastQualifiers()) {
35350953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    const ExtQuals *EQ = getExtQualsUnsafe();
35360953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    if (EQ->hasObjCGCAttr())
35370953e767ff7817f97b3ab20896b229891eeff45bJohn McCall      return EQ->getObjCGCAttr();
35380953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
35390953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3540d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian  QualType CT = getTypePtr()->getCanonicalTypeInternal();
3541a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  if (CT.hasLocalNonFastQualifiers()) {
35420953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    const ExtQuals *EQ = CT.getExtQualsUnsafe();
35430953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    if (EQ->hasObjCGCAttr())
35440953e767ff7817f97b3ab20896b229891eeff45bJohn McCall      return EQ->getObjCGCAttr();
35450953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
35460953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3547d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian  if (const ArrayType *AT = dyn_cast<ArrayType>(CT))
3548d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian      return AT->getElementType().getObjCGCAttr();
3549183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  if (const ObjCObjectPointerType *PT = CT->getAs<ObjCObjectPointerType>())
35501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return PT->getPointeeType().getObjCGCAttr();
3551ac423ba85bb59cc7cc1d43081b20d7e8d40355ffFariborz Jahanian  // We most look at all pointer types, not just pointer to interface types.
3552ac423ba85bb59cc7cc1d43081b20d7e8d40355ffFariborz Jahanian  if (const PointerType *PT = CT->getAs<PointerType>())
35531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return PT->getPointeeType().getObjCGCAttr();
35540953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  return Qualifiers::GCNone;
3555d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian}
35562455636163fdd18581d7fdae816433f886d88213Mike Stump
3557264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindolainline FunctionType::ExtInfo getFunctionExtInfo(const Type &t) {
3558264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola  if (const PointerType *PT = t.getAs<PointerType>()) {
3559183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall    if (const FunctionType *FT = PT->getPointeeType()->getAs<FunctionType>())
3560264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola      return FT->getExtInfo();
3561264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola  } else if (const FunctionType *FT = t.getAs<FunctionType>())
3562264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    return FT->getExtInfo();
35632455636163fdd18581d7fdae816433f886d88213Mike Stump
3564264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola  return FunctionType::ExtInfo();
35652455636163fdd18581d7fdae816433f886d88213Mike Stump}
35661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3567264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindolainline FunctionType::ExtInfo getFunctionExtInfo(QualType t) {
3568264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola  return getFunctionExtInfo(*t);
3569ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor}
3570ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor
3571b87786f045d798b070980c108c922e1475d27b15Douglas Gregor/// \brief Determine whether this set of qualifiers is a superset of the given
3572b87786f045d798b070980c108c922e1475d27b15Douglas Gregor/// set of qualifiers.
3573b87786f045d798b070980c108c922e1475d27b15Douglas Gregorinline bool Qualifiers::isSupersetOf(Qualifiers Other) const {
3574b87786f045d798b070980c108c922e1475d27b15Douglas Gregor  return Mask != Other.Mask && (Mask | Other.Mask) == Mask;
3575b87786f045d798b070980c108c922e1475d27b15Douglas Gregor}
3576b87786f045d798b070980c108c922e1475d27b15Douglas Gregor
3577e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// isMoreQualifiedThan - Determine whether this type is more
3578e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// qualified than the Other type. For example, "const volatile int"
3579e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// is more qualified than "const int", "volatile int", and
3580e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// "int". However, it is not more qualified than "const volatile
3581e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// int".
3582e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregorinline bool QualType::isMoreQualifiedThan(QualType Other) const {
35830953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // FIXME: work on arbitrary qualifiers
3584e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth  unsigned MyQuals = this->getCVRQualifiersThroughArrayTypes();
3585e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth  unsigned OtherQuals = Other.getCVRQualifiersThroughArrayTypes();
3586ecca7536488e425417dcb005c39cc15ae1947aabChris Lattner  if (getAddressSpace() != Other.getAddressSpace())
3587ecca7536488e425417dcb005c39cc15ae1947aabChris Lattner    return false;
3588e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor  return MyQuals != OtherQuals && (MyQuals | OtherQuals) == MyQuals;
3589e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor}
3590e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor
3591e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// isAtLeastAsQualifiedAs - Determine whether this type is at last
3592e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// as qualified as the Other type. For example, "const volatile
3593e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// int" is at least as qualified as "const int", "volatile int",
3594e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// "int", and "const volatile int".
3595e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregorinline bool QualType::isAtLeastAsQualifiedAs(QualType Other) const {
35960953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // FIXME: work on arbitrary qualifiers
3597e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth  unsigned MyQuals = this->getCVRQualifiersThroughArrayTypes();
3598e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth  unsigned OtherQuals = Other.getCVRQualifiersThroughArrayTypes();
3599ecca7536488e425417dcb005c39cc15ae1947aabChris Lattner  if (getAddressSpace() != Other.getAddressSpace())
3600ecca7536488e425417dcb005c39cc15ae1947aabChris Lattner    return false;
3601e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor  return (MyQuals | OtherQuals) == MyQuals;
3602e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor}
3603e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor
3604e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// getNonReferenceType - If Type is a reference type (e.g., const
3605e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// int&), returns the type that the reference refers to ("const
3606e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// int"). Otherwise, returns the type itself. This routine is used
3607e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// throughout Sema to implement C++ 5p6:
3608e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor///
3609e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor///   If an expression initially has the type "reference to T" (8.3.2,
3610e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor///   8.5.3), the type is adjusted to "T" prior to any further
3611e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor///   analysis, the expression designates the object or function
3612e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor///   denoted by the reference, and the expression is an lvalue.
3613e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregorinline QualType QualType::getNonReferenceType() const {
36146217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek  if (const ReferenceType *RefType = (*this)->getAs<ReferenceType>())
3615e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor    return RefType->getPointeeType();
3616e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor  else
3617e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor    return *this;
3618e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor}
3619e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor
3620611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isFunctionType() const {
3621a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<FunctionType>(CanonicalType);
3622611c1fff195d32df97706e0920c92468b2509900Chris Lattner}
3623611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isPointerType() const {
3624a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<PointerType>(CanonicalType);
3625611c1fff195d32df97706e0920c92468b2509900Chris Lattner}
362658f9f2c884af6b72d036b746a016d8031d31cb7aSteve Naroffinline bool Type::isAnyPointerType() const {
362758f9f2c884af6b72d036b746a016d8031d31cb7aSteve Naroff  return isPointerType() || isObjCObjectPointerType();
362858f9f2c884af6b72d036b746a016d8031d31cb7aSteve Naroff}
36295618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroffinline bool Type::isBlockPointerType() const {
3630a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<BlockPointerType>(CanonicalType);
36315618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff}
3632bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattnerinline bool Type::isReferenceType() const {
3633a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<ReferenceType>(CanonicalType);
3634bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner}
36357c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlinline bool Type::isLValueReferenceType() const {
3636a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<LValueReferenceType>(CanonicalType);
36377c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl}
36387c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlinline bool Type::isRValueReferenceType() const {
3639a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<RValueReferenceType>(CanonicalType);
36407c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl}
3641498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenekinline bool Type::isFunctionPointerType() const {
36426217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek  if (const PointerType* T = getAs<PointerType>())
3643498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek    return T->getPointeeType()->isFunctionType();
3644498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek  else
3645498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek    return false;
3646498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek}
3647f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlinline bool Type::isMemberPointerType() const {
3648a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<MemberPointerType>(CanonicalType);
3649f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl}
3650f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlinline bool Type::isMemberFunctionPointerType() const {
36516217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek  if (const MemberPointerType* T = getAs<MemberPointerType>())
36520bab0cdab751248ca389a5592bcb70eac5d39260John McCall    return T->isMemberFunctionPointer();
3653f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  else
3654f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    return false;
3655f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl}
3656db68e28c05a67735211e688009890cf834c22e75Douglas Gregorinline bool Type::isMemberDataPointerType() const {
3657db68e28c05a67735211e688009890cf834c22e75Douglas Gregor  if (const MemberPointerType* T = getAs<MemberPointerType>())
36580bab0cdab751248ca389a5592bcb70eac5d39260John McCall    return T->isMemberDataPointer();
3659db68e28c05a67735211e688009890cf834c22e75Douglas Gregor  else
3660db68e28c05a67735211e688009890cf834c22e75Douglas Gregor    return false;
3661db68e28c05a67735211e688009890cf834c22e75Douglas Gregor}
3662611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isArrayType() const {
3663a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<ArrayType>(CanonicalType);
3664611c1fff195d32df97706e0920c92468b2509900Chris Lattner}
3665c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattnerinline bool Type::isConstantArrayType() const {
3666a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<ConstantArrayType>(CanonicalType);
3667c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner}
3668c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattnerinline bool Type::isIncompleteArrayType() const {
3669a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<IncompleteArrayType>(CanonicalType);
3670c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner}
3671c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattnerinline bool Type::isVariableArrayType() const {
3672a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<VariableArrayType>(CanonicalType);
3673c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner}
3674898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorinline bool Type::isDependentSizedArrayType() const {
3675a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<DependentSizedArrayType>(CanonicalType);
3676898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor}
36773ff83dd534ccc828203670ce3f5125a4eb4199f8John McCallinline bool Type::isBuiltinType() const {
36783ff83dd534ccc828203670ce3f5125a4eb4199f8John McCall  return isa<BuiltinType>(CanonicalType);
36793ff83dd534ccc828203670ce3f5125a4eb4199f8John McCall}
3680611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isRecordType() const {
3681a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<RecordType>(CanonicalType);
3682611c1fff195d32df97706e0920c92468b2509900Chris Lattner}
36833ff83dd534ccc828203670ce3f5125a4eb4199f8John McCallinline bool Type::isEnumeralType() const {
36843ff83dd534ccc828203670ce3f5125a4eb4199f8John McCall  return isa<EnumType>(CanonicalType);
36853ff83dd534ccc828203670ce3f5125a4eb4199f8John McCall}
3686f23d364084d1aabea688222780d6fc1dd8c7f78cChris Lattnerinline bool Type::isAnyComplexType() const {
3687a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<ComplexType>(CanonicalType);
3688f23d364084d1aabea688222780d6fc1dd8c7f78cChris Lattner}
3689611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isVectorType() const {
3690a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<VectorType>(CanonicalType);
3691611c1fff195d32df97706e0920c92468b2509900Chris Lattner}
3692213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begemaninline bool Type::isExtVectorType() const {
3693a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<ExtVectorType>(CanonicalType);
3694611c1fff195d32df97706e0920c92468b2509900Chris Lattner}
3695d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroffinline bool Type::isObjCObjectPointerType() const {
3696a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<ObjCObjectPointerType>(CanonicalType);
3697d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff}
3698c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallinline bool Type::isObjCObjectType() const {
3699c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  return isa<ObjCObjectType>(CanonicalType);
3700368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner}
3701569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregorinline bool Type::isObjCObjectOrInterfaceType() const {
3702569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor  return isa<ObjCInterfaceType>(CanonicalType) ||
3703569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor    isa<ObjCObjectType>(CanonicalType);
3704569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor}
3705569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor
3706a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekinline bool Type::isObjCQualifiedIdType() const {
3707183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>())
3708d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff    return OPT->isObjCQualifiedIdType();
3709d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff  return false;
3710d58fabf7ed279be18a5e82617f809c9deff9be67Fariborz Jahanian}
3711470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroffinline bool Type::isObjCQualifiedClassType() const {
3712183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>())
3713470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroff    return OPT->isObjCQualifiedClassType();
3714470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroff  return false;
3715470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroff}
371614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroffinline bool Type::isObjCIdType() const {
3717183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>())
371814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff    return OPT->isObjCIdType();
371914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  return false;
372014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff}
372114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroffinline bool Type::isObjCClassType() const {
3722183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>())
372314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff    return OPT->isObjCClassType();
372414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  return false;
372514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff}
372613dcd00615de5c4279d97bdf63cd5f0a14fd9dccFariborz Jahanianinline bool Type::isObjCSelType() const {
37278d2c0a9814e56c2b22e22d1045181c735aef62fdFariborz Jahanian  if (const PointerType *OPT = getAs<PointerType>())
37288d2c0a9814e56c2b22e22d1045181c735aef62fdFariborz Jahanian    return OPT->getPointeeType()->isSpecificBuiltinType(BuiltinType::ObjCSel);
372913dcd00615de5c4279d97bdf63cd5f0a14fd9dccFariborz Jahanian  return false;
373013dcd00615de5c4279d97bdf63cd5f0a14fd9dccFariborz Jahanian}
3731de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroffinline bool Type::isObjCBuiltinType() const {
373213dcd00615de5c4279d97bdf63cd5f0a14fd9dccFariborz Jahanian  return isObjCIdType() || isObjCClassType() || isObjCSelType();
3733de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff}
373472c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregorinline bool Type::isTemplateTypeParmType() const {
3735a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<TemplateTypeParmType>(CanonicalType);
373672c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor}
373772c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor
3738e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbarinline bool Type::isSpecificBuiltinType(unsigned K) const {
3739183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  if (const BuiltinType *BT = getAs<BuiltinType>())
3740e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar    if (BT->getKind() == (BuiltinType::Kind) K)
3741e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar      return true;
3742e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar  return false;
3743e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar}
3744e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar
37452a984cad5ac3fdceeff2bd99daa7b90979313475John McCallinline bool Type::isPlaceholderType() const {
37462a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  if (const BuiltinType *BT = getAs<BuiltinType>())
37472a984cad5ac3fdceeff2bd99daa7b90979313475John McCall    return BT->isPlaceholderType();
37482a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  return false;
37492a984cad5ac3fdceeff2bd99daa7b90979313475John McCall}
37502a984cad5ac3fdceeff2bd99daa7b90979313475John McCall
3751063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor/// \brief Determines whether this is a type for which one can define
3752063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor/// an overloaded operator.
3753063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregorinline bool Type::isOverloadableType() const {
3754063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  return isDependentType() || isRecordType() || isEnumeralType();
3755904eed3f6148758d39a2d3c88f3133274460d645Douglas Gregor}
3756904eed3f6148758d39a2d3c88f3133274460d645Douglas Gregor
37578958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbarinline bool Type::hasPointerRepresentation() const {
37588958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar  return (isPointerType() || isReferenceType() || isBlockPointerType() ||
3759c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall          isObjCObjectPointerType() || isNullPtrType());
37608958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar}
37618958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar
3762820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanianinline bool Type::hasObjCPointerRepresentation() const {
3763c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  return isObjCObjectPointerType();
3764820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian}
3765820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian
376622caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner/// Insertion operator for diagnostics.  This allows sending QualType's into a
376722caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner/// diagnostic with <<.
376822caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattnerinline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
376922caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner                                           QualType T) {
377022caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner  DB.AddTaggedVal(reinterpret_cast<intptr_t>(T.getAsOpaquePtr()),
377122caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner                  Diagnostic::ak_qualtype);
377222caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner  return DB;
377322caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner}
37741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
377547c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth/// Insertion operator for partial diagnostics.  This allows sending QualType's
377647c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth/// into a diagnostic with <<.
377747c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruthinline const PartialDiagnostic &operator<<(const PartialDiagnostic &PD,
377847c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth                                           QualType T) {
377947c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth  PD.AddTaggedVal(reinterpret_cast<intptr_t>(T.getAsOpaquePtr()),
378047c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth                  Diagnostic::ak_qualtype);
378147c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth  return PD;
378247c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth}
378347c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth
378489c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor// Helper class template that is used by Type::getAs to ensure that one does
378589c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor// not try to look through a qualified type to get to an array type.
378689c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregortemplate<typename T,
378789c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor         bool isArrayType = (llvm::is_same<T, ArrayType>::value ||
378889c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor                             llvm::is_base_of<ArrayType, T>::value)>
378989c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregorstruct ArrayType_cannot_be_used_with_getAs { };
379089c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor
379189c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregortemplate<typename T>
379289c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregorstruct ArrayType_cannot_be_used_with_getAs<T, true>;
379389c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor
37941a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek/// Member-template getAs<specific type>'.
37951a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenektemplate <typename T> const T *Type::getAs() const {
379689c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor  ArrayType_cannot_be_used_with_getAs<T> at;
379789c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor  (void)at;
379889c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor
37991a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek  // If this is directly a T type, return it.
38001a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek  if (const T *Ty = dyn_cast<T>(this))
38011a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek    return Ty;
38021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
38031a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek  // If the canonical form of this type isn't the right kind, reject it.
38040953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  if (!isa<T>(CanonicalType))
38051a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek    return 0;
38061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
38070953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // If this is a typedef for the type, strip the typedef off without
38081a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek  // losing all typedef information.
3809bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  return cast<T>(getUnqualifiedDesugaredType());
38101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump}
381122caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner
38125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}  // end namespace clang
38135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
38145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif
3815