Type.h revision be191100e034b23a3e13053757a57b7f5068c24a
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"
21e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor#include "clang/AST/NestedNameSpecifier.h"
227532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor#include "clang/AST/TemplateName.h"
235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "llvm/Support/Casting.h"
2450d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor#include "llvm/Support/type_traits.h"
25fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff#include "llvm/ADT/APSInt.h"
265cf243a883872441d73ca49cea7e20de5802629bChris Lattner#include "llvm/ADT/FoldingSet.h"
275cf243a883872441d73ca49cea7e20de5802629bChris Lattner#include "llvm/ADT/PointerIntPair.h"
281734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor#include "llvm/ADT/PointerUnion.h"
297532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor
305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing llvm::isa;
315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing llvm::cast;
325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing llvm::cast_or_null;
335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing llvm::dyn_cast;
345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing llvm::dyn_cast_or_null;
356b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCallnamespace clang {
366b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall  enum {
376b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall    TypeAlignmentInBits = 3,
386b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall    TypeAlignment = 1 << TypeAlignmentInBits
396b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall  };
40aed1df80bf64228e1429c1edc408397f9174847cChris Lattner  class Type;
41aed1df80bf64228e1429c1edc408397f9174847cChris Lattner  class ExtQuals;
42aed1df80bf64228e1429c1edc408397f9174847cChris Lattner  class QualType;
436b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall}
445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
454e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattnernamespace llvm {
464e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner  template <typename T>
47daae940507f2e93c6fa12e8062fa958e34cc2d1cChris Lattner  class PointerLikeTypeTraits;
48bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner  template<>
49bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner  class PointerLikeTypeTraits< ::clang::Type*> {
50bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner  public:
51bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner    static inline void *getAsVoidPointer(::clang::Type *P) { return P; }
52bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner    static inline ::clang::Type *getFromVoidPointer(void *P) {
53bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner      return static_cast< ::clang::Type*>(P);
54bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner    }
556b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall    enum { NumLowBitsAvailable = clang::TypeAlignmentInBits };
56bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner  };
570953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  template<>
580953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  class PointerLikeTypeTraits< ::clang::ExtQuals*> {
590953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  public:
600953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    static inline void *getAsVoidPointer(::clang::ExtQuals *P) { return P; }
610953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    static inline ::clang::ExtQuals *getFromVoidPointer(void *P) {
620953e767ff7817f97b3ab20896b229891eeff45bJohn McCall      return static_cast< ::clang::ExtQuals*>(P);
630953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    }
646b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall    enum { NumLowBitsAvailable = clang::TypeAlignmentInBits };
650953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  };
66aed1df80bf64228e1429c1edc408397f9174847cChris Lattner
67aed1df80bf64228e1429c1edc408397f9174847cChris Lattner  template <>
68aed1df80bf64228e1429c1edc408397f9174847cChris Lattner  struct isPodLike<clang::QualType> { static const bool value = true; };
694e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner}
704e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner
715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang {
725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class ASTContext;
735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class TypedefDecl;
7455f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  class TemplateDecl;
7572c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor  class TemplateTypeParmDecl;
76aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor  class NonTypeTemplateParmDecl;
777532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor  class TemplateTemplateParmDecl;
785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class TagDecl;
795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class RecordDecl;
8049aa7ff1245abd03e6e998e01302df31e4c6f8f6Argyrios Kyrtzidis  class CXXRecordDecl;
815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class EnumDecl;
8221d50e12c3c412d8457071dc419363b7a7e8b855Ted Kremenek  class FieldDecl;
83a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  class ObjCInterfaceDecl;
84a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  class ObjCProtocolDecl;
85a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  class ObjCMethodDecl;
86ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  class UnresolvedUsingTypenameDecl;
875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class Expr;
88b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek  class Stmt;
895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class SourceLocation;
9092866e2e90f6d93fb95e25a7ac4438e239d89ce6Ted Kremenek  class StmtIteratorBase;
9140808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  class TemplateArgument;
92833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  class TemplateArgumentLoc;
93d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  class TemplateArgumentListInfo;
94ead608af31b6c9abeae1ca6d0b75094dac4641c0John McCall  class Type;
95465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  class ElaboratedType;
963b4ea54acf01f72f6eb74d96689dda86d950228fDaniel Dunbar  struct PrintingPolicy;
9772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor
98ead608af31b6c9abeae1ca6d0b75094dac4641c0John McCall  template <typename> class CanQual;
99ead608af31b6c9abeae1ca6d0b75094dac4641c0John McCall  typedef CanQual<Type> CanQualType;
100ead608af31b6c9abeae1ca6d0b75094dac4641c0John McCall
10172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  // Provide forward declarations for all of the *Type classes
10272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#define TYPE(Class, Base) class Class##Type;
10372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#include "clang/AST/TypeNodes.def"
104f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl
1050953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// Qualifiers - The collection of all-type qualifiers we support.
1060953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// Clang supports five independent qualifiers:
1070953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// * C99: const, volatile, and restrict
1080953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// * Embedded C (TR18037): address spaces
1090953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// * Objective C: the GC attributes (none, weak, or strong)
1100953e767ff7817f97b3ab20896b229891eeff45bJohn McCallclass Qualifiers {
1115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
1120953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  enum TQ { // NOTE: These flags must be kept in sync with DeclSpec::TQ.
1135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Const    = 0x1,
1145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Restrict = 0x2,
1155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Volatile = 0x4,
1160953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    CVRMask = Const | Volatile | Restrict
1175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
1181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1190953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  enum GC {
120d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian    GCNone = 0,
121d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian    Weak,
122d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian    Strong
123d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian  };
124efadb7768e7c7418185f5a4010ecd8b21ca9731bJohn McCall
1250953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  enum {
1260953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    /// The maximum supported address space number.
1270953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    /// 24 bits should be enough for anyone.
1280953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    MaxAddressSpace = 0xffffffu,
1290953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
1300953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    /// The width of the "fast" qualifier mask.
1310953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    FastWidth = 2,
1320953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
1330953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    /// The fast qualifier mask.
1340953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    FastMask = (1 << FastWidth) - 1
1350953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  };
1360953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
1370953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  Qualifiers() : Mask(0) {}
1380953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
1390953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  static Qualifiers fromFastMask(unsigned Mask) {
1400953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Qualifiers Qs;
1410953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Qs.addFastQualifiers(Mask);
1420953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return Qs;
1430953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
1440953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
1450953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  static Qualifiers fromCVRMask(unsigned CVR) {
1460953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Qualifiers Qs;
1470953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Qs.addCVRQualifiers(CVR);
1480953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return Qs;
1490953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
1500953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
1510953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Deserialize qualifiers from an opaque representation.
1520953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  static Qualifiers fromOpaqueValue(unsigned opaque) {
1530953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Qualifiers Qs;
1540953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Qs.Mask = opaque;
1550953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return Qs;
1560953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
1570953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
1580953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Serialize these qualifiers into an opaque representation.
1590953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  unsigned getAsOpaqueValue() const {
1600953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return Mask;
1610953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
1620953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
1630953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool hasConst() const { return Mask & Const; }
1640953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void setConst(bool flag) {
1650953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask = (Mask & ~Const) | (flag ? Const : 0);
1660953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
1670953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void removeConst() { Mask &= ~Const; }
1680953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void addConst() { Mask |= Const; }
1690953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
1700953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool hasVolatile() const { return Mask & Volatile; }
1710953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void setVolatile(bool flag) {
1720953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask = (Mask & ~Volatile) | (flag ? Volatile : 0);
1730953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
1740953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void removeVolatile() { Mask &= ~Volatile; }
1750953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void addVolatile() { Mask |= Volatile; }
1760953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
1770953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool hasRestrict() const { return Mask & Restrict; }
1780953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void setRestrict(bool flag) {
1790953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask = (Mask & ~Restrict) | (flag ? Restrict : 0);
1800953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
1810953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void removeRestrict() { Mask &= ~Restrict; }
1820953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void addRestrict() { Mask |= Restrict; }
1830953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
1840953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool hasCVRQualifiers() const { return getCVRQualifiers(); }
1850953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  unsigned getCVRQualifiers() const { return Mask & CVRMask; }
1860953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void setCVRQualifiers(unsigned mask) {
1870953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(!(mask & ~CVRMask) && "bitmask contains non-CVR bits");
1880953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask = (Mask & ~CVRMask) | mask;
1890953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
1900953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void removeCVRQualifiers(unsigned mask) {
1910953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(!(mask & ~CVRMask) && "bitmask contains non-CVR bits");
1920953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask &= ~mask;
1930953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
1940953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void removeCVRQualifiers() {
1950953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    removeCVRQualifiers(CVRMask);
1960953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
1970953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void addCVRQualifiers(unsigned mask) {
1980953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(!(mask & ~CVRMask) && "bitmask contains non-CVR bits");
1990953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask |= mask;
2000953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2010953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
2020953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool hasObjCGCAttr() const { return Mask & GCAttrMask; }
2030953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  GC getObjCGCAttr() const { return GC((Mask & GCAttrMask) >> GCAttrShift); }
2040953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void setObjCGCAttr(GC type) {
2050953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask = (Mask & ~GCAttrMask) | (type << GCAttrShift);
2060953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2070953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void removeObjCGCAttr() { setObjCGCAttr(GCNone); }
2080953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void addObjCGCAttr(GC type) {
2090953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(type);
2100953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    setObjCGCAttr(type);
2110953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2120953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
2130953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool hasAddressSpace() const { return Mask & AddressSpaceMask; }
2140953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  unsigned getAddressSpace() const { return Mask >> AddressSpaceShift; }
2150953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void setAddressSpace(unsigned space) {
2160953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(space <= MaxAddressSpace);
2170953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask = (Mask & ~AddressSpaceMask)
2180953e767ff7817f97b3ab20896b229891eeff45bJohn McCall         | (((uint32_t) space) << AddressSpaceShift);
2190953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2200953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void removeAddressSpace() { setAddressSpace(0); }
2210953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void addAddressSpace(unsigned space) {
2220953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(space);
2230953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    setAddressSpace(space);
2240953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2250953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
2260953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Fast qualifiers are those that can be allocated directly
2270953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // on a QualType object.
2280953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool hasFastQualifiers() const { return getFastQualifiers(); }
2290953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  unsigned getFastQualifiers() const { return Mask & FastMask; }
2300953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void setFastQualifiers(unsigned mask) {
2310953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(!(mask & ~FastMask) && "bitmask contains non-fast qualifier bits");
2320953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask = (Mask & ~FastMask) | mask;
2330953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2340953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void removeFastQualifiers(unsigned mask) {
2350953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(!(mask & ~FastMask) && "bitmask contains non-fast qualifier bits");
2360953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask &= ~mask;
2370953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2380953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void removeFastQualifiers() {
2390953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    removeFastQualifiers(FastMask);
2400953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2410953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void addFastQualifiers(unsigned mask) {
2420953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(!(mask & ~FastMask) && "bitmask contains non-fast qualifier bits");
2430953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask |= mask;
2440953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2450953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
2460953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// hasNonFastQualifiers - Return true if the set contains any
2470953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// qualifiers which require an ExtQuals node to be allocated.
2480953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool hasNonFastQualifiers() const { return Mask & ~FastMask; }
2490953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  Qualifiers getNonFastQualifiers() const {
2500953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Qualifiers Quals = *this;
2510953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Quals.setFastQualifiers(0);
2520953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return Quals;
2530953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2540953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
2550953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// hasQualifiers - Return true if the set contains any qualifiers.
2560953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool hasQualifiers() const { return Mask; }
2570953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool empty() const { return !Mask; }
2580953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
2590953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// \brief Add the qualifiers from the given set to this set.
2600953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void addQualifiers(Qualifiers Q) {
2610953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    // If the other set doesn't have any non-boolean qualifiers, just
2620953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    // bit-or it in.
2630953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    if (!(Q.Mask & ~CVRMask))
2640953e767ff7817f97b3ab20896b229891eeff45bJohn McCall      Mask |= Q.Mask;
2650953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    else {
2660953e767ff7817f97b3ab20896b229891eeff45bJohn McCall      Mask |= (Q.Mask & CVRMask);
2670953e767ff7817f97b3ab20896b229891eeff45bJohn McCall      if (Q.hasAddressSpace())
2680953e767ff7817f97b3ab20896b229891eeff45bJohn McCall        addAddressSpace(Q.getAddressSpace());
2690953e767ff7817f97b3ab20896b229891eeff45bJohn McCall      if (Q.hasObjCGCAttr())
2700953e767ff7817f97b3ab20896b229891eeff45bJohn McCall        addObjCGCAttr(Q.getObjCGCAttr());
2710953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    }
2720953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2730953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
274b87786f045d798b070980c108c922e1475d27b15Douglas Gregor  bool isSupersetOf(Qualifiers Other) const;
275b87786f045d798b070980c108c922e1475d27b15Douglas Gregor
2760953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool operator==(Qualifiers Other) const { return Mask == Other.Mask; }
2770953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool operator!=(Qualifiers Other) const { return Mask != Other.Mask; }
2780953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
2790953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  operator bool() const { return hasQualifiers(); }
2800953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
2810953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  Qualifiers &operator+=(Qualifiers R) {
2820953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    addQualifiers(R);
2830953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return *this;
2840953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2850953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
2860953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Union two qualifier sets.  If an enumerated qualifier appears
2870953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // in both sets, use the one from the right.
2880953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  friend Qualifiers operator+(Qualifiers L, Qualifiers R) {
2890953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    L += R;
2900953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return L;
2910953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2920953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
2930953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  std::string getAsString() const;
2940953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  std::string getAsString(const PrintingPolicy &Policy) const {
2950953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    std::string Buffer;
2960953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    getAsStringInternal(Buffer, Policy);
2970953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return Buffer;
2980953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2990953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void getAsStringInternal(std::string &S, const PrintingPolicy &Policy) const;
3000953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3010953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void Profile(llvm::FoldingSetNodeID &ID) const {
3020953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    ID.AddInteger(Mask);
3030953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
3040953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3050953e767ff7817f97b3ab20896b229891eeff45bJohn McCallprivate:
3060953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3070953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // bits:     |0 1 2|3 .. 4|5  ..  31|
3080953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  //           |C R V|GCAttr|AddrSpace|
3090953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  uint32_t Mask;
3100953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3110953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  static const uint32_t GCAttrMask = 0x18;
3120953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  static const uint32_t GCAttrShift = 3;
3130953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  static const uint32_t AddressSpaceMask = ~(CVRMask | GCAttrMask);
3140953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  static const uint32_t AddressSpaceShift = 5;
3150953e767ff7817f97b3ab20896b229891eeff45bJohn McCall};
3160953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3170953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3180953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// ExtQuals - We can encode up to three bits in the low bits of a
3190953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// type pointer, but there are many more type qualifiers that we want
3200953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// to be able to apply to an arbitrary type.  Therefore we have this
3210953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// struct, intended to be heap-allocated and used by QualType to
3220953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// store qualifiers.
3230953e767ff7817f97b3ab20896b229891eeff45bJohn McCall///
3240953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// The current design tags the 'const' and 'restrict' qualifiers in
3250953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// two low bits on the QualType pointer; a third bit records whether
3260953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// the pointer is an ExtQuals node.  'const' was chosen because it is
3270953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// orders of magnitude more common than the other two qualifiers, in
3280953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// both library and user code.  It's relatively rare to see
3290953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// 'restrict' in user code, but many standard C headers are saturated
3300953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// with 'restrict' declarations, so that representing them efficiently
3310953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// is a critical goal of this representation.
3320953e767ff7817f97b3ab20896b229891eeff45bJohn McCallclass ExtQuals : public llvm::FoldingSetNode {
3330953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // NOTE: changing the fast qualifiers should be straightforward as
3340953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // long as you don't make 'const' non-fast.
3350953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // 1. Qualifiers:
3360953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  //    a) Modify the bitmasks (Qualifiers::TQ and DeclSpec::TQ).
3370953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  //       Fast qualifiers must occupy the low-order bits.
3380953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  //    b) Update Qualifiers::FastWidth and FastMask.
3390953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // 2. QualType:
3400953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  //    a) Update is{Volatile,Restrict}Qualified(), defined inline.
3410953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  //    b) Update remove{Volatile,Restrict}, defined near the end of
3420953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  //       this header.
3430953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // 3. ASTContext:
3440953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  //    a) Update get{Volatile,Restrict}Type.
3450953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3460953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// Context - the context to which this set belongs.  We save this
3470953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// here so that QualifierCollector can use it to reapply extended
3480953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// qualifiers to an arbitrary type without requiring a context to
3490953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// be pushed through every single API dealing with qualifiers.
3500953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  ASTContext& Context;
3510953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3520953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// BaseType - the underlying type that this qualifies
3530953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  const Type *BaseType;
3540953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3550953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// Quals - the immutable set of qualifiers applied by this
3560953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// node;  always contains extended qualifiers.
3570953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  Qualifiers Quals;
3580953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3590953e767ff7817f97b3ab20896b229891eeff45bJohn McCallpublic:
3600953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  ExtQuals(ASTContext& Context, const Type *Base, Qualifiers Quals)
3610953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    : Context(Context), BaseType(Base), Quals(Quals)
3620953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  {
3630953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(Quals.hasNonFastQualifiers()
3640953e767ff7817f97b3ab20896b229891eeff45bJohn McCall           && "ExtQuals created with no fast qualifiers");
3650953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(!Quals.hasFastQualifiers()
3660953e767ff7817f97b3ab20896b229891eeff45bJohn McCall           && "ExtQuals created with fast qualifiers");
3670953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
3680953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3690953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  Qualifiers getQualifiers() const { return Quals; }
3700953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3710953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool hasVolatile() const { return Quals.hasVolatile(); }
3720953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3730953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool hasObjCGCAttr() const { return Quals.hasObjCGCAttr(); }
3740953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  Qualifiers::GC getObjCGCAttr() const { return Quals.getObjCGCAttr(); }
3750953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3760953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool hasAddressSpace() const { return Quals.hasAddressSpace(); }
3770953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  unsigned getAddressSpace() const { return Quals.getAddressSpace(); }
3780953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3790953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  const Type *getBaseType() const { return BaseType; }
3801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3810953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  ASTContext &getContext() const { return Context; }
3820953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3830953e767ff7817f97b3ab20896b229891eeff45bJohn McCallpublic:
3840953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void Profile(llvm::FoldingSetNodeID &ID) const {
3850953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Profile(ID, getBaseType(), Quals);
3860953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
3870953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  static void Profile(llvm::FoldingSetNodeID &ID,
3880953e767ff7817f97b3ab20896b229891eeff45bJohn McCall                      const Type *BaseType,
3890953e767ff7817f97b3ab20896b229891eeff45bJohn McCall                      Qualifiers Quals) {
3900953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(!Quals.hasFastQualifiers() && "fast qualifiers in ExtQuals hash!");
3910953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    ID.AddPointer(BaseType);
3920953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Quals.Profile(ID);
3930953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
3940953e767ff7817f97b3ab20896b229891eeff45bJohn McCall};
3950953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
396ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor/// CallingConv - Specifies the calling convention that a function uses.
397ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregorenum CallingConv {
398ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor  CC_Default,
399ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor  CC_C,           // __attribute__((cdecl))
400ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor  CC_X86StdCall,  // __attribute__((stdcall))
401f813a2c03fcb05381b3252010435f557eb6b3cdeDouglas Gregor  CC_X86FastCall, // __attribute__((fastcall))
402f813a2c03fcb05381b3252010435f557eb6b3cdeDouglas Gregor  CC_X86ThisCall  // __attribute__((thiscall))
403ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor};
404ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor
4050953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
4060953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// QualType - For efficiency, we don't store CV-qualified types as nodes on
4070953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// their own: instead each reference to a type stores the qualifiers.  This
4080953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// greatly reduces the number of nodes we need to allocate for types (for
4090953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// example we only need one for 'int', 'const int', 'volatile int',
4100953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// 'const volatile int', etc).
4110953e767ff7817f97b3ab20896b229891eeff45bJohn McCall///
4120953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// As an added efficiency bonus, instead of making this a pair, we
4130953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// just store the two bits we care about in the low bits of the
4140953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// pointer.  To handle the packing/unpacking, we make QualType be a
4150953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// simple wrapper class that acts like a smart pointer.  A third bit
4160953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// indicates whether there are extended qualifiers present, in which
4170953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// case the pointer points to a special structure.
4180953e767ff7817f97b3ab20896b229891eeff45bJohn McCallclass QualType {
4190953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Thankfully, these are efficiently composable.
4200953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  llvm::PointerIntPair<llvm::PointerUnion<const Type*,const ExtQuals*>,
4210953e767ff7817f97b3ab20896b229891eeff45bJohn McCall                       Qualifiers::FastWidth> Value;
4220953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
4230953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  const ExtQuals *getExtQualsUnsafe() const {
4240953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return Value.getPointer().get<const ExtQuals*>();
4250953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
4260953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
4270953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  const Type *getTypePtrUnsafe() const {
4280953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return Value.getPointer().get<const Type*>();
4290953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
4300953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
431fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  QualType getUnqualifiedTypeSlow() const;
432fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor
4330953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  friend class QualifierCollector;
4340953e767ff7817f97b3ab20896b229891eeff45bJohn McCallpublic:
4355cf243a883872441d73ca49cea7e20de5802629bChris Lattner  QualType() {}
4361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4375cf243a883872441d73ca49cea7e20de5802629bChris Lattner  QualType(const Type *Ptr, unsigned Quals)
4380953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    : Value(Ptr, Quals) {}
4390953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  QualType(const ExtQuals *Ptr, unsigned Quals)
4400953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    : Value(Ptr, Quals) {}
4410953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
442a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  unsigned getLocalFastQualifiers() const { return Value.getInt(); }
443a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  void setLocalFastQualifiers(unsigned Quals) { Value.setInt(Quals); }
4445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4450953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// Retrieves a pointer to the underlying (unqualified) type.
4460953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// This should really return a const Type, but it's not worth
4470953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// changing all the users right now.
4480953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  Type *getTypePtr() const {
449a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor    if (hasLocalNonFastQualifiers())
4500953e767ff7817f97b3ab20896b229891eeff45bJohn McCall      return const_cast<Type*>(getExtQualsUnsafe()->getBaseType());
4510953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return const_cast<Type*>(getTypePtrUnsafe());
4520953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
4531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4545cf243a883872441d73ca49cea7e20de5802629bChris Lattner  void *getAsOpaquePtr() const { return Value.getOpaqueValue(); }
4555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static QualType getFromOpaquePtr(void *Ptr) {
4565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    QualType T;
4575cf243a883872441d73ca49cea7e20de5802629bChris Lattner    T.Value.setFromOpaqueValue(Ptr);
4585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T;
4595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
4601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Type &operator*() const {
4625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return *getTypePtr();
4635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
4645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Type *operator->() const {
4665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return getTypePtr();
4675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
4681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
469467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall  bool isCanonical() const;
47054e14c4db764c0636160d26c5bbf491637c83a76John McCall  bool isCanonicalAsParam() const;
471467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall
4725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isNull - Return true if this QualType doesn't point to a type yet.
4735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isNull() const {
4740953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return Value.getPointer().isNull();
4755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
4765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
477a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Determine whether this particular QualType instance has the
478a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// "const" qualifier set, without looking through typedefs that may have
479a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// added "const" at a different level.
480a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  bool isLocalConstQualified() const {
481a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor    return (getLocalFastQualifiers() & Qualifiers::Const);
4820953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
483a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor
484a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Determine whether this type is const-qualified.
485fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  bool isConstQualified() const;
486a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor
487a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Determine whether this particular QualType instance has the
488a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// "restrict" qualifier set, without looking through typedefs that may have
489a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// added "restrict" at a different level.
490a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  bool isLocalRestrictQualified() const {
491a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor    return (getLocalFastQualifiers() & Qualifiers::Restrict);
492a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  }
493a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor
494a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Determine whether this type is restrict-qualified.
495fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  bool isRestrictQualified() const;
496a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor
497a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Determine whether this particular QualType instance has the
498a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// "volatile" qualifier set, without looking through typedefs that may have
499a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// added "volatile" at a different level.
500a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  bool isLocalVolatileQualified() const {
501a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor    return (hasLocalNonFastQualifiers() && getExtQualsUnsafe()->hasVolatile());
5025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
5030953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
504a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Determine whether this type is volatile-qualified.
505fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  bool isVolatileQualified() const;
506a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor
507a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Determine whether this particular QualType instance has any
508a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// qualifiers, without looking through any typedefs that might add
509a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// qualifiers at a different level.
510a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  bool hasLocalQualifiers() const {
511a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor    return getLocalFastQualifiers() || hasLocalNonFastQualifiers();
5120953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
5130953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
514a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Determine whether this type has any qualifiers.
515fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  bool hasQualifiers() const;
516a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor
517a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Determine whether this particular QualType instance has any
518a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// "non-fast" qualifiers, e.g., those that are stored in an ExtQualType
519a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// instance.
520a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  bool hasLocalNonFastQualifiers() const {
521a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor    return Value.getPointer().is<const ExtQuals*>();
5220953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
5230953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
524a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Retrieve the set of qualifiers local to this particular QualType
525a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// instance, not including any qualifiers acquired through typedefs or
526a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// other sugar.
527a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  Qualifiers getLocalQualifiers() const {
5280953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Qualifiers Quals;
529a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor    if (hasLocalNonFastQualifiers())
5300953e767ff7817f97b3ab20896b229891eeff45bJohn McCall      Quals = getExtQualsUnsafe()->getQualifiers();
531a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor    Quals.addFastQualifiers(getLocalFastQualifiers());
5320953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return Quals;
5330953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
5340953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
535a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Retrieve the set of qualifiers applied to this type.
536fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  Qualifiers getQualifiers() const;
537a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor
538a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Retrieve the set of CVR (const-volatile-restrict) qualifiers
539a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// local to this particular QualType instance, not including any qualifiers
540a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// acquired through typedefs or other sugar.
541a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  unsigned getLocalCVRQualifiers() const {
542a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor    unsigned CVR = getLocalFastQualifiers();
543a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor    if (isLocalVolatileQualified())
544a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor      CVR |= Qualifiers::Volatile;
5450953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return CVR;
5465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
547b381aac9bae6d608c72267dd0ed08ec6369e94e4Nuno Lopes
548a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Retrieve the set of CVR (const-volatile-restrict) qualifiers
549a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// applied to this type.
550fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  unsigned getCVRQualifiers() const;
551e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth
552e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth  /// \brief Retrieve the set of CVR (const-volatile-restrict) qualifiers
553e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth  /// applied to this type, looking through any number of unqualified array
554e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth  /// types to their element types' qualifiers.
555e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth  unsigned getCVRQualifiersThroughArrayTypes() const;
556e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth
557bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isConstant(ASTContext& Ctx) const {
558bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall    return QualType::isConstant(*this, Ctx);
559bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  }
5601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5610953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Don't promise in the API that anything besides 'const' can be
5620953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // easily added.
5630953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
5640953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// addConst - add the specified type qualifier to this QualType.
5650953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void addConst() {
5660953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    addFastQualifiers(Qualifiers::Const);
5670953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
5680953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  QualType withConst() const {
5690953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return withFastQualifiers(Qualifiers::Const);
5700953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
5710953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
5720953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void addFastQualifiers(unsigned TQs) {
5730953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(!(TQs & ~Qualifiers::FastMask)
5740953e767ff7817f97b3ab20896b229891eeff45bJohn McCall           && "non-fast qualifier bits set in mask!");
5750953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Value.setInt(Value.getInt() | TQs);
5760953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
5770953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
578a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  // FIXME: The remove* functions are semantically broken, because they might
579a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  // not remove a qualifier stored on a typedef. Most of the with* functions
580a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  // have the same problem.
5810953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void removeConst();
5820953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void removeVolatile();
5830953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void removeRestrict();
5840953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void removeCVRQualifiers(unsigned Mask);
5850953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
5860953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void removeFastQualifiers() { Value.setInt(0); }
5870953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void removeFastQualifiers(unsigned Mask) {
5880953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(!(Mask & ~Qualifiers::FastMask) && "mask has non-fast qualifiers");
5890953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Value.setInt(Value.getInt() & ~Mask);
5900953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
5915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
5920953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Creates a type with the given qualifiers in addition to any
5930953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // qualifiers already on this type.
5940953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  QualType withFastQualifiers(unsigned TQs) const {
5950953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    QualType T = *this;
5960953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    T.addFastQualifiers(TQs);
5970953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return T;
5980953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
5991c6a38bcea17801e9a4738753aee845381af2b6cSanjiv Gupta
6000953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Creates a type with exactly the given fast qualifiers, removing
6010953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // any existing fast qualifiers.
6020953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  QualType withExactFastQualifiers(unsigned TQs) const {
6030953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return withoutFastQualifiers().withFastQualifiers(TQs);
6045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
6050953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
6060953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Removes fast qualifiers, but leaves any extended qualifiers in place.
6070953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  QualType withoutFastQualifiers() const {
6080953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    QualType T = *this;
6090953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    T.removeFastQualifiers();
6100953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return T;
611c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  }
612971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis
613a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Return this type with all of the instance-specific qualifiers
614a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// removed, but without removing any qualifiers that may have been applied
615a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// through typedefs.
616a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  QualType getLocalUnqualifiedType() const { return QualType(getTypePtr(), 0); }
6171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
618a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Return the unqualified form of the given type, which might be
619a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// desugared to eliminate qualifiers introduced via typedefs.
620fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  QualType getUnqualifiedType() const {
621fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor    QualType T = getLocalUnqualifiedType();
622fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor    if (!T.hasQualifiers())
623fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor      return T;
624fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor
625fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor    return getUnqualifiedTypeSlow();
626a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  }
627a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor
628e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor  bool isMoreQualifiedThan(QualType Other) const;
629e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor  bool isAtLeastAsQualifiedAs(QualType Other) const;
630e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor  QualType getNonReferenceType() const;
6311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6322fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner  /// getDesugaredType - Return the specified type with any "sugar" removed from
6332fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner  /// the type.  This takes off typedefs, typeof's etc.  If the outer level of
6342fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner  /// the type is already concrete, it returns it unmodified.  This is similar
6352fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner  /// to getting the canonical type, but it doesn't remove *all* typedefs.  For
6362fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner  /// example, it returns "T*" as "T*", (not as "int*"), because the pointer is
6372fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner  /// concrete.
6380953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  ///
6390953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// Qualifiers are left in place.
640bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType getDesugaredType() const {
641bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall    return QualType::getDesugaredType(*this);
642bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  }
64398cd599ee8a9b259ed7388ee2921a20d97658864Douglas Gregor
6445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// operator==/!= - Indicate whether the specified types and qualifiers are
6455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// identical.
64650d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor  friend bool operator==(const QualType &LHS, const QualType &RHS) {
64750d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor    return LHS.Value == RHS.Value;
6485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
64950d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor  friend bool operator!=(const QualType &LHS, const QualType &RHS) {
65050d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor    return LHS.Value != RHS.Value;
6515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
652d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor  std::string getAsString() const;
653d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor
654d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor  std::string getAsString(const PrintingPolicy &Policy) const {
6555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    std::string S;
656d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor    getAsStringInternal(S, Policy);
6575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return S;
6585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
659e4f2142d00fa5fdb580c4e2413da91882d955381Chris Lattner  void getAsStringInternal(std::string &Str,
660e4f2142d00fa5fdb580c4e2413da91882d955381Chris Lattner                           const PrintingPolicy &Policy) const;
6611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
662c36d405a02fab41f6c45cb2bc750d64949742903Chris Lattner  void dump(const char *s) const;
663c36d405a02fab41f6c45cb2bc750d64949742903Chris Lattner  void dump() const;
6641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6653f2dcb1ca8bd2d5d3ccc5c80f4ab06f949d88a89Ted Kremenek  void Profile(llvm::FoldingSetNodeID &ID) const {
6663f2dcb1ca8bd2d5d3ccc5c80f4ab06f949d88a89Ted Kremenek    ID.AddPointer(getAsOpaquePtr());
6673f2dcb1ca8bd2d5d3ccc5c80f4ab06f949d88a89Ted Kremenek  }
6685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
669ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb  /// getAddressSpace - Return the address space of this type.
670ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb  inline unsigned getAddressSpace() const;
6711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
672d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian  /// GCAttrTypesAttr - Returns gc attribute of this type.
6730953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  inline Qualifiers::GC getObjCGCAttr() const;
674f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian
675f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian  /// isObjCGCWeak true when Type is objc's weak.
676f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian  bool isObjCGCWeak() const {
6770953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return getObjCGCAttr() == Qualifiers::Weak;
678f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian  }
679f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian
680f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian  /// isObjCGCStrong true when Type is objc's strong.
681f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian  bool isObjCGCStrong() const {
6820953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return getObjCGCAttr() == Qualifiers::Strong;
683f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian  }
6842455636163fdd18581d7fdae816433f886d88213Mike Stump
685bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCallprivate:
686bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  // These methods are implemented in a separate translation unit;
687bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  // "static"-ize them to avoid creating temporary QualTypes in the
688bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  // caller.
689bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  static bool isConstant(QualType T, ASTContext& Ctx);
690bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  static QualType getDesugaredType(QualType T);
6915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
6925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
6935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end clang.
6945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
6955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace llvm {
6965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Implement simplify_type for QualType, so that we can dyn_cast from QualType
6975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// to a specific Type class.
6985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencertemplate<> struct simplify_type<const ::clang::QualType> {
6995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  typedef ::clang::Type* SimpleType;
7005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static SimpleType getSimplifiedValue(const ::clang::QualType &Val) {
7015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return Val.getTypePtr();
7025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
7035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
7045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencertemplate<> struct simplify_type< ::clang::QualType>
7055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  : public simplify_type<const ::clang::QualType> {};
7061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7074e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner// Teach SmallPtrSet that QualType is "basically a pointer".
7084e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattnertemplate<>
709daae940507f2e93c6fa12e8062fa958e34cc2d1cChris Lattnerclass PointerLikeTypeTraits<clang::QualType> {
7104e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattnerpublic:
7114e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner  static inline void *getAsVoidPointer(clang::QualType P) {
7124e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner    return P.getAsOpaquePtr();
7134e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner  }
7144e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner  static inline clang::QualType getFromVoidPointer(void *P) {
7154e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner    return clang::QualType::getFromOpaquePtr(P);
7164e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner  }
7170953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Various qualifiers go in low bits.
7180eda3b31a672ea486fa92b9bc49a2c91be856b53Chris Lattner  enum { NumLowBitsAvailable = 0 };
7194e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner};
7201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
72173af669633e13c813f80cd15ecf3e6414778aee4Ted Kremenek} // end namespace llvm
7225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang {
7245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Type - This is the base class of the type hierarchy.  A central concept
7265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// with types is that each type always has a canonical type.  A canonical type
7275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// is the type with any typedef names stripped out of it or the types it
7285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// references.  For example, consider:
7295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
7305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///  typedef int  foo;
7315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///  typedef foo* bar;
7325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///    'int *'    'foo *'    'bar'
7335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
7345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// There will be a Type object created for 'int'.  Since int is canonical, its
7355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// canonicaltype pointer points to itself.  There is also a Type for 'foo' (a
73672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// TypedefType).  Its CanonicalType pointer points to the 'int' Type.  Next
7375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// there is a PointerType that represents 'int*', which, like 'int', is
7385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// canonical.  Finally, there is a PointerType type for 'foo*' whose canonical
73972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// type is 'int*', and there is a TypedefType for 'bar', whose canonical type
7405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// is also 'int*'.
7415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
7425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Non-canonical types are useful for emitting diagnostics, without losing
7435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// information about typedefs being used.  Canonical types are useful for type
7445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// comparisons (they allow by-pointer equality tests) and useful for reasoning
7455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// about whether something has a particular form (e.g. is a function type),
7465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// because they implicitly, recursively, strip all typedefs out of a type.
7475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
7485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Types, once created, are immutable.
7495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
7505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass Type {
7515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
7525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  enum TypeClass {
75372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#define TYPE(Class, Base) Class,
75427935ee59c30b0d8b610ab676aab8e65350af932John McCall#define LAST_TYPE(Class) TypeLast = Class,
75572564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#define ABSTRACT_TYPE(Class, Base)
75672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#include "clang/AST/TypeNodes.def"
75772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor    TagFirst = Record, TagLast = Enum
7585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
7591bb8a45f7386a23871598d05141a07af03067925Argyrios Kyrtzidis
7605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate:
761c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  Type(const Type&);           // DO NOT IMPLEMENT.
762c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  void operator=(const Type&); // DO NOT IMPLEMENT.
763c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
7645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType CanonicalType;
7655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// TypeClass bitfield - Enum that specifies what subclass this belongs to.
76727935ee59c30b0d8b610ab676aab8e65350af932John McCall  unsigned TC : 8;
76827935ee59c30b0d8b610ab676aab8e65350af932John McCall
76927935ee59c30b0d8b610ab676aab8e65350af932John McCall  /// Dependent - Whether this type is a dependent type (C++ [temp.dep.type]).
7705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// Note that this should stay at the end of the ivars for Type so that
7715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// subclasses can pack their bitfields into the same word.
77227935ee59c30b0d8b610ab676aab8e65350af932John McCall  bool Dependent : 1;
77360e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
77460e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor  /// \brief Whether the linkage of this type is already known.
77560e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor  mutable bool LinkageKnown : 1;
77660e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
77760e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor  /// \brief Linkage of this type.
77860e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor  mutable unsigned CachedLinkage : 2;
77960e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
7805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprotected:
78160e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor  /// \brief Compute the linkage of this type.
78260e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor  virtual Linkage getLinkageImpl() const;
78360e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
78460e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor  enum { BitsRemainingInType = 20 };
785c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
786124dd7b5777e29ecac006822bd4d4623f0dc4264Hartmut Kaiser  // silence VC++ warning C4355: 'this' : used in base member initializer list
787124dd7b5777e29ecac006822bd4d4623f0dc4264Hartmut Kaiser  Type *this_() { return this; }
788898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  Type(TypeClass tc, QualType Canonical, bool dependent)
789f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner    : CanonicalType(Canonical.isNull() ? QualType(this_(), 0) : Canonical),
79060e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor      TC(tc), Dependent(dependent), LinkageKnown(false),
79160e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor      CachedLinkage(NoLinkage) {}
792898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  virtual ~Type() {}
7934b05b1dee6cc65ae61d93dab7edff72710f24589Ted Kremenek  virtual void Destroy(ASTContext& C);
7945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;
7951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7968b9023ba35a86838789e2c9034a6128728c547aaChris Lattnerpublic:
797a8ae51f79d35b7c1822ba4a086176b4a8c862862Hartmut Kaiser  TypeClass getTypeClass() const { return static_cast<TypeClass>(TC); }
7981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
799467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall  bool isCanonicalUnqualified() const {
800467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall    return CanonicalType.getTypePtr() == this;
801467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall  }
8025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
8031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// Types are partitioned into 3 broad categories (C99 6.2.5p1):
8045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// object types, function types, and incomplete types.
8051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
806bad0e656c3732e3539a9cd6525de721d7e47408bDouglas Gregor  /// \brief Determines whether the type describes an object in memory.
807bad0e656c3732e3539a9cd6525de721d7e47408bDouglas Gregor  ///
808bad0e656c3732e3539a9cd6525de721d7e47408bDouglas Gregor  /// Note that this definition of object type corresponds to the C++
809bad0e656c3732e3539a9cd6525de721d7e47408bDouglas Gregor  /// definition of object type, which includes incomplete types, as
810bad0e656c3732e3539a9cd6525de721d7e47408bDouglas Gregor  /// opposed to the C definition (which does not include incomplete
811bad0e656c3732e3539a9cd6525de721d7e47408bDouglas Gregor  /// types).
8125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isObjectType() const;
8135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
8145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isIncompleteType - Return true if this is an incomplete type.
8155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// A type that can describe objects, but which lacks information needed to
8165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// determine its size (e.g. void, or a fwd declared struct). Clients of this
8171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// routine will need to determine if the size is actually required.
8185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isIncompleteType() const;
819d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner
820d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner  /// isIncompleteOrObjectType - Return true if this is an incomplete or object
821d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner  /// type, in other words, not a function type.
822d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner  bool isIncompleteOrObjectType() const {
823d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner    return !isFunctionType();
824d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner  }
82564b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
82664b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  /// isPODType - Return true if this is a plain-old-data type (C++ 3.9p10).
82764b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  bool isPODType() const;
82864b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
829ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl  /// isLiteralType - Return true if this is a literal type
830ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl  /// (C++0x [basic.types]p10)
831ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl  bool isLiteralType() const;
832ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl
833d7444aac1af1c2c1d5e5b7467ecf6006ee2d8abeSteve Naroff  /// isVariablyModifiedType (C99 6.7.5.2p2) - Return true for variable array
834d7444aac1af1c2c1d5e5b7467ecf6006ee2d8abeSteve Naroff  /// types that have a non-constant expression. This does not include "[]".
835d7444aac1af1c2c1d5e5b7467ecf6006ee2d8abeSteve Naroff  bool isVariablyModifiedType() const;
8361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// Helper methods to distinguish type categories. All type predicates
838ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb  /// operate on the canonical type, ignoring typedefs and qualifiers.
839e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar
8409b065ddabf572772991a4aadad5bf4921fac5069Tom Care  /// isBuiltinType - returns true if the type is a builtin type.
8419b065ddabf572772991a4aadad5bf4921fac5069Tom Care  bool isBuiltinType() const;
8429b065ddabf572772991a4aadad5bf4921fac5069Tom Care
843e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar  /// isSpecificBuiltinType - Test for a particular builtin type.
844e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar  bool isSpecificBuiltinType(unsigned K) const;
8451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
84696d2c438f5c9ada8229f7f2ac049d2e9957bc954Steve Naroff  /// isIntegerType() does *not* include complex integers (a GCC extension).
84796d2c438f5c9ada8229f7f2ac049d2e9957bc954Steve Naroff  /// isComplexIntegerType() can be used to test for complex integers.
8485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isIntegerType() const;     // C99 6.2.5p17 (int, char, bool, enum)
84913b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff  bool isEnumeralType() const;
85013b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff  bool isBooleanType() const;
85113b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff  bool isCharType() const;
85277a52233f7c0f162672652051bfe78b65ad4f789Douglas Gregor  bool isWideCharType() const;
85320093b4bf698f292c664676987541d5103b65b15Douglas Gregor  bool isAnyCharacterType() const;
8549d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor  bool isIntegralType(ASTContext &Ctx) const;
85520093b4bf698f292c664676987541d5103b65b15Douglas Gregor
8562ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor  /// \brief Determine whether this type is an integral or enumeration type.
8572ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor  bool isIntegralOrEnumerationType() const;
8582ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor
8595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// Floating point categories.
8605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isRealFloatingType() const; // C99 6.2.5p10 (float, double, long double)
86102f62a9fedbc370fba081303399410a3afdde29fSteve Naroff  /// isComplexType() does *not* include complex integers (a GCC extension).
86202f62a9fedbc370fba081303399410a3afdde29fSteve Naroff  /// isComplexIntegerType() can be used to test for complex integers.
8635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isComplexType() const;      // C99 6.2.5p11 (complex)
864f23d364084d1aabea688222780d6fc1dd8c7f78cChris Lattner  bool isAnyComplexType() const;   // C99 6.2.5p11 (complex) + Complex Int.
8655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isFloatingType() const;     // C99 6.2.5p11 (real floating + complex)
8665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isRealType() const;         // C99 6.2.5p17 (real floating + integer)
8675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isArithmeticType() const;   // C99 6.2.5p18 (integer + floating)
868c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  bool isVoidType() const;         // C99 6.2.5p19
869c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  bool isDerivedType() const;      // C99 6.2.5p20
870c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  bool isScalarType() const;       // C99 6.2.5p21 (arithmetic + pointers)
871d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor  bool isAggregateType() const;
8721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
873c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  // Type Predicates: Check to see if this type is structurally the specified
874ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb  // type, ignoring typedefs and qualifiers.
875c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  bool isFunctionType() const;
876183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  bool isFunctionNoProtoType() const { return getAs<FunctionNoProtoType>(); }
877183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  bool isFunctionProtoType() const { return getAs<FunctionProtoType>(); }
878befee48ff2a1dab236c5700f00ecca1cfdcd5837Chris Lattner  bool isPointerType() const;
87958f9f2c884af6b72d036b746a016d8031d31cb7aSteve Naroff  bool isAnyPointerType() const;   // Any C pointer or ObjC object pointer
8805618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  bool isBlockPointerType() const;
8817154a77e7c1f23418342d3b72836ab504aa7821eSteve Naroff  bool isVoidPointerType() const;
882a1d9fdea79ba7bbd71862b9f9f78f5f117331fc7Chris Lattner  bool isReferenceType() const;
8837c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  bool isLValueReferenceType() const;
8847c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  bool isRValueReferenceType() const;
885bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner  bool isFunctionPointerType() const;
886f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  bool isMemberPointerType() const;
887f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  bool isMemberFunctionPointerType() const;
888c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  bool isArrayType() const;
889c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  bool isConstantArrayType() const;
890c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  bool isIncompleteArrayType() const;
891c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  bool isVariableArrayType() const;
892898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  bool isDependentSizedArrayType() const;
893c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  bool isRecordType() const;
8941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  bool isClassType() const;
8951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  bool isStructureType() const;
896fb87b89fc9eb103e19fb8e4b925c23f0bd091b99Douglas Gregor  bool isStructureOrClassType() const;
8974cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroff  bool isUnionType() const;
898368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner  bool isComplexIntegerType() const;            // GCC _Complex integer type.
899368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner  bool isVectorType() const;                    // GCC vector type.
900213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman  bool isExtVectorType() const;                 // Extended vector type.
901d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff  bool isObjCObjectPointerType() const;         // Pointer to *any* ObjC object.
90214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  // FIXME: change this to 'raw' interface type, so we can used 'interface' type
90314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  // for the common case.
904c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool isObjCObjectType() const;                // NSString or typeof(*(id)0)
905368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner  bool isObjCQualifiedInterfaceType() const;    // NSString<foo>
906368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner  bool isObjCQualifiedIdType() const;           // id<foo>
907470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroff  bool isObjCQualifiedClassType() const;        // Class<foo>
90814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  bool isObjCIdType() const;                    // id
90914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  bool isObjCClassType() const;                 // Class
91013dcd00615de5c4279d97bdf63cd5f0a14fd9dccFariborz Jahanian  bool isObjCSelType() const;                 // Class
911de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff  bool isObjCBuiltinType() const;               // 'id' or 'Class'
91272c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor  bool isTemplateTypeParmType() const;          // C++ template type parameter
9136e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl  bool isNullPtrType() const;                   // C++0x nullptr_t
914898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
915898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// isDependentType - Whether this type is a dependent type, meaning
9161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// that its definition somehow depends on a template parameter
917898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// (C++ [temp.dep.type]).
918898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  bool isDependentType() const { return Dependent; }
919063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  bool isOverloadableType() const;
92072c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor
9214033642464e8ba0982f88f34cffad808d247b393Douglas Gregor  /// \brief Determine wither this type is a C++ elaborated-type-specifier.
9224033642464e8ba0982f88f34cffad808d247b393Douglas Gregor  bool isElaboratedTypeSpecifier() const;
9234033642464e8ba0982f88f34cffad808d247b393Douglas Gregor
9248958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar  /// hasPointerRepresentation - Whether this type is represented
9258958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar  /// natively as a pointer; this includes pointers, references, block
9268958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar  /// pointers, and Objective-C interface, qualified id, and qualified
9276e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl  /// interface types, as well as nullptr_t.
9288958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar  bool hasPointerRepresentation() const;
9298958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar
930820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian  /// hasObjCPointerRepresentation - Whether this type can represent
931820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian  /// an objective pointer type for the purpose of GC'ability
9321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  bool hasObjCPointerRepresentation() const;
933820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian
9348eee119bf4f1693dde17b8552c1f9f81bf2b681eDouglas Gregor  /// \brief Determine whether this type has a floating-point representation
9358eee119bf4f1693dde17b8552c1f9f81bf2b681eDouglas Gregor  /// of some sort, e.g., it is a floating-point type or a vector thereof.
9368eee119bf4f1693dde17b8552c1f9f81bf2b681eDouglas Gregor  bool hasFloatingRepresentation() const;
9378eee119bf4f1693dde17b8552c1f9f81bf2b681eDouglas Gregor
938c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  // Type Checking Functions: Check to see if this type is structurally the
939f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner  // specified type, ignoring typedefs and qualifiers, and return a pointer to
940f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner  // the best type we can.
941769c9cfc6e06bd9d8ffe7a4397b939f19b0e4dc3Ted Kremenek  const RecordType *getAsStructureType() const;
942898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// NOTE: getAs*ArrayType are methods on ASTContext.
943c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  const RecordType *getAsUnionType() const;
9444cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroff  const ComplexType *getAsComplexIntegerType() const; // GCC complex int type.
94514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  // The following is a convenience method that returns an ObjCObjectPointerType
94614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  // for object declared using an interface.
94714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  const ObjCObjectPointerType *getAsObjCInterfacePointerType() const;
94814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  const ObjCObjectPointerType *getAsObjCQualifiedIdType() const;
949c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  const ObjCObjectType *getAsObjCQualifiedInterfaceType() const;
950a91d6a6619a91d0ca7102d8ab5678d855f04d850Fariborz Jahanian  const CXXRecordDecl *getCXXRecordDeclForPointerType() const;
9511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
952c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor  /// \brief Retrieves the CXXRecordDecl that this type refers to, either
953c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor  /// because the type is a RecordType or because it is the injected-class-name
954c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor  /// type of a class template or class template partial specialization.
955c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor  CXXRecordDecl *getAsCXXRecordDecl() const;
956c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor
9571a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek  // Member-template getAs<specific type>'.  This scheme will eventually
9581a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek  // replace the specific getAsXXXX methods above.
959183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  //
960183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  // There are some specializations of this member template listed
961183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  // immediately following this class.
9621a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek  template <typename T> const T *getAs() const;
9631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
964c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  /// getArrayElementTypeNoTypeQual - If this is an array type, return the
965c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  /// element type of the array, potentially with type qualifiers missing.
966c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  /// This method should never be used when type qualifiers are meaningful.
967c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  const Type *getArrayElementTypeNoTypeQual() const;
9681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
969f8910df57799256c1897a8610dc52685729ae90eSteve Naroff  /// getPointeeType - If this is a pointer, ObjC object pointer, or block
970f8910df57799256c1897a8610dc52685729ae90eSteve Naroff  /// pointer, this returns the respective pointee.
97114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  QualType getPointeeType() const;
9721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
973bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// getUnqualifiedDesugaredType() - Return the specified type with
974bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// any "sugar" removed from the type, removing any typedefs,
975bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// typeofs, etc., as well as any qualifiers.
976bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  const Type *getUnqualifiedDesugaredType() const;
9771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
9785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// More type predicates useful for type checking/promotion
9795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isPromotableIntegerType() const; // C99 6.3.1.1p2
9805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
9815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isSignedIntegerType - Return true if this is an integer type that is
982d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner  /// signed, according to C99 6.2.5p4 [char, signed char, short, int, long..],
983d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner  /// an enum decl which has a signed representation, or a vector of signed
984d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner  /// integer element type.
9855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isSignedIntegerType() const;
9865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
9875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isUnsignedIntegerType - Return true if this is an integer type that is
988d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner  /// unsigned, according to C99 6.2.5p6 [which returns true for _Bool], an enum
989d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner  /// decl which has an unsigned representation, or a vector of unsigned integer
990d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner  /// element type.
9915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isUnsignedIntegerType() const;
992d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner
9935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isConstantSizeType - Return true if this is not a variable sized type,
9949bfa73c5ab7bf4b0e749d04f29da6884e8d5bd9fChris Lattner  /// according to the rules of C99 6.7.5p3.  It is not legal to call this on
9959bfa73c5ab7bf4b0e749d04f29da6884e8d5bd9fChris Lattner  /// incomplete types.
9963c2b3170041f69a92904e3bab9b6d654eaf260acEli Friedman  bool isConstantSizeType() const;
997c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner
99822b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman  /// isSpecifierType - Returns true if this type can be represented by some
99922b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman  /// set of type specifiers.
100022b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman  bool isSpecifierType() const;
100122b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman
10020b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor  /// \brief Determine the linkage of this type.
100360e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor  Linkage getLinkage() const;
100460e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
100560e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor  /// \brief Note that the linkage is no longer known.
100660e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor  void ClearLinkageCache();
100760e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
100860e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor  const char *getTypeClassName() const;
10090b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor
1010ead608af31b6c9abeae1ca6d0b75094dac4641c0John McCall  QualType getCanonicalTypeInternal() const {
1011ead608af31b6c9abeae1ca6d0b75094dac4641c0John McCall    return CanonicalType;
1012ead608af31b6c9abeae1ca6d0b75094dac4641c0John McCall  }
1013ead608af31b6c9abeae1ca6d0b75094dac4641c0John McCall  CanQualType getCanonicalTypeUnqualified() const; // in CanonicalType.h
1014c36d405a02fab41f6c45cb2bc750d64949742903Chris Lattner  void dump() const;
10155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *) { return true; }
1016be191100e034b23a3e13053757a57b7f5068c24aArgyrios Kyrtzidis
1017be191100e034b23a3e13053757a57b7f5068c24aArgyrios Kyrtzidis  friend class PCHReader;
1018be191100e034b23a3e13053757a57b7f5068c24aArgyrios Kyrtzidis  friend class PCHWriter;
10195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
10205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1021183700f494ec9b6701b6efe82bcb25f4c79ba561John McCalltemplate <> inline const TypedefType *Type::getAs() const {
1022183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  return dyn_cast<TypedefType>(this);
1023183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall}
1024183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall
1025183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall// We can do canonical leaf types faster, because we don't have to
1026183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall// worry about preserving child type decoration.
1027183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall#define TYPE(Class, Base)
1028183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall#define LEAF_TYPE(Class) \
1029183700f494ec9b6701b6efe82bcb25f4c79ba561John McCalltemplate <> inline const Class##Type *Type::getAs() const { \
10300953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  return dyn_cast<Class##Type>(CanonicalType); \
1031183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall}
1032183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall#include "clang/AST/TypeNodes.def"
1033183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall
1034183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall
10355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// BuiltinType - This class is used for builtin types like 'int'.  Builtin
10365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// types are always canonical and have a literal name field.
10375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass BuiltinType : public Type {
10385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
10395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  enum Kind {
10405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Void,
10411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
10425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Bool,     // This is bool and/or _Bool.
10435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Char_U,   // This is 'char' for targets where char is unsigned.
10445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    UChar,    // This is explicitly qualified unsigned char.
1045f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith    Char16,   // This is 'char16_t' for C++.
1046f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith    Char32,   // This is 'char32_t' for C++.
10475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    UShort,
10485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    UInt,
10495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ULong,
10505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ULongLong,
10512df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner    UInt128,  // __uint128_t
10521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
10535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Char_S,   // This is 'char' for targets where char is signed.
10545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    SChar,    // This is explicitly qualified signed char.
10552ff9b4c7c8fed9233a0b8de2e9507368c451aab6Argyrios Kyrtzidis    WChar,    // This is 'wchar_t' for C++.
10565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Short,
10575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Int,
10585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Long,
10595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    LongLong,
10602df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner    Int128,   // __int128_t
10611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
10628e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor    Float, Double, LongDouble,
10638e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor
10646e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl    NullPtr,  // This is the type of C++0x 'nullptr'.
10656e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl
1066898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    Overload,  // This represents the type of an overloaded function declaration.
1067e89d15944dd3be750a09805ad21222d2fa9321faAnders Carlsson    Dependent, // This represents the type of a type-dependent expression.
10681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1069de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff    UndeducedAuto, // In C++0x, this represents the type of an auto variable
1070e89d15944dd3be750a09805ad21222d2fa9321faAnders Carlsson                   // that has not been deduced yet.
1071e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall
1072e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall    /// The primitive Objective C 'id' type.  The type pointed to by the
1073e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall    /// user-visible 'id' type.  Only ever shows up in an AST as the base
1074e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall    /// type of an ObjCObjectType.
1075e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall    ObjCId,
1076e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall
1077e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall    /// The primitive Objective C 'Class' type.  The type pointed to by the
1078e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall    /// user-visible 'Class' type.  Only ever shows up in an AST as the
1079e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall    /// base type of an ObjCObjectType.
1080e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall    ObjCClass,
1081e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall
108213dcd00615de5c4279d97bdf63cd5f0a14fd9dccFariborz Jahanian    ObjCSel    // This represents the ObjC 'SEL' type.
10835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
10845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate:
10855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Kind TypeKind;
108660e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
108760e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregorprotected:
108860e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor  virtual Linkage getLinkageImpl() const;
108960e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
10905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
10911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  BuiltinType(Kind K)
10921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    : Type(Builtin, QualType(), /*Dependent=*/(K == Dependent)),
1093898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor      TypeKind(K) {}
10941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
10955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Kind getKind() const { return TypeKind; }
1096e4f2142d00fa5fdb580c4e2413da91882d955381Chris Lattner  const char *getName(const LangOptions &LO) const;
10971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1098bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1099bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1100bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
1101680523a91dd3351389667c8de17121ba7ae82673John McCall  bool isInteger() const {
1102680523a91dd3351389667c8de17121ba7ae82673John McCall    return TypeKind >= Bool && TypeKind <= Int128;
1103680523a91dd3351389667c8de17121ba7ae82673John McCall  }
1104680523a91dd3351389667c8de17121ba7ae82673John McCall
1105680523a91dd3351389667c8de17121ba7ae82673John McCall  bool isSignedInteger() const {
1106680523a91dd3351389667c8de17121ba7ae82673John McCall    return TypeKind >= Char_S && TypeKind <= Int128;
1107680523a91dd3351389667c8de17121ba7ae82673John McCall  }
1108680523a91dd3351389667c8de17121ba7ae82673John McCall
1109680523a91dd3351389667c8de17121ba7ae82673John McCall  bool isUnsignedInteger() const {
1110680523a91dd3351389667c8de17121ba7ae82673John McCall    return TypeKind >= Bool && TypeKind <= UInt128;
1111680523a91dd3351389667c8de17121ba7ae82673John McCall  }
1112680523a91dd3351389667c8de17121ba7ae82673John McCall
1113680523a91dd3351389667c8de17121ba7ae82673John McCall  bool isFloatingPoint() const {
1114680523a91dd3351389667c8de17121ba7ae82673John McCall    return TypeKind >= Float && TypeKind <= LongDouble;
1115680523a91dd3351389667c8de17121ba7ae82673John McCall  }
1116680523a91dd3351389667c8de17121ba7ae82673John McCall
11175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T) { return T->getTypeClass() == Builtin; }
11185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const BuiltinType *) { return true; }
11195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
11205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
11215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ComplexType - C99 6.2.5p11 - Complex values.  This supports the C99 complex
11225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// types (_Complex float etc) as well as the GCC integer complex extensions.
11235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
11245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ComplexType : public Type, public llvm::FoldingSetNode {
11255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType ElementType;
11265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ComplexType(QualType Element, QualType CanonicalPtr) :
11271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    Type(Complex, CanonicalPtr, Element->isDependentType()),
1128898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    ElementType(Element) {
11295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
11305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
113160e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
113260e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregorprotected:
113360e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor  virtual Linkage getLinkageImpl() const;
113460e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
11355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
11365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType getElementType() const { return ElementType; }
11371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1138bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1139bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1140bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
11415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void Profile(llvm::FoldingSetNodeID &ID) {
11425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Profile(ID, getElementType());
11435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
11445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static void Profile(llvm::FoldingSetNodeID &ID, QualType Element) {
11455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ID.AddPointer(Element.getAsOpaquePtr());
11465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
11471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
11485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T) { return T->getTypeClass() == Complex; }
11495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const ComplexType *) { return true; }
11505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
11515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
115268694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar/// PointerType - C99 6.7.5.1 - Pointer Declarators.
1153bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner///
115468694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbarclass PointerType : public Type, public llvm::FoldingSetNode {
1155bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner  QualType PointeeType;
11565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
11575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  PointerType(QualType Pointee, QualType CanonicalPtr) :
115868694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar    Type(Pointer, CanonicalPtr, Pointee->isDependentType()), PointeeType(Pointee) {
11595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
11605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
116160e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
116260e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregorprotected:
116360e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor  virtual Linkage getLinkageImpl() const;
116460e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
11655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
11661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
116768694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar  QualType getPointeeType() const { return PointeeType; }
116868694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar
1169bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1170bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1171bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
11725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void Profile(llvm::FoldingSetNodeID &ID) {
11735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Profile(ID, getPointeeType());
11745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
11755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) {
11765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ID.AddPointer(Pointee.getAsOpaquePtr());
11775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
11781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
11795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T) { return T->getTypeClass() == Pointer; }
11805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const PointerType *) { return true; }
11815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
11825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
11835618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff/// BlockPointerType - pointer to a block type.
11845618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff/// This type is to represent types syntactically represented as
11855618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff/// "void (^)(int)", etc. Pointee is required to always be a function type.
11865618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff///
11875618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroffclass BlockPointerType : public Type, public llvm::FoldingSetNode {
11885618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  QualType PointeeType;  // Block is some kind of pointer type
11895618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  BlockPointerType(QualType Pointee, QualType CanonicalCls) :
11901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    Type(BlockPointer, CanonicalCls, Pointee->isDependentType()),
1191898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    PointeeType(Pointee) {
11925618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  }
11935618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  friend class ASTContext;  // ASTContext creates these.
119460e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
119560e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregorprotected:
119660e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor  virtual Linkage getLinkageImpl() const;
119760e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
11985618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroffpublic:
11991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12005618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  // Get the pointee type. Pointee is required to always be a function type.
12015618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  QualType getPointeeType() const { return PointeeType; }
12025618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff
1203bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1204bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1205bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
12065618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  void Profile(llvm::FoldingSetNodeID &ID) {
12075618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff      Profile(ID, getPointeeType());
12085618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  }
12095618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) {
12105618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff      ID.AddPointer(Pointee.getAsOpaquePtr());
12115618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  }
12121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
12141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == BlockPointer;
12155618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  }
12165618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  static bool classof(const BlockPointerType *) { return true; }
12175618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff};
12185618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff
12197c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// ReferenceType - Base for LValueReferenceType and RValueReferenceType
12205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
122168694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbarclass ReferenceType : public Type, public llvm::FoldingSetNode {
122268694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar  QualType PointeeType;
122368694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar
122454e14c4db764c0636160d26c5bbf491637c83a76John McCall  /// True if the type was originally spelled with an lvalue sigil.
122554e14c4db764c0636160d26c5bbf491637c83a76John McCall  /// This is never true of rvalue references but can also be false
122654e14c4db764c0636160d26c5bbf491637c83a76John McCall  /// on lvalue references because of C++0x [dcl.typedef]p9,
122754e14c4db764c0636160d26c5bbf491637c83a76John McCall  /// as follows:
122854e14c4db764c0636160d26c5bbf491637c83a76John McCall  ///
122954e14c4db764c0636160d26c5bbf491637c83a76John McCall  ///   typedef int &ref;    // lvalue, spelled lvalue
123054e14c4db764c0636160d26c5bbf491637c83a76John McCall  ///   typedef int &&rvref; // rvalue
123154e14c4db764c0636160d26c5bbf491637c83a76John McCall  ///   ref &a;              // lvalue, inner ref, spelled lvalue
123254e14c4db764c0636160d26c5bbf491637c83a76John McCall  ///   ref &&a;             // lvalue, inner ref
123354e14c4db764c0636160d26c5bbf491637c83a76John McCall  ///   rvref &a;            // lvalue, inner ref, spelled lvalue
123454e14c4db764c0636160d26c5bbf491637c83a76John McCall  ///   rvref &&a;           // rvalue, inner ref
123554e14c4db764c0636160d26c5bbf491637c83a76John McCall  bool SpelledAsLValue;
123654e14c4db764c0636160d26c5bbf491637c83a76John McCall
123754e14c4db764c0636160d26c5bbf491637c83a76John McCall  /// True if the inner type is a reference type.  This only happens
123854e14c4db764c0636160d26c5bbf491637c83a76John McCall  /// in non-canonical forms.
123954e14c4db764c0636160d26c5bbf491637c83a76John McCall  bool InnerRef;
124054e14c4db764c0636160d26c5bbf491637c83a76John McCall
12417c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlprotected:
124254e14c4db764c0636160d26c5bbf491637c83a76John McCall  ReferenceType(TypeClass tc, QualType Referencee, QualType CanonicalRef,
124354e14c4db764c0636160d26c5bbf491637c83a76John McCall                bool SpelledAsLValue) :
12447c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl    Type(tc, CanonicalRef, Referencee->isDependentType()),
124554e14c4db764c0636160d26c5bbf491637c83a76John McCall    PointeeType(Referencee), SpelledAsLValue(SpelledAsLValue),
124654e14c4db764c0636160d26c5bbf491637c83a76John McCall    InnerRef(Referencee->isReferenceType()) {
12475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
124860e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
124960e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor  virtual Linkage getLinkageImpl() const;
125060e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
12515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
125254e14c4db764c0636160d26c5bbf491637c83a76John McCall  bool isSpelledAsLValue() const { return SpelledAsLValue; }
125373dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor  bool isInnerRef() const { return InnerRef; }
125473dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor
125554e14c4db764c0636160d26c5bbf491637c83a76John McCall  QualType getPointeeTypeAsWritten() const { return PointeeType; }
125654e14c4db764c0636160d26c5bbf491637c83a76John McCall  QualType getPointeeType() const {
125754e14c4db764c0636160d26c5bbf491637c83a76John McCall    // FIXME: this might strip inner qualifiers; okay?
125854e14c4db764c0636160d26c5bbf491637c83a76John McCall    const ReferenceType *T = this;
125954e14c4db764c0636160d26c5bbf491637c83a76John McCall    while (T->InnerRef)
126054e14c4db764c0636160d26c5bbf491637c83a76John McCall      T = T->PointeeType->getAs<ReferenceType>();
126154e14c4db764c0636160d26c5bbf491637c83a76John McCall    return T->PointeeType;
126254e14c4db764c0636160d26c5bbf491637c83a76John McCall  }
126368694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar
12645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void Profile(llvm::FoldingSetNodeID &ID) {
126554e14c4db764c0636160d26c5bbf491637c83a76John McCall    Profile(ID, PointeeType, SpelledAsLValue);
12665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
126754e14c4db764c0636160d26c5bbf491637c83a76John McCall  static void Profile(llvm::FoldingSetNodeID &ID,
126854e14c4db764c0636160d26c5bbf491637c83a76John McCall                      QualType Referencee,
126954e14c4db764c0636160d26c5bbf491637c83a76John McCall                      bool SpelledAsLValue) {
12705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ID.AddPointer(Referencee.getAsOpaquePtr());
127154e14c4db764c0636160d26c5bbf491637c83a76John McCall    ID.AddBoolean(SpelledAsLValue);
12725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
12735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
12747c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  static bool classof(const Type *T) {
12757c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl    return T->getTypeClass() == LValueReference ||
12767c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl           T->getTypeClass() == RValueReference;
12777c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  }
12785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const ReferenceType *) { return true; }
12797c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl};
12807c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl
12817c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// LValueReferenceType - C++ [dcl.ref] - Lvalue reference
12827c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl///
12837c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlclass LValueReferenceType : public ReferenceType {
128454e14c4db764c0636160d26c5bbf491637c83a76John McCall  LValueReferenceType(QualType Referencee, QualType CanonicalRef,
128554e14c4db764c0636160d26c5bbf491637c83a76John McCall                      bool SpelledAsLValue) :
128654e14c4db764c0636160d26c5bbf491637c83a76John McCall    ReferenceType(LValueReference, Referencee, CanonicalRef, SpelledAsLValue)
128754e14c4db764c0636160d26c5bbf491637c83a76John McCall  {}
12887c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  friend class ASTContext; // ASTContext creates these
12897c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlpublic:
1290bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1291bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1292bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
12937c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  static bool classof(const Type *T) {
12947c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl    return T->getTypeClass() == LValueReference;
12957c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  }
12967c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  static bool classof(const LValueReferenceType *) { return true; }
12977c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl};
12987c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl
12997c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// RValueReferenceType - C++0x [dcl.ref] - Rvalue reference
13007c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl///
13017c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlclass RValueReferenceType : public ReferenceType {
13027c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  RValueReferenceType(QualType Referencee, QualType CanonicalRef) :
130354e14c4db764c0636160d26c5bbf491637c83a76John McCall    ReferenceType(RValueReference, Referencee, CanonicalRef, false) {
13047c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  }
13057c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  friend class ASTContext; // ASTContext creates these
13067c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlpublic:
1307bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1308bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1309bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
13107c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  static bool classof(const Type *T) {
13117c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl    return T->getTypeClass() == RValueReference;
13127c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  }
13137c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  static bool classof(const RValueReferenceType *) { return true; }
1314f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl};
1315f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl
1316f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl/// MemberPointerType - C++ 8.3.3 - Pointers to members
1317f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl///
1318f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlclass MemberPointerType : public Type, public llvm::FoldingSetNode {
1319f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  QualType PointeeType;
1320f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  /// The class of which the pointee is a member. Must ultimately be a
1321f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  /// RecordType, but could be a typedef or a template parameter too.
1322f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  const Type *Class;
1323f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl
1324f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  MemberPointerType(QualType Pointee, const Type *Cls, QualType CanonicalPtr) :
1325f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    Type(MemberPointer, CanonicalPtr,
1326f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl         Cls->isDependentType() || Pointee->isDependentType()),
1327f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    PointeeType(Pointee), Class(Cls) {
1328f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  }
1329f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  friend class ASTContext; // ASTContext creates these.
133060e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
133160e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregorprotected:
133260e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor  virtual Linkage getLinkageImpl() const;
133360e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
1334f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlpublic:
1335f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl
1336f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  QualType getPointeeType() const { return PointeeType; }
1337f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl
1338f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  const Type *getClass() const { return Class; }
1339f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl
1340bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1341bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1342bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
1343f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  void Profile(llvm::FoldingSetNodeID &ID) {
1344f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    Profile(ID, getPointeeType(), getClass());
1345f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  }
1346f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee,
1347f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl                      const Type *Class) {
1348f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    ID.AddPointer(Pointee.getAsOpaquePtr());
1349f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    ID.AddPointer(Class);
1350f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  }
1351f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl
1352f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  static bool classof(const Type *T) {
1353f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    return T->getTypeClass() == MemberPointer;
1354f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  }
1355f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  static bool classof(const MemberPointerType *) { return true; }
13565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
13575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
13585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ArrayType - C99 6.7.5.2 - Array Declarators.
13595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
13602e7d352dbec06755105237afba183492d31d03cbTed Kremenekclass ArrayType : public Type, public llvm::FoldingSetNode {
13615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
13625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// ArraySizeModifier - Capture whether this is a normal array (e.g. int X[4])
1363898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// an array with a static size (e.g. int X[static 4]), or an array
1364898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// with a star size (e.g. int X[*]).
1365898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// 'static' is only allowed on function parameters.
13665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  enum ArraySizeModifier {
13675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Normal, Static, Star
13685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
13695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate:
1370fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  /// ElementType - The element type of the array.
1371fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  QualType ElementType;
13721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1373ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek  // NOTE: VC++ treats enums as signed, avoid using the ArraySizeModifier enum
1374c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff  /// NOTE: These fields are packed into the bitfields space in the Type class.
1375ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek  unsigned SizeModifier : 2;
13761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1377c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff  /// IndexTypeQuals - Capture qualifiers in declarations like:
1378c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff  /// 'int X[static restrict 4]'. For function parameters only.
1379c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff  unsigned IndexTypeQuals : 3;
13801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1381fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroffprotected:
1382898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  // C++ [temp.dep.type]p1:
1383898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  //   A type is dependent if it is...
1384898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  //     - an array type constructed from any dependent type or whose
1385898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  //       size is specified by a constant expression that is
1386898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  //       value-dependent,
1387c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff  ArrayType(TypeClass tc, QualType et, QualType can,
1388c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff            ArraySizeModifier sm, unsigned tq)
1389898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    : Type(tc, can, et->isDependentType() || tc == DependentSizedArray),
1390898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor      ElementType(et), SizeModifier(sm), IndexTypeQuals(tq) {}
1391898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
1392fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  friend class ASTContext;  // ASTContext creates these.
139360e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
139460e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor  virtual Linkage getLinkageImpl() const;
139560e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
1396fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroffpublic:
1397fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  QualType getElementType() const { return ElementType; }
1398ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek  ArraySizeModifier getSizeModifier() const {
1399ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek    return ArraySizeModifier(SizeModifier);
1400ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek  }
14010953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  Qualifiers getIndexTypeQualifiers() const {
14020953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return Qualifiers::fromCVRMask(IndexTypeQuals);
14030953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
14040953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  unsigned getIndexTypeCVRQualifiers() const { return IndexTypeQuals; }
14051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1406fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  static bool classof(const Type *T) {
1407fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff    return T->getTypeClass() == ConstantArray ||
1408c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman           T->getTypeClass() == VariableArray ||
1409898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor           T->getTypeClass() == IncompleteArray ||
1410898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor           T->getTypeClass() == DependentSizedArray;
1411fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  }
1412fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  static bool classof(const ArrayType *) { return true; }
1413fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff};
1414fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff
14157e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// ConstantArrayType - This class represents the canonical version of
14167e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// C arrays with a specified constant size.  For example, the canonical
14177e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// type for 'int A[4 + 4*100]' is a ConstantArrayType where the element
14187e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// type is 'int' and the size is 404.
14192e7d352dbec06755105237afba183492d31d03cbTed Kremenekclass ConstantArrayType : public ArrayType {
1420fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  llvm::APInt Size; // Allows us to unique the type.
14211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
14220be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner  ConstantArrayType(QualType et, QualType can, const llvm::APInt &size,
1423c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff                    ArraySizeModifier sm, unsigned tq)
14247e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor    : ArrayType(ConstantArray, et, can, sm, tq),
14257e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor      Size(size) {}
14267e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregorprotected:
14277e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  ConstantArrayType(TypeClass tc, QualType et, QualType can,
14287e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor                    const llvm::APInt &size, ArraySizeModifier sm, unsigned tq)
14297e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor    : ArrayType(tc, et, can, sm, tq), Size(size) {}
1430fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  friend class ASTContext;  // ASTContext creates these.
1431fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroffpublic:
1432c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  const llvm::APInt &getSize() const { return Size; }
1433bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1434bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1435bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
1436fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  void Profile(llvm::FoldingSetNodeID &ID) {
14371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    Profile(ID, getElementType(), getSize(),
14380953e767ff7817f97b3ab20896b229891eeff45bJohn McCall            getSizeModifier(), getIndexTypeCVRQualifiers());
1439fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  }
1440fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  static void Profile(llvm::FoldingSetNodeID &ID, QualType ET,
14410be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner                      const llvm::APInt &ArraySize, ArraySizeModifier SizeMod,
14420be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner                      unsigned TypeQuals) {
1443fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff    ID.AddPointer(ET.getAsOpaquePtr());
1444fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff    ID.AddInteger(ArraySize.getZExtValue());
14450be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner    ID.AddInteger(SizeMod);
14460be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner    ID.AddInteger(TypeQuals);
1447fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  }
14487e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  static bool classof(const Type *T) {
144946a617a792bfab0d9b1e057371ea3b9540802226John McCall    return T->getTypeClass() == ConstantArray;
1450fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  }
1451fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  static bool classof(const ConstantArrayType *) { return true; }
1452fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff};
1453fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff
1454da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// IncompleteArrayType - This class represents C arrays with an unspecified
1455da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// size.  For example 'int A[]' has an IncompleteArrayType where the element
1456da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// type is 'int' and the size is unspecified.
1457c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedmanclass IncompleteArrayType : public ArrayType {
14587e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor
1459c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman  IncompleteArrayType(QualType et, QualType can,
14607e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor                      ArraySizeModifier sm, unsigned tq)
1461c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman    : ArrayType(IncompleteArray, et, can, sm, tq) {}
1462c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman  friend class ASTContext;  // ASTContext creates these.
1463c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedmanpublic:
1464bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1465bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1466bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
14671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
14681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == IncompleteArray;
1469c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman  }
1470c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman  static bool classof(const IncompleteArrayType *) { return true; }
14711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1472c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman  friend class StmtIteratorBase;
14731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1474c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman  void Profile(llvm::FoldingSetNodeID &ID) {
14750953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Profile(ID, getElementType(), getSizeModifier(),
14760953e767ff7817f97b3ab20896b229891eeff45bJohn McCall            getIndexTypeCVRQualifiers());
1477c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman  }
14781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
14790be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner  static void Profile(llvm::FoldingSetNodeID &ID, QualType ET,
14800be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner                      ArraySizeModifier SizeMod, unsigned TypeQuals) {
1481c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman    ID.AddPointer(ET.getAsOpaquePtr());
14820be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner    ID.AddInteger(SizeMod);
14830be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner    ID.AddInteger(TypeQuals);
1484c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman  }
1485c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman};
1486c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman
1487da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// VariableArrayType - This class represents C arrays with a specified size
1488da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// which is not an integer-constant-expression.  For example, 'int s[x+foo()]'.
1489da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// Since the size expression is an arbitrary expression, we store it as such.
1490da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner///
1491da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// Note: VariableArrayType's aren't uniqued (since the expressions aren't) and
1492da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// should not be: two lexically equivalent variable array types could mean
1493da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// different things, for example, these variables do not have the same type
1494da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// dynamically:
1495da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner///
1496da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// void foo(int x) {
1497da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner///   int Y[x];
1498da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner///   ++x;
1499da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner///   int Z[x];
1500da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// }
1501da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner///
15022e7d352dbec06755105237afba183492d31d03cbTed Kremenekclass VariableArrayType : public ArrayType {
15031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// SizeExpr - An assignment expression. VLA's are only permitted within
15041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// a function block.
1505b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek  Stmt *SizeExpr;
15067e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  /// Brackets - The left and right array brackets.
15077e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  SourceRange Brackets;
15087e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor
1509c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff  VariableArrayType(QualType et, QualType can, Expr *e,
15107e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor                    ArraySizeModifier sm, unsigned tq,
15117e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor                    SourceRange brackets)
15127e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor    : ArrayType(VariableArray, et, can, sm, tq),
15137e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor      SizeExpr((Stmt*) e), Brackets(brackets) {}
15145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
15154b05b1dee6cc65ae61d93dab7edff72710f24589Ted Kremenek  virtual void Destroy(ASTContext& C);
15164b05b1dee6cc65ae61d93dab7edff72710f24589Ted Kremenek
15175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
15181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Expr *getSizeExpr() const {
1519b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek    // We use C-style casts instead of cast<> here because we do not wish
1520b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek    // to have a dependency of Type.h on Stmt.h/Expr.h.
1521b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek    return (Expr*) SizeExpr;
1522b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek  }
15237e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  SourceRange getBracketsRange() const { return Brackets; }
15247e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  SourceLocation getLBracketLoc() const { return Brackets.getBegin(); }
15257e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  SourceLocation getRBracketLoc() const { return Brackets.getEnd(); }
15261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1527bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1528bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1529bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
15301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
15311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == VariableArray;
15325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
1533fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  static bool classof(const VariableArrayType *) { return true; }
15341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
153592866e2e90f6d93fb95e25a7ac4438e239d89ce6Ted Kremenek  friend class StmtIteratorBase;
15361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
15372bd24ba6d10f8c811c8e2a57c8397e07082ba497Ted Kremenek  void Profile(llvm::FoldingSetNodeID &ID) {
1538bc5e150b6d94cf131f7d01bc715571b741c5b408Chris Lattner    assert(0 && "Cannnot unique VariableArrayTypes.");
15392bd24ba6d10f8c811c8e2a57c8397e07082ba497Ted Kremenek  }
15405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
15415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1542898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// DependentSizedArrayType - This type represents an array type in
1543898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// C++ whose size is a value-dependent expression. For example:
1544cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor///
1545cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor/// \code
15461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// template<typename T, int Size>
1547898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// class array {
1548898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor///   T data[Size];
1549898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// };
1550cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor/// \endcode
1551cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor///
1552898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// For these types, we won't actually know what the array bound is
1553898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// until template instantiation occurs, at which point this will
1554898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// become either a ConstantArrayType or a VariableArrayType.
1555898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorclass DependentSizedArrayType : public ArrayType {
155604d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor  ASTContext &Context;
15571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1558cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor  /// \brief An assignment expression that will instantiate to the
1559898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// size of the array.
1560cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor  ///
1561cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor  /// The expression itself might be NULL, in which case the array
1562cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor  /// type will have its size deduced from an initializer.
1563898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  Stmt *SizeExpr;
1564cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor
15657e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  /// Brackets - The left and right array brackets.
15667e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  SourceRange Brackets;
15671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
15681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  DependentSizedArrayType(ASTContext &Context, QualType et, QualType can,
156904d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor                          Expr *e, ArraySizeModifier sm, unsigned tq,
15707e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor                          SourceRange brackets)
15717e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor    : ArrayType(DependentSizedArray, et, can, sm, tq),
157204d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor      Context(Context), SizeExpr((Stmt*) e), Brackets(brackets) {}
1573898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  friend class ASTContext;  // ASTContext creates these.
1574898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  virtual void Destroy(ASTContext& C);
1575898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
1576898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorpublic:
15771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Expr *getSizeExpr() const {
1578898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    // We use C-style casts instead of cast<> here because we do not wish
1579898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    // to have a dependency of Type.h on Stmt.h/Expr.h.
1580898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    return (Expr*) SizeExpr;
1581898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  }
15827e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  SourceRange getBracketsRange() const { return Brackets; }
15837e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  SourceLocation getLBracketLoc() const { return Brackets.getBegin(); }
15847e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  SourceLocation getRBracketLoc() const { return Brackets.getEnd(); }
15851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1586bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1587bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1588bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
15891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
15901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == DependentSizedArray;
1591898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  }
1592898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  static bool classof(const DependentSizedArrayType *) { return true; }
15931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1594898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  friend class StmtIteratorBase;
15951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
15961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1597898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  void Profile(llvm::FoldingSetNodeID &ID) {
15981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    Profile(ID, Context, getElementType(),
15990953e767ff7817f97b3ab20896b229891eeff45bJohn McCall            getSizeModifier(), getIndexTypeCVRQualifiers(), getSizeExpr());
1600898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  }
16011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
16021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static void Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context,
16031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                      QualType ET, ArraySizeModifier SizeMod,
160404d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor                      unsigned TypeQuals, Expr *E);
1605898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor};
1606898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
1607f6ddb737cb882ffbf0b75a9abd50b930cc2b9068Douglas Gregor/// DependentSizedExtVectorType - This type represent an extended vector type
16089cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// where either the type or size is dependent. For example:
16099cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// @code
16109cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// template<typename T, int Size>
16119cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// class vector {
16129cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor///   typedef T __attribute__((ext_vector_type(Size))) type;
16139cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// }
16149cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// @endcode
16152ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregorclass DependentSizedExtVectorType : public Type, public llvm::FoldingSetNode {
16162ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor  ASTContext &Context;
16179cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor  Expr *SizeExpr;
16189cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor  /// ElementType - The element type of the array.
16199cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor  QualType ElementType;
16209cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor  SourceLocation loc;
16211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
16221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  DependentSizedExtVectorType(ASTContext &Context, QualType ElementType,
16232ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor                              QualType can, Expr *SizeExpr, SourceLocation loc)
16241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    : Type (DependentSizedExtVector, can, true),
16251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      Context(Context), SizeExpr(SizeExpr), ElementType(ElementType),
16262ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor      loc(loc) {}
16279cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor  friend class ASTContext;
16289cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor  virtual void Destroy(ASTContext& C);
16299cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor
16309cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregorpublic:
16312ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor  Expr *getSizeExpr() const { return SizeExpr; }
16329cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor  QualType getElementType() const { return ElementType; }
16339cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor  SourceLocation getAttributeLoc() const { return loc; }
16349cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor
1635bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1636bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1637bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
16381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
16391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == DependentSizedExtVector;
16409cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor  }
16411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const DependentSizedExtVectorType *) { return true; }
16422ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor
16432ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor  void Profile(llvm::FoldingSetNodeID &ID) {
16442ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor    Profile(ID, Context, getElementType(), getSizeExpr());
16452ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor  }
16461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
16472ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor  static void Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context,
16482ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor                      QualType ElementType, Expr *SizeExpr);
16499cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor};
16501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
16519cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor
165273322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// VectorType - GCC generic vector type. This type is created using
16531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// __attribute__((vector_size(n)), where "n" specifies the vector size in
165482287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson/// bytes; or from an Altivec __vector or vector declaration.
165582287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson/// Since the constructor takes the number of vector elements, the
165673322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// client is responsible for converting the size into the number of elements.
16575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass VectorType : public Type, public llvm::FoldingSetNode {
1658788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattnerpublic:
1659788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner  enum AltiVecSpecific {
1660788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner    NotAltiVec,  // is not AltiVec vector
1661788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner    AltiVec,     // is AltiVec vector
1662788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner    Pixel,       // is AltiVec 'vector Pixel'
1663788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner    Bool         // is AltiVec 'vector bool ...'
1664788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner  };
166573322924127c873c13101b705dd823f5539ffa5fSteve Naroffprotected:
16665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// ElementType - The element type of the vector.
16675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType ElementType;
16681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
16695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// NumElements - The number of elements in the vector.
16705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned NumElements;
16711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1672788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner  AltiVecSpecific AltiVecSpec;
167382287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson
167482287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson  VectorType(QualType vecType, unsigned nElements, QualType canonType,
1675788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner      AltiVecSpecific altiVecSpec) :
16761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    Type(Vector, canonType, vecType->isDependentType()),
1677788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner    ElementType(vecType), NumElements(nElements), AltiVecSpec(altiVecSpec) {}
16781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  VectorType(TypeClass tc, QualType vecType, unsigned nElements,
1679788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner             QualType canonType, AltiVecSpecific altiVecSpec)
16801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    : Type(tc, canonType, vecType->isDependentType()), ElementType(vecType),
1681788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner      NumElements(nElements), AltiVecSpec(altiVecSpec) {}
16825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
168360e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
168460e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor  virtual Linkage getLinkageImpl() const;
168560e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
16865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
16871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
16885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType getElementType() const { return ElementType; }
16891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  unsigned getNumElements() const { return NumElements; }
16905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1691bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1692bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1693bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
1694788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner  AltiVecSpecific getAltiVecSpecific() const { return AltiVecSpec; }
1695788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner
16965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void Profile(llvm::FoldingSetNodeID &ID) {
1697788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner    Profile(ID, getElementType(), getNumElements(), getTypeClass(), AltiVecSpec);
16985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
16991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static void Profile(llvm::FoldingSetNodeID &ID, QualType ElementType,
170082287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson                      unsigned NumElements, TypeClass TypeClass,
1701788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner                      unsigned AltiVecSpec) {
17025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ID.AddPointer(ElementType.getAsOpaquePtr());
17035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ID.AddInteger(NumElements);
170473322924127c873c13101b705dd823f5539ffa5fSteve Naroff    ID.AddInteger(TypeClass);
1705788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner    ID.AddInteger(AltiVecSpec);
170673322924127c873c13101b705dd823f5539ffa5fSteve Naroff  }
17070b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor
17081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
17091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == Vector || T->getTypeClass() == ExtVector;
17105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
17115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const VectorType *) { return true; }
17125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
17135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1714213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman/// ExtVectorType - Extended vector type. This type is created using
1715213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman/// __attribute__((ext_vector_type(n)), where "n" is the number of elements.
1716213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman/// Unlike vector_size, ext_vector_type is only allowed on typedef's. This
1717fcac0fff877a461bc5d5a57e6c6727a4c819d95aSteve Naroff/// class enables syntactic extensions, like Vector Components for accessing
1718fcac0fff877a461bc5d5a57e6c6727a4c819d95aSteve Naroff/// points, colors, and textures (modeled after OpenGL Shading Language).
1719213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begemanclass ExtVectorType : public VectorType {
1720213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman  ExtVectorType(QualType vecType, unsigned nElements, QualType canonType) :
1721788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner    VectorType(ExtVector, vecType, nElements, canonType, NotAltiVec) {}
172273322924127c873c13101b705dd823f5539ffa5fSteve Naroff  friend class ASTContext;  // ASTContext creates these.
172373322924127c873c13101b705dd823f5539ffa5fSteve Naroffpublic:
172488dca0464804b8b26ae605f89784c927e8493dddChris Lattner  static int getPointAccessorIdx(char c) {
172588dca0464804b8b26ae605f89784c927e8493dddChris Lattner    switch (c) {
172688dca0464804b8b26ae605f89784c927e8493dddChris Lattner    default: return -1;
172788dca0464804b8b26ae605f89784c927e8493dddChris Lattner    case 'x': return 0;
172888dca0464804b8b26ae605f89784c927e8493dddChris Lattner    case 'y': return 1;
172988dca0464804b8b26ae605f89784c927e8493dddChris Lattner    case 'z': return 2;
173088dca0464804b8b26ae605f89784c927e8493dddChris Lattner    case 'w': return 3;
173188dca0464804b8b26ae605f89784c927e8493dddChris Lattner    }
1732e1b31fedbc006e6e4071bbb4f74c6116b56cfa9fSteve Naroff  }
1733353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman  static int getNumericAccessorIdx(char c) {
173488dca0464804b8b26ae605f89784c927e8493dddChris Lattner    switch (c) {
1735353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      default: return -1;
1736353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '0': return 0;
1737353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '1': return 1;
1738353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '2': return 2;
1739353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '3': return 3;
1740353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '4': return 4;
1741353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '5': return 5;
1742353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '6': return 6;
1743353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '7': return 7;
1744353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '8': return 8;
1745353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '9': return 9;
1746131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman      case 'A':
1747353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case 'a': return 10;
1748131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman      case 'B':
1749353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case 'b': return 11;
1750131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman      case 'C':
1751353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case 'c': return 12;
1752131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman      case 'D':
1753353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case 'd': return 13;
1754131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman      case 'E':
1755353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case 'e': return 14;
1756131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman      case 'F':
1757353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case 'f': return 15;
175888dca0464804b8b26ae605f89784c927e8493dddChris Lattner    }
1759e1b31fedbc006e6e4071bbb4f74c6116b56cfa9fSteve Naroff  }
17601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1761b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner  static int getAccessorIdx(char c) {
1762b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner    if (int idx = getPointAccessorIdx(c)+1) return idx-1;
1763353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman    return getNumericAccessorIdx(c);
1764b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner  }
17651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
176688dca0464804b8b26ae605f89784c927e8493dddChris Lattner  bool isAccessorWithinNumElements(char c) const {
1767b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner    if (int idx = getAccessorIdx(c)+1)
176888dca0464804b8b26ae605f89784c927e8493dddChris Lattner      return unsigned(idx-1) < NumElements;
176988dca0464804b8b26ae605f89784c927e8493dddChris Lattner    return false;
1770e1b31fedbc006e6e4071bbb4f74c6116b56cfa9fSteve Naroff  }
1771bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1772bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1773bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
17741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
17751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == ExtVector;
177673322924127c873c13101b705dd823f5539ffa5fSteve Naroff  }
1777213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman  static bool classof(const ExtVectorType *) { return true; }
177873322924127c873c13101b705dd823f5539ffa5fSteve Naroff};
177973322924127c873c13101b705dd823f5539ffa5fSteve Naroff
17805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// FunctionType - C99 6.7.5.3 - Function Declarators.  This is the common base
178172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// class of FunctionNoProtoType and FunctionProtoType.
17825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
17835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass FunctionType : public Type {
1784bef0efd11bc4430a3ee437a3213cec5c18af855aChris Lattner  virtual void ANCHOR(); // Key function for FunctionType.
1785bef0efd11bc4430a3ee437a3213cec5c18af855aChris Lattner
17865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// SubClassData - This field is owned by the subclass, put here to pack
17875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// tightly with the ivars in Type.
17885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool SubClassData : 1;
1789971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis
179072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  /// TypeQuals - Used only by FunctionProtoType, put here to pack with the
1791971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis  /// other bitfields.
179272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  /// The qualifiers are part of FunctionProtoType because...
1793971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis  ///
1794971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis  /// C++ 8.3.5p4: The return type, the parameter type list and the
1795971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis  /// cv-qualifier-seq, [...], are part of the function type.
1796971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis  ///
1797971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis  unsigned TypeQuals : 3;
17982455636163fdd18581d7fdae816433f886d88213Mike Stump
17992455636163fdd18581d7fdae816433f886d88213Mike Stump  /// NoReturn - Indicates if the function type is attribute noreturn.
18002455636163fdd18581d7fdae816433f886d88213Mike Stump  unsigned NoReturn : 1;
18011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1802425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola  /// RegParm - How many arguments to pass inreg.
1803425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola  unsigned RegParm : 3;
1804425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola
1805ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor  /// CallConv - The calling convention used by the function.
1806f813a2c03fcb05381b3252010435f557eb6b3cdeDouglas Gregor  unsigned CallConv : 3;
1807ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor
18085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // The type returned by the function.
18095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType ResultType;
1810264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola
1811264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola public:
1812264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola  // This class is used for passing arround the information needed to
1813264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola  // construct a call. It is not actually used for storage, just for
1814264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola  // factoring together common arguments.
1815425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola  // If you add a field (say Foo), other than the obvious places (both, constructors,
1816425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola  // compile failures), what you need to update is
1817425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola  // * Operetor==
1818425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola  // * getFoo
1819425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola  // * withFoo
1820425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola  // * functionType. Add Foo, getFoo.
1821425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola  // * ASTContext::getFooType
1822425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola  // * ASTContext::mergeFunctionTypes
1823425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola  // * FunctionNoProtoType::Profile
1824425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola  // * FunctionProtoType::Profile
1825425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola  // * TypePrinter::PrintFunctionProto
1826425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola  // * PCH read and write
1827425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola  // * Codegen
1828425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola
1829264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola  class ExtInfo {
1830264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola   public:
1831264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    // Constructor with no defaults. Use this when you know that you
1832264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    // have all the elements (when reading a PCH file for example).
1833425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola    ExtInfo(bool noReturn, unsigned regParm, CallingConv cc) :
1834425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola        NoReturn(noReturn), RegParm(regParm), CC(cc) {}
1835264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola
1836264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    // Constructor with all defaults. Use when for example creating a
1837264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    // function know to use defaults.
1838425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola    ExtInfo() : NoReturn(false), RegParm(0), CC(CC_Default) {}
1839264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola
1840264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    bool getNoReturn() const { return NoReturn; }
1841425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola    unsigned getRegParm() const { return RegParm; }
1842264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    CallingConv getCC() const { return CC; }
1843264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola
1844264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    bool operator==(const ExtInfo &Other) const {
1845264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola      return getNoReturn() == Other.getNoReturn() &&
1846425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola          getRegParm() == Other.getRegParm() &&
1847264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola          getCC() == Other.getCC();
1848264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    }
1849264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    bool operator!=(const ExtInfo &Other) const {
1850264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola      return !(*this == Other);
1851264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    }
1852264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola
1853264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    // Note that we don't have setters. That is by design, use
1854264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    // the following with methods instead of mutating these objects.
1855264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola
1856264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    ExtInfo withNoReturn(bool noReturn) const {
1857425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola      return ExtInfo(noReturn, getRegParm(), getCC());
1858425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola    }
1859425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola
1860425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola    ExtInfo withRegParm(unsigned RegParm) const {
1861425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola      return ExtInfo(getNoReturn(), RegParm, getCC());
1862264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    }
1863264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola
1864264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    ExtInfo withCallingConv(CallingConv cc) const {
1865425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola      return ExtInfo(getNoReturn(), getRegParm(), cc);
1866264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    }
1867264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola
1868264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola   private:
1869264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    // True if we have __attribute__((noreturn))
1870264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    bool NoReturn;
1871425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola    // The value passed to __attribute__((regparm(x)))
1872425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola    unsigned RegParm;
1873264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    // The calling convention as specified via
1874f813a2c03fcb05381b3252010435f557eb6b3cdeDouglas Gregor    // __attribute__((cdecl|stdcall|fastcall|thiscall))
1875264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    CallingConv CC;
1876264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola  };
1877264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola
18785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprotected:
1879971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis  FunctionType(TypeClass tc, QualType res, bool SubclassInfo,
18802455636163fdd18581d7fdae816433f886d88213Mike Stump               unsigned typeQuals, QualType Canonical, bool Dependent,
1881264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola               const ExtInfo &Info)
1882898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    : Type(tc, Canonical, Dependent),
1883264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola      SubClassData(SubclassInfo), TypeQuals(typeQuals),
1884264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola      NoReturn(Info.getNoReturn()),
1885425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola      RegParm(Info.getRegParm()), CallConv(Info.getCC()), ResultType(res) {}
18865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool getSubClassData() const { return SubClassData; }
1887971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis  unsigned getTypeQuals() const { return TypeQuals; }
18885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
18891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
18905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType getResultType() const { return ResultType; }
1891425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola  unsigned getRegParmType() const { return RegParm; }
18922455636163fdd18581d7fdae816433f886d88213Mike Stump  bool getNoReturnAttr() const { return NoReturn; }
1893ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor  CallingConv getCallConv() const { return (CallingConv)CallConv; }
1894264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola  ExtInfo getExtInfo() const {
1895425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola    return ExtInfo(NoReturn, RegParm, (CallingConv)CallConv);
1896264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola  }
18975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
189804a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall  static llvm::StringRef getNameForCallConv(CallingConv CC);
189904a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall
19005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T) {
19015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T->getTypeClass() == FunctionNoProto ||
19025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer           T->getTypeClass() == FunctionProto;
19035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
19045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const FunctionType *) { return true; }
19055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
19065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
190772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// FunctionNoProtoType - Represents a K&R-style 'int foo()' function, which has
19085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// no information available about its arguments.
190972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregorclass FunctionNoProtoType : public FunctionType, public llvm::FoldingSetNode {
19102455636163fdd18581d7fdae816433f886d88213Mike Stump  FunctionNoProtoType(QualType Result, QualType Canonical,
1911264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola                      const ExtInfo &Info)
19121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    : FunctionType(FunctionNoProto, Result, false, 0, Canonical,
1913264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola                   /*Dependent=*/false, Info) {}
19145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
191560e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
191660e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregorprotected:
191760e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor  virtual Linkage getLinkageImpl() const;
191860e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
19195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
19205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // No additional state past what FunctionType provides.
19211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1922bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1923bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1924bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
19255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void Profile(llvm::FoldingSetNodeID &ID) {
1926264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    Profile(ID, getResultType(), getExtInfo());
19275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
19282455636163fdd18581d7fdae816433f886d88213Mike Stump  static void Profile(llvm::FoldingSetNodeID &ID, QualType ResultType,
1929264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola                      const ExtInfo &Info) {
1930264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    ID.AddInteger(Info.getCC());
1931425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola    ID.AddInteger(Info.getRegParm());
1932264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    ID.AddInteger(Info.getNoReturn());
19335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ID.AddPointer(ResultType.getAsOpaquePtr());
19345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
19351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
19365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T) {
19375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T->getTypeClass() == FunctionNoProto;
19385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
193972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  static bool classof(const FunctionNoProtoType *) { return true; }
19405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
19415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
194272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// FunctionProtoType - Represents a prototype with argument type info, e.g.
19435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 'int foo(int)' or 'int foo(void)'.  'void' is represented as having no
1944465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl/// arguments, not as having a single void argument. Such a type can have an
1945465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl/// exception specification, but this specification is not part of the canonical
1946465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl/// type.
194772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregorclass FunctionProtoType : public FunctionType, public llvm::FoldingSetNode {
1948898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// hasAnyDependentType - Determine whether there are any dependent
1949898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// types within the arguments passed in.
1950898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  static bool hasAnyDependentType(const QualType *ArgArray, unsigned numArgs) {
1951898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    for (unsigned Idx = 0; Idx < numArgs; ++Idx)
1952898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor      if (ArgArray[Idx]->isDependentType())
19534b4218f48fef71a179c5a8287dae281580faf52fNate Begeman    return true;
1954898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
1955898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    return false;
1956898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  }
1957898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
195872564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  FunctionProtoType(QualType Result, const QualType *ArgArray, unsigned numArgs,
1959465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl                    bool isVariadic, unsigned typeQuals, bool hasExs,
1960465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl                    bool hasAnyExs, const QualType *ExArray,
1961264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola                    unsigned numExs, QualType Canonical,
1962264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola                    const ExtInfo &Info)
1963898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    : FunctionType(FunctionProto, Result, isVariadic, typeQuals, Canonical,
19641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                   (Result->isDependentType() ||
1965264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola                    hasAnyDependentType(ArgArray, numArgs)),
1966264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola                   Info),
1967465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl      NumArgs(numArgs), NumExceptions(numExs), HasExceptionSpec(hasExs),
1968465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl      AnyExceptionSpec(hasAnyExs) {
1969942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner    // Fill in the trailing argument array.
1970465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl    QualType *ArgInfo = reinterpret_cast<QualType*>(this+1);
19715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    for (unsigned i = 0; i != numArgs; ++i)
19725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      ArgInfo[i] = ArgArray[i];
1973465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl    // Fill in the exception array.
1974465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl    QualType *Ex = ArgInfo + numArgs;
1975465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl    for (unsigned i = 0; i != numExs; ++i)
1976465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl      Ex[i] = ExArray[i];
19775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
1978465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
19795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// NumArgs - The number of arguments this function has, not counting '...'.
1980465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  unsigned NumArgs : 20;
1981465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
1982465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  /// NumExceptions - The number of types in the exception spec, if any.
1983465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  unsigned NumExceptions : 10;
1984465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
1985465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  /// HasExceptionSpec - Whether this function has an exception spec at all.
1986465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  bool HasExceptionSpec : 1;
1987465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
1988465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  /// AnyExceptionSpec - Whether this function has a throw(...) spec.
1989465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  bool AnyExceptionSpec : 1;
1990465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
1991942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner  /// ArgInfo - There is an variable size array after the class in memory that
1992942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner  /// holds the argument types.
1993465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
1994465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  /// Exceptions - There is another variable size array after ArgInfo that
1995465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  /// holds the exception types.
1996465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
19975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
19984b05b1dee6cc65ae61d93dab7edff72710f24589Ted Kremenek
199960e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregorprotected:
200060e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor  virtual Linkage getLinkageImpl() const;
200160e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
20025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
20035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned getNumArgs() const { return NumArgs; }
20045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType getArgType(unsigned i) const {
20055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    assert(i < NumArgs && "Invalid argument number!");
2006942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner    return arg_type_begin()[i];
20075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
2008465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
2009465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  bool hasExceptionSpec() const { return HasExceptionSpec; }
2010465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  bool hasAnyExceptionSpec() const { return AnyExceptionSpec; }
2011465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  unsigned getNumExceptions() const { return NumExceptions; }
2012465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  QualType getExceptionType(unsigned i) const {
2013465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl    assert(i < NumExceptions && "Invalid exception number!");
2014465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl    return exception_begin()[i];
2015465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  }
20161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  bool hasEmptyExceptionSpec() const {
20171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return hasExceptionSpec() && !hasAnyExceptionSpec() &&
2018a12823f6c0ec9e0e644a9d0ee153e973f49c63fcAnders Carlsson      getNumExceptions() == 0;
2019d3fd6bad1249d3f34d71b73e2333fab0db51cce4Anders Carlsson  }
2020465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
20215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isVariadic() const { return getSubClassData(); }
2022971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis  unsigned getTypeQuals() const { return FunctionType::getTypeQuals(); }
20231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
20245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  typedef const QualType *arg_type_iterator;
2025942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner  arg_type_iterator arg_type_begin() const {
2026942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner    return reinterpret_cast<const QualType *>(this+1);
2027942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner  }
2028942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner  arg_type_iterator arg_type_end() const { return arg_type_begin()+NumArgs; }
2029465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
2030465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  typedef const QualType *exception_iterator;
2031465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  exception_iterator exception_begin() const {
2032465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl    // exceptions begin where arguments end
2033465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl    return arg_type_end();
2034465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  }
2035465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  exception_iterator exception_end() const {
2036465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl    return exception_begin() + NumExceptions;
2037465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  }
2038465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
2039bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2040bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2041bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
20425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T) {
20435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T->getTypeClass() == FunctionProto;
20445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
204572564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  static bool classof(const FunctionProtoType *) { return true; }
2046465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
20475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void Profile(llvm::FoldingSetNodeID &ID);
20485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static void Profile(llvm::FoldingSetNodeID &ID, QualType Result,
2049942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner                      arg_type_iterator ArgTys, unsigned NumArgs,
2050465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl                      bool isVariadic, unsigned TypeQuals,
2051465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl                      bool hasExceptionSpec, bool anyExceptionSpec,
20522455636163fdd18581d7fdae816433f886d88213Mike Stump                      unsigned NumExceptions, exception_iterator Exs,
2053264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola                      const ExtInfo &ExtInfo);
20545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
20555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
20565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2057ed97649e9574b9d854fa4d6109c9333ae0993554John McCall/// \brief Represents the dependent type named by a dependently-scoped
2058ed97649e9574b9d854fa4d6109c9333ae0993554John McCall/// typename using declaration, e.g.
2059ed97649e9574b9d854fa4d6109c9333ae0993554John McCall///   using typename Base<T>::foo;
2060ed97649e9574b9d854fa4d6109c9333ae0993554John McCall/// Template instantiation turns these into the underlying type.
2061ed97649e9574b9d854fa4d6109c9333ae0993554John McCallclass UnresolvedUsingType : public Type {
2062ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  UnresolvedUsingTypenameDecl *Decl;
2063ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
206419c8576b7328f4dc2d07682f5da552875c1912efJohn McCall  UnresolvedUsingType(const UnresolvedUsingTypenameDecl *D)
206519c8576b7328f4dc2d07682f5da552875c1912efJohn McCall    : Type(UnresolvedUsing, QualType(), true),
206619c8576b7328f4dc2d07682f5da552875c1912efJohn McCall      Decl(const_cast<UnresolvedUsingTypenameDecl*>(D)) {}
2067ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  friend class ASTContext; // ASTContext creates these.
2068ed97649e9574b9d854fa4d6109c9333ae0993554John McCallpublic:
2069ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
2070ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  UnresolvedUsingTypenameDecl *getDecl() const { return Decl; }
2071ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
2072ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  bool isSugared() const { return false; }
2073ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  QualType desugar() const { return QualType(this, 0); }
2074ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
2075ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  static bool classof(const Type *T) {
2076ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    return T->getTypeClass() == UnresolvedUsing;
2077ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  }
2078ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  static bool classof(const UnresolvedUsingType *) { return true; }
2079ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
2080ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  void Profile(llvm::FoldingSetNodeID &ID) {
2081ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    return Profile(ID, Decl);
2082ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  }
2083ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  static void Profile(llvm::FoldingSetNodeID &ID,
2084ed97649e9574b9d854fa4d6109c9333ae0993554John McCall                      UnresolvedUsingTypenameDecl *D) {
2085ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    ID.AddPointer(D);
2086ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  }
2087ed97649e9574b9d854fa4d6109c9333ae0993554John McCall};
2088ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
2089ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
20905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass TypedefType : public Type {
20915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  TypedefDecl *Decl;
2092c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanianprotected:
209319c8576b7328f4dc2d07682f5da552875c1912efJohn McCall  TypedefType(TypeClass tc, const TypedefDecl *D, QualType can)
209419c8576b7328f4dc2d07682f5da552875c1912efJohn McCall    : Type(tc, can, can->isDependentType()),
209519c8576b7328f4dc2d07682f5da552875c1912efJohn McCall      Decl(const_cast<TypedefDecl*>(D)) {
20965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    assert(!isa<TypedefType>(can) && "Invalid canonical type");
20975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
20985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
20995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
21001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
21015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  TypedefDecl *getDecl() const { return Decl; }
21021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2103a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner  /// LookThroughTypedefs - Return the ultimate type this typedef corresponds to
2104fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor  /// potentially looking through *all* consecutive typedefs.  This returns the
2105a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner  /// sum of the type qualifiers, so if you have:
2106a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner  ///   typedef const int A;
2107a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner  ///   typedef volatile A B;
2108a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner  /// looking through the typedefs for B will give you "const volatile A".
2109a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner  QualType LookThroughTypedefs() const;
21101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2111bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return true; }
2112bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const;
2113bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
211472564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  static bool classof(const Type *T) { return T->getTypeClass() == Typedef; }
21155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const TypedefType *) { return true; }
21165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
21175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
211872564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// TypeOfExprType (GCC extension).
211972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregorclass TypeOfExprType : public Type {
2120d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  Expr *TOExpr;
21211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2122b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregorprotected:
2123dd0257c77719a13d4acd513df40b04300cbfc871Douglas Gregor  TypeOfExprType(Expr *E, QualType can = QualType());
2124d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  friend class ASTContext;  // ASTContext creates these.
2125d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroffpublic:
2126d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  Expr *getUnderlyingExpr() const { return TOExpr; }
21271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2128bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// \brief Remove a single level of sugar.
2129bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const;
2130bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
2131bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// \brief Returns whether this type directly provides sugar.
2132bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return true; }
2133bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
213472564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  static bool classof(const Type *T) { return T->getTypeClass() == TypeOfExpr; }
213572564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  static bool classof(const TypeOfExprType *) { return true; }
2136d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff};
2137d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff
2138c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// \brief Internal representation of canonical, dependent
21391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// typeof(expr) types.
2140c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor///
2141c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// This class is used internally by the ASTContext to manage
2142c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// canonical, dependent types, only. Clients will only see instances
2143c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// of this class via TypeOfExprType nodes.
21441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpclass DependentTypeOfExprType
2145b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor  : public TypeOfExprType, public llvm::FoldingSetNode {
2146b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor  ASTContext &Context;
21471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2148b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregorpublic:
21491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  DependentTypeOfExprType(ASTContext &Context, Expr *E)
2150b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor    : TypeOfExprType(E), Context(Context) { }
21511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2152bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2153bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2154bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
2155b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor  void Profile(llvm::FoldingSetNodeID &ID) {
2156b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor    Profile(ID, Context, getUnderlyingExpr());
2157b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor  }
21581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2159b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor  static void Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context,
2160b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor                      Expr *E);
2161b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor};
21621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2163d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff/// TypeOfType (GCC extension).
2164d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroffclass TypeOfType : public Type {
2165d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  QualType TOType;
21661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  TypeOfType(QualType T, QualType can)
216772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor    : Type(TypeOf, can, T->isDependentType()), TOType(T) {
2168d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff    assert(!isa<TypedefType>(can) && "Invalid canonical type");
2169d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  }
2170d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  friend class ASTContext;  // ASTContext creates these.
2171d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroffpublic:
2172d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  QualType getUnderlyingType() const { return TOType; }
21731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2174bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// \brief Remove a single level of sugar.
2175bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return getUnderlyingType(); }
2176bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
2177bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// \brief Returns whether this type directly provides sugar.
2178bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return true; }
2179bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
218072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  static bool classof(const Type *T) { return T->getTypeClass() == TypeOf; }
2181d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  static bool classof(const TypeOfType *) { return true; }
2182d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff};
21835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2184395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson/// DecltypeType (C++0x)
2185395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlssonclass DecltypeType : public Type {
2186395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson  Expr *E;
21871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2188563a03b1338d31c2462def43253a722bc885d384Anders Carlsson  // FIXME: We could get rid of UnderlyingType if we wanted to: We would have to
2189563a03b1338d31c2462def43253a722bc885d384Anders Carlsson  // Move getDesugaredType to ASTContext so that it can call getDecltypeForExpr
2190563a03b1338d31c2462def43253a722bc885d384Anders Carlsson  // from it.
2191563a03b1338d31c2462def43253a722bc885d384Anders Carlsson  QualType UnderlyingType;
21921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
21939d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregorprotected:
2194563a03b1338d31c2462def43253a722bc885d384Anders Carlsson  DecltypeType(Expr *E, QualType underlyingType, QualType can = QualType());
2195395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson  friend class ASTContext;  // ASTContext creates these.
2196395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlssonpublic:
2197395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson  Expr *getUnderlyingExpr() const { return E; }
2198563a03b1338d31c2462def43253a722bc885d384Anders Carlsson  QualType getUnderlyingType() const { return UnderlyingType; }
2199563a03b1338d31c2462def43253a722bc885d384Anders Carlsson
2200bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// \brief Remove a single level of sugar.
2201bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return getUnderlyingType(); }
2202bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
2203bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// \brief Returns whether this type directly provides sugar.
2204bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return !isDependentType(); }
2205bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
2206395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson  static bool classof(const Type *T) { return T->getTypeClass() == Decltype; }
2207395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson  static bool classof(const DecltypeType *) { return true; }
2208395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson};
22091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2210c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// \brief Internal representation of canonical, dependent
2211c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// decltype(expr) types.
2212c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor///
2213c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// This class is used internally by the ASTContext to manage
2214c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// canonical, dependent types, only. Clients will only see instances
2215c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// of this class via DecltypeType nodes.
22169d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregorclass DependentDecltypeType : public DecltypeType, public llvm::FoldingSetNode {
22179d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor  ASTContext &Context;
22181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
22199d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregorpublic:
22209d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor  DependentDecltypeType(ASTContext &Context, Expr *E);
22211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2222bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2223bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2224bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
22259d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor  void Profile(llvm::FoldingSetNodeID &ID) {
22269d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor    Profile(ID, Context, getUnderlyingExpr());
22279d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor  }
22281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
22299d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor  static void Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context,
22301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                      Expr *E);
22319d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor};
22321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
22335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass TagType : public Type {
22340b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor  /// Stores the TagDecl associated with this type. The decl will
22350b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor  /// point to the TagDecl that actually defines the entity (or is a
22360b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor  /// definition in progress), if there is such a definition. The
22370b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor  /// single-bit value will be non-zero when this tag is in the
22380b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor  /// process of being defined.
2239fc705b84347e6fb4746a1a7e26949f64c2f2f358Douglas Gregor  mutable llvm::PointerIntPair<TagDecl *, 1> decl;
22404b7c98378ae0c1a3635f0b7756848b4a9923f8bcTed Kremenek  friend class ASTContext;
22410b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor  friend class TagDecl;
22422ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor
22432ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregorprotected:
224419c8576b7328f4dc2d07682f5da552875c1912efJohn McCall  TagType(TypeClass TC, const TagDecl *D, QualType can);
22452ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor
224660e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor  virtual Linkage getLinkageImpl() const;
224760e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
22481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic:
22490b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor  TagDecl *getDecl() const { return decl.getPointer(); }
22501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
22510b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor  /// @brief Determines whether this type is in the process of being
22521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// defined.
22530b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor  bool isBeingDefined() const { return decl.getInt(); }
22540953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void setBeingDefined(bool Def) const { decl.setInt(Def? 1 : 0); }
22550b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor
22561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
225772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor    return T->getTypeClass() >= TagFirst && T->getTypeClass() <= TagLast;
225872564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  }
22595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const TagType *) { return true; }
226072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  static bool classof(const RecordType *) { return true; }
226172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  static bool classof(const EnumType *) { return true; }
22625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
22635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
22645edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner/// RecordType - This is a helper class that allows the use of isa/cast/dyncast
22655edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner/// to detect TagType objects of structs/unions/classes.
22665edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattnerclass RecordType : public TagType {
226749aa7ff1245abd03e6e998e01302df31e4c6f8f6Argyrios Kyrtzidisprotected:
226819c8576b7328f4dc2d07682f5da552875c1912efJohn McCall  explicit RecordType(const RecordDecl *D)
226919c8576b7328f4dc2d07682f5da552875c1912efJohn McCall    : TagType(Record, reinterpret_cast<const TagDecl*>(D), QualType()) { }
227072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  explicit RecordType(TypeClass TC, RecordDecl *D)
227119c8576b7328f4dc2d07682f5da552875c1912efJohn McCall    : TagType(TC, reinterpret_cast<const TagDecl*>(D), QualType()) { }
22722ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor  friend class ASTContext;   // ASTContext creates these.
22735edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattnerpublic:
22741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
22755edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner  RecordDecl *getDecl() const {
22765edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner    return reinterpret_cast<RecordDecl*>(TagType::getDecl());
22775edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner  }
22781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
22791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  // FIXME: This predicate is a helper to QualType/Type. It needs to
22805edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner  // recursively check all fields for const-ness. If any field is declared
22811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  // const, it needs to return false.
22825edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner  bool hasConstFields() const { return false; }
22835edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner
22845edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner  // FIXME: RecordType needs to check when it is created that all fields are in
22855edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner  // the same address space, and return that.
22865edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner  unsigned getAddressSpace() const { return 0; }
22871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2288bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2289bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2290bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
22912daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner  static bool classof(const TagType *T);
22922daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner  static bool classof(const Type *T) {
22932daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner    return isa<TagType>(T) && classof(cast<TagType>(T));
22942daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner  }
22955edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner  static bool classof(const RecordType *) { return true; }
22965edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner};
22975edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner
22985edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner/// EnumType - This is a helper class that allows the use of isa/cast/dyncast
22995edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner/// to detect TagType objects of enums.
23005edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattnerclass EnumType : public TagType {
230119c8576b7328f4dc2d07682f5da552875c1912efJohn McCall  explicit EnumType(const EnumDecl *D)
230219c8576b7328f4dc2d07682f5da552875c1912efJohn McCall    : TagType(Enum, reinterpret_cast<const TagDecl*>(D), QualType()) { }
23032ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor  friend class ASTContext;   // ASTContext creates these.
23045edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattnerpublic:
23051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
23065edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner  EnumDecl *getDecl() const {
23075edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner    return reinterpret_cast<EnumDecl*>(TagType::getDecl());
23085edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner  }
23091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2310bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2311bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2312bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
23132daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner  static bool classof(const TagType *T);
23142daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner  static bool classof(const Type *T) {
23152daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner    return isa<TagType>(T) && classof(cast<TagType>(T));
23162daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner  }
23175edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner  static bool classof(const EnumType *) { return true; }
23185edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner};
23195edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner
2320fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregorclass TemplateTypeParmType : public Type, public llvm::FoldingSetNode {
2321efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor  unsigned Depth : 15;
2322efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor  unsigned Index : 16;
2323efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor  unsigned ParameterPack : 1;
2324efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor  IdentifierInfo *Name;
232572c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor
2326efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor  TemplateTypeParmType(unsigned D, unsigned I, bool PP, IdentifierInfo *N,
2327efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor                       QualType Canon)
2328fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor    : Type(TemplateTypeParm, Canon, /*Dependent=*/true),
2329efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor      Depth(D), Index(I), ParameterPack(PP), Name(N) { }
233072c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor
23311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  TemplateTypeParmType(unsigned D, unsigned I, bool PP)
2332efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor    : Type(TemplateTypeParm, QualType(this, 0), /*Dependent=*/true),
2333efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor      Depth(D), Index(I), ParameterPack(PP), Name(0) { }
233472c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor
2335fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor  friend class ASTContext;  // ASTContext creates these
233672c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor
2337fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregorpublic:
2338efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor  unsigned getDepth() const { return Depth; }
2339efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor  unsigned getIndex() const { return Index; }
2340efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor  bool isParameterPack() const { return ParameterPack; }
2341efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor  IdentifierInfo *getName() const { return Name; }
23421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2343bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2344bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2345bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
2346fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor  void Profile(llvm::FoldingSetNodeID &ID) {
2347efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor    Profile(ID, Depth, Index, ParameterPack, Name);
2348fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor  }
2349fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor
23501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static void Profile(llvm::FoldingSetNodeID &ID, unsigned Depth,
23511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                      unsigned Index, bool ParameterPack,
2352efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor                      IdentifierInfo *Name) {
2353fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor    ID.AddInteger(Depth);
2354fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor    ID.AddInteger(Index);
235576e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson    ID.AddBoolean(ParameterPack);
2356efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor    ID.AddPointer(Name);
2357fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor  }
2358fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor
23591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
23601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == TemplateTypeParm;
236172c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor  }
236272c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor  static bool classof(const TemplateTypeParmType *T) { return true; }
236372c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor};
2364fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor
236549a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// \brief Represents the result of substituting a type for a template
236649a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// type parameter.
236749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall///
236849a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// Within an instantiated template, all template type parameters have
236949a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// been replaced with these.  They are used solely to record that a
237049a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// type was originally written as a template type parameter;
237149a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// therefore they are never canonical.
237249a832bd499d6f61c23655f1fac99f0dd229756eJohn McCallclass SubstTemplateTypeParmType : public Type, public llvm::FoldingSetNode {
237349a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  // The original type parameter.
237449a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  const TemplateTypeParmType *Replaced;
237549a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall
237649a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  SubstTemplateTypeParmType(const TemplateTypeParmType *Param, QualType Canon)
237749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall    : Type(SubstTemplateTypeParm, Canon, Canon->isDependentType()),
237849a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall      Replaced(Param) { }
237949a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall
238049a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  friend class ASTContext;
238149a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall
238249a832bd499d6f61c23655f1fac99f0dd229756eJohn McCallpublic:
2383efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor  IdentifierInfo *getName() const { return Replaced->getName(); }
2384efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor
238549a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  /// Gets the template parameter that was substituted for.
238649a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  const TemplateTypeParmType *getReplacedParameter() const {
238749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall    return Replaced;
238849a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  }
238949a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall
239049a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  /// Gets the type that was substituted for the template
239149a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  /// parameter.
239249a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  QualType getReplacementType() const {
239349a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall    return getCanonicalTypeInternal();
239449a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  }
239549a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall
239649a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  bool isSugared() const { return true; }
239749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  QualType desugar() const { return getReplacementType(); }
239849a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall
239949a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  void Profile(llvm::FoldingSetNodeID &ID) {
240049a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall    Profile(ID, getReplacedParameter(), getReplacementType());
240149a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  }
240249a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  static void Profile(llvm::FoldingSetNodeID &ID,
240349a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall                      const TemplateTypeParmType *Replaced,
240449a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall                      QualType Replacement) {
240549a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall    ID.AddPointer(Replaced);
240649a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall    ID.AddPointer(Replacement.getAsOpaquePtr());
240749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  }
240849a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall
240949a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  static bool classof(const Type *T) {
241049a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall    return T->getTypeClass() == SubstTemplateTypeParm;
241149a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  }
241249a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  static bool classof(const SubstTemplateTypeParmType *T) { return true; }
241349a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall};
241449a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall
24157532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// \brief Represents the type of a template specialization as written
24167532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// in the source code.
241755f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor///
24187532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// Template specialization types represent the syntactic form of a
24197532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// template-id that refers to a type, e.g., @c vector<int>. Some
24207532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// template specialization types are syntactic sugar, whose canonical
24217532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// type will point to some other type node that represents the
24227532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// instantiation or class template specialization. For example, a
242355f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor/// class template specialization type of @c vector<int> will refer to
24241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// a tag type for the instantiation
242555f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor/// @c std::vector<int, std::allocator<int>>.
24267532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor///
24277532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// Other template specialization types, for which the template name
24287532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// is dependent, may be canonical types. These types are always
24297532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// dependent.
24301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpclass TemplateSpecializationType
243155f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  : public Type, public llvm::FoldingSetNode {
243233500955d731c73717af52088b7fc0e7a85681e7John McCall  /// \brief The name of the template being specialized.
24337532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor  TemplateName Template;
243455f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
243540808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  /// \brief - The number of template arguments named in this class
243640808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  /// template specialization.
243755f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  unsigned NumArgs;
243855f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
2439ef99001908e799c388f1363b1e607dad5f5b57d3John McCall  TemplateSpecializationType(TemplateName T,
24407532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor                             const TemplateArgument *Args,
24417532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor                             unsigned NumArgs, QualType Canon);
244255f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
24435908e9f25bc9a334c99c095e0b1e6a515445be2dDouglas Gregor  virtual void Destroy(ASTContext& C);
24445908e9f25bc9a334c99c095e0b1e6a515445be2dDouglas Gregor
244555f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  friend class ASTContext;  // ASTContext creates these
244655f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
244755f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregorpublic:
244840808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  /// \brief Determine whether any of the given template arguments are
244940808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  /// dependent.
245040808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  static bool anyDependentTemplateArguments(const TemplateArgument *Args,
24511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                            unsigned NumArgs);
245240808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor
2453833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  static bool anyDependentTemplateArguments(const TemplateArgumentLoc *Args,
2454833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                            unsigned NumArgs);
2455833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
2456d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  static bool anyDependentTemplateArguments(const TemplateArgumentListInfo &);
2457d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall
2458df667e71b1daadeacb230cf94fc717843f1a138aDouglas Gregor  /// \brief Print a template argument list, including the '<' and '>'
2459df667e71b1daadeacb230cf94fc717843f1a138aDouglas Gregor  /// enclosing the template arguments.
2460df667e71b1daadeacb230cf94fc717843f1a138aDouglas Gregor  static std::string PrintTemplateArgumentList(const TemplateArgument *Args,
2461d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor                                               unsigned NumArgs,
2462d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor                                               const PrintingPolicy &Policy);
2463df667e71b1daadeacb230cf94fc717843f1a138aDouglas Gregor
2464833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  static std::string PrintTemplateArgumentList(const TemplateArgumentLoc *Args,
2465833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                               unsigned NumArgs,
2466833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                               const PrintingPolicy &Policy);
2467833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
2468d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  static std::string PrintTemplateArgumentList(const TemplateArgumentListInfo &,
2469d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall                                               const PrintingPolicy &Policy);
2470d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall
247131f17ecbef57b5679c017c375db330546b7b5145John McCall  /// True if this template specialization type matches a current
247231f17ecbef57b5679c017c375db330546b7b5145John McCall  /// instantiation in the context in which it is found.
247331f17ecbef57b5679c017c375db330546b7b5145John McCall  bool isCurrentInstantiation() const {
247471d74bc0d6e522ce7c21a599db8e19d3883b518fJohn McCall    return isa<InjectedClassNameType>(getCanonicalTypeInternal());
247531f17ecbef57b5679c017c375db330546b7b5145John McCall  }
247631f17ecbef57b5679c017c375db330546b7b5145John McCall
247740808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  typedef const TemplateArgument * iterator;
247840808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor
247940808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  iterator begin() const { return getArgs(); }
248033500955d731c73717af52088b7fc0e7a85681e7John McCall  iterator end() const; // defined inline in TemplateBase.h
248140808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor
24827532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor  /// \brief Retrieve the name of the template that we are specializing.
24837532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor  TemplateName getTemplateName() const { return Template; }
248455f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
248540808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  /// \brief Retrieve the template arguments.
24861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  const TemplateArgument *getArgs() const {
248740808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor    return reinterpret_cast<const TemplateArgument *>(this + 1);
248840808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  }
248940808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor
249040808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  /// \brief Retrieve the number of template arguments.
249155f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  unsigned getNumArgs() const { return NumArgs; }
249255f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
249355f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  /// \brief Retrieve a specific template argument as a type.
249455f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  /// \precondition @c isArgType(Arg)
249533500955d731c73717af52088b7fc0e7a85681e7John McCall  const TemplateArgument &getArg(unsigned Idx) const; // in TemplateBase.h
249655f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
249731f17ecbef57b5679c017c375db330546b7b5145John McCall  bool isSugared() const {
249831f17ecbef57b5679c017c375db330546b7b5145John McCall    return !isDependentType() || isCurrentInstantiation();
249931f17ecbef57b5679c017c375db330546b7b5145John McCall  }
2500bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return getCanonicalTypeInternal(); }
2501bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
2502ef99001908e799c388f1363b1e607dad5f5b57d3John McCall  void Profile(llvm::FoldingSetNodeID &ID, ASTContext &Ctx) {
250371d74bc0d6e522ce7c21a599db8e19d3883b518fJohn McCall    Profile(ID, Template, getArgs(), NumArgs, Ctx);
250455f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  }
250555f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
25067532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor  static void Profile(llvm::FoldingSetNodeID &ID, TemplateName T,
250731f17ecbef57b5679c017c375db330546b7b5145John McCall                      const TemplateArgument *Args,
250831f17ecbef57b5679c017c375db330546b7b5145John McCall                      unsigned NumArgs,
2509828e226ab7ed08b3eb766549e9d3306432137460Douglas Gregor                      ASTContext &Context);
251055f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
25111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
25121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == TemplateSpecialization;
251355f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  }
25147532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor  static bool classof(const TemplateSpecializationType *T) { return true; }
251555f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor};
251655f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
251731f17ecbef57b5679c017c375db330546b7b5145John McCall/// \brief The injected class name of a C++ class template or class
251831f17ecbef57b5679c017c375db330546b7b5145John McCall/// template partial specialization.  Used to record that a type was
251931f17ecbef57b5679c017c375db330546b7b5145John McCall/// spelled with a bare identifier rather than as a template-id; the
252031f17ecbef57b5679c017c375db330546b7b5145John McCall/// equivalent for non-templated classes is just RecordType.
25213cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall///
252231f17ecbef57b5679c017c375db330546b7b5145John McCall/// Injected class name types are always dependent.  Template
252331f17ecbef57b5679c017c375db330546b7b5145John McCall/// instantiation turns these into RecordTypes.
25243cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall///
252531f17ecbef57b5679c017c375db330546b7b5145John McCall/// Injected class name types are always canonical.  This works
252631f17ecbef57b5679c017c375db330546b7b5145John McCall/// because it is impossible to compare an injected class name type
252731f17ecbef57b5679c017c375db330546b7b5145John McCall/// with the corresponding non-injected template type, for the same
252831f17ecbef57b5679c017c375db330546b7b5145John McCall/// reason that it is impossible to directly compare template
252931f17ecbef57b5679c017c375db330546b7b5145John McCall/// parameters from different dependent contexts: injected class name
253031f17ecbef57b5679c017c375db330546b7b5145John McCall/// types can only occur within the scope of a particular templated
253131f17ecbef57b5679c017c375db330546b7b5145John McCall/// declaration, and within that scope every template specialization
253231f17ecbef57b5679c017c375db330546b7b5145John McCall/// will canonicalize to the injected class name (when appropriate
253331f17ecbef57b5679c017c375db330546b7b5145John McCall/// according to the rules of the language).
25343cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCallclass InjectedClassNameType : public Type {
25353cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  CXXRecordDecl *Decl;
25363cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall
253731f17ecbef57b5679c017c375db330546b7b5145John McCall  /// The template specialization which this type represents.
253831f17ecbef57b5679c017c375db330546b7b5145John McCall  /// For example, in
253931f17ecbef57b5679c017c375db330546b7b5145John McCall  ///   template <class T> class A { ... };
254031f17ecbef57b5679c017c375db330546b7b5145John McCall  /// this is A<T>, whereas in
254131f17ecbef57b5679c017c375db330546b7b5145John McCall  ///   template <class X, class Y> class A<B<X,Y> > { ... };
254231f17ecbef57b5679c017c375db330546b7b5145John McCall  /// this is A<B<X,Y> >.
254331f17ecbef57b5679c017c375db330546b7b5145John McCall  ///
254431f17ecbef57b5679c017c375db330546b7b5145John McCall  /// It is always unqualified, always a template specialization type,
254531f17ecbef57b5679c017c375db330546b7b5145John McCall  /// and always dependent.
254631f17ecbef57b5679c017c375db330546b7b5145John McCall  QualType InjectedType;
25473cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall
25483cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  friend class ASTContext; // ASTContext creates these.
25499ffce2182e4fe72052d620698d272207f494b1cfDouglas Gregor  friend class TagDecl; // TagDecl mutilates the Decl
255043921b53b582145f0d1b7c48223bd4d9f0a9d1beArgyrios Kyrtzidis  friend class PCHReader; // FIXME: ASTContext::getInjectedClassNameType is not
255143921b53b582145f0d1b7c48223bd4d9f0a9d1beArgyrios Kyrtzidis                          // currently suitable for PCH reading, too much
255243921b53b582145f0d1b7c48223bd4d9f0a9d1beArgyrios Kyrtzidis                          // interdependencies.
255331f17ecbef57b5679c017c375db330546b7b5145John McCall  InjectedClassNameType(CXXRecordDecl *D, QualType TST)
255431f17ecbef57b5679c017c375db330546b7b5145John McCall    : Type(InjectedClassName, QualType(), true),
255531f17ecbef57b5679c017c375db330546b7b5145John McCall      Decl(D), InjectedType(TST) {
25563cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall    assert(isa<TemplateSpecializationType>(TST));
25573cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall    assert(!TST.hasQualifiers());
255831f17ecbef57b5679c017c375db330546b7b5145John McCall    assert(TST->isDependentType());
25593cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  }
25603cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall
25613cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCallpublic:
256231f17ecbef57b5679c017c375db330546b7b5145John McCall  QualType getInjectedSpecializationType() const { return InjectedType; }
256331f17ecbef57b5679c017c375db330546b7b5145John McCall  const TemplateSpecializationType *getInjectedTST() const {
256431f17ecbef57b5679c017c375db330546b7b5145John McCall    return cast<TemplateSpecializationType>(InjectedType.getTypePtr());
25653cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  }
25663cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall
25673cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  CXXRecordDecl *getDecl() const { return Decl; }
25683cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall
256931f17ecbef57b5679c017c375db330546b7b5145John McCall  bool isSugared() const { return false; }
257031f17ecbef57b5679c017c375db330546b7b5145John McCall  QualType desugar() const { return QualType(this, 0); }
25713cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall
25723cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  static bool classof(const Type *T) {
25733cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall    return T->getTypeClass() == InjectedClassName;
25743cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  }
25753cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  static bool classof(const InjectedClassNameType *T) { return true; }
25763cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall};
25773cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall
2578465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// \brief The kind of a tag type.
2579465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnaraenum TagTypeKind {
2580465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// \brief The "struct" keyword.
2581465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  TTK_Struct,
2582465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// \brief The "union" keyword.
2583465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  TTK_Union,
2584465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// \brief The "class" keyword.
2585465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  TTK_Class,
2586465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// \brief The "enum" keyword.
2587465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  TTK_Enum
2588465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara};
2589465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
25904a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// \brief The elaboration keyword that precedes a qualified type name or
25914a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// introduces an elaborated-type-specifier.
25924a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregorenum ElaboratedTypeKeyword {
25934a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor  /// \brief The "struct" keyword introduces the elaborated-type-specifier.
25944a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor  ETK_Struct,
25954a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor  /// \brief The "union" keyword introduces the elaborated-type-specifier.
25964a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor  ETK_Union,
2597465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// \brief The "class" keyword introduces the elaborated-type-specifier.
2598465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  ETK_Class,
25994a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor  /// \brief The "enum" keyword introduces the elaborated-type-specifier.
2600465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  ETK_Enum,
2601465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// \brief The "typename" keyword precedes the qualified type name, e.g.,
2602465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// \c typename T::type.
2603465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  ETK_Typename,
2604465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// \brief No keyword precedes the qualified type name.
2605465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  ETK_None
26064a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor};
2607465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
2608465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// A helper class for Type nodes having an ElaboratedTypeKeyword.
2609465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// The keyword in stored in the free bits of the base class.
2610465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// Also provides a few static helpers for converting and printing
2611465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// elaborated type keyword and tag type kind enumerations.
2612465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnaraclass TypeWithKeyword : public Type {
2613465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// Keyword - Encodes an ElaboratedTypeKeyword enumeration constant.
2614465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  unsigned Keyword : 3;
2615465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
2616465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnaraprotected:
2617465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  TypeWithKeyword(ElaboratedTypeKeyword Keyword, TypeClass tc,
2618465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara                  QualType Canonical, bool dependent)
2619465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    : Type(tc, Canonical, dependent), Keyword(Keyword) {}
2620465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
2621465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnarapublic:
2622465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  virtual ~TypeWithKeyword(); // pin vtable to Type.cpp
2623465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
2624465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  ElaboratedTypeKeyword getKeyword() const {
2625465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    return static_cast<ElaboratedTypeKeyword>(Keyword);
2626465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  }
2627465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
2628465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// getKeywordForTypeSpec - Converts a type specifier (DeclSpec::TST)
2629465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// into an elaborated type keyword.
2630465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  static ElaboratedTypeKeyword getKeywordForTypeSpec(unsigned TypeSpec);
2631465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
2632465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// getTagTypeKindForTypeSpec - Converts a type specifier (DeclSpec::TST)
2633465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// into a tag type kind.  It is an error to provide a type specifier
2634465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// which *isn't* a tag kind here.
2635465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  static TagTypeKind getTagTypeKindForTypeSpec(unsigned TypeSpec);
2636465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
2637465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// getKeywordForTagDeclKind - Converts a TagTypeKind into an
2638465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// elaborated type keyword.
2639465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  static ElaboratedTypeKeyword getKeywordForTagTypeKind(TagTypeKind Tag);
2640465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
2641465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// getTagTypeKindForKeyword - Converts an elaborated type keyword into
2642465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  // a TagTypeKind. It is an error to provide an elaborated type keyword
2643465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// which *isn't* a tag kind here.
2644465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  static TagTypeKind getTagTypeKindForKeyword(ElaboratedTypeKeyword Keyword);
2645465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
2646465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  static bool KeywordIsTagTypeKind(ElaboratedTypeKeyword Keyword);
2647465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
2648465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  static const char *getKeywordName(ElaboratedTypeKeyword Keyword);
2649465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
2650465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  static const char *getTagTypeKindName(TagTypeKind Kind) {
2651465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    return getKeywordName(getKeywordForTagTypeKind(Kind));
2652465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  }
2653465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
2654465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  class CannotCastToThisType {};
2655465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  static CannotCastToThisType classof(const Type *);
2656465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara};
2657465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
2658465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// \brief Represents a type that was referred to using an elaborated type
2659465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// keyword, e.g., struct S, or via a qualified name, e.g., N::M::type,
2660465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// or both.
2661e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor///
2662e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor/// This type is used to keep track of a type name as written in the
2663465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// source code, including tag keywords and any nested-name-specifiers.
2664465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// The type itself is always "sugar", used to express what was written
2665465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// in the source code but containing no additional semantic information.
2666465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnaraclass ElaboratedType : public TypeWithKeyword, public llvm::FoldingSetNode {
2667465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
2668ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor  /// \brief The nested name specifier containing the qualifier.
2669ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor  NestedNameSpecifier *NNS;
2670e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor
2671e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor  /// \brief The type that this qualified name refers to.
2672e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor  QualType NamedType;
2673e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor
2674465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  ElaboratedType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS,
2675465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara                 QualType NamedType, QualType CanonType)
2676465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    : TypeWithKeyword(Keyword, Elaborated, CanonType,
2677465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara                      NamedType->isDependentType()),
2678465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara      NNS(NNS), NamedType(NamedType) {
2679465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    assert(!(Keyword == ETK_None && NNS == 0) &&
2680465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara           "ElaboratedType cannot have elaborated type keyword "
2681465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara           "and name qualifier both null.");
2682465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  }
2683e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor
2684e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor  friend class ASTContext;  // ASTContext creates these
2685e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor
2686e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregorpublic:
268733500955d731c73717af52088b7fc0e7a85681e7John McCall  ~ElaboratedType();
2688465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
2689ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor  /// \brief Retrieve the qualification on this type.
2690ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor  NestedNameSpecifier *getQualifier() const { return NNS; }
2691e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor
2692e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor  /// \brief Retrieve the type named by the qualified-id.
2693e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor  QualType getNamedType() const { return NamedType; }
2694e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor
2695bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// \brief Remove a single level of sugar.
2696bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return getNamedType(); }
2697bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
2698bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// \brief Returns whether this type directly provides sugar.
2699bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return true; }
2700bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
2701e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor  void Profile(llvm::FoldingSetNodeID &ID) {
2702465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    Profile(ID, getKeyword(), NNS, NamedType);
2703e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor  }
2704e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor
2705465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  static void Profile(llvm::FoldingSetNodeID &ID, ElaboratedTypeKeyword Keyword,
2706465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara                      NestedNameSpecifier *NNS, QualType NamedType) {
2707465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    ID.AddInteger(Keyword);
2708ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor    ID.AddPointer(NNS);
2709ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor    NamedType.Profile(ID);
2710ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor  }
2711e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor
27121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
2713465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    return T->getTypeClass() == Elaborated;
2714e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor  }
2715465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  static bool classof(const ElaboratedType *T) { return true; }
2716e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor};
2717e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor
27184a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// \brief Represents a qualified type name for which the type name is
27194a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// dependent.
2720d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor///
27214a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// DependentNameType represents a class of dependent types that involve a
27224a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// dependent nested-name-specifier (e.g., "T::") followed by a (dependent)
27234a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// name of a type. The DependentNameType may start with a "typename" (for a
27244a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// typename-specifier), "class", "struct", "union", or "enum" (for a
27254a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// dependent elaborated-type-specifier), or nothing (in contexts where we
27264a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// know that we must be referring to a type, e.g., in a base class specifier).
2727465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnaraclass DependentNameType : public TypeWithKeyword, public llvm::FoldingSetNode {
2728465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
2729d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  /// \brief The nested name specifier containing the qualifier.
2730d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  NestedNameSpecifier *NNS;
2731d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor
2732d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  /// \brief The type that this typename specifier refers to.
273333500955d731c73717af52088b7fc0e7a85681e7John McCall  const IdentifierInfo *Name;
2734d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor
27354a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor  DependentNameType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS,
27364a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor                    const IdentifierInfo *Name, QualType CanonType)
2737465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    : TypeWithKeyword(Keyword, DependentName, CanonType, true),
2738465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara      NNS(NNS), Name(Name) {
27391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    assert(NNS->isDependent() &&
27404714c12a1ab759156b78be8f109ea4c12213af57Douglas Gregor           "DependentNameType requires a dependent nested-name-specifier");
2741d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  }
2742d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor
2743d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  friend class ASTContext;  // ASTContext creates these
2744d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor
2745d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregorpublic:
274633500955d731c73717af52088b7fc0e7a85681e7John McCall  virtual ~DependentNameType();
2747465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
2748d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  /// \brief Retrieve the qualification on this type.
2749d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  NestedNameSpecifier *getQualifier() const { return NNS; }
2750d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor
27511734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor  /// \brief Retrieve the type named by the typename specifier as an
27521734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor  /// identifier.
27531734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor  ///
27541734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor  /// This routine will return a non-NULL identifier pointer when the
27551734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor  /// form of the original typename was terminated by an identifier,
27561734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor  /// e.g., "typename T::type".
27571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  const IdentifierInfo *getIdentifier() const {
275833500955d731c73717af52088b7fc0e7a85681e7John McCall    return Name;
27591734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor  }
2760d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor
2761bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2762bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2763bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
2764d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  void Profile(llvm::FoldingSetNodeID &ID) {
2765465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    Profile(ID, getKeyword(), NNS, Name);
2766d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  }
2767d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor
27684a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor  static void Profile(llvm::FoldingSetNodeID &ID, ElaboratedTypeKeyword Keyword,
276933500955d731c73717af52088b7fc0e7a85681e7John McCall                      NestedNameSpecifier *NNS, const IdentifierInfo *Name) {
27704a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor    ID.AddInteger(Keyword);
2771d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor    ID.AddPointer(NNS);
277233500955d731c73717af52088b7fc0e7a85681e7John McCall    ID.AddPointer(Name);
2773d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  }
2774d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor
27751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
27764714c12a1ab759156b78be8f109ea4c12213af57Douglas Gregor    return T->getTypeClass() == DependentName;
2777d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  }
27784714c12a1ab759156b78be8f109ea4c12213af57Douglas Gregor  static bool classof(const DependentNameType *T) { return true; }
2779d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor};
2780d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor
278133500955d731c73717af52088b7fc0e7a85681e7John McCall/// DependentTemplateSpecializationType - Represents a template
278233500955d731c73717af52088b7fc0e7a85681e7John McCall/// specialization type whose template cannot be resolved, e.g.
278333500955d731c73717af52088b7fc0e7a85681e7John McCall///   A<T>::template B<T>
278433500955d731c73717af52088b7fc0e7a85681e7John McCallclass DependentTemplateSpecializationType :
278533500955d731c73717af52088b7fc0e7a85681e7John McCall  public TypeWithKeyword, public llvm::FoldingSetNode {
278633500955d731c73717af52088b7fc0e7a85681e7John McCall
278733500955d731c73717af52088b7fc0e7a85681e7John McCall  /// \brief The nested name specifier containing the qualifier.
278833500955d731c73717af52088b7fc0e7a85681e7John McCall  NestedNameSpecifier *NNS;
278933500955d731c73717af52088b7fc0e7a85681e7John McCall
279033500955d731c73717af52088b7fc0e7a85681e7John McCall  /// \brief The identifier of the template.
279133500955d731c73717af52088b7fc0e7a85681e7John McCall  const IdentifierInfo *Name;
279233500955d731c73717af52088b7fc0e7a85681e7John McCall
279333500955d731c73717af52088b7fc0e7a85681e7John McCall  /// \brief - The number of template arguments named in this class
279433500955d731c73717af52088b7fc0e7a85681e7John McCall  /// template specialization.
279533500955d731c73717af52088b7fc0e7a85681e7John McCall  unsigned NumArgs;
279633500955d731c73717af52088b7fc0e7a85681e7John McCall
279733500955d731c73717af52088b7fc0e7a85681e7John McCall  const TemplateArgument *getArgBuffer() const {
279833500955d731c73717af52088b7fc0e7a85681e7John McCall    return reinterpret_cast<const TemplateArgument*>(this+1);
279933500955d731c73717af52088b7fc0e7a85681e7John McCall  }
280033500955d731c73717af52088b7fc0e7a85681e7John McCall  TemplateArgument *getArgBuffer() {
280133500955d731c73717af52088b7fc0e7a85681e7John McCall    return reinterpret_cast<TemplateArgument*>(this+1);
280233500955d731c73717af52088b7fc0e7a85681e7John McCall  }
280333500955d731c73717af52088b7fc0e7a85681e7John McCall
2804ef99001908e799c388f1363b1e607dad5f5b57d3John McCall  DependentTemplateSpecializationType(ElaboratedTypeKeyword Keyword,
280533500955d731c73717af52088b7fc0e7a85681e7John McCall                                      NestedNameSpecifier *NNS,
280633500955d731c73717af52088b7fc0e7a85681e7John McCall                                      const IdentifierInfo *Name,
280733500955d731c73717af52088b7fc0e7a85681e7John McCall                                      unsigned NumArgs,
280833500955d731c73717af52088b7fc0e7a85681e7John McCall                                      const TemplateArgument *Args,
280933500955d731c73717af52088b7fc0e7a85681e7John McCall                                      QualType Canon);
281033500955d731c73717af52088b7fc0e7a85681e7John McCall
281133500955d731c73717af52088b7fc0e7a85681e7John McCall  virtual void Destroy(ASTContext& C);
281233500955d731c73717af52088b7fc0e7a85681e7John McCall
281333500955d731c73717af52088b7fc0e7a85681e7John McCall  friend class ASTContext;  // ASTContext creates these
281433500955d731c73717af52088b7fc0e7a85681e7John McCall
281533500955d731c73717af52088b7fc0e7a85681e7John McCallpublic:
281633500955d731c73717af52088b7fc0e7a85681e7John McCall  virtual ~DependentTemplateSpecializationType();
281733500955d731c73717af52088b7fc0e7a85681e7John McCall
281833500955d731c73717af52088b7fc0e7a85681e7John McCall  NestedNameSpecifier *getQualifier() const { return NNS; }
281933500955d731c73717af52088b7fc0e7a85681e7John McCall  const IdentifierInfo *getIdentifier() const { return Name; }
282033500955d731c73717af52088b7fc0e7a85681e7John McCall
282133500955d731c73717af52088b7fc0e7a85681e7John McCall  /// \brief Retrieve the template arguments.
282233500955d731c73717af52088b7fc0e7a85681e7John McCall  const TemplateArgument *getArgs() const {
282333500955d731c73717af52088b7fc0e7a85681e7John McCall    return getArgBuffer();
282433500955d731c73717af52088b7fc0e7a85681e7John McCall  }
282533500955d731c73717af52088b7fc0e7a85681e7John McCall
282633500955d731c73717af52088b7fc0e7a85681e7John McCall  /// \brief Retrieve the number of template arguments.
282733500955d731c73717af52088b7fc0e7a85681e7John McCall  unsigned getNumArgs() const { return NumArgs; }
282833500955d731c73717af52088b7fc0e7a85681e7John McCall
282933500955d731c73717af52088b7fc0e7a85681e7John McCall  const TemplateArgument &getArg(unsigned Idx) const; // in TemplateBase.h
283033500955d731c73717af52088b7fc0e7a85681e7John McCall
283133500955d731c73717af52088b7fc0e7a85681e7John McCall  typedef const TemplateArgument * iterator;
283233500955d731c73717af52088b7fc0e7a85681e7John McCall  iterator begin() const { return getArgs(); }
283333500955d731c73717af52088b7fc0e7a85681e7John McCall  iterator end() const; // inline in TemplateBase.h
283433500955d731c73717af52088b7fc0e7a85681e7John McCall
283533500955d731c73717af52088b7fc0e7a85681e7John McCall  bool isSugared() const { return false; }
283633500955d731c73717af52088b7fc0e7a85681e7John McCall  QualType desugar() const { return QualType(this, 0); }
283733500955d731c73717af52088b7fc0e7a85681e7John McCall
2838ef99001908e799c388f1363b1e607dad5f5b57d3John McCall  void Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context) {
283933500955d731c73717af52088b7fc0e7a85681e7John McCall    Profile(ID, Context, getKeyword(), NNS, Name, NumArgs, getArgs());
284033500955d731c73717af52088b7fc0e7a85681e7John McCall  }
284133500955d731c73717af52088b7fc0e7a85681e7John McCall
284233500955d731c73717af52088b7fc0e7a85681e7John McCall  static void Profile(llvm::FoldingSetNodeID &ID,
284333500955d731c73717af52088b7fc0e7a85681e7John McCall                      ASTContext &Context,
284433500955d731c73717af52088b7fc0e7a85681e7John McCall                      ElaboratedTypeKeyword Keyword,
284533500955d731c73717af52088b7fc0e7a85681e7John McCall                      NestedNameSpecifier *Qualifier,
284633500955d731c73717af52088b7fc0e7a85681e7John McCall                      const IdentifierInfo *Name,
284733500955d731c73717af52088b7fc0e7a85681e7John McCall                      unsigned NumArgs,
284833500955d731c73717af52088b7fc0e7a85681e7John McCall                      const TemplateArgument *Args);
284933500955d731c73717af52088b7fc0e7a85681e7John McCall
285033500955d731c73717af52088b7fc0e7a85681e7John McCall  static bool classof(const Type *T) {
285133500955d731c73717af52088b7fc0e7a85681e7John McCall    return T->getTypeClass() == DependentTemplateSpecialization;
285233500955d731c73717af52088b7fc0e7a85681e7John McCall  }
285333500955d731c73717af52088b7fc0e7a85681e7John McCall  static bool classof(const DependentTemplateSpecializationType *T) {
285433500955d731c73717af52088b7fc0e7a85681e7John McCall    return true;
285533500955d731c73717af52088b7fc0e7a85681e7John McCall  }
285633500955d731c73717af52088b7fc0e7a85681e7John McCall};
285733500955d731c73717af52088b7fc0e7a85681e7John McCall
2858c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// ObjCObjectType - Represents a class type in Objective C.
2859c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// Every Objective C type is a combination of a base type and a
2860c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// list of protocols.
2861c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall///
2862c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// Given the following declarations:
2863c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall///   @class C;
2864c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall///   @protocol P;
2865c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall///
2866c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// 'C' is an ObjCInterfaceType C.  It is sugar for an ObjCObjectType
2867c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// with base C and no protocols.
2868c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall///
2869c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// 'C<P>' is an ObjCObjectType with base C and protocol list [P].
2870c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall///
2871e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// 'id' is a TypedefType which is sugar for an ObjCPointerType whose
2872e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// pointee is an ObjCObjectType with base BuiltinType::ObjCIdType
2873e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// and no protocols.
2874c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall///
2875e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// 'id<P>' is an ObjCPointerType whose pointee is an ObjCObjecType
2876e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// with base BuiltinType::ObjCIdType and protocol list [P].  Eventually
2877e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// this should get its own sugar class to better represent the source.
2878c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallclass ObjCObjectType : public Type {
2879c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  // Pad the bit count up so that NumProtocols is 2-byte aligned
2880c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  unsigned : BitsRemainingInType - 16;
2881c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
2882c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  /// \brief The number of protocols stored after the
2883c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  /// ObjCObjectPointerType node.
2884c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  ///
2885e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// These protocols are those written directly on the type.  If
2886e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// protocol qualifiers ever become additive, the iterators will
2887e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// get kindof complicated.
2888e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///
2889c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  /// In the canonical object type, these are sorted alphabetically
2890c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  /// and uniqued.
2891c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  unsigned NumProtocols : 16;
2892c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff
2893c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  /// Either a BuiltinType or an InterfaceType or sugar for either.
2894c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  QualType BaseType;
2895c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
2896c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  ObjCProtocolDecl * const *getProtocolStorage() const {
2897c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return const_cast<ObjCObjectType*>(this)->getProtocolStorage();
2898c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  }
2899c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
2900c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  ObjCProtocolDecl **getProtocolStorage();
2901c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
2902c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallprotected:
2903c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  ObjCObjectType(QualType Canonical, QualType Base,
2904c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall                 ObjCProtocolDecl * const *Protocols, unsigned NumProtocols);
2905c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
2906c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  enum Nonce_ObjCInterface { Nonce_ObjCInterface };
2907c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  ObjCObjectType(enum Nonce_ObjCInterface)
2908c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    : Type(ObjCInterface, QualType(), false),
2909c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall      NumProtocols(0),
2910c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall      BaseType(QualType(this_(), 0)) {}
2911c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff
291260e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregorprotected:
291360e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor  Linkage getLinkageImpl() const; // key function
291460e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
29153536b443bc50d58a79f14fca9b6842541a434854Steve Naroffpublic:
2916e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// getBaseType - Gets the base type of this object type.  This is
2917e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// always (possibly sugar for) one of:
2918e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///  - the 'id' builtin type (as opposed to the 'id' type visible to the
2919e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///    user, which is a typedef for an ObjCPointerType)
2920e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///  - the 'Class' builtin type (same caveat)
2921e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///  - an ObjCObjectType (currently always an ObjCInterfaceType)
2922c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  QualType getBaseType() const { return BaseType; }
292371842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek
2924c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool isObjCId() const {
2925c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getBaseType()->isSpecificBuiltinType(BuiltinType::ObjCId);
2926c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  }
2927c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool isObjCClass() const {
2928c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getBaseType()->isSpecificBuiltinType(BuiltinType::ObjCClass);
2929c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  }
2930c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool isObjCUnqualifiedId() const { return qual_empty() && isObjCId(); }
2931c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool isObjCUnqualifiedClass() const { return qual_empty() && isObjCClass(); }
2932c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool isObjCUnqualifiedIdOrClass() const {
2933c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    if (!qual_empty()) return false;
2934c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    if (const BuiltinType *T = getBaseType()->getAs<BuiltinType>())
2935c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall      return T->getKind() == BuiltinType::ObjCId ||
2936c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall             T->getKind() == BuiltinType::ObjCClass;
2937c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return false;
2938c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  }
2939c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool isObjCQualifiedId() const { return !qual_empty() && isObjCId(); }
2940c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool isObjCQualifiedClass() const { return !qual_empty() && isObjCClass(); }
2941c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
2942c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  /// Gets the interface declaration for this object type, if the base type
2943c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  /// really is an interface.
2944c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  ObjCInterfaceDecl *getInterface() const;
2945c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
2946c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  typedef ObjCProtocolDecl * const *qual_iterator;
2947c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
2948c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  qual_iterator qual_begin() const { return getProtocolStorage(); }
2949c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  qual_iterator qual_end() const { return qual_begin() + getNumProtocols(); }
2950c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
2951c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool qual_empty() const { return getNumProtocols() == 0; }
29521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2953c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff  /// getNumProtocols - Return the number of qualifying protocols in this
2954c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff  /// interface type, or 0 if there are none.
295571842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek  unsigned getNumProtocols() const { return NumProtocols; }
295614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff
2957c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  /// \brief Fetch a protocol by index.
295873dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor  ObjCProtocolDecl *getProtocol(unsigned I) const {
295973dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor    assert(I < getNumProtocols() && "Out-of-range protocol access");
296073dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor    return qual_begin()[I];
296173dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor  }
296273dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor
2963bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2964bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2965bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
2966c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  static bool classof(const Type *T) {
2967c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return T->getTypeClass() == ObjCObject ||
2968c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall           T->getTypeClass() == ObjCInterface;
2969c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  }
2970c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  static bool classof(const ObjCObjectType *) { return true; }
2971c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall};
2972c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
2973c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// ObjCObjectTypeImpl - A class providing a concrete implementation
2974c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// of ObjCObjectType, so as to not increase the footprint of
2975c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// ObjCInterfaceType.  Code outside of ASTContext and the core type
2976c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// system should not reference this type.
2977c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallclass ObjCObjectTypeImpl : public ObjCObjectType, public llvm::FoldingSetNode {
2978c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  friend class ASTContext;
2979c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
2980c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  // If anyone adds fields here, ObjCObjectType::getProtocolStorage()
2981c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  // will need to be modified.
2982c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
2983c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  ObjCObjectTypeImpl(QualType Canonical, QualType Base,
2984c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall                     ObjCProtocolDecl * const *Protocols,
2985c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall                     unsigned NumProtocols)
2986c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    : ObjCObjectType(Canonical, Base, Protocols, NumProtocols) {}
2987c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
2988c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallpublic:
2989c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  void Destroy(ASTContext& C); // key function
2990c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
2991c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff  void Profile(llvm::FoldingSetNodeID &ID);
29921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static void Profile(llvm::FoldingSetNodeID &ID,
2993c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall                      QualType Base,
2994c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall                      ObjCProtocolDecl *const *protocols,
2995c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall                      unsigned NumProtocols);
2996c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall};
29971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2998c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallinline ObjCProtocolDecl **ObjCObjectType::getProtocolStorage() {
2999c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  return reinterpret_cast<ObjCProtocolDecl**>(
3000c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall            static_cast<ObjCObjectTypeImpl*>(this) + 1);
3001c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall}
3002c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3003c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// ObjCInterfaceType - Interfaces are the core concept in Objective-C for
3004c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// object oriented design.  They basically correspond to C++ classes.  There
3005c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// are two kinds of interface types, normal interfaces like "NSString" and
3006c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// qualified interfaces, which are qualified with a protocol list like
3007c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// "NSString<NSCopyable, NSAmazing>".
3008e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall///
3009e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// ObjCInterfaceType guarantees the following properties when considered
3010e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// as a subtype of its superclass, ObjCObjectType:
3011e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall///   - There are no protocol qualifiers.  To reinforce this, code which
3012e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall///     tries to invoke the protocol methods via an ObjCInterfaceType will
3013e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall///     fail to compile.
3014e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall///   - It is its own base type.  That is, if T is an ObjCInterfaceType*,
3015e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall///     T->getBaseType() == QualType(T, 0).
3016c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallclass ObjCInterfaceType : public ObjCObjectType {
3017c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  ObjCInterfaceDecl *Decl;
3018c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3019c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  ObjCInterfaceType(const ObjCInterfaceDecl *D)
3020c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    : ObjCObjectType(Nonce_ObjCInterface),
3021c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall      Decl(const_cast<ObjCInterfaceDecl*>(D)) {}
3022c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  friend class ASTContext;  // ASTContext creates these.
3023c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallpublic:
3024c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  void Destroy(ASTContext& C); // key function
3025c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3026e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// getDecl - Get the declaration of this interface.
3027c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  ObjCInterfaceDecl *getDecl() const { return Decl; }
3028c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3029c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool isSugared() const { return false; }
3030c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  QualType desugar() const { return QualType(this, 0); }
30310b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor
30321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
30331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == ObjCInterface;
30343536b443bc50d58a79f14fca9b6842541a434854Steve Naroff  }
3035a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const ObjCInterfaceType *) { return true; }
3036c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3037c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  // Nonsense to "hide" certain members of ObjCObjectType within this
3038c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  // class.  People asking for protocols on an ObjCInterfaceType are
3039c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  // not going to get what they want: ObjCInterfaceTypes are
3040c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  // guaranteed to have no protocols.
3041c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  enum {
3042c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    qual_iterator,
3043c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    qual_begin,
3044c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    qual_end,
3045c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    getNumProtocols,
3046c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    getProtocol
3047c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  };
30483536b443bc50d58a79f14fca9b6842541a434854Steve Naroff};
30493536b443bc50d58a79f14fca9b6842541a434854Steve Naroff
3050c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallinline ObjCInterfaceDecl *ObjCObjectType::getInterface() const {
3051c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  if (const ObjCInterfaceType *T =
3052c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall        getBaseType()->getAs<ObjCInterfaceType>())
3053c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return T->getDecl();
3054c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  return 0;
3055c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall}
3056c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3057e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// ObjCObjectPointerType - Used to represent a pointer to an
3058e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// Objective C object.  These are constructed from pointer
3059e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// declarators when the pointee type is an ObjCObjectType (or sugar
3060e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// for one).  In addition, the 'id' and 'Class' types are typedefs
3061e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// for these, and the protocol-qualified types 'id<P>' and 'Class<P>'
3062e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// are translated into these.
306314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff///
3064e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// Pointers to pointers to Objective C objects are still PointerTypes;
3065e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// only the first level of pointer gets it own type implementation.
306614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroffclass ObjCObjectPointerType : public Type, public llvm::FoldingSetNode {
3067e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  QualType PointeeType;
30681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3069c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  ObjCObjectPointerType(QualType Canonical, QualType Pointee)
3070c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    : Type(ObjCObjectPointer, Canonical, false),
3071c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall      PointeeType(Pointee) {}
307214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  friend class ASTContext;  // ASTContext creates these.
30731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
307460e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregorprotected:
307560e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor  virtual Linkage getLinkageImpl() const;
307660e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
307714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroffpublic:
307871842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek  void Destroy(ASTContext& C);
307971842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek
3080e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// getPointeeType - Gets the type pointed to by this ObjC pointer.
3081e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// The result will always be an ObjCObjectType or sugar thereof.
308214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  QualType getPointeeType() const { return PointeeType; }
308314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff
3084e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// getObjCObjectType - Gets the type pointed to by this ObjC
3085e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// pointer.  This method always returns non-null.
3086e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///
3087e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// This method is equivalent to getPointeeType() except that
3088e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// it discards any typedefs (or other sugar) between this
3089e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// type and the "outermost" object type.  So for:
3090e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///   @class A; @protocol P; @protocol Q;
3091e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///   typedef A<P> AP;
3092e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///   typedef A A1;
3093e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///   typedef A1<P> A1P;
3094e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///   typedef A1P<Q> A1PQ;
3095e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// For 'A*', getObjectType() will return 'A'.
3096e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// For 'A<P>*', getObjectType() will return 'A<P>'.
3097e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// For 'AP*', getObjectType() will return 'A<P>'.
3098e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// For 'A1*', getObjectType() will return 'A'.
3099e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// For 'A1<P>*', getObjectType() will return 'A1<P>'.
3100e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// For 'A1P*', getObjectType() will return 'A1<P>'.
3101e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// For 'A1PQ*', getObjectType() will return 'A1<Q>', because
3102e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///   adding protocols to a protocol-qualified base discards the
3103e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///   old qualifiers (for now).  But if it didn't, getObjectType()
3104e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///   would return 'A1P<Q>' (and we'd have to make iterating over
3105e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///   qualifiers more complicated).
3106c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  const ObjCObjectType *getObjectType() const {
3107c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return PointeeType->getAs<ObjCObjectType>();
3108c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  }
3109c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3110e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// getInterfaceType - If this pointer points to an Objective C
3111e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// @interface type, gets the type for that interface.  Any protocol
3112e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// qualifiers on the interface are ignored.
3113e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///
3114e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// \return null if the base type for this pointer is 'id' or 'Class'
31151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  const ObjCInterfaceType *getInterfaceType() const {
3116c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getObjectType()->getBaseType()->getAs<ObjCInterfaceType>();
311714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  }
3118e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall
3119e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// getInterfaceDecl - If this pointer points to an Objective @interface
3120e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// type, gets the declaration for that interface.
3121e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///
3122e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// \return null if the base type for this pointer is 'id' or 'Class'
312314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  ObjCInterfaceDecl *getInterfaceDecl() const {
3124e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall    return getObjectType()->getInterface();
312514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  }
3126e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall
3127e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// isObjCIdType - True if this is equivalent to the 'id' type, i.e. if
3128e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// its object type is the primitive 'id' type with no protocols.
312914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  bool isObjCIdType() const {
3130c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getObjectType()->isObjCUnqualifiedId();
313114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  }
3132e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall
3133e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// isObjCClassType - True if this is equivalent to the 'Class' type,
3134e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// i.e. if its object tive is the primitive 'Class' type with no protocols.
313514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  bool isObjCClassType() const {
3136c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getObjectType()->isObjCUnqualifiedClass();
3137de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff  }
31388d2c0a9814e56c2b22e22d1045181c735aef62fdFariborz Jahanian
3139e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// isObjCQualifiedIdType - True if this is equivalent to 'id<P>' for some
3140e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// non-empty set of protocols.
31411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  bool isObjCQualifiedIdType() const {
3142c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getObjectType()->isObjCQualifiedId();
3143de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff  }
3144e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall
3145e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// isObjCQualifiedClassType - True if this is equivalent to 'Class<P>' for
3146e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// some non-empty set of protocols.
3147470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroff  bool isObjCQualifiedClassType() const {
3148c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getObjectType()->isObjCQualifiedClass();
314914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  }
3150e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall
3151e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// An iterator over the qualifiers on the object type.  Provided
3152e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// for convenience.  This will always iterate over the full set of
3153e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// protocols on a type, not just those provided directly.
3154c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  typedef ObjCObjectType::qual_iterator qual_iterator;
315514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff
315671842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek  qual_iterator qual_begin() const {
3157c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getObjectType()->qual_begin();
315871842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek  }
3159c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  qual_iterator qual_end() const {
3160c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getObjectType()->qual_end();
316171842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek  }
3162c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool qual_empty() const { return getObjectType()->qual_empty(); }
316314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff
3164e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// getNumProtocols - Return the number of qualifying protocols on
3165e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// the object type.
3166c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  unsigned getNumProtocols() const {
3167c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getObjectType()->getNumProtocols();
3168c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  }
316914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff
3170e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// \brief Retrieve a qualifying protocol by index on the object
3171e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// type.
317273dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor  ObjCProtocolDecl *getProtocol(unsigned I) const {
3173c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getObjectType()->getProtocol(I);
317473dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor  }
317573dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor
3176bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
3177bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
3178bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
3179e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  void Profile(llvm::FoldingSetNodeID &ID) {
3180e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall    Profile(ID, getPointeeType());
3181e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  }
3182c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  static void Profile(llvm::FoldingSetNodeID &ID, QualType T) {
3183c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    ID.AddPointer(T.getAsOpaquePtr());
3184c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  }
31851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
31861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == ObjCObjectPointer;
318714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  }
318814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  static bool classof(const ObjCObjectPointerType *) { return true; }
318914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff};
31901bb8a45f7386a23871598d05141a07af03067925Argyrios Kyrtzidis
31910953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// A qualifier set is used to build a set of qualifiers.
31920953e767ff7817f97b3ab20896b229891eeff45bJohn McCallclass QualifierCollector : public Qualifiers {
31930953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  ASTContext *Context;
31940953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
31950953e767ff7817f97b3ab20896b229891eeff45bJohn McCallpublic:
31960953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  QualifierCollector(Qualifiers Qs = Qualifiers())
31970953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    : Qualifiers(Qs), Context(0) {}
31980953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  QualifierCollector(ASTContext &Context, Qualifiers Qs = Qualifiers())
31990953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    : Qualifiers(Qs), Context(&Context) {}
32000953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
32010953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void setContext(ASTContext &C) { Context = &C; }
32020953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
32030953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// Collect any qualifiers on the given type and return an
32040953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// unqualified type.
32050953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  const Type *strip(QualType QT) {
3206a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor    addFastQualifiers(QT.getLocalFastQualifiers());
3207a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor    if (QT.hasLocalNonFastQualifiers()) {
32080953e767ff7817f97b3ab20896b229891eeff45bJohn McCall      const ExtQuals *EQ = QT.getExtQualsUnsafe();
32090953e767ff7817f97b3ab20896b229891eeff45bJohn McCall      Context = &EQ->getContext();
32100953e767ff7817f97b3ab20896b229891eeff45bJohn McCall      addQualifiers(EQ->getQualifiers());
32110953e767ff7817f97b3ab20896b229891eeff45bJohn McCall      return EQ->getBaseType();
32120953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    }
32130953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return QT.getTypePtrUnsafe();
32140953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
32150953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
32160953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// Apply the collected qualifiers to the given type.
32170953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  QualType apply(QualType QT) const;
32180953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
32190953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// Apply the collected qualifiers to the given type.
32200953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  QualType apply(const Type* T) const;
32210953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
32220953e767ff7817f97b3ab20896b229891eeff45bJohn McCall};
32230953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
32240953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3225611c1fff195d32df97706e0920c92468b2509900Chris Lattner// Inline function definitions.
32265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3227467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCallinline bool QualType::isCanonical() const {
3228467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall  const Type *T = getTypePtr();
3229a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  if (hasLocalQualifiers())
3230467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall    return T->isCanonicalUnqualified() && !isa<ArrayType>(T);
3231467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall  return T->isCanonicalUnqualified();
3232467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall}
3233467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall
323454e14c4db764c0636160d26c5bbf491637c83a76John McCallinline bool QualType::isCanonicalAsParam() const {
3235a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  if (hasLocalQualifiers()) return false;
323654e14c4db764c0636160d26c5bbf491637c83a76John McCall  const Type *T = getTypePtr();
323754e14c4db764c0636160d26c5bbf491637c83a76John McCall  return T->isCanonicalUnqualified() &&
323854e14c4db764c0636160d26c5bbf491637c83a76John McCall           !isa<FunctionType>(T) && !isa<ArrayType>(T);
323954e14c4db764c0636160d26c5bbf491637c83a76John McCall}
324054e14c4db764c0636160d26c5bbf491637c83a76John McCall
3241fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregorinline bool QualType::isConstQualified() const {
3242fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  return isLocalConstQualified() ||
3243fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor              getTypePtr()->getCanonicalTypeInternal().isLocalConstQualified();
3244fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor}
3245fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor
3246fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregorinline bool QualType::isRestrictQualified() const {
3247fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  return isLocalRestrictQualified() ||
3248fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor            getTypePtr()->getCanonicalTypeInternal().isLocalRestrictQualified();
3249fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor}
3250fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor
3251fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor
3252fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregorinline bool QualType::isVolatileQualified() const {
3253fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  return isLocalVolatileQualified() ||
3254fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  getTypePtr()->getCanonicalTypeInternal().isLocalVolatileQualified();
3255fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor}
3256fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor
3257fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregorinline bool QualType::hasQualifiers() const {
3258fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  return hasLocalQualifiers() ||
3259fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor                  getTypePtr()->getCanonicalTypeInternal().hasLocalQualifiers();
3260fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor}
3261fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor
3262fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregorinline Qualifiers QualType::getQualifiers() const {
3263fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  Qualifiers Quals = getLocalQualifiers();
3264fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  Quals.addQualifiers(
3265fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor                 getTypePtr()->getCanonicalTypeInternal().getLocalQualifiers());
3266fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  return Quals;
3267fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor}
3268fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor
3269fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregorinline unsigned QualType::getCVRQualifiers() const {
3270fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  return getLocalCVRQualifiers() |
3271fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor              getTypePtr()->getCanonicalTypeInternal().getLocalCVRQualifiers();
3272fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor}
3273e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth
3274e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth/// getCVRQualifiersThroughArrayTypes - If there are CVR qualifiers for this
3275e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth/// type, returns them. Otherwise, if this is an array type, recurses
3276e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth/// on the element type until some qualifiers have been found or a non-array
3277e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth/// type reached.
3278e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruthinline unsigned QualType::getCVRQualifiersThroughArrayTypes() const {
3279e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth  if (unsigned Quals = getCVRQualifiers())
3280e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth    return Quals;
3281e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth  QualType CT = getTypePtr()->getCanonicalTypeInternal();
3282e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth  if (const ArrayType *AT = dyn_cast<ArrayType>(CT))
3283e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth    return AT->getElementType().getCVRQualifiersThroughArrayTypes();
3284e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth  return 0;
3285e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth}
3286e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth
32870953e767ff7817f97b3ab20896b229891eeff45bJohn McCallinline void QualType::removeConst() {
32880953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  removeFastQualifiers(Qualifiers::Const);
32890953e767ff7817f97b3ab20896b229891eeff45bJohn McCall}
32900953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
32910953e767ff7817f97b3ab20896b229891eeff45bJohn McCallinline void QualType::removeRestrict() {
32920953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  removeFastQualifiers(Qualifiers::Restrict);
32930953e767ff7817f97b3ab20896b229891eeff45bJohn McCall}
32940953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
32950953e767ff7817f97b3ab20896b229891eeff45bJohn McCallinline void QualType::removeVolatile() {
32960953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  QualifierCollector Qc;
32970953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  const Type *Ty = Qc.strip(*this);
32980953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  if (Qc.hasVolatile()) {
32990953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Qc.removeVolatile();
33000953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    *this = Qc.apply(Ty);
33010953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
33020953e767ff7817f97b3ab20896b229891eeff45bJohn McCall}
33030953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
33040953e767ff7817f97b3ab20896b229891eeff45bJohn McCallinline void QualType::removeCVRQualifiers(unsigned Mask) {
33056b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall  assert(!(Mask & ~Qualifiers::CVRMask) && "mask has non-CVR bits");
33060953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
33070953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Fast path: we don't need to touch the slow qualifiers.
33080953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  if (!(Mask & ~Qualifiers::FastMask)) {
33090953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    removeFastQualifiers(Mask);
33100953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return;
33110953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
33120953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
33130953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  QualifierCollector Qc;
33140953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  const Type *Ty = Qc.strip(*this);
33150953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  Qc.removeCVRQualifiers(Mask);
33160953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  *this = Qc.apply(Ty);
3317ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb}
3318ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb
3319ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb/// getAddressSpace - Return the address space of this type.
3320ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lambinline unsigned QualType::getAddressSpace() const {
3321a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  if (hasLocalNonFastQualifiers()) {
33220953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    const ExtQuals *EQ = getExtQualsUnsafe();
33230953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    if (EQ->hasAddressSpace())
33240953e767ff7817f97b3ab20896b229891eeff45bJohn McCall      return EQ->getAddressSpace();
33250953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
33260953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
33274243a94b43ef6207938f3023dfcfb804dd545363Chris Lattner  QualType CT = getTypePtr()->getCanonicalTypeInternal();
3328a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  if (CT.hasLocalNonFastQualifiers()) {
33290953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    const ExtQuals *EQ = CT.getExtQualsUnsafe();
33300953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    if (EQ->hasAddressSpace())
33310953e767ff7817f97b3ab20896b229891eeff45bJohn McCall      return EQ->getAddressSpace();
33320953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
33330953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
33344243a94b43ef6207938f3023dfcfb804dd545363Chris Lattner  if (const ArrayType *AT = dyn_cast<ArrayType>(CT))
3335c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner    return AT->getElementType().getAddressSpace();
33364243a94b43ef6207938f3023dfcfb804dd545363Chris Lattner  if (const RecordType *RT = dyn_cast<RecordType>(CT))
33378e7dafec4b70303dfaff95151cd06bfc5532720cNate Begeman    return RT->getAddressSpace();
3338ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb  return 0;
3339ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb}
3340611c1fff195d32df97706e0920c92468b2509900Chris Lattner
3341d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian/// getObjCGCAttr - Return the gc attribute of this type.
33420953e767ff7817f97b3ab20896b229891eeff45bJohn McCallinline Qualifiers::GC QualType::getObjCGCAttr() const {
3343a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  if (hasLocalNonFastQualifiers()) {
33440953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    const ExtQuals *EQ = getExtQualsUnsafe();
33450953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    if (EQ->hasObjCGCAttr())
33460953e767ff7817f97b3ab20896b229891eeff45bJohn McCall      return EQ->getObjCGCAttr();
33470953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
33480953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3349d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian  QualType CT = getTypePtr()->getCanonicalTypeInternal();
3350a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  if (CT.hasLocalNonFastQualifiers()) {
33510953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    const ExtQuals *EQ = CT.getExtQualsUnsafe();
33520953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    if (EQ->hasObjCGCAttr())
33530953e767ff7817f97b3ab20896b229891eeff45bJohn McCall      return EQ->getObjCGCAttr();
33540953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
33550953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3356d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian  if (const ArrayType *AT = dyn_cast<ArrayType>(CT))
3357d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian      return AT->getElementType().getObjCGCAttr();
3358183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  if (const ObjCObjectPointerType *PT = CT->getAs<ObjCObjectPointerType>())
33591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return PT->getPointeeType().getObjCGCAttr();
3360ac423ba85bb59cc7cc1d43081b20d7e8d40355ffFariborz Jahanian  // We most look at all pointer types, not just pointer to interface types.
3361ac423ba85bb59cc7cc1d43081b20d7e8d40355ffFariborz Jahanian  if (const PointerType *PT = CT->getAs<PointerType>())
33621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return PT->getPointeeType().getObjCGCAttr();
33630953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  return Qualifiers::GCNone;
3364d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian}
33652455636163fdd18581d7fdae816433f886d88213Mike Stump
3366264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindolainline FunctionType::ExtInfo getFunctionExtInfo(const Type &t) {
3367264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola  if (const PointerType *PT = t.getAs<PointerType>()) {
3368183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall    if (const FunctionType *FT = PT->getPointeeType()->getAs<FunctionType>())
3369264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola      return FT->getExtInfo();
3370264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola  } else if (const FunctionType *FT = t.getAs<FunctionType>())
3371264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    return FT->getExtInfo();
33722455636163fdd18581d7fdae816433f886d88213Mike Stump
3373264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola  return FunctionType::ExtInfo();
33742455636163fdd18581d7fdae816433f886d88213Mike Stump}
33751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3376264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindolainline FunctionType::ExtInfo getFunctionExtInfo(QualType t) {
3377264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola  return getFunctionExtInfo(*t);
3378ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor}
3379ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor
3380b87786f045d798b070980c108c922e1475d27b15Douglas Gregor/// \brief Determine whether this set of qualifiers is a superset of the given
3381b87786f045d798b070980c108c922e1475d27b15Douglas Gregor/// set of qualifiers.
3382b87786f045d798b070980c108c922e1475d27b15Douglas Gregorinline bool Qualifiers::isSupersetOf(Qualifiers Other) const {
3383b87786f045d798b070980c108c922e1475d27b15Douglas Gregor  return Mask != Other.Mask && (Mask | Other.Mask) == Mask;
3384b87786f045d798b070980c108c922e1475d27b15Douglas Gregor}
3385b87786f045d798b070980c108c922e1475d27b15Douglas Gregor
3386e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// isMoreQualifiedThan - Determine whether this type is more
3387e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// qualified than the Other type. For example, "const volatile int"
3388e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// is more qualified than "const int", "volatile int", and
3389e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// "int". However, it is not more qualified than "const volatile
3390e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// int".
3391e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregorinline bool QualType::isMoreQualifiedThan(QualType Other) const {
33920953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // FIXME: work on arbitrary qualifiers
3393e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth  unsigned MyQuals = this->getCVRQualifiersThroughArrayTypes();
3394e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth  unsigned OtherQuals = Other.getCVRQualifiersThroughArrayTypes();
3395ecca7536488e425417dcb005c39cc15ae1947aabChris Lattner  if (getAddressSpace() != Other.getAddressSpace())
3396ecca7536488e425417dcb005c39cc15ae1947aabChris Lattner    return false;
3397e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor  return MyQuals != OtherQuals && (MyQuals | OtherQuals) == MyQuals;
3398e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor}
3399e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor
3400e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// isAtLeastAsQualifiedAs - Determine whether this type is at last
3401e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// as qualified as the Other type. For example, "const volatile
3402e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// int" is at least as qualified as "const int", "volatile int",
3403e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// "int", and "const volatile int".
3404e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregorinline bool QualType::isAtLeastAsQualifiedAs(QualType Other) const {
34050953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // FIXME: work on arbitrary qualifiers
3406e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth  unsigned MyQuals = this->getCVRQualifiersThroughArrayTypes();
3407e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth  unsigned OtherQuals = Other.getCVRQualifiersThroughArrayTypes();
3408ecca7536488e425417dcb005c39cc15ae1947aabChris Lattner  if (getAddressSpace() != Other.getAddressSpace())
3409ecca7536488e425417dcb005c39cc15ae1947aabChris Lattner    return false;
3410e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor  return (MyQuals | OtherQuals) == MyQuals;
3411e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor}
3412e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor
3413e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// getNonReferenceType - If Type is a reference type (e.g., const
3414e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// int&), returns the type that the reference refers to ("const
3415e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// int"). Otherwise, returns the type itself. This routine is used
3416e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// throughout Sema to implement C++ 5p6:
3417e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor///
3418e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor///   If an expression initially has the type "reference to T" (8.3.2,
3419e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor///   8.5.3), the type is adjusted to "T" prior to any further
3420e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor///   analysis, the expression designates the object or function
3421e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor///   denoted by the reference, and the expression is an lvalue.
3422e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregorinline QualType QualType::getNonReferenceType() const {
34236217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek  if (const ReferenceType *RefType = (*this)->getAs<ReferenceType>())
3424e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor    return RefType->getPointeeType();
3425e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor  else
3426e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor    return *this;
3427e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor}
3428e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor
3429611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isFunctionType() const {
3430a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<FunctionType>(CanonicalType);
3431611c1fff195d32df97706e0920c92468b2509900Chris Lattner}
3432611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isPointerType() const {
3433a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<PointerType>(CanonicalType);
3434611c1fff195d32df97706e0920c92468b2509900Chris Lattner}
343558f9f2c884af6b72d036b746a016d8031d31cb7aSteve Naroffinline bool Type::isAnyPointerType() const {
343658f9f2c884af6b72d036b746a016d8031d31cb7aSteve Naroff  return isPointerType() || isObjCObjectPointerType();
343758f9f2c884af6b72d036b746a016d8031d31cb7aSteve Naroff}
34385618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroffinline bool Type::isBlockPointerType() const {
3439a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<BlockPointerType>(CanonicalType);
34405618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff}
3441bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattnerinline bool Type::isReferenceType() const {
3442a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<ReferenceType>(CanonicalType);
3443bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner}
34447c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlinline bool Type::isLValueReferenceType() const {
3445a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<LValueReferenceType>(CanonicalType);
34467c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl}
34477c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlinline bool Type::isRValueReferenceType() const {
3448a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<RValueReferenceType>(CanonicalType);
34497c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl}
3450498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenekinline bool Type::isFunctionPointerType() const {
34516217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek  if (const PointerType* T = getAs<PointerType>())
3452498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek    return T->getPointeeType()->isFunctionType();
3453498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek  else
3454498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek    return false;
3455498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek}
3456f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlinline bool Type::isMemberPointerType() const {
3457a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<MemberPointerType>(CanonicalType);
3458f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl}
3459f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlinline bool Type::isMemberFunctionPointerType() const {
34606217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek  if (const MemberPointerType* T = getAs<MemberPointerType>())
3461f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    return T->getPointeeType()->isFunctionType();
3462f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  else
3463f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    return false;
3464f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl}
3465611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isArrayType() const {
3466a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<ArrayType>(CanonicalType);
3467611c1fff195d32df97706e0920c92468b2509900Chris Lattner}
3468c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattnerinline bool Type::isConstantArrayType() const {
3469a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<ConstantArrayType>(CanonicalType);
3470c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner}
3471c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattnerinline bool Type::isIncompleteArrayType() const {
3472a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<IncompleteArrayType>(CanonicalType);
3473c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner}
3474c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattnerinline bool Type::isVariableArrayType() const {
3475a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<VariableArrayType>(CanonicalType);
3476c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner}
3477898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorinline bool Type::isDependentSizedArrayType() const {
3478a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<DependentSizedArrayType>(CanonicalType);
3479898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor}
3480611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isRecordType() const {
3481a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<RecordType>(CanonicalType);
3482611c1fff195d32df97706e0920c92468b2509900Chris Lattner}
3483f23d364084d1aabea688222780d6fc1dd8c7f78cChris Lattnerinline bool Type::isAnyComplexType() const {
3484a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<ComplexType>(CanonicalType);
3485f23d364084d1aabea688222780d6fc1dd8c7f78cChris Lattner}
3486611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isVectorType() const {
3487a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<VectorType>(CanonicalType);
3488611c1fff195d32df97706e0920c92468b2509900Chris Lattner}
3489213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begemaninline bool Type::isExtVectorType() const {
3490a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<ExtVectorType>(CanonicalType);
3491611c1fff195d32df97706e0920c92468b2509900Chris Lattner}
3492d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroffinline bool Type::isObjCObjectPointerType() const {
3493a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<ObjCObjectPointerType>(CanonicalType);
3494d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff}
3495c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallinline bool Type::isObjCObjectType() const {
3496c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  return isa<ObjCObjectType>(CanonicalType);
3497368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner}
3498a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekinline bool Type::isObjCQualifiedIdType() const {
3499183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>())
3500d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff    return OPT->isObjCQualifiedIdType();
3501d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff  return false;
3502d58fabf7ed279be18a5e82617f809c9deff9be67Fariborz Jahanian}
3503470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroffinline bool Type::isObjCQualifiedClassType() const {
3504183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>())
3505470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroff    return OPT->isObjCQualifiedClassType();
3506470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroff  return false;
3507470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroff}
350814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroffinline bool Type::isObjCIdType() const {
3509183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>())
351014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff    return OPT->isObjCIdType();
351114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  return false;
351214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff}
351314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroffinline bool Type::isObjCClassType() const {
3514183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>())
351514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff    return OPT->isObjCClassType();
351614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  return false;
351714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff}
351813dcd00615de5c4279d97bdf63cd5f0a14fd9dccFariborz Jahanianinline bool Type::isObjCSelType() const {
35198d2c0a9814e56c2b22e22d1045181c735aef62fdFariborz Jahanian  if (const PointerType *OPT = getAs<PointerType>())
35208d2c0a9814e56c2b22e22d1045181c735aef62fdFariborz Jahanian    return OPT->getPointeeType()->isSpecificBuiltinType(BuiltinType::ObjCSel);
352113dcd00615de5c4279d97bdf63cd5f0a14fd9dccFariborz Jahanian  return false;
352213dcd00615de5c4279d97bdf63cd5f0a14fd9dccFariborz Jahanian}
3523de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroffinline bool Type::isObjCBuiltinType() const {
352413dcd00615de5c4279d97bdf63cd5f0a14fd9dccFariborz Jahanian  return isObjCIdType() || isObjCClassType() || isObjCSelType();
3525de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff}
352672c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregorinline bool Type::isTemplateTypeParmType() const {
3527a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<TemplateTypeParmType>(CanonicalType);
352872c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor}
352972c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor
35309b065ddabf572772991a4aadad5bf4921fac5069Tom Careinline bool Type::isBuiltinType() const {
35319b065ddabf572772991a4aadad5bf4921fac5069Tom Care  return getAs<BuiltinType>();
35329b065ddabf572772991a4aadad5bf4921fac5069Tom Care}
35339b065ddabf572772991a4aadad5bf4921fac5069Tom Care
3534e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbarinline bool Type::isSpecificBuiltinType(unsigned K) const {
3535183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  if (const BuiltinType *BT = getAs<BuiltinType>())
3536e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar    if (BT->getKind() == (BuiltinType::Kind) K)
3537e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar      return true;
3538e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar  return false;
3539e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar}
3540e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar
3541063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor/// \brief Determines whether this is a type for which one can define
3542063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor/// an overloaded operator.
3543063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregorinline bool Type::isOverloadableType() const {
3544063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  return isDependentType() || isRecordType() || isEnumeralType();
3545904eed3f6148758d39a2d3c88f3133274460d645Douglas Gregor}
3546904eed3f6148758d39a2d3c88f3133274460d645Douglas Gregor
35478958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbarinline bool Type::hasPointerRepresentation() const {
35488958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar  return (isPointerType() || isReferenceType() || isBlockPointerType() ||
3549c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall          isObjCObjectPointerType() || isNullPtrType());
35508958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar}
35518958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar
3552820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanianinline bool Type::hasObjCPointerRepresentation() const {
3553c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  return isObjCObjectPointerType();
3554820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian}
3555820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian
355622caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner/// Insertion operator for diagnostics.  This allows sending QualType's into a
355722caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner/// diagnostic with <<.
355822caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattnerinline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
355922caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner                                           QualType T) {
356022caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner  DB.AddTaggedVal(reinterpret_cast<intptr_t>(T.getAsOpaquePtr()),
356122caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner                  Diagnostic::ak_qualtype);
356222caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner  return DB;
356322caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner}
35641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
356547c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth/// Insertion operator for partial diagnostics.  This allows sending QualType's
356647c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth/// into a diagnostic with <<.
356747c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruthinline const PartialDiagnostic &operator<<(const PartialDiagnostic &PD,
356847c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth                                           QualType T) {
356947c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth  PD.AddTaggedVal(reinterpret_cast<intptr_t>(T.getAsOpaquePtr()),
357047c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth                  Diagnostic::ak_qualtype);
357147c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth  return PD;
357247c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth}
357347c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth
357489c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor// Helper class template that is used by Type::getAs to ensure that one does
357589c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor// not try to look through a qualified type to get to an array type.
357689c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregortemplate<typename T,
357789c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor         bool isArrayType = (llvm::is_same<T, ArrayType>::value ||
357889c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor                             llvm::is_base_of<ArrayType, T>::value)>
357989c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregorstruct ArrayType_cannot_be_used_with_getAs { };
358089c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor
358189c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregortemplate<typename T>
358289c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregorstruct ArrayType_cannot_be_used_with_getAs<T, true>;
358389c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor
35841a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek/// Member-template getAs<specific type>'.
35851a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenektemplate <typename T> const T *Type::getAs() const {
358689c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor  ArrayType_cannot_be_used_with_getAs<T> at;
358789c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor  (void)at;
358889c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor
35891a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek  // If this is directly a T type, return it.
35901a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek  if (const T *Ty = dyn_cast<T>(this))
35911a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek    return Ty;
35921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
35931a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek  // If the canonical form of this type isn't the right kind, reject it.
35940953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  if (!isa<T>(CanonicalType))
35951a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek    return 0;
35961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
35970953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // If this is a typedef for the type, strip the typedef off without
35981a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek  // losing all typedef information.
3599bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  return cast<T>(getUnqualifiedDesugaredType());
36001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump}
360122caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner
36025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}  // end namespace clang
36035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
36045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif
3605