Type.h revision d0937224f383c7cc72c947119380f9713a070c73
15f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===--- Type.h - C Language Family Type Representation ---------*- C++ -*-===//
25f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
35f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//                     The LLVM Compiler Infrastructure
45f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
50bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// This file is distributed under the University of Illinois Open Source
60bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// License. See LICENSE.TXT for details.
75f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
85f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
95f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//  This file defines the Type interface and subclasses.
115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#ifndef LLVM_CLANG_AST_TYPE_H
155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#define LLVM_CLANG_AST_TYPE_H
165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1722caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner#include "clang/Basic/Diagnostic.h"
181734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor#include "clang/Basic/IdentifierTable.h"
190b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor#include "clang/Basic/Linkage.h"
2047c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth#include "clang/Basic/PartialDiagnostic.h"
211fb0caaa7bef765b85972274e3b434af2572c141John McCall#include "clang/Basic/Visibility.h"
22e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor#include "clang/AST/NestedNameSpecifier.h"
237532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor#include "clang/AST/TemplateName.h"
245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "llvm/Support/Casting.h"
2550d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor#include "llvm/Support/type_traits.h"
26fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff#include "llvm/ADT/APSInt.h"
275cf243a883872441d73ca49cea7e20de5802629bChris Lattner#include "llvm/ADT/FoldingSet.h"
285cf243a883872441d73ca49cea7e20de5802629bChris Lattner#include "llvm/ADT/PointerIntPair.h"
291734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor#include "llvm/ADT/PointerUnion.h"
307532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor
315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing llvm::isa;
325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing llvm::cast;
335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing llvm::cast_or_null;
345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing llvm::dyn_cast;
355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing llvm::dyn_cast_or_null;
366b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCallnamespace clang {
376b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall  enum {
38f7616b9067790757f4e12e834b216c53c8c04ebeDouglas Gregor    TypeAlignmentInBits = 4,
396b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall    TypeAlignment = 1 << TypeAlignmentInBits
406b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall  };
41aed1df80bf64228e1429c1edc408397f9174847cChris Lattner  class Type;
42aed1df80bf64228e1429c1edc408397f9174847cChris Lattner  class ExtQuals;
43aed1df80bf64228e1429c1edc408397f9174847cChris Lattner  class QualType;
446b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall}
455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
464e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattnernamespace llvm {
474e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner  template <typename T>
48daae940507f2e93c6fa12e8062fa958e34cc2d1cChris Lattner  class PointerLikeTypeTraits;
49bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner  template<>
50bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner  class PointerLikeTypeTraits< ::clang::Type*> {
51bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner  public:
52bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner    static inline void *getAsVoidPointer(::clang::Type *P) { return P; }
53bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner    static inline ::clang::Type *getFromVoidPointer(void *P) {
54bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner      return static_cast< ::clang::Type*>(P);
55bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner    }
566b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall    enum { NumLowBitsAvailable = clang::TypeAlignmentInBits };
57bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner  };
580953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  template<>
590953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  class PointerLikeTypeTraits< ::clang::ExtQuals*> {
600953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  public:
610953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    static inline void *getAsVoidPointer(::clang::ExtQuals *P) { return P; }
620953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    static inline ::clang::ExtQuals *getFromVoidPointer(void *P) {
630953e767ff7817f97b3ab20896b229891eeff45bJohn McCall      return static_cast< ::clang::ExtQuals*>(P);
640953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    }
656b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall    enum { NumLowBitsAvailable = clang::TypeAlignmentInBits };
660953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  };
67aed1df80bf64228e1429c1edc408397f9174847cChris Lattner
68aed1df80bf64228e1429c1edc408397f9174847cChris Lattner  template <>
69aed1df80bf64228e1429c1edc408397f9174847cChris Lattner  struct isPodLike<clang::QualType> { static const bool value = true; };
704e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner}
714e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner
725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang {
735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class ASTContext;
745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class TypedefDecl;
7555f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  class TemplateDecl;
7672c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor  class TemplateTypeParmDecl;
77aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor  class NonTypeTemplateParmDecl;
787532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor  class TemplateTemplateParmDecl;
795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class TagDecl;
805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class RecordDecl;
8149aa7ff1245abd03e6e998e01302df31e4c6f8f6Argyrios Kyrtzidis  class CXXRecordDecl;
825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class EnumDecl;
8321d50e12c3c412d8457071dc419363b7a7e8b855Ted Kremenek  class FieldDecl;
84a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  class ObjCInterfaceDecl;
85a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  class ObjCProtocolDecl;
86a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  class ObjCMethodDecl;
87ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  class UnresolvedUsingTypenameDecl;
885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class Expr;
89b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek  class Stmt;
905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class SourceLocation;
9192866e2e90f6d93fb95e25a7ac4438e239d89ce6Ted Kremenek  class StmtIteratorBase;
9240808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  class TemplateArgument;
93833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  class TemplateArgumentLoc;
94d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  class TemplateArgumentListInfo;
95ead608af31b6c9abeae1ca6d0b75094dac4641c0John McCall  class Type;
96465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  class ElaboratedType;
973b4ea54acf01f72f6eb74d96689dda86d950228fDaniel Dunbar  struct PrintingPolicy;
9872564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor
99ead608af31b6c9abeae1ca6d0b75094dac4641c0John McCall  template <typename> class CanQual;
100ead608af31b6c9abeae1ca6d0b75094dac4641c0John McCall  typedef CanQual<Type> CanQualType;
101ead608af31b6c9abeae1ca6d0b75094dac4641c0John McCall
10272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  // Provide forward declarations for all of the *Type classes
10372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#define TYPE(Class, Base) class Class##Type;
10472564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#include "clang/AST/TypeNodes.def"
105f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl
1060953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// Qualifiers - The collection of all-type qualifiers we support.
1070953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// Clang supports five independent qualifiers:
1080953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// * C99: const, volatile, and restrict
1090953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// * Embedded C (TR18037): address spaces
1100953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// * Objective C: the GC attributes (none, weak, or strong)
1110953e767ff7817f97b3ab20896b229891eeff45bJohn McCallclass Qualifiers {
1125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
1130953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  enum TQ { // NOTE: These flags must be kept in sync with DeclSpec::TQ.
1145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Const    = 0x1,
1155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Restrict = 0x2,
1165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Volatile = 0x4,
1170953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    CVRMask = Const | Volatile | Restrict
1185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
1191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1200953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  enum GC {
121d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian    GCNone = 0,
122d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian    Weak,
123d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian    Strong
124d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian  };
125efadb7768e7c7418185f5a4010ecd8b21ca9731bJohn McCall
1260953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  enum {
1270953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    /// The maximum supported address space number.
1280953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    /// 24 bits should be enough for anyone.
1290953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    MaxAddressSpace = 0xffffffu,
1300953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
1310953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    /// The width of the "fast" qualifier mask.
132f7616b9067790757f4e12e834b216c53c8c04ebeDouglas Gregor    FastWidth = 3,
1330953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
1340953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    /// The fast qualifier mask.
1350953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    FastMask = (1 << FastWidth) - 1
1360953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  };
1370953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
1380953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  Qualifiers() : Mask(0) {}
1390953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
1400953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  static Qualifiers fromFastMask(unsigned Mask) {
1410953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Qualifiers Qs;
1420953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Qs.addFastQualifiers(Mask);
1430953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return Qs;
1440953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
1450953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
1460953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  static Qualifiers fromCVRMask(unsigned CVR) {
1470953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Qualifiers Qs;
1480953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Qs.addCVRQualifiers(CVR);
1490953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return Qs;
1500953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
1510953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
1520953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Deserialize qualifiers from an opaque representation.
1530953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  static Qualifiers fromOpaqueValue(unsigned opaque) {
1540953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Qualifiers Qs;
1550953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Qs.Mask = opaque;
1560953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return Qs;
1570953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
1580953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
1590953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Serialize these qualifiers into an opaque representation.
1600953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  unsigned getAsOpaqueValue() const {
1610953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return Mask;
1620953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
1630953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
1640953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool hasConst() const { return Mask & Const; }
1650953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void setConst(bool flag) {
1660953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask = (Mask & ~Const) | (flag ? Const : 0);
1670953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
1680953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void removeConst() { Mask &= ~Const; }
1690953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void addConst() { Mask |= Const; }
1700953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
1710953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool hasVolatile() const { return Mask & Volatile; }
1720953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void setVolatile(bool flag) {
1730953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask = (Mask & ~Volatile) | (flag ? Volatile : 0);
1740953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
1750953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void removeVolatile() { Mask &= ~Volatile; }
1760953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void addVolatile() { Mask |= Volatile; }
1770953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
1780953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool hasRestrict() const { return Mask & Restrict; }
1790953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void setRestrict(bool flag) {
1800953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask = (Mask & ~Restrict) | (flag ? Restrict : 0);
1810953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
1820953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void removeRestrict() { Mask &= ~Restrict; }
1830953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void addRestrict() { Mask |= Restrict; }
1840953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
1850953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool hasCVRQualifiers() const { return getCVRQualifiers(); }
1860953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  unsigned getCVRQualifiers() const { return Mask & CVRMask; }
1870953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void setCVRQualifiers(unsigned mask) {
1880953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(!(mask & ~CVRMask) && "bitmask contains non-CVR bits");
1890953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask = (Mask & ~CVRMask) | mask;
1900953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
1910953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void removeCVRQualifiers(unsigned mask) {
1920953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(!(mask & ~CVRMask) && "bitmask contains non-CVR bits");
1930953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask &= ~mask;
1940953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
1950953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void removeCVRQualifiers() {
1960953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    removeCVRQualifiers(CVRMask);
1970953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
1980953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void addCVRQualifiers(unsigned mask) {
1990953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(!(mask & ~CVRMask) && "bitmask contains non-CVR bits");
2000953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask |= mask;
2010953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2020953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
2030953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool hasObjCGCAttr() const { return Mask & GCAttrMask; }
2040953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  GC getObjCGCAttr() const { return GC((Mask & GCAttrMask) >> GCAttrShift); }
2050953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void setObjCGCAttr(GC type) {
2060953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask = (Mask & ~GCAttrMask) | (type << GCAttrShift);
2070953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2080953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void removeObjCGCAttr() { setObjCGCAttr(GCNone); }
2090953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void addObjCGCAttr(GC type) {
2100953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(type);
2110953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    setObjCGCAttr(type);
2120953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2130953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
2140953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool hasAddressSpace() const { return Mask & AddressSpaceMask; }
2150953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  unsigned getAddressSpace() const { return Mask >> AddressSpaceShift; }
2160953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void setAddressSpace(unsigned space) {
2170953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(space <= MaxAddressSpace);
2180953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask = (Mask & ~AddressSpaceMask)
2190953e767ff7817f97b3ab20896b229891eeff45bJohn McCall         | (((uint32_t) space) << AddressSpaceShift);
2200953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2210953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void removeAddressSpace() { setAddressSpace(0); }
2220953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void addAddressSpace(unsigned space) {
2230953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(space);
2240953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    setAddressSpace(space);
2250953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2260953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
2270953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Fast qualifiers are those that can be allocated directly
2280953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // on a QualType object.
2290953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool hasFastQualifiers() const { return getFastQualifiers(); }
2300953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  unsigned getFastQualifiers() const { return Mask & FastMask; }
2310953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void setFastQualifiers(unsigned mask) {
2320953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(!(mask & ~FastMask) && "bitmask contains non-fast qualifier bits");
2330953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask = (Mask & ~FastMask) | mask;
2340953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2350953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void removeFastQualifiers(unsigned mask) {
2360953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(!(mask & ~FastMask) && "bitmask contains non-fast qualifier bits");
2370953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask &= ~mask;
2380953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2390953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void removeFastQualifiers() {
2400953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    removeFastQualifiers(FastMask);
2410953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2420953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void addFastQualifiers(unsigned mask) {
2430953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(!(mask & ~FastMask) && "bitmask contains non-fast qualifier bits");
2440953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask |= mask;
2450953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2460953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
2470953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// hasNonFastQualifiers - Return true if the set contains any
2480953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// qualifiers which require an ExtQuals node to be allocated.
2490953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool hasNonFastQualifiers() const { return Mask & ~FastMask; }
2500953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  Qualifiers getNonFastQualifiers() const {
2510953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Qualifiers Quals = *this;
2520953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Quals.setFastQualifiers(0);
2530953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return Quals;
2540953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2550953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
2560953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// hasQualifiers - Return true if the set contains any qualifiers.
2570953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool hasQualifiers() const { return Mask; }
2580953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool empty() const { return !Mask; }
2590953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
2600953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// \brief Add the qualifiers from the given set to this set.
2610953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void addQualifiers(Qualifiers Q) {
2620953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    // If the other set doesn't have any non-boolean qualifiers, just
2630953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    // bit-or it in.
2640953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    if (!(Q.Mask & ~CVRMask))
2650953e767ff7817f97b3ab20896b229891eeff45bJohn McCall      Mask |= Q.Mask;
2660953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    else {
2670953e767ff7817f97b3ab20896b229891eeff45bJohn McCall      Mask |= (Q.Mask & CVRMask);
2680953e767ff7817f97b3ab20896b229891eeff45bJohn McCall      if (Q.hasAddressSpace())
2690953e767ff7817f97b3ab20896b229891eeff45bJohn McCall        addAddressSpace(Q.getAddressSpace());
2700953e767ff7817f97b3ab20896b229891eeff45bJohn McCall      if (Q.hasObjCGCAttr())
2710953e767ff7817f97b3ab20896b229891eeff45bJohn McCall        addObjCGCAttr(Q.getObjCGCAttr());
2720953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    }
2730953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2740953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
275b87786f045d798b070980c108c922e1475d27b15Douglas Gregor  bool isSupersetOf(Qualifiers Other) const;
276b87786f045d798b070980c108c922e1475d27b15Douglas Gregor
2770953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool operator==(Qualifiers Other) const { return Mask == Other.Mask; }
2780953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool operator!=(Qualifiers Other) const { return Mask != Other.Mask; }
2790953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
2800953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  operator bool() const { return hasQualifiers(); }
2810953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
2820953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  Qualifiers &operator+=(Qualifiers R) {
2830953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    addQualifiers(R);
2840953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return *this;
2850953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2860953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
2870953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Union two qualifier sets.  If an enumerated qualifier appears
2880953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // in both sets, use the one from the right.
2890953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  friend Qualifiers operator+(Qualifiers L, Qualifiers R) {
2900953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    L += R;
2910953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return L;
2920953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2933cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor
2943cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor  Qualifiers &operator-=(Qualifiers R) {
2953cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor    Mask = Mask & ~(R.Mask);
2963cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor    return *this;
2973cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor  }
2980953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
2993cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor  /// \brief Compute the difference between two qualifier sets.
3003cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor  friend Qualifiers operator-(Qualifiers L, Qualifiers R) {
3013cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor    L -= R;
3023cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor    return L;
3033cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor  }
3043cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor
3050953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  std::string getAsString() const;
3060953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  std::string getAsString(const PrintingPolicy &Policy) const {
3070953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    std::string Buffer;
3080953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    getAsStringInternal(Buffer, Policy);
3090953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return Buffer;
3100953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
3110953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void getAsStringInternal(std::string &S, const PrintingPolicy &Policy) const;
3120953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3130953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void Profile(llvm::FoldingSetNodeID &ID) const {
3140953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    ID.AddInteger(Mask);
3150953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
3160953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3170953e767ff7817f97b3ab20896b229891eeff45bJohn McCallprivate:
3180953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3190953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // bits:     |0 1 2|3 .. 4|5  ..  31|
3200953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  //           |C R V|GCAttr|AddrSpace|
3210953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  uint32_t Mask;
3220953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3230953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  static const uint32_t GCAttrMask = 0x18;
3240953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  static const uint32_t GCAttrShift = 3;
3250953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  static const uint32_t AddressSpaceMask = ~(CVRMask | GCAttrMask);
3260953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  static const uint32_t AddressSpaceShift = 5;
3270953e767ff7817f97b3ab20896b229891eeff45bJohn McCall};
3280953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3291ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor/// \brief Base class that is common to both the \c ExtQuals and \c Type
3301ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor/// classes, which allows \c QualType to access the common fields between the
3311ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor/// two.
3321ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor///
3331ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregorclass ExtQualsTypeCommonBase {
3341ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregorprotected:
3351ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor  ExtQualsTypeCommonBase(const Type *BaseType) : BaseType(BaseType) { }
3361ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor
3371ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor  /// \brief The "base" type of an extended qualifiers type (\c ExtQuals) or
3381ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor  /// a self-referential pointer (for \c Type).
3391ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor  ///
3401ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor  /// This pointer allows an efficient mapping from a QualType to its
3411ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor  /// underlying type pointer.
3421ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor  const Type *BaseType;
3431ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor
3441ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor  friend class QualType;
3451ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor};
3461ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor
34755270e4bde91bd30d16086ae71f0f65caf3b8a51Douglas Gregor/// ExtQuals - We can encode up to four bits in the low bits of a
3480953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// type pointer, but there are many more type qualifiers that we want
3490953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// to be able to apply to an arbitrary type.  Therefore we have this
3500953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// struct, intended to be heap-allocated and used by QualType to
3510953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// store qualifiers.
3520953e767ff7817f97b3ab20896b229891eeff45bJohn McCall///
35355270e4bde91bd30d16086ae71f0f65caf3b8a51Douglas Gregor/// The current design tags the 'const', 'restrict', and 'volatile' qualifiers
35455270e4bde91bd30d16086ae71f0f65caf3b8a51Douglas Gregor/// in three low bits on the QualType pointer; a fourth bit records whether
35555270e4bde91bd30d16086ae71f0f65caf3b8a51Douglas Gregor/// the pointer is an ExtQuals node. The extended qualifiers (address spaces,
35655270e4bde91bd30d16086ae71f0f65caf3b8a51Douglas Gregor/// Objective-C GC attributes) are much more rare.
3571ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregorclass ExtQuals : public ExtQualsTypeCommonBase, public llvm::FoldingSetNode {
3580953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // NOTE: changing the fast qualifiers should be straightforward as
3590953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // long as you don't make 'const' non-fast.
3600953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // 1. Qualifiers:
3610953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  //    a) Modify the bitmasks (Qualifiers::TQ and DeclSpec::TQ).
3620953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  //       Fast qualifiers must occupy the low-order bits.
3630953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  //    b) Update Qualifiers::FastWidth and FastMask.
3640953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // 2. QualType:
3650953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  //    a) Update is{Volatile,Restrict}Qualified(), defined inline.
3660953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  //    b) Update remove{Volatile,Restrict}, defined near the end of
3670953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  //       this header.
3680953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // 3. ASTContext:
3690953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  //    a) Update get{Volatile,Restrict}Type.
3700953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3710953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// Quals - the immutable set of qualifiers applied by this
3720953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// node;  always contains extended qualifiers.
3730953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  Qualifiers Quals;
3740953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3750953e767ff7817f97b3ab20896b229891eeff45bJohn McCallpublic:
3761ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor  ExtQuals(const Type *Base, Qualifiers Quals)
3771ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor    : ExtQualsTypeCommonBase(Base), Quals(Quals)
3780953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  {
3790953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(Quals.hasNonFastQualifiers()
3800953e767ff7817f97b3ab20896b229891eeff45bJohn McCall           && "ExtQuals created with no fast qualifiers");
3810953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(!Quals.hasFastQualifiers()
3820953e767ff7817f97b3ab20896b229891eeff45bJohn McCall           && "ExtQuals created with fast qualifiers");
3830953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
3840953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3850953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  Qualifiers getQualifiers() const { return Quals; }
3860953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3870953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool hasObjCGCAttr() const { return Quals.hasObjCGCAttr(); }
3880953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  Qualifiers::GC getObjCGCAttr() const { return Quals.getObjCGCAttr(); }
3890953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3900953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool hasAddressSpace() const { return Quals.hasAddressSpace(); }
3910953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  unsigned getAddressSpace() const { return Quals.getAddressSpace(); }
3920953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3930953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  const Type *getBaseType() const { return BaseType; }
3941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3950953e767ff7817f97b3ab20896b229891eeff45bJohn McCallpublic:
3960953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void Profile(llvm::FoldingSetNodeID &ID) const {
3970953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Profile(ID, getBaseType(), Quals);
3980953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
3990953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  static void Profile(llvm::FoldingSetNodeID &ID,
4000953e767ff7817f97b3ab20896b229891eeff45bJohn McCall                      const Type *BaseType,
4010953e767ff7817f97b3ab20896b229891eeff45bJohn McCall                      Qualifiers Quals) {
4020953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(!Quals.hasFastQualifiers() && "fast qualifiers in ExtQuals hash!");
4030953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    ID.AddPointer(BaseType);
4040953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Quals.Profile(ID);
4050953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
4060953e767ff7817f97b3ab20896b229891eeff45bJohn McCall};
4070953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
408ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor/// CallingConv - Specifies the calling convention that a function uses.
409ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregorenum CallingConv {
410ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor  CC_Default,
411ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor  CC_C,           // __attribute__((cdecl))
412ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor  CC_X86StdCall,  // __attribute__((stdcall))
413f813a2c03fcb05381b3252010435f557eb6b3cdeDouglas Gregor  CC_X86FastCall, // __attribute__((fastcall))
41452fc314e1b5e1baee6305067cf831763d02bd243Dawn Perchik  CC_X86ThisCall, // __attribute__((thiscall))
41552fc314e1b5e1baee6305067cf831763d02bd243Dawn Perchik  CC_X86Pascal    // __attribute__((pascal))
416ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor};
417ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor
41849f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCalltypedef std::pair<const Type*, Qualifiers> SplitQualType;
4190953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
4200953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// QualType - For efficiency, we don't store CV-qualified types as nodes on
4210953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// their own: instead each reference to a type stores the qualifiers.  This
4220953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// greatly reduces the number of nodes we need to allocate for types (for
4230953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// example we only need one for 'int', 'const int', 'volatile int',
4240953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// 'const volatile int', etc).
4250953e767ff7817f97b3ab20896b229891eeff45bJohn McCall///
4260953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// As an added efficiency bonus, instead of making this a pair, we
4270953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// just store the two bits we care about in the low bits of the
4280953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// pointer.  To handle the packing/unpacking, we make QualType be a
4290953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// simple wrapper class that acts like a smart pointer.  A third bit
4300953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// indicates whether there are extended qualifiers present, in which
4310953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// case the pointer points to a special structure.
4320953e767ff7817f97b3ab20896b229891eeff45bJohn McCallclass QualType {
4330953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Thankfully, these are efficiently composable.
4340953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  llvm::PointerIntPair<llvm::PointerUnion<const Type*,const ExtQuals*>,
4350953e767ff7817f97b3ab20896b229891eeff45bJohn McCall                       Qualifiers::FastWidth> Value;
4360953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
4370953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  const ExtQuals *getExtQualsUnsafe() const {
4380953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return Value.getPointer().get<const ExtQuals*>();
4390953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
4400953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
4410953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  const Type *getTypePtrUnsafe() const {
4420953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return Value.getPointer().get<const Type*>();
4430953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
4440953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
445fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  QualType getUnqualifiedTypeSlow() const;
446fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor
4470953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  friend class QualifierCollector;
4480953e767ff7817f97b3ab20896b229891eeff45bJohn McCallpublic:
4495cf243a883872441d73ca49cea7e20de5802629bChris Lattner  QualType() {}
4501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4515cf243a883872441d73ca49cea7e20de5802629bChris Lattner  QualType(const Type *Ptr, unsigned Quals)
4520953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    : Value(Ptr, Quals) {}
4530953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  QualType(const ExtQuals *Ptr, unsigned Quals)
4540953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    : Value(Ptr, Quals) {}
4550953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
456a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  unsigned getLocalFastQualifiers() const { return Value.getInt(); }
457a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  void setLocalFastQualifiers(unsigned Quals) { Value.setInt(Quals); }
4585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4590953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// Retrieves a pointer to the underlying (unqualified) type.
4600953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// This should really return a const Type, but it's not worth
4610953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// changing all the users right now.
4621ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor  ///
4631ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor  /// This function requires that the type not be NULL. If the type might be
4641ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor  /// NULL, use the (slightly less efficient) \c getTypePtrOrNull().
4650953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  Type *getTypePtr() const {
4661ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor    assert(!isNull() && "Cannot retrieve a NULL type pointer");
4671ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor    uintptr_t CommonPtrVal
4681ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor      = reinterpret_cast<uintptr_t>(Value.getOpaqueValue());
4691ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor    CommonPtrVal &= ~(uintptr_t)((1 << TypeAlignmentInBits) - 1);
4701ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor    ExtQualsTypeCommonBase *CommonPtr
4711ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor      = reinterpret_cast<ExtQualsTypeCommonBase*>(CommonPtrVal);
4721ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor    return const_cast<Type *>(CommonPtr->BaseType);
4731ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor  }
4741ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor
4751ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor  Type *getTypePtrOrNull() const {
4761ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor    uintptr_t TypePtrPtrVal
4771ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor      = reinterpret_cast<uintptr_t>(Value.getOpaqueValue());
4781ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor    TypePtrPtrVal &= ~(uintptr_t)((1 << TypeAlignmentInBits) - 1);
4791ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor    Type **TypePtrPtr = reinterpret_cast<Type**>(TypePtrPtrVal);
4801ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor    return TypePtrPtr? *TypePtrPtr : 0;
4810953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
4821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
48349f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  /// Divides a QualType into its unqualified type and a set of local
48449f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  /// qualifiers.
48549f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  SplitQualType split() const {
48649f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall    if (!hasLocalNonFastQualifiers())
48749f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall      return SplitQualType(getTypePtrUnsafe(),
48849f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall                           Qualifiers::fromFastMask(getLocalFastQualifiers()));
48949f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall
49049f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall    const ExtQuals *eq = getExtQualsUnsafe();
49149f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall    Qualifiers qs = eq->getQualifiers();
49249f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall    qs.addFastQualifiers(getLocalFastQualifiers());
49349f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall    return SplitQualType(eq->getBaseType(), qs);
49449f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  }
49549f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall
4965cf243a883872441d73ca49cea7e20de5802629bChris Lattner  void *getAsOpaquePtr() const { return Value.getOpaqueValue(); }
4975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static QualType getFromOpaquePtr(void *Ptr) {
4985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    QualType T;
4995cf243a883872441d73ca49cea7e20de5802629bChris Lattner    T.Value.setFromOpaqueValue(Ptr);
5005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T;
5015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
5021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Type &operator*() const {
5045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return *getTypePtr();
5055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
5065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
5075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Type *operator->() const {
5085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return getTypePtr();
5095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
5101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
511467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall  bool isCanonical() const;
51254e14c4db764c0636160d26c5bbf491637c83a76John McCall  bool isCanonicalAsParam() const;
513467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall
5145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isNull - Return true if this QualType doesn't point to a type yet.
5155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isNull() const {
5160953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return Value.getPointer().isNull();
5175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
5185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
519a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Determine whether this particular QualType instance has the
520a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// "const" qualifier set, without looking through typedefs that may have
521a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// added "const" at a different level.
522a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  bool isLocalConstQualified() const {
523a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor    return (getLocalFastQualifiers() & Qualifiers::Const);
5240953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
525a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor
526a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Determine whether this type is const-qualified.
527fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  bool isConstQualified() const;
528a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor
529a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Determine whether this particular QualType instance has the
530a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// "restrict" qualifier set, without looking through typedefs that may have
531a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// added "restrict" at a different level.
532a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  bool isLocalRestrictQualified() const {
533a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor    return (getLocalFastQualifiers() & Qualifiers::Restrict);
534a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  }
535a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor
536a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Determine whether this type is restrict-qualified.
537fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  bool isRestrictQualified() const;
538a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor
539a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Determine whether this particular QualType instance has the
540a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// "volatile" qualifier set, without looking through typedefs that may have
541a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// added "volatile" at a different level.
542a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  bool isLocalVolatileQualified() const {
543f7616b9067790757f4e12e834b216c53c8c04ebeDouglas Gregor    return (getLocalFastQualifiers() & Qualifiers::Volatile);
5445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
5450953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
546a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Determine whether this type is volatile-qualified.
547fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  bool isVolatileQualified() const;
548a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor
549a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Determine whether this particular QualType instance has any
550a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// qualifiers, without looking through any typedefs that might add
551a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// qualifiers at a different level.
552a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  bool hasLocalQualifiers() const {
553a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor    return getLocalFastQualifiers() || hasLocalNonFastQualifiers();
5540953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
5550953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
556a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Determine whether this type has any qualifiers.
557fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  bool hasQualifiers() const;
558a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor
559a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Determine whether this particular QualType instance has any
560a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// "non-fast" qualifiers, e.g., those that are stored in an ExtQualType
561a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// instance.
562a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  bool hasLocalNonFastQualifiers() const {
563a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor    return Value.getPointer().is<const ExtQuals*>();
5640953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
5650953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
566a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Retrieve the set of qualifiers local to this particular QualType
567a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// instance, not including any qualifiers acquired through typedefs or
568a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// other sugar.
569a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  Qualifiers getLocalQualifiers() const {
5700953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Qualifiers Quals;
571a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor    if (hasLocalNonFastQualifiers())
5720953e767ff7817f97b3ab20896b229891eeff45bJohn McCall      Quals = getExtQualsUnsafe()->getQualifiers();
573a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor    Quals.addFastQualifiers(getLocalFastQualifiers());
5740953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return Quals;
5750953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
5760953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
577a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Retrieve the set of qualifiers applied to this type.
578fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  Qualifiers getQualifiers() const;
579a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor
580a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Retrieve the set of CVR (const-volatile-restrict) qualifiers
581a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// local to this particular QualType instance, not including any qualifiers
582a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// acquired through typedefs or other sugar.
583a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  unsigned getLocalCVRQualifiers() const {
584f7616b9067790757f4e12e834b216c53c8c04ebeDouglas Gregor    return getLocalFastQualifiers();
5855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
586b381aac9bae6d608c72267dd0ed08ec6369e94e4Nuno Lopes
587a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Retrieve the set of CVR (const-volatile-restrict) qualifiers
588a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// applied to this type.
589fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  unsigned getCVRQualifiers() const;
590e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth
591e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth  /// \brief Retrieve the set of CVR (const-volatile-restrict) qualifiers
592e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth  /// applied to this type, looking through any number of unqualified array
593e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth  /// types to their element types' qualifiers.
594e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth  unsigned getCVRQualifiersThroughArrayTypes() const;
595e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth
596bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isConstant(ASTContext& Ctx) const {
597bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall    return QualType::isConstant(*this, Ctx);
598bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  }
5991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6000953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Don't promise in the API that anything besides 'const' can be
6010953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // easily added.
6020953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
6030953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// addConst - add the specified type qualifier to this QualType.
6040953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void addConst() {
6050953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    addFastQualifiers(Qualifiers::Const);
6060953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
6070953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  QualType withConst() const {
6080953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return withFastQualifiers(Qualifiers::Const);
6090953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
6100953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
6110953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void addFastQualifiers(unsigned TQs) {
6120953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(!(TQs & ~Qualifiers::FastMask)
6130953e767ff7817f97b3ab20896b229891eeff45bJohn McCall           && "non-fast qualifier bits set in mask!");
6140953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Value.setInt(Value.getInt() | TQs);
6150953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
6160953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
61749f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  void removeLocalConst();
61849f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  void removeLocalVolatile();
61949f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  void removeLocalRestrict();
62049f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  void removeLocalCVRQualifiers(unsigned Mask);
6210953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
62249f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  void removeLocalFastQualifiers() { Value.setInt(0); }
62349f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  void removeLocalFastQualifiers(unsigned Mask) {
6240953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(!(Mask & ~Qualifiers::FastMask) && "mask has non-fast qualifiers");
6250953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Value.setInt(Value.getInt() & ~Mask);
6260953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
6275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
6280953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Creates a type with the given qualifiers in addition to any
6290953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // qualifiers already on this type.
6300953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  QualType withFastQualifiers(unsigned TQs) const {
6310953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    QualType T = *this;
6320953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    T.addFastQualifiers(TQs);
6330953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return T;
6340953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
6351c6a38bcea17801e9a4738753aee845381af2b6cSanjiv Gupta
6360953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Creates a type with exactly the given fast qualifiers, removing
6370953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // any existing fast qualifiers.
63849f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  QualType withExactLocalFastQualifiers(unsigned TQs) const {
63949f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall    return withoutLocalFastQualifiers().withFastQualifiers(TQs);
6405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
6410953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
6420953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Removes fast qualifiers, but leaves any extended qualifiers in place.
64349f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  QualType withoutLocalFastQualifiers() const {
6440953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    QualType T = *this;
64549f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall    T.removeLocalFastQualifiers();
6460953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return T;
647c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  }
648971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis
649a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Return this type with all of the instance-specific qualifiers
650a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// removed, but without removing any qualifiers that may have been applied
651a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// through typedefs.
652a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  QualType getLocalUnqualifiedType() const { return QualType(getTypePtr(), 0); }
6531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
654a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Return the unqualified form of the given type, which might be
655a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// desugared to eliminate qualifiers introduced via typedefs.
656fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  QualType getUnqualifiedType() const {
657fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor    QualType T = getLocalUnqualifiedType();
658fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor    if (!T.hasQualifiers())
659fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor      return T;
660fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor
661fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor    return getUnqualifiedTypeSlow();
662a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  }
663a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor
664e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor  bool isMoreQualifiedThan(QualType Other) const;
665e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor  bool isAtLeastAsQualifiedAs(QualType Other) const;
666e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor  QualType getNonReferenceType() const;
6671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6686398235d7890a81b785ea5af3b6e66d86bf184ccDouglas Gregor  /// \brief Determine the type of a (typically non-lvalue) expression with the
6696398235d7890a81b785ea5af3b6e66d86bf184ccDouglas Gregor  /// specified result type.
6705291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor  ///
6716398235d7890a81b785ea5af3b6e66d86bf184ccDouglas Gregor  /// This routine should be used for expressions for which the return type is
6726398235d7890a81b785ea5af3b6e66d86bf184ccDouglas Gregor  /// explicitly specified (e.g., in a cast or call) and isn't necessarily
6736398235d7890a81b785ea5af3b6e66d86bf184ccDouglas Gregor  /// an lvalue. It removes a top-level reference (since there are no
6745291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor  /// expressions of reference type) and deletes top-level cvr-qualifiers
6755291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor  /// from non-class types (in C++) or all types (in C).
6766398235d7890a81b785ea5af3b6e66d86bf184ccDouglas Gregor  QualType getNonLValueExprType(ASTContext &Context) const;
6775291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor
6782fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner  /// getDesugaredType - Return the specified type with any "sugar" removed from
6792fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner  /// the type.  This takes off typedefs, typeof's etc.  If the outer level of
6802fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner  /// the type is already concrete, it returns it unmodified.  This is similar
6812fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner  /// to getting the canonical type, but it doesn't remove *all* typedefs.  For
6822fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner  /// example, it returns "T*" as "T*", (not as "int*"), because the pointer is
6832fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner  /// concrete.
6840953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  ///
6850953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// Qualifiers are left in place.
68649f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  QualType getDesugaredType(ASTContext &Context) const {
68749f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall    return getDesugaredType(*this, Context);
68849f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  }
68949f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall
69049f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  SplitQualType getSplitDesugaredType() const {
69149f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall    return getSplitDesugaredType(*this);
692bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  }
69398cd599ee8a9b259ed7388ee2921a20d97658864Douglas Gregor
694075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  /// IgnoreParens - Returns the specified type after dropping any
695075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  /// outer-level parentheses.
696075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  QualType IgnoreParens() const {
697075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara    return QualType::IgnoreParens(*this);
698075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  }
699075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
7005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// operator==/!= - Indicate whether the specified types and qualifiers are
7015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// identical.
70250d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor  friend bool operator==(const QualType &LHS, const QualType &RHS) {
70350d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor    return LHS.Value == RHS.Value;
7045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
70550d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor  friend bool operator!=(const QualType &LHS, const QualType &RHS) {
70650d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor    return LHS.Value != RHS.Value;
7075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
70849f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  std::string getAsString() const {
70949f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall    return getAsString(split());
71049f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  }
71149f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  static std::string getAsString(SplitQualType split) {
71249f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall    return getAsString(split.first, split.second);
71349f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  }
71449f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  static std::string getAsString(const Type *ty, Qualifiers qs);
715d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor
716d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor  std::string getAsString(const PrintingPolicy &Policy) const {
7175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    std::string S;
718d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor    getAsStringInternal(S, Policy);
7195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return S;
7205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
721e4f2142d00fa5fdb580c4e2413da91882d955381Chris Lattner  void getAsStringInternal(std::string &Str,
72249f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall                           const PrintingPolicy &Policy) const {
72349f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall    return getAsStringInternal(split(), Str, Policy);
72449f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  }
72549f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  static void getAsStringInternal(SplitQualType split, std::string &out,
72649f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall                                  const PrintingPolicy &policy) {
72749f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall    return getAsStringInternal(split.first, split.second, out, policy);
72849f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  }
72949f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  static void getAsStringInternal(const Type *ty, Qualifiers qs,
73049f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall                                  std::string &out,
73149f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall                                  const PrintingPolicy &policy);
7321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
733c36d405a02fab41f6c45cb2bc750d64949742903Chris Lattner  void dump(const char *s) const;
734c36d405a02fab41f6c45cb2bc750d64949742903Chris Lattner  void dump() const;
7351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7363f2dcb1ca8bd2d5d3ccc5c80f4ab06f949d88a89Ted Kremenek  void Profile(llvm::FoldingSetNodeID &ID) const {
7373f2dcb1ca8bd2d5d3ccc5c80f4ab06f949d88a89Ted Kremenek    ID.AddPointer(getAsOpaquePtr());
7383f2dcb1ca8bd2d5d3ccc5c80f4ab06f949d88a89Ted Kremenek  }
7395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
740ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb  /// getAddressSpace - Return the address space of this type.
741ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb  inline unsigned getAddressSpace() const;
7421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
743d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian  /// GCAttrTypesAttr - Returns gc attribute of this type.
7440953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  inline Qualifiers::GC getObjCGCAttr() const;
745f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian
746f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian  /// isObjCGCWeak true when Type is objc's weak.
747f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian  bool isObjCGCWeak() const {
7480953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return getObjCGCAttr() == Qualifiers::Weak;
749f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian  }
750f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian
751f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian  /// isObjCGCStrong true when Type is objc's strong.
752f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian  bool isObjCGCStrong() const {
7530953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return getObjCGCAttr() == Qualifiers::Strong;
754f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian  }
7552455636163fdd18581d7fdae816433f886d88213Mike Stump
756bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCallprivate:
757bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  // These methods are implemented in a separate translation unit;
758bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  // "static"-ize them to avoid creating temporary QualTypes in the
759bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  // caller.
760bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  static bool isConstant(QualType T, ASTContext& Ctx);
76149f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  static QualType getDesugaredType(QualType T, ASTContext &Context);
76249f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  static SplitQualType getSplitDesugaredType(QualType T);
763075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  static QualType IgnoreParens(QualType T);
7645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
7655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end clang.
7675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace llvm {
7695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Implement simplify_type for QualType, so that we can dyn_cast from QualType
7705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// to a specific Type class.
7715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencertemplate<> struct simplify_type<const ::clang::QualType> {
7725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  typedef ::clang::Type* SimpleType;
7735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static SimpleType getSimplifiedValue(const ::clang::QualType &Val) {
7744472fc641ea3069463798fb56a04043c28ea2910Douglas Gregor    return Val.getTypePtr();
7755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
7765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
7775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencertemplate<> struct simplify_type< ::clang::QualType>
7785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  : public simplify_type<const ::clang::QualType> {};
7791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7804e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner// Teach SmallPtrSet that QualType is "basically a pointer".
7814e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattnertemplate<>
782daae940507f2e93c6fa12e8062fa958e34cc2d1cChris Lattnerclass PointerLikeTypeTraits<clang::QualType> {
7834e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattnerpublic:
7844e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner  static inline void *getAsVoidPointer(clang::QualType P) {
7854e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner    return P.getAsOpaquePtr();
7864e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner  }
7874e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner  static inline clang::QualType getFromVoidPointer(void *P) {
7884e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner    return clang::QualType::getFromOpaquePtr(P);
7894e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner  }
7900953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Various qualifiers go in low bits.
7910eda3b31a672ea486fa92b9bc49a2c91be856b53Chris Lattner  enum { NumLowBitsAvailable = 0 };
7924e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner};
7931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
79473af669633e13c813f80cd15ecf3e6414778aee4Ted Kremenek} // end namespace llvm
7955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang {
7975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Type - This is the base class of the type hierarchy.  A central concept
7995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// with types is that each type always has a canonical type.  A canonical type
8005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// is the type with any typedef names stripped out of it or the types it
8015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// references.  For example, consider:
8025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
8035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///  typedef int  foo;
8045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///  typedef foo* bar;
8055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///    'int *'    'foo *'    'bar'
8065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
8075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// There will be a Type object created for 'int'.  Since int is canonical, its
8085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// canonicaltype pointer points to itself.  There is also a Type for 'foo' (a
80972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// TypedefType).  Its CanonicalType pointer points to the 'int' Type.  Next
8105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// there is a PointerType that represents 'int*', which, like 'int', is
8115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// canonical.  Finally, there is a PointerType type for 'foo*' whose canonical
81272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// type is 'int*', and there is a TypedefType for 'bar', whose canonical type
8135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// is also 'int*'.
8145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
8155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Non-canonical types are useful for emitting diagnostics, without losing
8165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// information about typedefs being used.  Canonical types are useful for type
8175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// comparisons (they allow by-pointer equality tests) and useful for reasoning
8185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// about whether something has a particular form (e.g. is a function type),
8195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// because they implicitly, recursively, strip all typedefs out of a type.
8205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
8215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Types, once created, are immutable.
8225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
8231ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregorclass Type : public ExtQualsTypeCommonBase {
8245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
8255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  enum TypeClass {
82672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#define TYPE(Class, Base) Class,
82727935ee59c30b0d8b610ab676aab8e65350af932John McCall#define LAST_TYPE(Class) TypeLast = Class,
82872564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#define ABSTRACT_TYPE(Class, Base)
82972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#include "clang/AST/TypeNodes.def"
83072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor    TagFirst = Record, TagLast = Enum
8315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
8321bb8a45f7386a23871598d05141a07af03067925Argyrios Kyrtzidis
8335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate:
834c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  Type(const Type&);           // DO NOT IMPLEMENT.
835c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  void operator=(const Type&); // DO NOT IMPLEMENT.
836c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
8375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType CanonicalType;
8385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
839b870b88df784c2940efce448ebfaf54dece14666John McCall  /// Bitfields required by the Type class.
840b870b88df784c2940efce448ebfaf54dece14666John McCall  class TypeBitfields {
841b870b88df784c2940efce448ebfaf54dece14666John McCall    friend class Type;
842b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall    template <class T> friend class TypePropertyCache;
84327935ee59c30b0d8b610ab676aab8e65350af932John McCall
844b870b88df784c2940efce448ebfaf54dece14666John McCall    /// TypeClass bitfield - Enum that specifies what subclass this belongs to.
845b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned TC : 8;
846b870b88df784c2940efce448ebfaf54dece14666John McCall
847b870b88df784c2940efce448ebfaf54dece14666John McCall    /// Dependent - Whether this type is a dependent type (C++ [temp.dep.type]).
848b870b88df784c2940efce448ebfaf54dece14666John McCall    /// Note that this should stay at the end of the ivars for Type so that
849b870b88df784c2940efce448ebfaf54dece14666John McCall    /// subclasses can pack their bitfields into the same word.
850bdb5b0e8ad8ed297ad01eb2ccd0d6d5ed6058033Francois Pichet    unsigned Dependent : 1;
85160e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
852b870b88df784c2940efce448ebfaf54dece14666John McCall    /// \brief Whether this type is a variably-modified type (C99 6.7.5).
853bdb5b0e8ad8ed297ad01eb2ccd0d6d5ed6058033Francois Pichet    unsigned VariablyModified : 1;
854d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor
855d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    /// \brief Whether this type contains an unexpanded parameter pack
856d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    /// (for C++0x variadic templates).
857d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    unsigned ContainsUnexpandedParameterPack : 1;
85835495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor
8591fb0caaa7bef765b85972274e3b434af2572c141John McCall    /// \brief Nonzero if the cache (i.e. the bitfields here starting
8601fb0caaa7bef765b85972274e3b434af2572c141John McCall    /// with 'Cache') is valid.  If so, then this is a
8611fb0caaa7bef765b85972274e3b434af2572c141John McCall    /// LangOptions::VisibilityMode+1.
8621fb0caaa7bef765b85972274e3b434af2572c141John McCall    mutable unsigned CacheValidAndVisibility : 2;
86360e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
864b870b88df784c2940efce448ebfaf54dece14666John McCall    /// \brief Linkage of this type.
865b870b88df784c2940efce448ebfaf54dece14666John McCall    mutable unsigned CachedLinkage : 2;
86607a353c2af3a3c557205466d4f4ed2513462ebfeSebastian Redl
867b870b88df784c2940efce448ebfaf54dece14666John McCall    /// \brief Whether this type involves and local or unnamed types.
868bdb5b0e8ad8ed297ad01eb2ccd0d6d5ed6058033Francois Pichet    mutable unsigned CachedLocalOrUnnamed : 1;
869db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor
870b870b88df784c2940efce448ebfaf54dece14666John McCall    /// \brief FromAST - Whether this type comes from an AST file.
871bdb5b0e8ad8ed297ad01eb2ccd0d6d5ed6058033Francois Pichet    mutable unsigned FromAST : 1;
872b870b88df784c2940efce448ebfaf54dece14666John McCall
8731fb0caaa7bef765b85972274e3b434af2572c141John McCall    bool isCacheValid() const {
8741fb0caaa7bef765b85972274e3b434af2572c141John McCall      return (CacheValidAndVisibility != 0);
8751fb0caaa7bef765b85972274e3b434af2572c141John McCall    }
8761fb0caaa7bef765b85972274e3b434af2572c141John McCall    Visibility getVisibility() const {
8771fb0caaa7bef765b85972274e3b434af2572c141John McCall      assert(isCacheValid() && "getting linkage from invalid cache");
8781fb0caaa7bef765b85972274e3b434af2572c141John McCall      return static_cast<Visibility>(CacheValidAndVisibility-1);
8791fb0caaa7bef765b85972274e3b434af2572c141John McCall    }
8801fb0caaa7bef765b85972274e3b434af2572c141John McCall    Linkage getLinkage() const {
8811fb0caaa7bef765b85972274e3b434af2572c141John McCall      assert(isCacheValid() && "getting linkage from invalid cache");
8821fb0caaa7bef765b85972274e3b434af2572c141John McCall      return static_cast<Linkage>(CachedLinkage);
8831fb0caaa7bef765b85972274e3b434af2572c141John McCall    }
8841fb0caaa7bef765b85972274e3b434af2572c141John McCall    bool hasLocalOrUnnamedType() const {
8851fb0caaa7bef765b85972274e3b434af2572c141John McCall      assert(isCacheValid() && "getting linkage from invalid cache");
8861fb0caaa7bef765b85972274e3b434af2572c141John McCall      return CachedLocalOrUnnamed;
8871fb0caaa7bef765b85972274e3b434af2572c141John McCall    }
888b870b88df784c2940efce448ebfaf54dece14666John McCall  };
889d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  enum { NumTypeBits = 17 };
890b870b88df784c2940efce448ebfaf54dece14666John McCall
891b870b88df784c2940efce448ebfaf54dece14666John McCallprotected:
892b870b88df784c2940efce448ebfaf54dece14666John McCall  // These classes allow subclasses to somewhat cleanly pack bitfields
893b870b88df784c2940efce448ebfaf54dece14666John McCall  // into Type.
894b870b88df784c2940efce448ebfaf54dece14666John McCall
895b870b88df784c2940efce448ebfaf54dece14666John McCall  class ArrayTypeBitfields {
896b870b88df784c2940efce448ebfaf54dece14666John McCall    friend class ArrayType;
897b870b88df784c2940efce448ebfaf54dece14666John McCall
898b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned : NumTypeBits;
899b870b88df784c2940efce448ebfaf54dece14666John McCall
900b870b88df784c2940efce448ebfaf54dece14666John McCall    /// IndexTypeQuals - CVR qualifiers from declarations like
901b870b88df784c2940efce448ebfaf54dece14666John McCall    /// 'int X[static restrict 4]'. For function parameters only.
902b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned IndexTypeQuals : 3;
903b870b88df784c2940efce448ebfaf54dece14666John McCall
904b870b88df784c2940efce448ebfaf54dece14666John McCall    /// SizeModifier - storage class qualifiers from declarations like
905b870b88df784c2940efce448ebfaf54dece14666John McCall    /// 'int X[static restrict 4]'. For function parameters only.
906b870b88df784c2940efce448ebfaf54dece14666John McCall    /// Actually an ArrayType::ArraySizeModifier.
907b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned SizeModifier : 3;
908b870b88df784c2940efce448ebfaf54dece14666John McCall  };
909b870b88df784c2940efce448ebfaf54dece14666John McCall
910b870b88df784c2940efce448ebfaf54dece14666John McCall  class BuiltinTypeBitfields {
911b870b88df784c2940efce448ebfaf54dece14666John McCall    friend class BuiltinType;
912b870b88df784c2940efce448ebfaf54dece14666John McCall
913b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned : NumTypeBits;
914b870b88df784c2940efce448ebfaf54dece14666John McCall
915b870b88df784c2940efce448ebfaf54dece14666John McCall    /// The kind (BuiltinType::Kind) of builtin type this is.
916b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned Kind : 8;
917b870b88df784c2940efce448ebfaf54dece14666John McCall  };
918b870b88df784c2940efce448ebfaf54dece14666John McCall
919b870b88df784c2940efce448ebfaf54dece14666John McCall  class FunctionTypeBitfields {
920b870b88df784c2940efce448ebfaf54dece14666John McCall    friend class FunctionType;
921b870b88df784c2940efce448ebfaf54dece14666John McCall
922b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned : NumTypeBits;
923b870b88df784c2940efce448ebfaf54dece14666John McCall
924b870b88df784c2940efce448ebfaf54dece14666John McCall    /// Extra information which affects how the function is called, like
925b870b88df784c2940efce448ebfaf54dece14666John McCall    /// regparm and the calling convention.
926b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned ExtInfo : 8;
927b870b88df784c2940efce448ebfaf54dece14666John McCall
928b870b88df784c2940efce448ebfaf54dece14666John McCall    /// A bit to be used by the subclass.
929bdb5b0e8ad8ed297ad01eb2ccd0d6d5ed6058033Francois Pichet    unsigned SubclassInfo : 1;
930b870b88df784c2940efce448ebfaf54dece14666John McCall
931b870b88df784c2940efce448ebfaf54dece14666John McCall    /// TypeQuals - Used only by FunctionProtoType, put here to pack with the
932b870b88df784c2940efce448ebfaf54dece14666John McCall    /// other bitfields.
933b870b88df784c2940efce448ebfaf54dece14666John McCall    /// The qualifiers are part of FunctionProtoType because...
934b870b88df784c2940efce448ebfaf54dece14666John McCall    ///
935b870b88df784c2940efce448ebfaf54dece14666John McCall    /// C++ 8.3.5p4: The return type, the parameter type list and the
936b870b88df784c2940efce448ebfaf54dece14666John McCall    /// cv-qualifier-seq, [...], are part of the function type.
937b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned TypeQuals : 3;
938b870b88df784c2940efce448ebfaf54dece14666John McCall  };
939b870b88df784c2940efce448ebfaf54dece14666John McCall
940b870b88df784c2940efce448ebfaf54dece14666John McCall  class ObjCObjectTypeBitfields {
941b870b88df784c2940efce448ebfaf54dece14666John McCall    friend class ObjCObjectType;
942b870b88df784c2940efce448ebfaf54dece14666John McCall
943b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned : NumTypeBits;
944b870b88df784c2940efce448ebfaf54dece14666John McCall
945b870b88df784c2940efce448ebfaf54dece14666John McCall    /// NumProtocols - The number of protocols stored directly on this
946b870b88df784c2940efce448ebfaf54dece14666John McCall    /// object type.
947b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned NumProtocols : 32 - NumTypeBits;
948b870b88df784c2940efce448ebfaf54dece14666John McCall  };
949b870b88df784c2940efce448ebfaf54dece14666John McCall
950b870b88df784c2940efce448ebfaf54dece14666John McCall  class ReferenceTypeBitfields {
951b870b88df784c2940efce448ebfaf54dece14666John McCall    friend class ReferenceType;
952b870b88df784c2940efce448ebfaf54dece14666John McCall
953b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned : NumTypeBits;
954b870b88df784c2940efce448ebfaf54dece14666John McCall
955b870b88df784c2940efce448ebfaf54dece14666John McCall    /// True if the type was originally spelled with an lvalue sigil.
956b870b88df784c2940efce448ebfaf54dece14666John McCall    /// This is never true of rvalue references but can also be false
957b870b88df784c2940efce448ebfaf54dece14666John McCall    /// on lvalue references because of C++0x [dcl.typedef]p9,
958b870b88df784c2940efce448ebfaf54dece14666John McCall    /// as follows:
959b870b88df784c2940efce448ebfaf54dece14666John McCall    ///
960b870b88df784c2940efce448ebfaf54dece14666John McCall    ///   typedef int &ref;    // lvalue, spelled lvalue
961b870b88df784c2940efce448ebfaf54dece14666John McCall    ///   typedef int &&rvref; // rvalue
962b870b88df784c2940efce448ebfaf54dece14666John McCall    ///   ref &a;              // lvalue, inner ref, spelled lvalue
963b870b88df784c2940efce448ebfaf54dece14666John McCall    ///   ref &&a;             // lvalue, inner ref
964b870b88df784c2940efce448ebfaf54dece14666John McCall    ///   rvref &a;            // lvalue, inner ref, spelled lvalue
965b870b88df784c2940efce448ebfaf54dece14666John McCall    ///   rvref &&a;           // rvalue, inner ref
966bdb5b0e8ad8ed297ad01eb2ccd0d6d5ed6058033Francois Pichet    unsigned SpelledAsLValue : 1;
967b870b88df784c2940efce448ebfaf54dece14666John McCall
968b870b88df784c2940efce448ebfaf54dece14666John McCall    /// True if the inner type is a reference type.  This only happens
969b870b88df784c2940efce448ebfaf54dece14666John McCall    /// in non-canonical forms.
970bdb5b0e8ad8ed297ad01eb2ccd0d6d5ed6058033Francois Pichet    unsigned InnerRef : 1;
971b870b88df784c2940efce448ebfaf54dece14666John McCall  };
972b870b88df784c2940efce448ebfaf54dece14666John McCall
97377be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall  class TypeWithKeywordBitfields {
97477be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall    friend class TypeWithKeyword;
97577be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall
97677be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall    unsigned : NumTypeBits;
97777be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall
97877be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall    /// An ElaboratedTypeKeyword.  8 bits for efficient access.
97977be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall    unsigned Keyword : 8;
98077be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall  };
98177be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall
982b870b88df784c2940efce448ebfaf54dece14666John McCall  class VectorTypeBitfields {
983b870b88df784c2940efce448ebfaf54dece14666John McCall    friend class VectorType;
98407a353c2af3a3c557205466d4f4ed2513462ebfeSebastian Redl
985b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned : NumTypeBits;
98671c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall
987e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson    /// VecKind - The kind of vector, either a generic vector type or some
988e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson    /// target-specific vector type such as for AltiVec or Neon.
989cc3b946c35c4372272034e6f0663089477a9a5bdBob Wilson    unsigned VecKind : 3;
990b870b88df784c2940efce448ebfaf54dece14666John McCall
991b870b88df784c2940efce448ebfaf54dece14666John McCall    /// NumElements - The number of elements in the vector.
992cc3b946c35c4372272034e6f0663089477a9a5bdBob Wilson    unsigned NumElements : 29 - NumTypeBits;
993b870b88df784c2940efce448ebfaf54dece14666John McCall  };
994b870b88df784c2940efce448ebfaf54dece14666John McCall
995b870b88df784c2940efce448ebfaf54dece14666John McCall  union {
996b870b88df784c2940efce448ebfaf54dece14666John McCall    TypeBitfields TypeBits;
997b870b88df784c2940efce448ebfaf54dece14666John McCall    ArrayTypeBitfields ArrayTypeBits;
998b870b88df784c2940efce448ebfaf54dece14666John McCall    BuiltinTypeBitfields BuiltinTypeBits;
999b870b88df784c2940efce448ebfaf54dece14666John McCall    FunctionTypeBitfields FunctionTypeBits;
1000b870b88df784c2940efce448ebfaf54dece14666John McCall    ObjCObjectTypeBitfields ObjCObjectTypeBits;
1001b870b88df784c2940efce448ebfaf54dece14666John McCall    ReferenceTypeBitfields ReferenceTypeBits;
100277be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall    TypeWithKeywordBitfields TypeWithKeywordBits;
1003b870b88df784c2940efce448ebfaf54dece14666John McCall    VectorTypeBitfields VectorTypeBits;
1004b870b88df784c2940efce448ebfaf54dece14666John McCall  };
1005b870b88df784c2940efce448ebfaf54dece14666John McCall
1006b870b88df784c2940efce448ebfaf54dece14666John McCallprivate:
10073c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief Set whether this type comes from an AST file.
10083c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  void setFromAST(bool V = true) const {
1009b870b88df784c2940efce448ebfaf54dece14666John McCall    TypeBits.FromAST = V;
101007a353c2af3a3c557205466d4f4ed2513462ebfeSebastian Redl  }
101107a353c2af3a3c557205466d4f4ed2513462ebfeSebastian Redl
1012b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall  template <class T> friend class TypePropertyCache;
10131fb0caaa7bef765b85972274e3b434af2572c141John McCall
10145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprotected:
1015124dd7b5777e29ecac006822bd4d4623f0dc4264Hartmut Kaiser  // silence VC++ warning C4355: 'this' : used in base member initializer list
1016124dd7b5777e29ecac006822bd4d4623f0dc4264Hartmut Kaiser  Type *this_() { return this; }
1017d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  Type(TypeClass tc, QualType Canonical, bool Dependent, bool VariablyModified,
1018d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor       bool ContainsUnexpandedParameterPack)
10191ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor    : ExtQualsTypeCommonBase(this),
10201ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor      CanonicalType(Canonical.isNull() ? QualType(this_(), 0) : Canonical) {
1021b870b88df784c2940efce448ebfaf54dece14666John McCall    TypeBits.TC = tc;
1022b870b88df784c2940efce448ebfaf54dece14666John McCall    TypeBits.Dependent = Dependent;
1023b870b88df784c2940efce448ebfaf54dece14666John McCall    TypeBits.VariablyModified = VariablyModified;
1024d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    TypeBits.ContainsUnexpandedParameterPack = ContainsUnexpandedParameterPack;
10251fb0caaa7bef765b85972274e3b434af2572c141John McCall    TypeBits.CacheValidAndVisibility = 0;
1026b870b88df784c2940efce448ebfaf54dece14666John McCall    TypeBits.CachedLocalOrUnnamed = false;
1027b870b88df784c2940efce448ebfaf54dece14666John McCall    TypeBits.CachedLinkage = NoLinkage;
1028b870b88df784c2940efce448ebfaf54dece14666John McCall    TypeBits.FromAST = false;
1029b870b88df784c2940efce448ebfaf54dece14666John McCall  }
10305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;
10311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1032b870b88df784c2940efce448ebfaf54dece14666John McCall  void setDependent(bool D = true) { TypeBits.Dependent = D; }
1033b870b88df784c2940efce448ebfaf54dece14666John McCall  void setVariablyModified(bool VM = true) { TypeBits.VariablyModified = VM; }
1034d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  void setContainsUnexpandedParameterPack(bool PP = true) {
1035d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    TypeBits.ContainsUnexpandedParameterPack = PP;
1036d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  }
1037d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor
10388b9023ba35a86838789e2c9034a6128728c547aaChris Lattnerpublic:
1039b870b88df784c2940efce448ebfaf54dece14666John McCall  TypeClass getTypeClass() const { return static_cast<TypeClass>(TypeBits.TC); }
10401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
10413c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief Whether this type comes from an AST file.
1042b870b88df784c2940efce448ebfaf54dece14666John McCall  bool isFromAST() const { return TypeBits.FromAST; }
104307a353c2af3a3c557205466d4f4ed2513462ebfeSebastian Redl
1044d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// \brief Whether this type is or contains an unexpanded parameter
1045d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// pack, used to support C++0x variadic templates.
1046d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  ///
1047d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// A type that contains a parameter pack shall be expanded by the
1048d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// ellipsis operator at some point. For example, the typedef in the
1049d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// following example contains an unexpanded parameter pack 'T':
1050d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  ///
1051d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// \code
1052d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// template<typename ...T>
1053d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// struct X {
1054d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  ///   typedef T* pointer_types; // ill-formed; T is a parameter pack.
1055d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// };
1056d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// \endcode
1057d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  ///
1058d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// Note that this routine does not specify which
1059d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  bool containsUnexpandedParameterPack() const {
1060d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    return TypeBits.ContainsUnexpandedParameterPack;
1061d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  }
1062d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor
1063467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall  bool isCanonicalUnqualified() const {
1064467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall    return CanonicalType.getTypePtr() == this;
1065467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall  }
10665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
10671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// Types are partitioned into 3 broad categories (C99 6.2.5p1):
10685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// object types, function types, and incomplete types.
10691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
10705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isIncompleteType - Return true if this is an incomplete type.
10715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// A type that can describe objects, but which lacks information needed to
10725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// determine its size (e.g. void, or a fwd declared struct). Clients of this
10731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// routine will need to determine if the size is actually required.
10745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isIncompleteType() const;
1075d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner
1076d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner  /// isIncompleteOrObjectType - Return true if this is an incomplete or object
1077d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner  /// type, in other words, not a function type.
1078d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner  bool isIncompleteOrObjectType() const {
1079d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner    return !isFunctionType();
1080d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner  }
108164b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
108264b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  /// isPODType - Return true if this is a plain-old-data type (C++ 3.9p10).
108364b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  bool isPODType() const;
108464b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
1085ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl  /// isLiteralType - Return true if this is a literal type
1086ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl  /// (C++0x [basic.types]p10)
1087ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl  bool isLiteralType() const;
1088ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl
10895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// Helper methods to distinguish type categories. All type predicates
1090ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb  /// operate on the canonical type, ignoring typedefs and qualifiers.
1091e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar
10929b065ddabf572772991a4aadad5bf4921fac5069Tom Care  /// isBuiltinType - returns true if the type is a builtin type.
10939b065ddabf572772991a4aadad5bf4921fac5069Tom Care  bool isBuiltinType() const;
10949b065ddabf572772991a4aadad5bf4921fac5069Tom Care
1095e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar  /// isSpecificBuiltinType - Test for a particular builtin type.
1096e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar  bool isSpecificBuiltinType(unsigned K) const;
10971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
10982a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  /// isPlaceholderType - Test for a type which does not represent an
10992a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  /// actual type-system type but is instead used as a placeholder for
11002a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  /// various convenient purposes within Clang.  All such types are
11012a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  /// BuiltinTypes.
11022a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  bool isPlaceholderType() const;
11032a984cad5ac3fdceeff2bd99daa7b90979313475John McCall
110496d2c438f5c9ada8229f7f2ac049d2e9957bc954Steve Naroff  /// isIntegerType() does *not* include complex integers (a GCC extension).
110596d2c438f5c9ada8229f7f2ac049d2e9957bc954Steve Naroff  /// isComplexIntegerType() can be used to test for complex integers.
11065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isIntegerType() const;     // C99 6.2.5p17 (int, char, bool, enum)
110713b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff  bool isEnumeralType() const;
110813b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff  bool isBooleanType() const;
110913b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff  bool isCharType() const;
111077a52233f7c0f162672652051bfe78b65ad4f789Douglas Gregor  bool isWideCharType() const;
111120093b4bf698f292c664676987541d5103b65b15Douglas Gregor  bool isAnyCharacterType() const;
11129d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor  bool isIntegralType(ASTContext &Ctx) const;
111320093b4bf698f292c664676987541d5103b65b15Douglas Gregor
11142ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor  /// \brief Determine whether this type is an integral or enumeration type.
11152ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor  bool isIntegralOrEnumerationType() const;
11161274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor  /// \brief Determine whether this type is an integral or unscoped enumeration
11171274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor  /// type.
11181274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor  bool isIntegralOrUnscopedEnumerationType() const;
11192ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor
11205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// Floating point categories.
11215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isRealFloatingType() const; // C99 6.2.5p10 (float, double, long double)
112202f62a9fedbc370fba081303399410a3afdde29fSteve Naroff  /// isComplexType() does *not* include complex integers (a GCC extension).
112302f62a9fedbc370fba081303399410a3afdde29fSteve Naroff  /// isComplexIntegerType() can be used to test for complex integers.
11245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isComplexType() const;      // C99 6.2.5p11 (complex)
1125f23d364084d1aabea688222780d6fc1dd8c7f78cChris Lattner  bool isAnyComplexType() const;   // C99 6.2.5p11 (complex) + Complex Int.
11265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isFloatingType() const;     // C99 6.2.5p11 (real floating + complex)
11275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isRealType() const;         // C99 6.2.5p17 (real floating + integer)
11285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isArithmeticType() const;   // C99 6.2.5p18 (integer + floating)
1129c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  bool isVoidType() const;         // C99 6.2.5p19
1130c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  bool isDerivedType() const;      // C99 6.2.5p20
1131c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  bool isScalarType() const;       // C99 6.2.5p21 (arithmetic + pointers)
1132d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor  bool isAggregateType() const;
11331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1134c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  // Type Predicates: Check to see if this type is structurally the specified
1135ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb  // type, ignoring typedefs and qualifiers.
1136c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  bool isFunctionType() const;
1137183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  bool isFunctionNoProtoType() const { return getAs<FunctionNoProtoType>(); }
1138183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  bool isFunctionProtoType() const { return getAs<FunctionProtoType>(); }
1139befee48ff2a1dab236c5700f00ecca1cfdcd5837Chris Lattner  bool isPointerType() const;
114058f9f2c884af6b72d036b746a016d8031d31cb7aSteve Naroff  bool isAnyPointerType() const;   // Any C pointer or ObjC object pointer
11415618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  bool isBlockPointerType() const;
11427154a77e7c1f23418342d3b72836ab504aa7821eSteve Naroff  bool isVoidPointerType() const;
1143a1d9fdea79ba7bbd71862b9f9f78f5f117331fc7Chris Lattner  bool isReferenceType() const;
11447c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  bool isLValueReferenceType() const;
11457c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  bool isRValueReferenceType() const;
1146bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner  bool isFunctionPointerType() const;
1147f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  bool isMemberPointerType() const;
1148f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  bool isMemberFunctionPointerType() const;
1149db68e28c05a67735211e688009890cf834c22e75Douglas Gregor  bool isMemberDataPointerType() const;
1150c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  bool isArrayType() const;
1151c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  bool isConstantArrayType() const;
1152c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  bool isIncompleteArrayType() const;
1153c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  bool isVariableArrayType() const;
1154898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  bool isDependentSizedArrayType() const;
1155c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  bool isRecordType() const;
11561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  bool isClassType() const;
11571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  bool isStructureType() const;
1158fb87b89fc9eb103e19fb8e4b925c23f0bd091b99Douglas Gregor  bool isStructureOrClassType() const;
11594cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroff  bool isUnionType() const;
1160368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner  bool isComplexIntegerType() const;            // GCC _Complex integer type.
1161368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner  bool isVectorType() const;                    // GCC vector type.
1162213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman  bool isExtVectorType() const;                 // Extended vector type.
1163d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff  bool isObjCObjectPointerType() const;         // Pointer to *any* ObjC object.
116414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  // FIXME: change this to 'raw' interface type, so we can used 'interface' type
116514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  // for the common case.
1166c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool isObjCObjectType() const;                // NSString or typeof(*(id)0)
1167368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner  bool isObjCQualifiedInterfaceType() const;    // NSString<foo>
1168368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner  bool isObjCQualifiedIdType() const;           // id<foo>
1169470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroff  bool isObjCQualifiedClassType() const;        // Class<foo>
1170569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor  bool isObjCObjectOrInterfaceType() const;
117114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  bool isObjCIdType() const;                    // id
117214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  bool isObjCClassType() const;                 // Class
117313dcd00615de5c4279d97bdf63cd5f0a14fd9dccFariborz Jahanian  bool isObjCSelType() const;                 // Class
1174de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff  bool isObjCBuiltinType() const;               // 'id' or 'Class'
117572c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor  bool isTemplateTypeParmType() const;          // C++ template type parameter
11766e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl  bool isNullPtrType() const;                   // C++0x nullptr_t
1177898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
1178daa8e4e888758d55a7a759dd4a91b83921cef222John McCall  enum ScalarTypeKind {
1179daa8e4e888758d55a7a759dd4a91b83921cef222John McCall    STK_Pointer,
1180daa8e4e888758d55a7a759dd4a91b83921cef222John McCall    STK_MemberPointer,
1181daa8e4e888758d55a7a759dd4a91b83921cef222John McCall    STK_Bool,
1182daa8e4e888758d55a7a759dd4a91b83921cef222John McCall    STK_Integral,
1183daa8e4e888758d55a7a759dd4a91b83921cef222John McCall    STK_Floating,
1184daa8e4e888758d55a7a759dd4a91b83921cef222John McCall    STK_IntegralComplex,
1185daa8e4e888758d55a7a759dd4a91b83921cef222John McCall    STK_FloatingComplex
1186daa8e4e888758d55a7a759dd4a91b83921cef222John McCall  };
1187daa8e4e888758d55a7a759dd4a91b83921cef222John McCall  /// getScalarTypeKind - Given that this is a scalar type, classify it.
1188daa8e4e888758d55a7a759dd4a91b83921cef222John McCall  ScalarTypeKind getScalarTypeKind() const;
1189daa8e4e888758d55a7a759dd4a91b83921cef222John McCall
1190898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// isDependentType - Whether this type is a dependent type, meaning
11911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// that its definition somehow depends on a template parameter
1192898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// (C++ [temp.dep.type]).
1193b870b88df784c2940efce448ebfaf54dece14666John McCall  bool isDependentType() const { return TypeBits.Dependent; }
119435495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor
119535495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor  /// \brief Whether this type is a variably-modified type (C99 6.7.5).
1196b870b88df784c2940efce448ebfaf54dece14666John McCall  bool isVariablyModifiedType() const { return TypeBits.VariablyModified; }
119735495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor
1198db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor  /// \brief Whether this type is or contains a local or unnamed type.
1199db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor  bool hasUnnamedOrLocalType() const;
1200db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor
1201063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  bool isOverloadableType() const;
120272c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor
12034033642464e8ba0982f88f34cffad808d247b393Douglas Gregor  /// \brief Determine wither this type is a C++ elaborated-type-specifier.
12044033642464e8ba0982f88f34cffad808d247b393Douglas Gregor  bool isElaboratedTypeSpecifier() const;
12054033642464e8ba0982f88f34cffad808d247b393Douglas Gregor
12068958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar  /// hasPointerRepresentation - Whether this type is represented
12078958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar  /// natively as a pointer; this includes pointers, references, block
12088958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar  /// pointers, and Objective-C interface, qualified id, and qualified
12096e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl  /// interface types, as well as nullptr_t.
12108958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar  bool hasPointerRepresentation() const;
12118958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar
1212820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian  /// hasObjCPointerRepresentation - Whether this type can represent
1213820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian  /// an objective pointer type for the purpose of GC'ability
12141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  bool hasObjCPointerRepresentation() const;
1215820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian
1216f60946222721d9ba3c059563935c17b84703187aDouglas Gregor  /// \brief Determine whether this type has an integer representation
1217f60946222721d9ba3c059563935c17b84703187aDouglas Gregor  /// of some sort, e.g., it is an integer type or a vector.
1218f60946222721d9ba3c059563935c17b84703187aDouglas Gregor  bool hasIntegerRepresentation() const;
1219f60946222721d9ba3c059563935c17b84703187aDouglas Gregor
1220f60946222721d9ba3c059563935c17b84703187aDouglas Gregor  /// \brief Determine whether this type has an signed integer representation
1221f60946222721d9ba3c059563935c17b84703187aDouglas Gregor  /// of some sort, e.g., it is an signed integer type or a vector.
1222f60946222721d9ba3c059563935c17b84703187aDouglas Gregor  bool hasSignedIntegerRepresentation() const;
1223f60946222721d9ba3c059563935c17b84703187aDouglas Gregor
1224f60946222721d9ba3c059563935c17b84703187aDouglas Gregor  /// \brief Determine whether this type has an unsigned integer representation
1225f60946222721d9ba3c059563935c17b84703187aDouglas Gregor  /// of some sort, e.g., it is an unsigned integer type or a vector.
1226f60946222721d9ba3c059563935c17b84703187aDouglas Gregor  bool hasUnsignedIntegerRepresentation() const;
1227f60946222721d9ba3c059563935c17b84703187aDouglas Gregor
12288eee119bf4f1693dde17b8552c1f9f81bf2b681eDouglas Gregor  /// \brief Determine whether this type has a floating-point representation
12298eee119bf4f1693dde17b8552c1f9f81bf2b681eDouglas Gregor  /// of some sort, e.g., it is a floating-point type or a vector thereof.
12308eee119bf4f1693dde17b8552c1f9f81bf2b681eDouglas Gregor  bool hasFloatingRepresentation() const;
1231f60946222721d9ba3c059563935c17b84703187aDouglas Gregor
1232c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  // Type Checking Functions: Check to see if this type is structurally the
1233f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner  // specified type, ignoring typedefs and qualifiers, and return a pointer to
1234f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner  // the best type we can.
1235769c9cfc6e06bd9d8ffe7a4397b939f19b0e4dc3Ted Kremenek  const RecordType *getAsStructureType() const;
1236898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// NOTE: getAs*ArrayType are methods on ASTContext.
1237c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  const RecordType *getAsUnionType() const;
12384cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroff  const ComplexType *getAsComplexIntegerType() const; // GCC complex int type.
123914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  // The following is a convenience method that returns an ObjCObjectPointerType
124014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  // for object declared using an interface.
124114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  const ObjCObjectPointerType *getAsObjCInterfacePointerType() const;
124214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  const ObjCObjectPointerType *getAsObjCQualifiedIdType() const;
1243c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  const ObjCObjectType *getAsObjCQualifiedInterfaceType() const;
1244a91d6a6619a91d0ca7102d8ab5678d855f04d850Fariborz Jahanian  const CXXRecordDecl *getCXXRecordDeclForPointerType() const;
12451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1246c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor  /// \brief Retrieves the CXXRecordDecl that this type refers to, either
1247c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor  /// because the type is a RecordType or because it is the injected-class-name
1248c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor  /// type of a class template or class template partial specialization.
1249c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor  CXXRecordDecl *getAsCXXRecordDecl() const;
1250c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor
1251fa78c91c54dd99ec61a9e27e6b74a549f5c9fa9cDan Gohman  // Member-template getAs<specific type>'.  Look through sugar for
1252fa78c91c54dd99ec61a9e27e6b74a549f5c9fa9cDan Gohman  // an instance of <specific type>.   This scheme will eventually
12531a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek  // replace the specific getAsXXXX methods above.
1254183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  //
1255183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  // There are some specializations of this member template listed
1256183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  // immediately following this class.
12571a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek  template <typename T> const T *getAs() const;
12581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1259c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  /// getArrayElementTypeNoTypeQual - If this is an array type, return the
1260c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  /// element type of the array, potentially with type qualifiers missing.
1261c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  /// This method should never be used when type qualifiers are meaningful.
1262c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  const Type *getArrayElementTypeNoTypeQual() const;
12631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1264f8910df57799256c1897a8610dc52685729ae90eSteve Naroff  /// getPointeeType - If this is a pointer, ObjC object pointer, or block
1265f8910df57799256c1897a8610dc52685729ae90eSteve Naroff  /// pointer, this returns the respective pointee.
126614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  QualType getPointeeType() const;
12671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1268bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// getUnqualifiedDesugaredType() - Return the specified type with
1269bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// any "sugar" removed from the type, removing any typedefs,
1270bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// typeofs, etc., as well as any qualifiers.
1271bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  const Type *getUnqualifiedDesugaredType() const;
12721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// More type predicates useful for type checking/promotion
12745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isPromotableIntegerType() const; // C99 6.3.1.1p2
12755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
12765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isSignedIntegerType - Return true if this is an integer type that is
1277d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner  /// signed, according to C99 6.2.5p4 [char, signed char, short, int, long..],
1278d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner  /// an enum decl which has a signed representation, or a vector of signed
1279d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner  /// integer element type.
12805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isSignedIntegerType() const;
12815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
12825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isUnsignedIntegerType - Return true if this is an integer type that is
1283d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner  /// unsigned, according to C99 6.2.5p6 [which returns true for _Bool], an enum
1284d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner  /// decl which has an unsigned representation, or a vector of unsigned integer
1285d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner  /// element type.
12865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isUnsignedIntegerType() const;
1287d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner
12885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isConstantSizeType - Return true if this is not a variable sized type,
12899bfa73c5ab7bf4b0e749d04f29da6884e8d5bd9fChris Lattner  /// according to the rules of C99 6.7.5p3.  It is not legal to call this on
12909bfa73c5ab7bf4b0e749d04f29da6884e8d5bd9fChris Lattner  /// incomplete types.
12913c2b3170041f69a92904e3bab9b6d654eaf260acEli Friedman  bool isConstantSizeType() const;
1292c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner
129322b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman  /// isSpecifierType - Returns true if this type can be represented by some
129422b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman  /// set of type specifiers.
129522b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman  bool isSpecifierType() const;
129622b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman
12970b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor  /// \brief Determine the linkage of this type.
129860e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor  Linkage getLinkage() const;
12991fb0caaa7bef765b85972274e3b434af2572c141John McCall
13001fb0caaa7bef765b85972274e3b434af2572c141John McCall  /// \brief Determine the visibility of this type.
13011fb0caaa7bef765b85972274e3b434af2572c141John McCall  Visibility getVisibility() const;
13021fb0caaa7bef765b85972274e3b434af2572c141John McCall
13031fb0caaa7bef765b85972274e3b434af2572c141John McCall  /// \brief Determine the linkage and visibility of this type.
13041fb0caaa7bef765b85972274e3b434af2572c141John McCall  std::pair<Linkage,Visibility> getLinkageAndVisibility() const;
130560e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
130660e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor  /// \brief Note that the linkage is no longer known.
130760e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor  void ClearLinkageCache();
130860e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
130960e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor  const char *getTypeClassName() const;
13100b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor
1311ead608af31b6c9abeae1ca6d0b75094dac4641c0John McCall  QualType getCanonicalTypeInternal() const {
1312ead608af31b6c9abeae1ca6d0b75094dac4641c0John McCall    return CanonicalType;
1313ead608af31b6c9abeae1ca6d0b75094dac4641c0John McCall  }
1314ead608af31b6c9abeae1ca6d0b75094dac4641c0John McCall  CanQualType getCanonicalTypeUnqualified() const; // in CanonicalType.h
1315c36d405a02fab41f6c45cb2bc750d64949742903Chris Lattner  void dump() const;
13165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *) { return true; }
1317be191100e034b23a3e13053757a57b7f5068c24aArgyrios Kyrtzidis
1318c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl  friend class ASTReader;
1319a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian Redl  friend class ASTWriter;
13205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
13215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1322183700f494ec9b6701b6efe82bcb25f4c79ba561John McCalltemplate <> inline const TypedefType *Type::getAs() const {
1323183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  return dyn_cast<TypedefType>(this);
1324183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall}
1325183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall
1326183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall// We can do canonical leaf types faster, because we don't have to
1327183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall// worry about preserving child type decoration.
1328183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall#define TYPE(Class, Base)
1329183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall#define LEAF_TYPE(Class) \
1330183700f494ec9b6701b6efe82bcb25f4c79ba561John McCalltemplate <> inline const Class##Type *Type::getAs() const { \
13310953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  return dyn_cast<Class##Type>(CanonicalType); \
1332183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall}
1333183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall#include "clang/AST/TypeNodes.def"
1334183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall
1335183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall
13365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// BuiltinType - This class is used for builtin types like 'int'.  Builtin
13375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// types are always canonical and have a literal name field.
13385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass BuiltinType : public Type {
13395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
13405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  enum Kind {
13415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Void,
13421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
13435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Bool,     // This is bool and/or _Bool.
13445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Char_U,   // This is 'char' for targets where char is unsigned.
13455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    UChar,    // This is explicitly qualified unsigned char.
1346f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith    Char16,   // This is 'char16_t' for C++.
1347f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith    Char32,   // This is 'char32_t' for C++.
13485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    UShort,
13495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    UInt,
13505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ULong,
13515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ULongLong,
13522df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner    UInt128,  // __uint128_t
13531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
13545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Char_S,   // This is 'char' for targets where char is signed.
13555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    SChar,    // This is explicitly qualified signed char.
13562ff9b4c7c8fed9233a0b8de2e9507368c451aab6Argyrios Kyrtzidis    WChar,    // This is 'wchar_t' for C++.
13575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Short,
13585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Int,
13595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Long,
13605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    LongLong,
13612df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner    Int128,   // __int128_t
13621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
13638e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor    Float, Double, LongDouble,
13648e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor
13656e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl    NullPtr,  // This is the type of C++0x 'nullptr'.
13666e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl
13672a984cad5ac3fdceeff2bd99daa7b90979313475John McCall    /// This represents the type of an expression whose type is
13682a984cad5ac3fdceeff2bd99daa7b90979313475John McCall    /// totally unknown, e.g. 'T::foo'.  It is permitted for this to
13692a984cad5ac3fdceeff2bd99daa7b90979313475John McCall    /// appear in situations where the structure of the type is
13702a984cad5ac3fdceeff2bd99daa7b90979313475John McCall    /// theoretically deducible.
13712a984cad5ac3fdceeff2bd99daa7b90979313475John McCall    Dependent,
13722a984cad5ac3fdceeff2bd99daa7b90979313475John McCall
1373898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    Overload,  // This represents the type of an overloaded function declaration.
13741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1375de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff    UndeducedAuto, // In C++0x, this represents the type of an auto variable
1376e89d15944dd3be750a09805ad21222d2fa9321faAnders Carlsson                   // that has not been deduced yet.
1377e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall
1378e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall    /// The primitive Objective C 'id' type.  The type pointed to by the
1379e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall    /// user-visible 'id' type.  Only ever shows up in an AST as the base
1380e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall    /// type of an ObjCObjectType.
1381e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall    ObjCId,
1382e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall
1383e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall    /// The primitive Objective C 'Class' type.  The type pointed to by the
1384e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall    /// user-visible 'Class' type.  Only ever shows up in an AST as the
1385e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall    /// base type of an ObjCObjectType.
1386e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall    ObjCClass,
1387e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall
138813dcd00615de5c4279d97bdf63cd5f0a14fd9dccFariborz Jahanian    ObjCSel    // This represents the ObjC 'SEL' type.
13895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
139071c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall
13915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
13921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  BuiltinType(Kind K)
139335495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    : Type(Builtin, QualType(), /*Dependent=*/(K == Dependent),
1394d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor           /*VariablyModified=*/false,
1395d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor           /*Unexpanded paramter pack=*/false) {
1396b870b88df784c2940efce448ebfaf54dece14666John McCall    BuiltinTypeBits.Kind = K;
139771c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  }
13981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1399b870b88df784c2940efce448ebfaf54dece14666John McCall  Kind getKind() const { return static_cast<Kind>(BuiltinTypeBits.Kind); }
1400e4f2142d00fa5fdb580c4e2413da91882d955381Chris Lattner  const char *getName(const LangOptions &LO) const;
14011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1402bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1403bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1404bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
1405680523a91dd3351389667c8de17121ba7ae82673John McCall  bool isInteger() const {
140671c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    return getKind() >= Bool && getKind() <= Int128;
1407680523a91dd3351389667c8de17121ba7ae82673John McCall  }
1408680523a91dd3351389667c8de17121ba7ae82673John McCall
1409680523a91dd3351389667c8de17121ba7ae82673John McCall  bool isSignedInteger() const {
141071c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    return getKind() >= Char_S && getKind() <= Int128;
1411680523a91dd3351389667c8de17121ba7ae82673John McCall  }
1412680523a91dd3351389667c8de17121ba7ae82673John McCall
1413680523a91dd3351389667c8de17121ba7ae82673John McCall  bool isUnsignedInteger() const {
141471c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    return getKind() >= Bool && getKind() <= UInt128;
1415680523a91dd3351389667c8de17121ba7ae82673John McCall  }
1416680523a91dd3351389667c8de17121ba7ae82673John McCall
1417680523a91dd3351389667c8de17121ba7ae82673John McCall  bool isFloatingPoint() const {
141871c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    return getKind() >= Float && getKind() <= LongDouble;
1419680523a91dd3351389667c8de17121ba7ae82673John McCall  }
1420680523a91dd3351389667c8de17121ba7ae82673John McCall
14212a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  /// Determines whether this type is a "forbidden" placeholder type,
14222a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  /// i.e. a type which cannot appear in arbitrary positions in a
14232a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  /// fully-formed expression.
14242a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  bool isPlaceholderType() const {
142571c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    return getKind() == Overload ||
142671c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall           getKind() == UndeducedAuto;
14272a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  }
14282a984cad5ac3fdceeff2bd99daa7b90979313475John McCall
14295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T) { return T->getTypeClass() == Builtin; }
14305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const BuiltinType *) { return true; }
14315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
14325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
14335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ComplexType - C99 6.2.5p11 - Complex values.  This supports the C99 complex
14345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// types (_Complex float etc) as well as the GCC integer complex extensions.
14355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
14365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ComplexType : public Type, public llvm::FoldingSetNode {
14375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType ElementType;
14385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ComplexType(QualType Element, QualType CanonicalPtr) :
143935495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    Type(Complex, CanonicalPtr, Element->isDependentType(),
1440d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor         Element->isVariablyModifiedType(),
1441d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor         Element->containsUnexpandedParameterPack()),
1442898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    ElementType(Element) {
14435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
14445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
144560e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
14465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
14475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType getElementType() const { return ElementType; }
14481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1449bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1450bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1451bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
14525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void Profile(llvm::FoldingSetNodeID &ID) {
14535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Profile(ID, getElementType());
14545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
14555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static void Profile(llvm::FoldingSetNodeID &ID, QualType Element) {
14565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ID.AddPointer(Element.getAsOpaquePtr());
14575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
14581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
14595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T) { return T->getTypeClass() == Complex; }
14605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const ComplexType *) { return true; }
14615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
14625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1463075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara/// ParenType - Sugar for parentheses used when specifying types.
1464075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara///
1465075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnaraclass ParenType : public Type, public llvm::FoldingSetNode {
1466075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  QualType Inner;
1467075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
1468075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  ParenType(QualType InnerType, QualType CanonType) :
1469075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara    Type(Paren, CanonType, InnerType->isDependentType(),
1470d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor         InnerType->isVariablyModifiedType(),
1471d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor         InnerType->containsUnexpandedParameterPack()),
1472075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara    Inner(InnerType) {
1473075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  }
1474075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  friend class ASTContext;  // ASTContext creates these.
1475075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
1476075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnarapublic:
1477075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
1478075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  QualType getInnerType() const { return Inner; }
1479075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
1480075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  bool isSugared() const { return true; }
1481075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  QualType desugar() const { return getInnerType(); }
1482075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
1483075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  void Profile(llvm::FoldingSetNodeID &ID) {
1484075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara    Profile(ID, getInnerType());
1485075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  }
1486075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  static void Profile(llvm::FoldingSetNodeID &ID, QualType Inner) {
1487075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara    Inner.Profile(ID);
1488075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  }
1489075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
1490075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  static bool classof(const Type *T) { return T->getTypeClass() == Paren; }
1491075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  static bool classof(const ParenType *) { return true; }
1492075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara};
1493075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
149468694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar/// PointerType - C99 6.7.5.1 - Pointer Declarators.
1495bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner///
149668694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbarclass PointerType : public Type, public llvm::FoldingSetNode {
1497bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner  QualType PointeeType;
14985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
14995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  PointerType(QualType Pointee, QualType CanonicalPtr) :
150035495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    Type(Pointer, CanonicalPtr, Pointee->isDependentType(),
1501d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor         Pointee->isVariablyModifiedType(),
1502d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor         Pointee->containsUnexpandedParameterPack()),
150335495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    PointeeType(Pointee) {
15045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
15055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
150660e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
15075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
15081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
150968694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar  QualType getPointeeType() const { return PointeeType; }
151068694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar
1511bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1512bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1513bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
15145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void Profile(llvm::FoldingSetNodeID &ID) {
15155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Profile(ID, getPointeeType());
15165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
15175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) {
15185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ID.AddPointer(Pointee.getAsOpaquePtr());
15195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
15201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
15215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T) { return T->getTypeClass() == Pointer; }
15225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const PointerType *) { return true; }
15235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
15245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
15255618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff/// BlockPointerType - pointer to a block type.
15265618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff/// This type is to represent types syntactically represented as
15275618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff/// "void (^)(int)", etc. Pointee is required to always be a function type.
15285618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff///
15295618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroffclass BlockPointerType : public Type, public llvm::FoldingSetNode {
15305618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  QualType PointeeType;  // Block is some kind of pointer type
15315618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  BlockPointerType(QualType Pointee, QualType CanonicalCls) :
153235495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    Type(BlockPointer, CanonicalCls, Pointee->isDependentType(),
1533d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor         Pointee->isVariablyModifiedType(),
1534d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor         Pointee->containsUnexpandedParameterPack()),
1535898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    PointeeType(Pointee) {
15365618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  }
15375618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  friend class ASTContext;  // ASTContext creates these.
153860e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
15395618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroffpublic:
15401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
15415618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  // Get the pointee type. Pointee is required to always be a function type.
15425618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  QualType getPointeeType() const { return PointeeType; }
15435618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff
1544bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1545bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1546bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
15475618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  void Profile(llvm::FoldingSetNodeID &ID) {
15485618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff      Profile(ID, getPointeeType());
15495618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  }
15505618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) {
15515618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff      ID.AddPointer(Pointee.getAsOpaquePtr());
15525618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  }
15531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
15541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
15551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == BlockPointer;
15565618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  }
15575618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  static bool classof(const BlockPointerType *) { return true; }
15585618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff};
15595618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff
15607c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// ReferenceType - Base for LValueReferenceType and RValueReferenceType
15615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
156268694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbarclass ReferenceType : public Type, public llvm::FoldingSetNode {
156368694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar  QualType PointeeType;
156468694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar
15657c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlprotected:
156654e14c4db764c0636160d26c5bbf491637c83a76John McCall  ReferenceType(TypeClass tc, QualType Referencee, QualType CanonicalRef,
156754e14c4db764c0636160d26c5bbf491637c83a76John McCall                bool SpelledAsLValue) :
156835495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    Type(tc, CanonicalRef, Referencee->isDependentType(),
1569d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor         Referencee->isVariablyModifiedType(),
1570d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor         Referencee->containsUnexpandedParameterPack()),
1571d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    PointeeType(Referencee)
1572d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  {
1573b870b88df784c2940efce448ebfaf54dece14666John McCall    ReferenceTypeBits.SpelledAsLValue = SpelledAsLValue;
1574b870b88df784c2940efce448ebfaf54dece14666John McCall    ReferenceTypeBits.InnerRef = Referencee->isReferenceType();
15755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
157660e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
15775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
1578b870b88df784c2940efce448ebfaf54dece14666John McCall  bool isSpelledAsLValue() const { return ReferenceTypeBits.SpelledAsLValue; }
1579b870b88df784c2940efce448ebfaf54dece14666John McCall  bool isInnerRef() const { return ReferenceTypeBits.InnerRef; }
158073dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor
158154e14c4db764c0636160d26c5bbf491637c83a76John McCall  QualType getPointeeTypeAsWritten() const { return PointeeType; }
158254e14c4db764c0636160d26c5bbf491637c83a76John McCall  QualType getPointeeType() const {
158354e14c4db764c0636160d26c5bbf491637c83a76John McCall    // FIXME: this might strip inner qualifiers; okay?
158454e14c4db764c0636160d26c5bbf491637c83a76John McCall    const ReferenceType *T = this;
158571c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    while (T->isInnerRef())
158654e14c4db764c0636160d26c5bbf491637c83a76John McCall      T = T->PointeeType->getAs<ReferenceType>();
158754e14c4db764c0636160d26c5bbf491637c83a76John McCall    return T->PointeeType;
158854e14c4db764c0636160d26c5bbf491637c83a76John McCall  }
158968694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar
15905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void Profile(llvm::FoldingSetNodeID &ID) {
159171c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    Profile(ID, PointeeType, isSpelledAsLValue());
15925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
159354e14c4db764c0636160d26c5bbf491637c83a76John McCall  static void Profile(llvm::FoldingSetNodeID &ID,
159454e14c4db764c0636160d26c5bbf491637c83a76John McCall                      QualType Referencee,
159554e14c4db764c0636160d26c5bbf491637c83a76John McCall                      bool SpelledAsLValue) {
15965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ID.AddPointer(Referencee.getAsOpaquePtr());
159754e14c4db764c0636160d26c5bbf491637c83a76John McCall    ID.AddBoolean(SpelledAsLValue);
15985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
15995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
16007c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  static bool classof(const Type *T) {
16017c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl    return T->getTypeClass() == LValueReference ||
16027c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl           T->getTypeClass() == RValueReference;
16037c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  }
16045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const ReferenceType *) { return true; }
16057c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl};
16067c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl
16077c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// LValueReferenceType - C++ [dcl.ref] - Lvalue reference
16087c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl///
16097c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlclass LValueReferenceType : public ReferenceType {
161054e14c4db764c0636160d26c5bbf491637c83a76John McCall  LValueReferenceType(QualType Referencee, QualType CanonicalRef,
161154e14c4db764c0636160d26c5bbf491637c83a76John McCall                      bool SpelledAsLValue) :
161254e14c4db764c0636160d26c5bbf491637c83a76John McCall    ReferenceType(LValueReference, Referencee, CanonicalRef, SpelledAsLValue)
161354e14c4db764c0636160d26c5bbf491637c83a76John McCall  {}
16147c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  friend class ASTContext; // ASTContext creates these
16157c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlpublic:
1616bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1617bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1618bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
16197c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  static bool classof(const Type *T) {
16207c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl    return T->getTypeClass() == LValueReference;
16217c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  }
16227c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  static bool classof(const LValueReferenceType *) { return true; }
16237c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl};
16247c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl
16257c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// RValueReferenceType - C++0x [dcl.ref] - Rvalue reference
16267c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl///
16277c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlclass RValueReferenceType : public ReferenceType {
16287c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  RValueReferenceType(QualType Referencee, QualType CanonicalRef) :
162954e14c4db764c0636160d26c5bbf491637c83a76John McCall    ReferenceType(RValueReference, Referencee, CanonicalRef, false) {
16307c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  }
16317c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  friend class ASTContext; // ASTContext creates these
16327c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlpublic:
1633bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1634bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1635bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
16367c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  static bool classof(const Type *T) {
16377c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl    return T->getTypeClass() == RValueReference;
16387c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  }
16397c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  static bool classof(const RValueReferenceType *) { return true; }
1640f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl};
1641f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl
1642f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl/// MemberPointerType - C++ 8.3.3 - Pointers to members
1643f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl///
1644f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlclass MemberPointerType : public Type, public llvm::FoldingSetNode {
1645f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  QualType PointeeType;
1646f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  /// The class of which the pointee is a member. Must ultimately be a
1647f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  /// RecordType, but could be a typedef or a template parameter too.
1648f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  const Type *Class;
1649f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl
1650f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  MemberPointerType(QualType Pointee, const Type *Cls, QualType CanonicalPtr) :
1651f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    Type(MemberPointer, CanonicalPtr,
165235495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor         Cls->isDependentType() || Pointee->isDependentType(),
1653d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor         Pointee->isVariablyModifiedType(),
1654d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor         (Cls->containsUnexpandedParameterPack() ||
1655d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor          Pointee->containsUnexpandedParameterPack())),
1656f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    PointeeType(Pointee), Class(Cls) {
1657f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  }
1658f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  friend class ASTContext; // ASTContext creates these.
165960e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
1660f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlpublic:
1661f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  QualType getPointeeType() const { return PointeeType; }
1662f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl
16630bab0cdab751248ca389a5592bcb70eac5d39260John McCall  /// Returns true if the member type (i.e. the pointee type) is a
16640bab0cdab751248ca389a5592bcb70eac5d39260John McCall  /// function type rather than a data-member type.
16650bab0cdab751248ca389a5592bcb70eac5d39260John McCall  bool isMemberFunctionPointer() const {
16660bab0cdab751248ca389a5592bcb70eac5d39260John McCall    return PointeeType->isFunctionProtoType();
16670bab0cdab751248ca389a5592bcb70eac5d39260John McCall  }
16680bab0cdab751248ca389a5592bcb70eac5d39260John McCall
16690bab0cdab751248ca389a5592bcb70eac5d39260John McCall  /// Returns true if the member type (i.e. the pointee type) is a
16700bab0cdab751248ca389a5592bcb70eac5d39260John McCall  /// data type rather than a function type.
16710bab0cdab751248ca389a5592bcb70eac5d39260John McCall  bool isMemberDataPointer() const {
16720bab0cdab751248ca389a5592bcb70eac5d39260John McCall    return !PointeeType->isFunctionProtoType();
16730bab0cdab751248ca389a5592bcb70eac5d39260John McCall  }
16740bab0cdab751248ca389a5592bcb70eac5d39260John McCall
1675f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  const Type *getClass() const { return Class; }
1676f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl
1677bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1678bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1679bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
1680f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  void Profile(llvm::FoldingSetNodeID &ID) {
1681f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    Profile(ID, getPointeeType(), getClass());
1682f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  }
1683f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee,
1684f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl                      const Type *Class) {
1685f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    ID.AddPointer(Pointee.getAsOpaquePtr());
1686f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    ID.AddPointer(Class);
1687f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  }
1688f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl
1689f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  static bool classof(const Type *T) {
1690f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    return T->getTypeClass() == MemberPointer;
1691f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  }
1692f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  static bool classof(const MemberPointerType *) { return true; }
16935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
16945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
16955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ArrayType - C99 6.7.5.2 - Array Declarators.
16965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
16972e7d352dbec06755105237afba183492d31d03cbTed Kremenekclass ArrayType : public Type, public llvm::FoldingSetNode {
16985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
16995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// ArraySizeModifier - Capture whether this is a normal array (e.g. int X[4])
1700898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// an array with a static size (e.g. int X[static 4]), or an array
1701898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// with a star size (e.g. int X[*]).
1702898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// 'static' is only allowed on function parameters.
17035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  enum ArraySizeModifier {
17045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Normal, Static, Star
17055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
17065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate:
1707fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  /// ElementType - The element type of the array.
1708fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  QualType ElementType;
17091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1710fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroffprotected:
1711898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  // C++ [temp.dep.type]p1:
1712898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  //   A type is dependent if it is...
1713898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  //     - an array type constructed from any dependent type or whose
1714898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  //       size is specified by a constant expression that is
1715898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  //       value-dependent,
1716c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff  ArrayType(TypeClass tc, QualType et, QualType can,
1717d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor            ArraySizeModifier sm, unsigned tq,
1718d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor            bool ContainsUnexpandedParameterPack)
171935495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    : Type(tc, can, et->isDependentType() || tc == DependentSizedArray,
1720d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor           (tc == VariableArray || et->isVariablyModifiedType()),
1721d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor           ContainsUnexpandedParameterPack),
172271c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall      ElementType(et) {
1723b870b88df784c2940efce448ebfaf54dece14666John McCall    ArrayTypeBits.IndexTypeQuals = tq;
1724b870b88df784c2940efce448ebfaf54dece14666John McCall    ArrayTypeBits.SizeModifier = sm;
172571c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  }
1726898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
1727fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  friend class ASTContext;  // ASTContext creates these.
172860e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
1729fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroffpublic:
1730fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  QualType getElementType() const { return ElementType; }
1731ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek  ArraySizeModifier getSizeModifier() const {
1732b870b88df784c2940efce448ebfaf54dece14666John McCall    return ArraySizeModifier(ArrayTypeBits.SizeModifier);
1733ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek  }
17340953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  Qualifiers getIndexTypeQualifiers() const {
173571c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    return Qualifiers::fromCVRMask(getIndexTypeCVRQualifiers());
173671c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  }
173771c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  unsigned getIndexTypeCVRQualifiers() const {
1738b870b88df784c2940efce448ebfaf54dece14666John McCall    return ArrayTypeBits.IndexTypeQuals;
17390953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
17401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1741fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  static bool classof(const Type *T) {
1742fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff    return T->getTypeClass() == ConstantArray ||
1743c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman           T->getTypeClass() == VariableArray ||
1744898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor           T->getTypeClass() == IncompleteArray ||
1745898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor           T->getTypeClass() == DependentSizedArray;
1746fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  }
1747fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  static bool classof(const ArrayType *) { return true; }
1748fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff};
1749fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff
17507e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// ConstantArrayType - This class represents the canonical version of
17517e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// C arrays with a specified constant size.  For example, the canonical
17527e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// type for 'int A[4 + 4*100]' is a ConstantArrayType where the element
17537e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// type is 'int' and the size is 404.
17542e7d352dbec06755105237afba183492d31d03cbTed Kremenekclass ConstantArrayType : public ArrayType {
1755fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  llvm::APInt Size; // Allows us to unique the type.
17561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
17570be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner  ConstantArrayType(QualType et, QualType can, const llvm::APInt &size,
1758c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff                    ArraySizeModifier sm, unsigned tq)
1759d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    : ArrayType(ConstantArray, et, can, sm, tq,
1760d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor                et->containsUnexpandedParameterPack()),
17617e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor      Size(size) {}
17627e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregorprotected:
17637e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  ConstantArrayType(TypeClass tc, QualType et, QualType can,
17647e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor                    const llvm::APInt &size, ArraySizeModifier sm, unsigned tq)
1765d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    : ArrayType(tc, et, can, sm, tq, et->containsUnexpandedParameterPack()),
1766d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor      Size(size) {}
1767fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  friend class ASTContext;  // ASTContext creates these.
1768fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroffpublic:
1769c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  const llvm::APInt &getSize() const { return Size; }
1770bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1771bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1772bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
17732767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor
17742767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor  /// \brief Determine the number of bits required to address a member of
17752767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor  // an array with the given element type and number of elements.
17762767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor  static unsigned getNumAddressingBits(ASTContext &Context,
17772767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor                                       QualType ElementType,
17782767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor                                       const llvm::APInt &NumElements);
17792767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor
17802767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor  /// \brief Determine the maximum number of active bits that an array's size
17812767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor  /// can require, which limits the maximum size of the array.
17822767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor  static unsigned getMaxSizeBits(ASTContext &Context);
17832767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor
1784fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  void Profile(llvm::FoldingSetNodeID &ID) {
17851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    Profile(ID, getElementType(), getSize(),
17860953e767ff7817f97b3ab20896b229891eeff45bJohn McCall            getSizeModifier(), getIndexTypeCVRQualifiers());
1787fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  }
1788fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  static void Profile(llvm::FoldingSetNodeID &ID, QualType ET,
17890be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner                      const llvm::APInt &ArraySize, ArraySizeModifier SizeMod,
17900be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner                      unsigned TypeQuals) {
1791fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff    ID.AddPointer(ET.getAsOpaquePtr());
1792fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff    ID.AddInteger(ArraySize.getZExtValue());
17930be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner    ID.AddInteger(SizeMod);
17940be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner    ID.AddInteger(TypeQuals);
1795fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  }
17967e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  static bool classof(const Type *T) {
179746a617a792bfab0d9b1e057371ea3b9540802226John McCall    return T->getTypeClass() == ConstantArray;
1798fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  }
1799fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  static bool classof(const ConstantArrayType *) { return true; }
1800fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff};
1801fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff
1802da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// IncompleteArrayType - This class represents C arrays with an unspecified
1803da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// size.  For example 'int A[]' has an IncompleteArrayType where the element
1804da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// type is 'int' and the size is unspecified.
1805c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedmanclass IncompleteArrayType : public ArrayType {
18067e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor
1807c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman  IncompleteArrayType(QualType et, QualType can,
18087e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor                      ArraySizeModifier sm, unsigned tq)
1809d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    : ArrayType(IncompleteArray, et, can, sm, tq,
1810d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor                et->containsUnexpandedParameterPack()) {}
1811c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman  friend class ASTContext;  // ASTContext creates these.
1812c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedmanpublic:
1813bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1814bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1815bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
18161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
18171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == IncompleteArray;
1818c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman  }
1819c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman  static bool classof(const IncompleteArrayType *) { return true; }
18201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1821c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman  friend class StmtIteratorBase;
18221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1823c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman  void Profile(llvm::FoldingSetNodeID &ID) {
18240953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Profile(ID, getElementType(), getSizeModifier(),
18250953e767ff7817f97b3ab20896b229891eeff45bJohn McCall            getIndexTypeCVRQualifiers());
1826c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman  }
18271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
18280be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner  static void Profile(llvm::FoldingSetNodeID &ID, QualType ET,
18290be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner                      ArraySizeModifier SizeMod, unsigned TypeQuals) {
1830c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman    ID.AddPointer(ET.getAsOpaquePtr());
18310be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner    ID.AddInteger(SizeMod);
18320be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner    ID.AddInteger(TypeQuals);
1833c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman  }
1834c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman};
1835c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman
1836da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// VariableArrayType - This class represents C arrays with a specified size
1837da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// which is not an integer-constant-expression.  For example, 'int s[x+foo()]'.
1838da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// Since the size expression is an arbitrary expression, we store it as such.
1839da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner///
1840da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// Note: VariableArrayType's aren't uniqued (since the expressions aren't) and
1841da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// should not be: two lexically equivalent variable array types could mean
1842da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// different things, for example, these variables do not have the same type
1843da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// dynamically:
1844da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner///
1845da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// void foo(int x) {
1846da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner///   int Y[x];
1847da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner///   ++x;
1848da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner///   int Z[x];
1849da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// }
1850da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner///
18512e7d352dbec06755105237afba183492d31d03cbTed Kremenekclass VariableArrayType : public ArrayType {
18521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// SizeExpr - An assignment expression. VLA's are only permitted within
18531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// a function block.
1854b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek  Stmt *SizeExpr;
18557e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  /// Brackets - The left and right array brackets.
18567e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  SourceRange Brackets;
18577e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor
1858c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff  VariableArrayType(QualType et, QualType can, Expr *e,
18597e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor                    ArraySizeModifier sm, unsigned tq,
18607e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor                    SourceRange brackets)
1861d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    : ArrayType(VariableArray, et, can, sm, tq,
1862d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor                et->containsUnexpandedParameterPack()),
18637e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor      SizeExpr((Stmt*) e), Brackets(brackets) {}
18645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
18654b05b1dee6cc65ae61d93dab7edff72710f24589Ted Kremenek
18665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
18671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Expr *getSizeExpr() const {
1868b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek    // We use C-style casts instead of cast<> here because we do not wish
1869b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek    // to have a dependency of Type.h on Stmt.h/Expr.h.
1870b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek    return (Expr*) SizeExpr;
1871b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek  }
18727e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  SourceRange getBracketsRange() const { return Brackets; }
18737e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  SourceLocation getLBracketLoc() const { return Brackets.getBegin(); }
18747e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  SourceLocation getRBracketLoc() const { return Brackets.getEnd(); }
18751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1876bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1877bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1878bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
18791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
18801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == VariableArray;
18815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
1882fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  static bool classof(const VariableArrayType *) { return true; }
18831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
188492866e2e90f6d93fb95e25a7ac4438e239d89ce6Ted Kremenek  friend class StmtIteratorBase;
18851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
18862bd24ba6d10f8c811c8e2a57c8397e07082ba497Ted Kremenek  void Profile(llvm::FoldingSetNodeID &ID) {
1887bc5e150b6d94cf131f7d01bc715571b741c5b408Chris Lattner    assert(0 && "Cannnot unique VariableArrayTypes.");
18882bd24ba6d10f8c811c8e2a57c8397e07082ba497Ted Kremenek  }
18895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
18905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1891898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// DependentSizedArrayType - This type represents an array type in
1892898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// C++ whose size is a value-dependent expression. For example:
1893cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor///
1894cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor/// \code
18951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// template<typename T, int Size>
1896898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// class array {
1897898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor///   T data[Size];
1898898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// };
1899cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor/// \endcode
1900cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor///
1901898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// For these types, we won't actually know what the array bound is
1902898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// until template instantiation occurs, at which point this will
1903898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// become either a ConstantArrayType or a VariableArrayType.
1904898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorclass DependentSizedArrayType : public ArrayType {
190504d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor  ASTContext &Context;
19061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1907cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor  /// \brief An assignment expression that will instantiate to the
1908898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// size of the array.
1909cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor  ///
1910cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor  /// The expression itself might be NULL, in which case the array
1911cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor  /// type will have its size deduced from an initializer.
1912898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  Stmt *SizeExpr;
1913cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor
19147e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  /// Brackets - The left and right array brackets.
19157e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  SourceRange Brackets;
19161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
19171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  DependentSizedArrayType(ASTContext &Context, QualType et, QualType can,
191804d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor                          Expr *e, ArraySizeModifier sm, unsigned tq,
1919d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor                          SourceRange brackets);
1920d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor
1921898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  friend class ASTContext;  // ASTContext creates these.
1922898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
1923898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorpublic:
19241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Expr *getSizeExpr() const {
1925898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    // We use C-style casts instead of cast<> here because we do not wish
1926898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    // to have a dependency of Type.h on Stmt.h/Expr.h.
1927898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    return (Expr*) SizeExpr;
1928898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  }
19297e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  SourceRange getBracketsRange() const { return Brackets; }
19307e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  SourceLocation getLBracketLoc() const { return Brackets.getBegin(); }
19317e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  SourceLocation getRBracketLoc() const { return Brackets.getEnd(); }
19321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1933bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1934bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1935bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
19361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
19371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == DependentSizedArray;
1938898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  }
1939898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  static bool classof(const DependentSizedArrayType *) { return true; }
19401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1941898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  friend class StmtIteratorBase;
19421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
19431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1944898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  void Profile(llvm::FoldingSetNodeID &ID) {
19451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    Profile(ID, Context, getElementType(),
19460953e767ff7817f97b3ab20896b229891eeff45bJohn McCall            getSizeModifier(), getIndexTypeCVRQualifiers(), getSizeExpr());
1947898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  }
19481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
19491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static void Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context,
19501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                      QualType ET, ArraySizeModifier SizeMod,
195104d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor                      unsigned TypeQuals, Expr *E);
1952898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor};
1953898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
1954f6ddb737cb882ffbf0b75a9abd50b930cc2b9068Douglas Gregor/// DependentSizedExtVectorType - This type represent an extended vector type
19559cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// where either the type or size is dependent. For example:
19569cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// @code
19579cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// template<typename T, int Size>
19589cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// class vector {
19599cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor///   typedef T __attribute__((ext_vector_type(Size))) type;
19609cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// }
19619cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// @endcode
19622ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregorclass DependentSizedExtVectorType : public Type, public llvm::FoldingSetNode {
19632ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor  ASTContext &Context;
19649cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor  Expr *SizeExpr;
19659cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor  /// ElementType - The element type of the array.
19669cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor  QualType ElementType;
19679cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor  SourceLocation loc;
19681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
19691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  DependentSizedExtVectorType(ASTContext &Context, QualType ElementType,
1970d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor                              QualType can, Expr *SizeExpr, SourceLocation loc);
1971d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor
19729cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor  friend class ASTContext;
19739cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor
19749cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregorpublic:
19752ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor  Expr *getSizeExpr() const { return SizeExpr; }
19769cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor  QualType getElementType() const { return ElementType; }
19779cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor  SourceLocation getAttributeLoc() const { return loc; }
19789cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor
1979bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1980bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1981bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
19821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
19831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == DependentSizedExtVector;
19849cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor  }
19851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const DependentSizedExtVectorType *) { return true; }
19862ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor
19872ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor  void Profile(llvm::FoldingSetNodeID &ID) {
19882ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor    Profile(ID, Context, getElementType(), getSizeExpr());
19892ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor  }
19901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
19912ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor  static void Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context,
19922ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor                      QualType ElementType, Expr *SizeExpr);
19939cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor};
19941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
19959cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor
199673322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// VectorType - GCC generic vector type. This type is created using
19971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// __attribute__((vector_size(n)), where "n" specifies the vector size in
199882287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson/// bytes; or from an Altivec __vector or vector declaration.
199982287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson/// Since the constructor takes the number of vector elements, the
200073322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// client is responsible for converting the size into the number of elements.
20015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass VectorType : public Type, public llvm::FoldingSetNode {
2002788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattnerpublic:
2003e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson  enum VectorKind {
2004e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson    GenericVector,  // not a target-specific vector type
2005e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson    AltiVecVector,  // is AltiVec vector
2006e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson    AltiVecPixel,   // is AltiVec 'vector Pixel'
2007e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson    AltiVecBool,    // is AltiVec 'vector bool ...'
2008491328c90c00ecad6ad27fa0ab3cdf9195a4a820Bob Wilson    NeonVector,     // is ARM Neon vector
2009491328c90c00ecad6ad27fa0ab3cdf9195a4a820Bob Wilson    NeonPolyVector  // is ARM Neon polynomial vector
2010788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner  };
201173322924127c873c13101b705dd823f5539ffa5fSteve Naroffprotected:
20125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// ElementType - The element type of the vector.
20135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType ElementType;
20141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
201582287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson  VectorType(QualType vecType, unsigned nElements, QualType canonType,
2016d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor             VectorKind vecKind);
201735495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor
20181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  VectorType(TypeClass tc, QualType vecType, unsigned nElements,
2019d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor             QualType canonType, VectorKind vecKind);
2020d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor
20215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
202260e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
20235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
20241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
20255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType getElementType() const { return ElementType; }
2026b870b88df784c2940efce448ebfaf54dece14666John McCall  unsigned getNumElements() const { return VectorTypeBits.NumElements; }
20275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2028bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2029bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2030bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
2031e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson  VectorKind getVectorKind() const {
2032e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson    return VectorKind(VectorTypeBits.VecKind);
203371c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  }
2034788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner
20355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void Profile(llvm::FoldingSetNodeID &ID) {
203671c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    Profile(ID, getElementType(), getNumElements(),
2037e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson            getTypeClass(), getVectorKind());
20385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
20391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static void Profile(llvm::FoldingSetNodeID &ID, QualType ElementType,
204082287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson                      unsigned NumElements, TypeClass TypeClass,
2041e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson                      VectorKind VecKind) {
20425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ID.AddPointer(ElementType.getAsOpaquePtr());
20435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ID.AddInteger(NumElements);
204473322924127c873c13101b705dd823f5539ffa5fSteve Naroff    ID.AddInteger(TypeClass);
2045e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson    ID.AddInteger(VecKind);
204673322924127c873c13101b705dd823f5539ffa5fSteve Naroff  }
20470b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor
20481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
20491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == Vector || T->getTypeClass() == ExtVector;
20505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
20515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const VectorType *) { return true; }
20525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
20535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2054213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman/// ExtVectorType - Extended vector type. This type is created using
2055213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman/// __attribute__((ext_vector_type(n)), where "n" is the number of elements.
2056213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman/// Unlike vector_size, ext_vector_type is only allowed on typedef's. This
2057fcac0fff877a461bc5d5a57e6c6727a4c819d95aSteve Naroff/// class enables syntactic extensions, like Vector Components for accessing
2058fcac0fff877a461bc5d5a57e6c6727a4c819d95aSteve Naroff/// points, colors, and textures (modeled after OpenGL Shading Language).
2059213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begemanclass ExtVectorType : public VectorType {
2060213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman  ExtVectorType(QualType vecType, unsigned nElements, QualType canonType) :
2061e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson    VectorType(ExtVector, vecType, nElements, canonType, GenericVector) {}
206273322924127c873c13101b705dd823f5539ffa5fSteve Naroff  friend class ASTContext;  // ASTContext creates these.
206373322924127c873c13101b705dd823f5539ffa5fSteve Naroffpublic:
206488dca0464804b8b26ae605f89784c927e8493dddChris Lattner  static int getPointAccessorIdx(char c) {
206588dca0464804b8b26ae605f89784c927e8493dddChris Lattner    switch (c) {
206688dca0464804b8b26ae605f89784c927e8493dddChris Lattner    default: return -1;
206788dca0464804b8b26ae605f89784c927e8493dddChris Lattner    case 'x': return 0;
206888dca0464804b8b26ae605f89784c927e8493dddChris Lattner    case 'y': return 1;
206988dca0464804b8b26ae605f89784c927e8493dddChris Lattner    case 'z': return 2;
207088dca0464804b8b26ae605f89784c927e8493dddChris Lattner    case 'w': return 3;
207188dca0464804b8b26ae605f89784c927e8493dddChris Lattner    }
2072e1b31fedbc006e6e4071bbb4f74c6116b56cfa9fSteve Naroff  }
2073353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman  static int getNumericAccessorIdx(char c) {
207488dca0464804b8b26ae605f89784c927e8493dddChris Lattner    switch (c) {
2075353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      default: return -1;
2076353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '0': return 0;
2077353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '1': return 1;
2078353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '2': return 2;
2079353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '3': return 3;
2080353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '4': return 4;
2081353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '5': return 5;
2082353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '6': return 6;
2083353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '7': return 7;
2084353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '8': return 8;
2085353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '9': return 9;
2086131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman      case 'A':
2087353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case 'a': return 10;
2088131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman      case 'B':
2089353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case 'b': return 11;
2090131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman      case 'C':
2091353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case 'c': return 12;
2092131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman      case 'D':
2093353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case 'd': return 13;
2094131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman      case 'E':
2095353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case 'e': return 14;
2096131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman      case 'F':
2097353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case 'f': return 15;
209888dca0464804b8b26ae605f89784c927e8493dddChris Lattner    }
2099e1b31fedbc006e6e4071bbb4f74c6116b56cfa9fSteve Naroff  }
21001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2101b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner  static int getAccessorIdx(char c) {
2102b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner    if (int idx = getPointAccessorIdx(c)+1) return idx-1;
2103353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman    return getNumericAccessorIdx(c);
2104b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner  }
21051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
210688dca0464804b8b26ae605f89784c927e8493dddChris Lattner  bool isAccessorWithinNumElements(char c) const {
2107b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner    if (int idx = getAccessorIdx(c)+1)
210871c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall      return unsigned(idx-1) < getNumElements();
210988dca0464804b8b26ae605f89784c927e8493dddChris Lattner    return false;
2110e1b31fedbc006e6e4071bbb4f74c6116b56cfa9fSteve Naroff  }
2111bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2112bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2113bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
21141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
21151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == ExtVector;
211673322924127c873c13101b705dd823f5539ffa5fSteve Naroff  }
2117213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman  static bool classof(const ExtVectorType *) { return true; }
211873322924127c873c13101b705dd823f5539ffa5fSteve Naroff};
211973322924127c873c13101b705dd823f5539ffa5fSteve Naroff
21205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// FunctionType - C99 6.7.5.3 - Function Declarators.  This is the common base
212172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// class of FunctionNoProtoType and FunctionProtoType.
21225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
21235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass FunctionType : public Type {
21245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // The type returned by the function.
21255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType ResultType;
2126264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola
2127264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola public:
2128075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  // This class is used for passing around the information needed to
2129264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola  // construct a call. It is not actually used for storage, just for
2130264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola  // factoring together common arguments.
2131075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  // If you add a field (say Foo), other than the obvious places (both,
2132075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  // constructors, compile failures), what you need to update is
2133075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  // * Operator==
2134425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola  // * getFoo
2135425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola  // * withFoo
2136425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola  // * functionType. Add Foo, getFoo.
2137425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola  // * ASTContext::getFooType
2138425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola  // * ASTContext::mergeFunctionTypes
2139425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola  // * FunctionNoProtoType::Profile
2140425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola  // * FunctionProtoType::Profile
2141425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola  // * TypePrinter::PrintFunctionProto
21423c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  // * AST read and write
2143425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola  // * Codegen
2144425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola
2145264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola  class ExtInfo {
2146b870b88df784c2940efce448ebfaf54dece14666John McCall    enum { CallConvMask = 0x7 };
2147b870b88df784c2940efce448ebfaf54dece14666John McCall    enum { NoReturnMask = 0x8 };
2148b870b88df784c2940efce448ebfaf54dece14666John McCall    enum { RegParmMask = ~(CallConvMask | NoReturnMask),
2149b870b88df784c2940efce448ebfaf54dece14666John McCall           RegParmOffset = 4 };
2150b870b88df784c2940efce448ebfaf54dece14666John McCall
215171c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    unsigned Bits;
215271c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall
215371c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    ExtInfo(unsigned Bits) : Bits(Bits) {}
215471c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall
215571c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    friend class FunctionType;
215671c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall
2157264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola   public:
2158264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    // Constructor with no defaults. Use this when you know that you
21593c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl    // have all the elements (when reading an AST file for example).
216071c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    ExtInfo(bool noReturn, unsigned regParm, CallingConv cc) {
2161b870b88df784c2940efce448ebfaf54dece14666John McCall      Bits = ((unsigned) cc) |
2162b870b88df784c2940efce448ebfaf54dece14666John McCall             (noReturn ? NoReturnMask : 0) |
2163b870b88df784c2940efce448ebfaf54dece14666John McCall             (regParm << RegParmOffset);
216471c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    }
2165264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola
2166264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    // Constructor with all defaults. Use when for example creating a
2167264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    // function know to use defaults.
216871c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    ExtInfo() : Bits(0) {}
2169264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola
2170b870b88df784c2940efce448ebfaf54dece14666John McCall    bool getNoReturn() const { return Bits & NoReturnMask; }
2171b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned getRegParm() const { return Bits >> RegParmOffset; }
2172b870b88df784c2940efce448ebfaf54dece14666John McCall    CallingConv getCC() const { return CallingConv(Bits & CallConvMask); }
2173264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola
217471c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    bool operator==(ExtInfo Other) const {
217571c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall      return Bits == Other.Bits;
2176264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    }
217771c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    bool operator!=(ExtInfo Other) const {
217871c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall      return Bits != Other.Bits;
2179264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    }
2180264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola
2181264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    // Note that we don't have setters. That is by design, use
2182264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    // the following with methods instead of mutating these objects.
2183264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola
2184264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    ExtInfo withNoReturn(bool noReturn) const {
218571c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall      if (noReturn)
218671c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall        return ExtInfo(Bits | NoReturnMask);
218771c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall      else
218871c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall        return ExtInfo(Bits & ~NoReturnMask);
2189425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola    }
2190425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola
2191425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola    ExtInfo withRegParm(unsigned RegParm) const {
2192b870b88df784c2940efce448ebfaf54dece14666John McCall      return ExtInfo((Bits & ~RegParmMask) | (RegParm << RegParmOffset));
2193264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    }
2194264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola
2195264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    ExtInfo withCallingConv(CallingConv cc) const {
2196b870b88df784c2940efce448ebfaf54dece14666John McCall      return ExtInfo((Bits & ~CallConvMask) | (unsigned) cc);
2197264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    }
2198264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola
219971c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    void Profile(llvm::FoldingSetNodeID &ID) {
220071c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall      ID.AddInteger(Bits);
220171c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    }
2202264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola  };
2203264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola
22045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprotected:
2205971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis  FunctionType(TypeClass tc, QualType res, bool SubclassInfo,
22062455636163fdd18581d7fdae816433f886d88213Mike Stump               unsigned typeQuals, QualType Canonical, bool Dependent,
2207d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor               bool VariablyModified, bool ContainsUnexpandedParameterPack,
2208d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor               ExtInfo Info)
2209d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    : Type(tc, Canonical, Dependent, VariablyModified,
2210d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor           ContainsUnexpandedParameterPack),
2211d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor      ResultType(res) {
2212b870b88df784c2940efce448ebfaf54dece14666John McCall    FunctionTypeBits.ExtInfo = Info.Bits;
2213b870b88df784c2940efce448ebfaf54dece14666John McCall    FunctionTypeBits.SubclassInfo = SubclassInfo;
2214b870b88df784c2940efce448ebfaf54dece14666John McCall    FunctionTypeBits.TypeQuals = typeQuals;
221571c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  }
2216b870b88df784c2940efce448ebfaf54dece14666John McCall  bool getSubClassData() const { return FunctionTypeBits.SubclassInfo; }
2217b870b88df784c2940efce448ebfaf54dece14666John McCall  unsigned getTypeQuals() const { return FunctionTypeBits.TypeQuals; }
22185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
22191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
22205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType getResultType() const { return ResultType; }
22215291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor
2222b870b88df784c2940efce448ebfaf54dece14666John McCall  unsigned getRegParmType() const { return getExtInfo().getRegParm(); }
2223b870b88df784c2940efce448ebfaf54dece14666John McCall  bool getNoReturnAttr() const { return getExtInfo().getNoReturn(); }
2224b870b88df784c2940efce448ebfaf54dece14666John McCall  CallingConv getCallConv() const { return getExtInfo().getCC(); }
2225b870b88df784c2940efce448ebfaf54dece14666John McCall  ExtInfo getExtInfo() const { return ExtInfo(FunctionTypeBits.ExtInfo); }
22265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
22275291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor  /// \brief Determine the type of an expression that calls a function of
22285291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor  /// this type.
22295291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor  QualType getCallResultType(ASTContext &Context) const {
22306398235d7890a81b785ea5af3b6e66d86bf184ccDouglas Gregor    return getResultType().getNonLValueExprType(Context);
22315291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor  }
22325291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor
223304a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall  static llvm::StringRef getNameForCallConv(CallingConv CC);
223404a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall
22355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T) {
22365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T->getTypeClass() == FunctionNoProto ||
22375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer           T->getTypeClass() == FunctionProto;
22385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
22395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const FunctionType *) { return true; }
22405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
22415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
224272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// FunctionNoProtoType - Represents a K&R-style 'int foo()' function, which has
22435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// no information available about its arguments.
224472564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregorclass FunctionNoProtoType : public FunctionType, public llvm::FoldingSetNode {
224571c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  FunctionNoProtoType(QualType Result, QualType Canonical, ExtInfo Info)
22461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    : FunctionType(FunctionNoProto, Result, false, 0, Canonical,
224735495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor                   /*Dependent=*/false, Result->isVariablyModifiedType(),
2248d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor                   /*ContainsUnexpandedParameterPack=*/false, Info) {}
2249d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor
22505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
225160e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
22525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
22535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // No additional state past what FunctionType provides.
22541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2255bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2256bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2257bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
22585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void Profile(llvm::FoldingSetNodeID &ID) {
2259264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    Profile(ID, getResultType(), getExtInfo());
22605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
22612455636163fdd18581d7fdae816433f886d88213Mike Stump  static void Profile(llvm::FoldingSetNodeID &ID, QualType ResultType,
226271c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall                      ExtInfo Info) {
226371c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    Info.Profile(ID);
22645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ID.AddPointer(ResultType.getAsOpaquePtr());
22655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
22661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
22675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T) {
22685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T->getTypeClass() == FunctionNoProto;
22695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
227072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  static bool classof(const FunctionNoProtoType *) { return true; }
22715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
22725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
227372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// FunctionProtoType - Represents a prototype with argument type info, e.g.
22745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 'int foo(int)' or 'int foo(void)'.  'void' is represented as having no
2275465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl/// arguments, not as having a single void argument. Such a type can have an
2276465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl/// exception specification, but this specification is not part of the canonical
2277465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl/// type.
227872564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregorclass FunctionProtoType : public FunctionType, public llvm::FoldingSetNode {
2279d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// \brief Determine whether there are any argument types that
2280d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// contain an unexpanded parameter pack.
2281d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  static bool containsAnyUnexpandedParameterPack(const QualType *ArgArray,
2282d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor                                                 unsigned numArgs) {
2283d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    for (unsigned Idx = 0; Idx < numArgs; ++Idx)
2284d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor      if (ArgArray[Idx]->containsUnexpandedParameterPack())
2285d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor        return true;
2286d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor
2287d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    return false;
2288d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  }
2289d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor
229072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  FunctionProtoType(QualType Result, const QualType *ArgArray, unsigned numArgs,
2291465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl                    bool isVariadic, unsigned typeQuals, bool hasExs,
2292465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl                    bool hasAnyExs, const QualType *ExArray,
2293264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola                    unsigned numExs, QualType Canonical,
229435495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor                    const ExtInfo &Info);
2295465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
22965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// NumArgs - The number of arguments this function has, not counting '...'.
2297465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  unsigned NumArgs : 20;
2298465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
2299465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  /// NumExceptions - The number of types in the exception spec, if any.
2300465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  unsigned NumExceptions : 10;
2301465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
2302465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  /// HasExceptionSpec - Whether this function has an exception spec at all.
230334e80e94a21eb1ac2a9405d918e711e8b12256a9John McCall  unsigned HasExceptionSpec : 1;
2304465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
2305465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  /// AnyExceptionSpec - Whether this function has a throw(...) spec.
230634e80e94a21eb1ac2a9405d918e711e8b12256a9John McCall  unsigned AnyExceptionSpec : 1;
2307465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
2308942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner  /// ArgInfo - There is an variable size array after the class in memory that
2309942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner  /// holds the argument types.
2310465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
2311465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  /// Exceptions - There is another variable size array after ArgInfo that
2312465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  /// holds the exception types.
2313465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
23145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
23154b05b1dee6cc65ae61d93dab7edff72710f24589Ted Kremenek
23165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
23175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned getNumArgs() const { return NumArgs; }
23185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType getArgType(unsigned i) const {
23195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    assert(i < NumArgs && "Invalid argument number!");
2320942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner    return arg_type_begin()[i];
23215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
2322465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
2323465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  bool hasExceptionSpec() const { return HasExceptionSpec; }
2324465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  bool hasAnyExceptionSpec() const { return AnyExceptionSpec; }
2325465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  unsigned getNumExceptions() const { return NumExceptions; }
2326465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  QualType getExceptionType(unsigned i) const {
2327465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl    assert(i < NumExceptions && "Invalid exception number!");
2328465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl    return exception_begin()[i];
2329465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  }
23301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  bool hasEmptyExceptionSpec() const {
23311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return hasExceptionSpec() && !hasAnyExceptionSpec() &&
2332a12823f6c0ec9e0e644a9d0ee153e973f49c63fcAnders Carlsson      getNumExceptions() == 0;
2333d3fd6bad1249d3f34d71b73e2333fab0db51cce4Anders Carlsson  }
2334465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
23355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isVariadic() const { return getSubClassData(); }
2336971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis  unsigned getTypeQuals() const { return FunctionType::getTypeQuals(); }
23371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
23385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  typedef const QualType *arg_type_iterator;
2339942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner  arg_type_iterator arg_type_begin() const {
2340942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner    return reinterpret_cast<const QualType *>(this+1);
2341942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner  }
2342942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner  arg_type_iterator arg_type_end() const { return arg_type_begin()+NumArgs; }
2343465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
2344465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  typedef const QualType *exception_iterator;
2345465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  exception_iterator exception_begin() const {
2346465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl    // exceptions begin where arguments end
2347465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl    return arg_type_end();
2348465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  }
2349465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  exception_iterator exception_end() const {
2350465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl    return exception_begin() + NumExceptions;
2351465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  }
2352465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
2353bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2354bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2355bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
23565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T) {
23575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T->getTypeClass() == FunctionProto;
23585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
235972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  static bool classof(const FunctionProtoType *) { return true; }
2360465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
23615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void Profile(llvm::FoldingSetNodeID &ID);
23625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static void Profile(llvm::FoldingSetNodeID &ID, QualType Result,
2363942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner                      arg_type_iterator ArgTys, unsigned NumArgs,
2364465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl                      bool isVariadic, unsigned TypeQuals,
2365465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl                      bool hasExceptionSpec, bool anyExceptionSpec,
23662455636163fdd18581d7fdae816433f886d88213Mike Stump                      unsigned NumExceptions, exception_iterator Exs,
236771c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall                      ExtInfo ExtInfo);
23685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
23695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
23705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2371ed97649e9574b9d854fa4d6109c9333ae0993554John McCall/// \brief Represents the dependent type named by a dependently-scoped
2372ed97649e9574b9d854fa4d6109c9333ae0993554John McCall/// typename using declaration, e.g.
2373ed97649e9574b9d854fa4d6109c9333ae0993554John McCall///   using typename Base<T>::foo;
2374ed97649e9574b9d854fa4d6109c9333ae0993554John McCall/// Template instantiation turns these into the underlying type.
2375ed97649e9574b9d854fa4d6109c9333ae0993554John McCallclass UnresolvedUsingType : public Type {
2376ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  UnresolvedUsingTypenameDecl *Decl;
2377ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
237819c8576b7328f4dc2d07682f5da552875c1912efJohn McCall  UnresolvedUsingType(const UnresolvedUsingTypenameDecl *D)
2379d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    : Type(UnresolvedUsing, QualType(), true, false,
2380d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor           /*ContainsUnexpandedParameterPack=*/false),
238119c8576b7328f4dc2d07682f5da552875c1912efJohn McCall      Decl(const_cast<UnresolvedUsingTypenameDecl*>(D)) {}
2382ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  friend class ASTContext; // ASTContext creates these.
2383ed97649e9574b9d854fa4d6109c9333ae0993554John McCallpublic:
2384ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
2385ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  UnresolvedUsingTypenameDecl *getDecl() const { return Decl; }
2386ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
2387ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  bool isSugared() const { return false; }
2388ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  QualType desugar() const { return QualType(this, 0); }
2389ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
2390ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  static bool classof(const Type *T) {
2391ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    return T->getTypeClass() == UnresolvedUsing;
2392ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  }
2393ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  static bool classof(const UnresolvedUsingType *) { return true; }
2394ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
2395ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  void Profile(llvm::FoldingSetNodeID &ID) {
2396ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    return Profile(ID, Decl);
2397ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  }
2398ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  static void Profile(llvm::FoldingSetNodeID &ID,
2399ed97649e9574b9d854fa4d6109c9333ae0993554John McCall                      UnresolvedUsingTypenameDecl *D) {
2400ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    ID.AddPointer(D);
2401ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  }
2402ed97649e9574b9d854fa4d6109c9333ae0993554John McCall};
2403ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
2404ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
24055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass TypedefType : public Type {
24065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  TypedefDecl *Decl;
2407c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanianprotected:
240819c8576b7328f4dc2d07682f5da552875c1912efJohn McCall  TypedefType(TypeClass tc, const TypedefDecl *D, QualType can)
2409d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    : Type(tc, can, can->isDependentType(), can->isVariablyModifiedType(),
2410d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor           /*ContainsUnexpandedParameterPack=*/false),
241119c8576b7328f4dc2d07682f5da552875c1912efJohn McCall      Decl(const_cast<TypedefDecl*>(D)) {
24125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    assert(!isa<TypedefType>(can) && "Invalid canonical type");
24135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
24145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
24155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
24161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
24175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  TypedefDecl *getDecl() const { return Decl; }
24181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2419bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return true; }
2420bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const;
2421bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
242272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  static bool classof(const Type *T) { return T->getTypeClass() == Typedef; }
24235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const TypedefType *) { return true; }
24245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
24255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
242672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// TypeOfExprType (GCC extension).
242772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregorclass TypeOfExprType : public Type {
2428d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  Expr *TOExpr;
24291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2430b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregorprotected:
2431dd0257c77719a13d4acd513df40b04300cbfc871Douglas Gregor  TypeOfExprType(Expr *E, QualType can = QualType());
2432d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  friend class ASTContext;  // ASTContext creates these.
2433d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroffpublic:
2434d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  Expr *getUnderlyingExpr() const { return TOExpr; }
24351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2436bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// \brief Remove a single level of sugar.
2437bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const;
2438bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
2439bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// \brief Returns whether this type directly provides sugar.
2440bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return true; }
2441bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
244272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  static bool classof(const Type *T) { return T->getTypeClass() == TypeOfExpr; }
244372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  static bool classof(const TypeOfExprType *) { return true; }
2444d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff};
2445d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff
2446c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// \brief Internal representation of canonical, dependent
24471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// typeof(expr) types.
2448c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor///
2449c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// This class is used internally by the ASTContext to manage
2450c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// canonical, dependent types, only. Clients will only see instances
2451c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// of this class via TypeOfExprType nodes.
24521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpclass DependentTypeOfExprType
2453b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor  : public TypeOfExprType, public llvm::FoldingSetNode {
2454b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor  ASTContext &Context;
24551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2456b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregorpublic:
24571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  DependentTypeOfExprType(ASTContext &Context, Expr *E)
2458b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor    : TypeOfExprType(E), Context(Context) { }
24591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2460bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2461bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2462bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
2463b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor  void Profile(llvm::FoldingSetNodeID &ID) {
2464b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor    Profile(ID, Context, getUnderlyingExpr());
2465b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor  }
24661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2467b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor  static void Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context,
2468b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor                      Expr *E);
2469b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor};
24701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2471d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff/// TypeOfType (GCC extension).
2472d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroffclass TypeOfType : public Type {
2473d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  QualType TOType;
24741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  TypeOfType(QualType T, QualType can)
2475d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    : Type(TypeOf, can, T->isDependentType(), T->isVariablyModifiedType(),
2476d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor           T->containsUnexpandedParameterPack()),
247735495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor      TOType(T) {
2478d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff    assert(!isa<TypedefType>(can) && "Invalid canonical type");
2479d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  }
2480d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  friend class ASTContext;  // ASTContext creates these.
2481d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroffpublic:
2482d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  QualType getUnderlyingType() const { return TOType; }
24831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2484bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// \brief Remove a single level of sugar.
2485bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return getUnderlyingType(); }
2486bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
2487bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// \brief Returns whether this type directly provides sugar.
2488bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return true; }
2489bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
249072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  static bool classof(const Type *T) { return T->getTypeClass() == TypeOf; }
2491d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  static bool classof(const TypeOfType *) { return true; }
2492d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff};
24935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2494395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson/// DecltypeType (C++0x)
2495395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlssonclass DecltypeType : public Type {
2496395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson  Expr *E;
24971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2498563a03b1338d31c2462def43253a722bc885d384Anders Carlsson  // FIXME: We could get rid of UnderlyingType if we wanted to: We would have to
2499563a03b1338d31c2462def43253a722bc885d384Anders Carlsson  // Move getDesugaredType to ASTContext so that it can call getDecltypeForExpr
2500563a03b1338d31c2462def43253a722bc885d384Anders Carlsson  // from it.
2501563a03b1338d31c2462def43253a722bc885d384Anders Carlsson  QualType UnderlyingType;
25021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
25039d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregorprotected:
2504563a03b1338d31c2462def43253a722bc885d384Anders Carlsson  DecltypeType(Expr *E, QualType underlyingType, QualType can = QualType());
2505395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson  friend class ASTContext;  // ASTContext creates these.
2506395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlssonpublic:
2507395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson  Expr *getUnderlyingExpr() const { return E; }
2508563a03b1338d31c2462def43253a722bc885d384Anders Carlsson  QualType getUnderlyingType() const { return UnderlyingType; }
2509563a03b1338d31c2462def43253a722bc885d384Anders Carlsson
2510bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// \brief Remove a single level of sugar.
2511bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return getUnderlyingType(); }
2512bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
2513bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// \brief Returns whether this type directly provides sugar.
2514bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return !isDependentType(); }
2515bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
2516395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson  static bool classof(const Type *T) { return T->getTypeClass() == Decltype; }
2517395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson  static bool classof(const DecltypeType *) { return true; }
2518395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson};
25191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2520c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// \brief Internal representation of canonical, dependent
2521c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// decltype(expr) types.
2522c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor///
2523c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// This class is used internally by the ASTContext to manage
2524c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// canonical, dependent types, only. Clients will only see instances
2525c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// of this class via DecltypeType nodes.
25269d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregorclass DependentDecltypeType : public DecltypeType, public llvm::FoldingSetNode {
25279d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor  ASTContext &Context;
25281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
25299d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregorpublic:
25309d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor  DependentDecltypeType(ASTContext &Context, Expr *E);
25311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2532bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2533bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2534bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
25359d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor  void Profile(llvm::FoldingSetNodeID &ID) {
25369d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor    Profile(ID, Context, getUnderlyingExpr());
25379d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor  }
25381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
25399d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor  static void Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context,
25401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                      Expr *E);
25419d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor};
25421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
25435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass TagType : public Type {
2544ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl  /// Stores the TagDecl associated with this type. The decl may point to any
2545ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl  /// TagDecl that declares the entity.
2546ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl  TagDecl * decl;
25472ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor
25482ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregorprotected:
254919c8576b7328f4dc2d07682f5da552875c1912efJohn McCall  TagType(TypeClass TC, const TagDecl *D, QualType can);
25502ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor
25511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic:
2552ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl  TagDecl *getDecl() const;
25531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
25540b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor  /// @brief Determines whether this type is in the process of being
25551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// defined.
2556ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl  bool isBeingDefined() const;
25570b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor
25581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
255972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor    return T->getTypeClass() >= TagFirst && T->getTypeClass() <= TagLast;
256072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  }
25615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const TagType *) { return true; }
256272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  static bool classof(const RecordType *) { return true; }
256372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  static bool classof(const EnumType *) { return true; }
25645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
25655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
25665edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner/// RecordType - This is a helper class that allows the use of isa/cast/dyncast
25675edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner/// to detect TagType objects of structs/unions/classes.
25685edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattnerclass RecordType : public TagType {
256949aa7ff1245abd03e6e998e01302df31e4c6f8f6Argyrios Kyrtzidisprotected:
257019c8576b7328f4dc2d07682f5da552875c1912efJohn McCall  explicit RecordType(const RecordDecl *D)
257119c8576b7328f4dc2d07682f5da552875c1912efJohn McCall    : TagType(Record, reinterpret_cast<const TagDecl*>(D), QualType()) { }
257272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  explicit RecordType(TypeClass TC, RecordDecl *D)
257319c8576b7328f4dc2d07682f5da552875c1912efJohn McCall    : TagType(TC, reinterpret_cast<const TagDecl*>(D), QualType()) { }
25742ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor  friend class ASTContext;   // ASTContext creates these.
25755edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattnerpublic:
25761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
25775edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner  RecordDecl *getDecl() const {
25785edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner    return reinterpret_cast<RecordDecl*>(TagType::getDecl());
25795edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner  }
25801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
25811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  // FIXME: This predicate is a helper to QualType/Type. It needs to
25825edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner  // recursively check all fields for const-ness. If any field is declared
25831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  // const, it needs to return false.
25845edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner  bool hasConstFields() const { return false; }
25855edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner
25865edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner  // FIXME: RecordType needs to check when it is created that all fields are in
25875edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner  // the same address space, and return that.
25885edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner  unsigned getAddressSpace() const { return 0; }
25891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2590bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2591bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2592bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
25932daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner  static bool classof(const TagType *T);
25942daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner  static bool classof(const Type *T) {
25952daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner    return isa<TagType>(T) && classof(cast<TagType>(T));
25962daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner  }
25975edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner  static bool classof(const RecordType *) { return true; }
25985edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner};
25995edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner
26005edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner/// EnumType - This is a helper class that allows the use of isa/cast/dyncast
26015edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner/// to detect TagType objects of enums.
26025edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattnerclass EnumType : public TagType {
260319c8576b7328f4dc2d07682f5da552875c1912efJohn McCall  explicit EnumType(const EnumDecl *D)
260419c8576b7328f4dc2d07682f5da552875c1912efJohn McCall    : TagType(Enum, reinterpret_cast<const TagDecl*>(D), QualType()) { }
26052ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor  friend class ASTContext;   // ASTContext creates these.
26065edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattnerpublic:
26071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
26085edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner  EnumDecl *getDecl() const {
26095edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner    return reinterpret_cast<EnumDecl*>(TagType::getDecl());
26105edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner  }
26111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2612bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2613bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2614bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
26152daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner  static bool classof(const TagType *T);
26162daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner  static bool classof(const Type *T) {
26172daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner    return isa<TagType>(T) && classof(cast<TagType>(T));
26182daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner  }
26195edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner  static bool classof(const EnumType *) { return true; }
26205edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner};
26215edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner
2622fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregorclass TemplateTypeParmType : public Type, public llvm::FoldingSetNode {
2623efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor  unsigned Depth : 15;
2624efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor  unsigned ParameterPack : 1;
262577be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall  unsigned Index : 16;
2626efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor  IdentifierInfo *Name;
262772c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor
2628efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor  TemplateTypeParmType(unsigned D, unsigned I, bool PP, IdentifierInfo *N,
2629efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor                       QualType Canon)
263035495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    : Type(TemplateTypeParm, Canon, /*Dependent=*/true,
2631d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor           /*VariablyModified=*/false, PP),
263277be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall      Depth(D), ParameterPack(PP), Index(I), Name(N) { }
263372c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor
26341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  TemplateTypeParmType(unsigned D, unsigned I, bool PP)
263535495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    : Type(TemplateTypeParm, QualType(this, 0), /*Dependent=*/true,
2636d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor           /*VariablyModified=*/false, PP),
263777be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall      Depth(D), ParameterPack(PP), Index(I), Name(0) { }
263872c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor
2639fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor  friend class ASTContext;  // ASTContext creates these
264072c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor
2641fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregorpublic:
2642efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor  unsigned getDepth() const { return Depth; }
2643efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor  unsigned getIndex() const { return Index; }
2644efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor  bool isParameterPack() const { return ParameterPack; }
2645efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor  IdentifierInfo *getName() const { return Name; }
26461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2647bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2648bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2649bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
2650fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor  void Profile(llvm::FoldingSetNodeID &ID) {
2651efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor    Profile(ID, Depth, Index, ParameterPack, Name);
2652fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor  }
2653fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor
26541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static void Profile(llvm::FoldingSetNodeID &ID, unsigned Depth,
26551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                      unsigned Index, bool ParameterPack,
2656efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor                      IdentifierInfo *Name) {
2657fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor    ID.AddInteger(Depth);
2658fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor    ID.AddInteger(Index);
265976e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson    ID.AddBoolean(ParameterPack);
2660efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor    ID.AddPointer(Name);
2661fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor  }
2662fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor
26631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
26641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == TemplateTypeParm;
266572c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor  }
266672c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor  static bool classof(const TemplateTypeParmType *T) { return true; }
266772c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor};
2668fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor
266949a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// \brief Represents the result of substituting a type for a template
267049a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// type parameter.
267149a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall///
267249a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// Within an instantiated template, all template type parameters have
267349a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// been replaced with these.  They are used solely to record that a
267449a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// type was originally written as a template type parameter;
267549a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// therefore they are never canonical.
267649a832bd499d6f61c23655f1fac99f0dd229756eJohn McCallclass SubstTemplateTypeParmType : public Type, public llvm::FoldingSetNode {
267749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  // The original type parameter.
267849a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  const TemplateTypeParmType *Replaced;
267949a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall
268049a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  SubstTemplateTypeParmType(const TemplateTypeParmType *Param, QualType Canon)
268135495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    : Type(SubstTemplateTypeParm, Canon, Canon->isDependentType(),
2682d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor           Canon->isVariablyModifiedType(),
2683d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor           Canon->containsUnexpandedParameterPack()),
268449a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall      Replaced(Param) { }
268549a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall
268649a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  friend class ASTContext;
268749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall
268849a832bd499d6f61c23655f1fac99f0dd229756eJohn McCallpublic:
2689efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor  IdentifierInfo *getName() const { return Replaced->getName(); }
2690efed5c832de630715dd42211dd3b2aab5dd97a1bDouglas Gregor
269149a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  /// Gets the template parameter that was substituted for.
269249a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  const TemplateTypeParmType *getReplacedParameter() const {
269349a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall    return Replaced;
269449a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  }
269549a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall
269649a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  /// Gets the type that was substituted for the template
269749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  /// parameter.
269849a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  QualType getReplacementType() const {
269949a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall    return getCanonicalTypeInternal();
270049a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  }
270149a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall
270249a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  bool isSugared() const { return true; }
270349a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  QualType desugar() const { return getReplacementType(); }
270449a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall
270549a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  void Profile(llvm::FoldingSetNodeID &ID) {
270649a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall    Profile(ID, getReplacedParameter(), getReplacementType());
270749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  }
270849a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  static void Profile(llvm::FoldingSetNodeID &ID,
270949a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall                      const TemplateTypeParmType *Replaced,
271049a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall                      QualType Replacement) {
271149a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall    ID.AddPointer(Replaced);
271249a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall    ID.AddPointer(Replacement.getAsOpaquePtr());
271349a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  }
271449a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall
271549a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  static bool classof(const Type *T) {
271649a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall    return T->getTypeClass() == SubstTemplateTypeParm;
271749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  }
271849a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  static bool classof(const SubstTemplateTypeParmType *T) { return true; }
271949a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall};
272049a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall
27217532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// \brief Represents the type of a template specialization as written
27227532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// in the source code.
272355f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor///
27247532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// Template specialization types represent the syntactic form of a
27257532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// template-id that refers to a type, e.g., @c vector<int>. Some
27267532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// template specialization types are syntactic sugar, whose canonical
27277532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// type will point to some other type node that represents the
27287532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// instantiation or class template specialization. For example, a
272955f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor/// class template specialization type of @c vector<int> will refer to
27301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// a tag type for the instantiation
273155f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor/// @c std::vector<int, std::allocator<int>>.
27327532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor///
27337532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// Other template specialization types, for which the template name
27347532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// is dependent, may be canonical types. These types are always
27357532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// dependent.
27361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpclass TemplateSpecializationType
273755f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  : public Type, public llvm::FoldingSetNode {
273833500955d731c73717af52088b7fc0e7a85681e7John McCall  /// \brief The name of the template being specialized.
27397532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor  TemplateName Template;
274055f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
274140808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  /// \brief - The number of template arguments named in this class
274240808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  /// template specialization.
274355f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  unsigned NumArgs;
274455f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
2745ef99001908e799c388f1363b1e607dad5f5b57d3John McCall  TemplateSpecializationType(TemplateName T,
27467532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor                             const TemplateArgument *Args,
27477532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor                             unsigned NumArgs, QualType Canon);
274855f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
274955f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  friend class ASTContext;  // ASTContext creates these
275055f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
275155f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregorpublic:
275240808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  /// \brief Determine whether any of the given template arguments are
275340808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  /// dependent.
275440808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  static bool anyDependentTemplateArguments(const TemplateArgument *Args,
27551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                            unsigned NumArgs);
275640808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor
2757833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  static bool anyDependentTemplateArguments(const TemplateArgumentLoc *Args,
2758833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                            unsigned NumArgs);
2759833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
2760d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  static bool anyDependentTemplateArguments(const TemplateArgumentListInfo &);
2761d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall
2762df667e71b1daadeacb230cf94fc717843f1a138aDouglas Gregor  /// \brief Print a template argument list, including the '<' and '>'
2763df667e71b1daadeacb230cf94fc717843f1a138aDouglas Gregor  /// enclosing the template arguments.
2764df667e71b1daadeacb230cf94fc717843f1a138aDouglas Gregor  static std::string PrintTemplateArgumentList(const TemplateArgument *Args,
2765d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor                                               unsigned NumArgs,
2766d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor                                               const PrintingPolicy &Policy);
2767df667e71b1daadeacb230cf94fc717843f1a138aDouglas Gregor
2768833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  static std::string PrintTemplateArgumentList(const TemplateArgumentLoc *Args,
2769833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                               unsigned NumArgs,
2770833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                               const PrintingPolicy &Policy);
2771833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
2772d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  static std::string PrintTemplateArgumentList(const TemplateArgumentListInfo &,
2773d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall                                               const PrintingPolicy &Policy);
2774d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall
277531f17ecbef57b5679c017c375db330546b7b5145John McCall  /// True if this template specialization type matches a current
277631f17ecbef57b5679c017c375db330546b7b5145John McCall  /// instantiation in the context in which it is found.
277731f17ecbef57b5679c017c375db330546b7b5145John McCall  bool isCurrentInstantiation() const {
277871d74bc0d6e522ce7c21a599db8e19d3883b518fJohn McCall    return isa<InjectedClassNameType>(getCanonicalTypeInternal());
277931f17ecbef57b5679c017c375db330546b7b5145John McCall  }
278031f17ecbef57b5679c017c375db330546b7b5145John McCall
278140808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  typedef const TemplateArgument * iterator;
278240808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor
278340808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  iterator begin() const { return getArgs(); }
278433500955d731c73717af52088b7fc0e7a85681e7John McCall  iterator end() const; // defined inline in TemplateBase.h
278540808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor
27867532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor  /// \brief Retrieve the name of the template that we are specializing.
27877532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor  TemplateName getTemplateName() const { return Template; }
278855f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
278940808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  /// \brief Retrieve the template arguments.
27901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  const TemplateArgument *getArgs() const {
279140808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor    return reinterpret_cast<const TemplateArgument *>(this + 1);
279240808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  }
279340808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor
279440808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  /// \brief Retrieve the number of template arguments.
279555f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  unsigned getNumArgs() const { return NumArgs; }
279655f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
279755f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  /// \brief Retrieve a specific template argument as a type.
279855f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  /// \precondition @c isArgType(Arg)
279933500955d731c73717af52088b7fc0e7a85681e7John McCall  const TemplateArgument &getArg(unsigned Idx) const; // in TemplateBase.h
280055f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
280131f17ecbef57b5679c017c375db330546b7b5145John McCall  bool isSugared() const {
280231f17ecbef57b5679c017c375db330546b7b5145John McCall    return !isDependentType() || isCurrentInstantiation();
280331f17ecbef57b5679c017c375db330546b7b5145John McCall  }
2804bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return getCanonicalTypeInternal(); }
2805bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
2806ef99001908e799c388f1363b1e607dad5f5b57d3John McCall  void Profile(llvm::FoldingSetNodeID &ID, ASTContext &Ctx) {
280771d74bc0d6e522ce7c21a599db8e19d3883b518fJohn McCall    Profile(ID, Template, getArgs(), NumArgs, Ctx);
280855f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  }
280955f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
28107532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor  static void Profile(llvm::FoldingSetNodeID &ID, TemplateName T,
281131f17ecbef57b5679c017c375db330546b7b5145John McCall                      const TemplateArgument *Args,
281231f17ecbef57b5679c017c375db330546b7b5145John McCall                      unsigned NumArgs,
2813828e226ab7ed08b3eb766549e9d3306432137460Douglas Gregor                      ASTContext &Context);
281455f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
28151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
28161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == TemplateSpecialization;
281755f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  }
28187532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor  static bool classof(const TemplateSpecializationType *T) { return true; }
281955f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor};
282055f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
282131f17ecbef57b5679c017c375db330546b7b5145John McCall/// \brief The injected class name of a C++ class template or class
282231f17ecbef57b5679c017c375db330546b7b5145John McCall/// template partial specialization.  Used to record that a type was
282331f17ecbef57b5679c017c375db330546b7b5145John McCall/// spelled with a bare identifier rather than as a template-id; the
282431f17ecbef57b5679c017c375db330546b7b5145John McCall/// equivalent for non-templated classes is just RecordType.
28253cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall///
282631f17ecbef57b5679c017c375db330546b7b5145John McCall/// Injected class name types are always dependent.  Template
282731f17ecbef57b5679c017c375db330546b7b5145John McCall/// instantiation turns these into RecordTypes.
28283cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall///
282931f17ecbef57b5679c017c375db330546b7b5145John McCall/// Injected class name types are always canonical.  This works
283031f17ecbef57b5679c017c375db330546b7b5145John McCall/// because it is impossible to compare an injected class name type
283131f17ecbef57b5679c017c375db330546b7b5145John McCall/// with the corresponding non-injected template type, for the same
283231f17ecbef57b5679c017c375db330546b7b5145John McCall/// reason that it is impossible to directly compare template
283331f17ecbef57b5679c017c375db330546b7b5145John McCall/// parameters from different dependent contexts: injected class name
283431f17ecbef57b5679c017c375db330546b7b5145John McCall/// types can only occur within the scope of a particular templated
283531f17ecbef57b5679c017c375db330546b7b5145John McCall/// declaration, and within that scope every template specialization
283631f17ecbef57b5679c017c375db330546b7b5145John McCall/// will canonicalize to the injected class name (when appropriate
283731f17ecbef57b5679c017c375db330546b7b5145John McCall/// according to the rules of the language).
28383cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCallclass InjectedClassNameType : public Type {
28393cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  CXXRecordDecl *Decl;
28403cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall
284131f17ecbef57b5679c017c375db330546b7b5145John McCall  /// The template specialization which this type represents.
284231f17ecbef57b5679c017c375db330546b7b5145John McCall  /// For example, in
284331f17ecbef57b5679c017c375db330546b7b5145John McCall  ///   template <class T> class A { ... };
284431f17ecbef57b5679c017c375db330546b7b5145John McCall  /// this is A<T>, whereas in
284531f17ecbef57b5679c017c375db330546b7b5145John McCall  ///   template <class X, class Y> class A<B<X,Y> > { ... };
284631f17ecbef57b5679c017c375db330546b7b5145John McCall  /// this is A<B<X,Y> >.
284731f17ecbef57b5679c017c375db330546b7b5145John McCall  ///
284831f17ecbef57b5679c017c375db330546b7b5145John McCall  /// It is always unqualified, always a template specialization type,
284931f17ecbef57b5679c017c375db330546b7b5145John McCall  /// and always dependent.
285031f17ecbef57b5679c017c375db330546b7b5145John McCall  QualType InjectedType;
28513cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall
28523cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  friend class ASTContext; // ASTContext creates these.
2853c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl  friend class ASTReader; // FIXME: ASTContext::getInjectedClassNameType is not
2854c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl                          // currently suitable for AST reading, too much
285543921b53b582145f0d1b7c48223bd4d9f0a9d1beArgyrios Kyrtzidis                          // interdependencies.
285631f17ecbef57b5679c017c375db330546b7b5145John McCall  InjectedClassNameType(CXXRecordDecl *D, QualType TST)
285735495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    : Type(InjectedClassName, QualType(), /*Dependent=*/true,
2858d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor           /*VariablyModified=*/false,
2859d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor           /*ContainsUnexpandedParameterPack=*/false),
286031f17ecbef57b5679c017c375db330546b7b5145John McCall      Decl(D), InjectedType(TST) {
28613cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall    assert(isa<TemplateSpecializationType>(TST));
28623cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall    assert(!TST.hasQualifiers());
286331f17ecbef57b5679c017c375db330546b7b5145John McCall    assert(TST->isDependentType());
28643cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  }
28653cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall
28663cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCallpublic:
286731f17ecbef57b5679c017c375db330546b7b5145John McCall  QualType getInjectedSpecializationType() const { return InjectedType; }
286831f17ecbef57b5679c017c375db330546b7b5145John McCall  const TemplateSpecializationType *getInjectedTST() const {
286931f17ecbef57b5679c017c375db330546b7b5145John McCall    return cast<TemplateSpecializationType>(InjectedType.getTypePtr());
28703cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  }
28713cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall
2872ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl  CXXRecordDecl *getDecl() const;
28733cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall
287431f17ecbef57b5679c017c375db330546b7b5145John McCall  bool isSugared() const { return false; }
287531f17ecbef57b5679c017c375db330546b7b5145John McCall  QualType desugar() const { return QualType(this, 0); }
28763cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall
28773cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  static bool classof(const Type *T) {
28783cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall    return T->getTypeClass() == InjectedClassName;
28793cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  }
28803cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  static bool classof(const InjectedClassNameType *T) { return true; }
28813cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall};
28823cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall
2883465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// \brief The kind of a tag type.
2884465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnaraenum TagTypeKind {
2885465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// \brief The "struct" keyword.
2886465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  TTK_Struct,
2887465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// \brief The "union" keyword.
2888465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  TTK_Union,
2889465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// \brief The "class" keyword.
2890465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  TTK_Class,
2891465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// \brief The "enum" keyword.
2892465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  TTK_Enum
2893465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara};
2894465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
28954a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// \brief The elaboration keyword that precedes a qualified type name or
28964a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// introduces an elaborated-type-specifier.
28974a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregorenum ElaboratedTypeKeyword {
28984a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor  /// \brief The "struct" keyword introduces the elaborated-type-specifier.
28994a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor  ETK_Struct,
29004a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor  /// \brief The "union" keyword introduces the elaborated-type-specifier.
29014a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor  ETK_Union,
2902465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// \brief The "class" keyword introduces the elaborated-type-specifier.
2903465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  ETK_Class,
29044a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor  /// \brief The "enum" keyword introduces the elaborated-type-specifier.
2905465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  ETK_Enum,
2906465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// \brief The "typename" keyword precedes the qualified type name, e.g.,
2907465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// \c typename T::type.
2908465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  ETK_Typename,
2909465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// \brief No keyword precedes the qualified type name.
2910465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  ETK_None
29114a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor};
2912465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
2913465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// A helper class for Type nodes having an ElaboratedTypeKeyword.
2914465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// The keyword in stored in the free bits of the base class.
2915465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// Also provides a few static helpers for converting and printing
2916465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// elaborated type keyword and tag type kind enumerations.
2917465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnaraclass TypeWithKeyword : public Type {
2918465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnaraprotected:
2919465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  TypeWithKeyword(ElaboratedTypeKeyword Keyword, TypeClass tc,
2920d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor                  QualType Canonical, bool Dependent, bool VariablyModified,
2921d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor                  bool ContainsUnexpandedParameterPack)
2922d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  : Type(tc, Canonical, Dependent, VariablyModified,
2923d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor         ContainsUnexpandedParameterPack) {
292477be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall    TypeWithKeywordBits.Keyword = Keyword;
292577be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall  }
2926465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
2927465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnarapublic:
2928465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  ElaboratedTypeKeyword getKeyword() const {
292977be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall    return static_cast<ElaboratedTypeKeyword>(TypeWithKeywordBits.Keyword);
2930465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  }
2931465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
2932465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// getKeywordForTypeSpec - Converts a type specifier (DeclSpec::TST)
2933465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// into an elaborated type keyword.
2934465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  static ElaboratedTypeKeyword getKeywordForTypeSpec(unsigned TypeSpec);
2935465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
2936465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// getTagTypeKindForTypeSpec - Converts a type specifier (DeclSpec::TST)
2937465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// into a tag type kind.  It is an error to provide a type specifier
2938465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// which *isn't* a tag kind here.
2939465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  static TagTypeKind getTagTypeKindForTypeSpec(unsigned TypeSpec);
2940465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
2941465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// getKeywordForTagDeclKind - Converts a TagTypeKind into an
2942465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// elaborated type keyword.
2943465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  static ElaboratedTypeKeyword getKeywordForTagTypeKind(TagTypeKind Tag);
2944465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
2945465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// getTagTypeKindForKeyword - Converts an elaborated type keyword into
2946465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  // a TagTypeKind. It is an error to provide an elaborated type keyword
2947465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// which *isn't* a tag kind here.
2948465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  static TagTypeKind getTagTypeKindForKeyword(ElaboratedTypeKeyword Keyword);
2949465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
2950465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  static bool KeywordIsTagTypeKind(ElaboratedTypeKeyword Keyword);
2951465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
2952465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  static const char *getKeywordName(ElaboratedTypeKeyword Keyword);
2953465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
2954465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  static const char *getTagTypeKindName(TagTypeKind Kind) {
2955465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    return getKeywordName(getKeywordForTagTypeKind(Kind));
2956465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  }
2957465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
2958465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  class CannotCastToThisType {};
2959465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  static CannotCastToThisType classof(const Type *);
2960465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara};
2961465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
2962465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// \brief Represents a type that was referred to using an elaborated type
2963465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// keyword, e.g., struct S, or via a qualified name, e.g., N::M::type,
2964465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// or both.
2965e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor///
2966e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor/// This type is used to keep track of a type name as written in the
2967465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// source code, including tag keywords and any nested-name-specifiers.
2968465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// The type itself is always "sugar", used to express what was written
2969465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// in the source code but containing no additional semantic information.
2970465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnaraclass ElaboratedType : public TypeWithKeyword, public llvm::FoldingSetNode {
2971465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
2972ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor  /// \brief The nested name specifier containing the qualifier.
2973ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor  NestedNameSpecifier *NNS;
2974e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor
2975e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor  /// \brief The type that this qualified name refers to.
2976e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor  QualType NamedType;
2977e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor
2978465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  ElaboratedType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS,
2979465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara                 QualType NamedType, QualType CanonType)
2980465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    : TypeWithKeyword(Keyword, Elaborated, CanonType,
298135495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor                      NamedType->isDependentType(),
2982d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor                      NamedType->isVariablyModifiedType(),
2983d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor                      NamedType->containsUnexpandedParameterPack()),
2984465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara      NNS(NNS), NamedType(NamedType) {
2985465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    assert(!(Keyword == ETK_None && NNS == 0) &&
2986465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara           "ElaboratedType cannot have elaborated type keyword "
2987465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara           "and name qualifier both null.");
2988465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  }
2989e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor
2990e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor  friend class ASTContext;  // ASTContext creates these
2991e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor
2992e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregorpublic:
299333500955d731c73717af52088b7fc0e7a85681e7John McCall  ~ElaboratedType();
2994465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
2995ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor  /// \brief Retrieve the qualification on this type.
2996ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor  NestedNameSpecifier *getQualifier() const { return NNS; }
2997e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor
2998e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor  /// \brief Retrieve the type named by the qualified-id.
2999e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor  QualType getNamedType() const { return NamedType; }
3000e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor
3001bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// \brief Remove a single level of sugar.
3002bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return getNamedType(); }
3003bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
3004bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// \brief Returns whether this type directly provides sugar.
3005bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return true; }
3006bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
3007e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor  void Profile(llvm::FoldingSetNodeID &ID) {
3008465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    Profile(ID, getKeyword(), NNS, NamedType);
3009e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor  }
3010e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor
3011465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  static void Profile(llvm::FoldingSetNodeID &ID, ElaboratedTypeKeyword Keyword,
3012465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara                      NestedNameSpecifier *NNS, QualType NamedType) {
3013465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    ID.AddInteger(Keyword);
3014ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor    ID.AddPointer(NNS);
3015ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor    NamedType.Profile(ID);
3016ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor  }
3017e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor
30181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
3019465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    return T->getTypeClass() == Elaborated;
3020e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor  }
3021465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  static bool classof(const ElaboratedType *T) { return true; }
3022e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor};
3023e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor
30244a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// \brief Represents a qualified type name for which the type name is
30254a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// dependent.
3026d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor///
30274a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// DependentNameType represents a class of dependent types that involve a
30284a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// dependent nested-name-specifier (e.g., "T::") followed by a (dependent)
30294a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// name of a type. The DependentNameType may start with a "typename" (for a
30304a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// typename-specifier), "class", "struct", "union", or "enum" (for a
30314a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// dependent elaborated-type-specifier), or nothing (in contexts where we
30324a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// know that we must be referring to a type, e.g., in a base class specifier).
3033465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnaraclass DependentNameType : public TypeWithKeyword, public llvm::FoldingSetNode {
3034465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
3035d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  /// \brief The nested name specifier containing the qualifier.
3036d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  NestedNameSpecifier *NNS;
3037d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor
3038d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  /// \brief The type that this typename specifier refers to.
303933500955d731c73717af52088b7fc0e7a85681e7John McCall  const IdentifierInfo *Name;
3040d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor
30414a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor  DependentNameType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS,
30424a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor                    const IdentifierInfo *Name, QualType CanonType)
304335495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    : TypeWithKeyword(Keyword, DependentName, CanonType, /*Dependent=*/true,
3044d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor                      /*VariablyModified=*/false,
3045d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor                      NNS->containsUnexpandedParameterPack()),
3046465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara      NNS(NNS), Name(Name) {
30471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    assert(NNS->isDependent() &&
30484714c12a1ab759156b78be8f109ea4c12213af57Douglas Gregor           "DependentNameType requires a dependent nested-name-specifier");
3049d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  }
3050d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor
3051d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  friend class ASTContext;  // ASTContext creates these
3052d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor
3053d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregorpublic:
3054d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  /// \brief Retrieve the qualification on this type.
3055d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  NestedNameSpecifier *getQualifier() const { return NNS; }
3056d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor
30571734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor  /// \brief Retrieve the type named by the typename specifier as an
30581734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor  /// identifier.
30591734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor  ///
30601734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor  /// This routine will return a non-NULL identifier pointer when the
30611734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor  /// form of the original typename was terminated by an identifier,
30621734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor  /// e.g., "typename T::type".
30631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  const IdentifierInfo *getIdentifier() const {
306433500955d731c73717af52088b7fc0e7a85681e7John McCall    return Name;
30651734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor  }
3066d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor
3067bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
3068bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
3069bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
3070d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  void Profile(llvm::FoldingSetNodeID &ID) {
3071465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    Profile(ID, getKeyword(), NNS, Name);
3072d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  }
3073d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor
30744a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor  static void Profile(llvm::FoldingSetNodeID &ID, ElaboratedTypeKeyword Keyword,
307533500955d731c73717af52088b7fc0e7a85681e7John McCall                      NestedNameSpecifier *NNS, const IdentifierInfo *Name) {
30764a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor    ID.AddInteger(Keyword);
3077d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor    ID.AddPointer(NNS);
307833500955d731c73717af52088b7fc0e7a85681e7John McCall    ID.AddPointer(Name);
3079d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  }
3080d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor
30811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
30824714c12a1ab759156b78be8f109ea4c12213af57Douglas Gregor    return T->getTypeClass() == DependentName;
3083d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  }
30844714c12a1ab759156b78be8f109ea4c12213af57Douglas Gregor  static bool classof(const DependentNameType *T) { return true; }
3085d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor};
3086d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor
308733500955d731c73717af52088b7fc0e7a85681e7John McCall/// DependentTemplateSpecializationType - Represents a template
308833500955d731c73717af52088b7fc0e7a85681e7John McCall/// specialization type whose template cannot be resolved, e.g.
308933500955d731c73717af52088b7fc0e7a85681e7John McCall///   A<T>::template B<T>
309033500955d731c73717af52088b7fc0e7a85681e7John McCallclass DependentTemplateSpecializationType :
309133500955d731c73717af52088b7fc0e7a85681e7John McCall  public TypeWithKeyword, public llvm::FoldingSetNode {
309233500955d731c73717af52088b7fc0e7a85681e7John McCall
309333500955d731c73717af52088b7fc0e7a85681e7John McCall  /// \brief The nested name specifier containing the qualifier.
309433500955d731c73717af52088b7fc0e7a85681e7John McCall  NestedNameSpecifier *NNS;
309533500955d731c73717af52088b7fc0e7a85681e7John McCall
309633500955d731c73717af52088b7fc0e7a85681e7John McCall  /// \brief The identifier of the template.
309733500955d731c73717af52088b7fc0e7a85681e7John McCall  const IdentifierInfo *Name;
309833500955d731c73717af52088b7fc0e7a85681e7John McCall
309933500955d731c73717af52088b7fc0e7a85681e7John McCall  /// \brief - The number of template arguments named in this class
310033500955d731c73717af52088b7fc0e7a85681e7John McCall  /// template specialization.
310133500955d731c73717af52088b7fc0e7a85681e7John McCall  unsigned NumArgs;
310233500955d731c73717af52088b7fc0e7a85681e7John McCall
310333500955d731c73717af52088b7fc0e7a85681e7John McCall  const TemplateArgument *getArgBuffer() const {
310433500955d731c73717af52088b7fc0e7a85681e7John McCall    return reinterpret_cast<const TemplateArgument*>(this+1);
310533500955d731c73717af52088b7fc0e7a85681e7John McCall  }
310633500955d731c73717af52088b7fc0e7a85681e7John McCall  TemplateArgument *getArgBuffer() {
310733500955d731c73717af52088b7fc0e7a85681e7John McCall    return reinterpret_cast<TemplateArgument*>(this+1);
310833500955d731c73717af52088b7fc0e7a85681e7John McCall  }
310933500955d731c73717af52088b7fc0e7a85681e7John McCall
3110ef99001908e799c388f1363b1e607dad5f5b57d3John McCall  DependentTemplateSpecializationType(ElaboratedTypeKeyword Keyword,
311133500955d731c73717af52088b7fc0e7a85681e7John McCall                                      NestedNameSpecifier *NNS,
311233500955d731c73717af52088b7fc0e7a85681e7John McCall                                      const IdentifierInfo *Name,
311333500955d731c73717af52088b7fc0e7a85681e7John McCall                                      unsigned NumArgs,
311433500955d731c73717af52088b7fc0e7a85681e7John McCall                                      const TemplateArgument *Args,
311533500955d731c73717af52088b7fc0e7a85681e7John McCall                                      QualType Canon);
311633500955d731c73717af52088b7fc0e7a85681e7John McCall
311733500955d731c73717af52088b7fc0e7a85681e7John McCall  friend class ASTContext;  // ASTContext creates these
311833500955d731c73717af52088b7fc0e7a85681e7John McCall
311933500955d731c73717af52088b7fc0e7a85681e7John McCallpublic:
312033500955d731c73717af52088b7fc0e7a85681e7John McCall  NestedNameSpecifier *getQualifier() const { return NNS; }
312133500955d731c73717af52088b7fc0e7a85681e7John McCall  const IdentifierInfo *getIdentifier() const { return Name; }
312233500955d731c73717af52088b7fc0e7a85681e7John McCall
312333500955d731c73717af52088b7fc0e7a85681e7John McCall  /// \brief Retrieve the template arguments.
312433500955d731c73717af52088b7fc0e7a85681e7John McCall  const TemplateArgument *getArgs() const {
312533500955d731c73717af52088b7fc0e7a85681e7John McCall    return getArgBuffer();
312633500955d731c73717af52088b7fc0e7a85681e7John McCall  }
312733500955d731c73717af52088b7fc0e7a85681e7John McCall
312833500955d731c73717af52088b7fc0e7a85681e7John McCall  /// \brief Retrieve the number of template arguments.
312933500955d731c73717af52088b7fc0e7a85681e7John McCall  unsigned getNumArgs() const { return NumArgs; }
313033500955d731c73717af52088b7fc0e7a85681e7John McCall
313133500955d731c73717af52088b7fc0e7a85681e7John McCall  const TemplateArgument &getArg(unsigned Idx) const; // in TemplateBase.h
313233500955d731c73717af52088b7fc0e7a85681e7John McCall
313333500955d731c73717af52088b7fc0e7a85681e7John McCall  typedef const TemplateArgument * iterator;
313433500955d731c73717af52088b7fc0e7a85681e7John McCall  iterator begin() const { return getArgs(); }
313533500955d731c73717af52088b7fc0e7a85681e7John McCall  iterator end() const; // inline in TemplateBase.h
313633500955d731c73717af52088b7fc0e7a85681e7John McCall
313733500955d731c73717af52088b7fc0e7a85681e7John McCall  bool isSugared() const { return false; }
313833500955d731c73717af52088b7fc0e7a85681e7John McCall  QualType desugar() const { return QualType(this, 0); }
313933500955d731c73717af52088b7fc0e7a85681e7John McCall
3140ef99001908e799c388f1363b1e607dad5f5b57d3John McCall  void Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context) {
314133500955d731c73717af52088b7fc0e7a85681e7John McCall    Profile(ID, Context, getKeyword(), NNS, Name, NumArgs, getArgs());
314233500955d731c73717af52088b7fc0e7a85681e7John McCall  }
314333500955d731c73717af52088b7fc0e7a85681e7John McCall
314433500955d731c73717af52088b7fc0e7a85681e7John McCall  static void Profile(llvm::FoldingSetNodeID &ID,
314533500955d731c73717af52088b7fc0e7a85681e7John McCall                      ASTContext &Context,
314633500955d731c73717af52088b7fc0e7a85681e7John McCall                      ElaboratedTypeKeyword Keyword,
314733500955d731c73717af52088b7fc0e7a85681e7John McCall                      NestedNameSpecifier *Qualifier,
314833500955d731c73717af52088b7fc0e7a85681e7John McCall                      const IdentifierInfo *Name,
314933500955d731c73717af52088b7fc0e7a85681e7John McCall                      unsigned NumArgs,
315033500955d731c73717af52088b7fc0e7a85681e7John McCall                      const TemplateArgument *Args);
315133500955d731c73717af52088b7fc0e7a85681e7John McCall
315233500955d731c73717af52088b7fc0e7a85681e7John McCall  static bool classof(const Type *T) {
315333500955d731c73717af52088b7fc0e7a85681e7John McCall    return T->getTypeClass() == DependentTemplateSpecialization;
315433500955d731c73717af52088b7fc0e7a85681e7John McCall  }
315533500955d731c73717af52088b7fc0e7a85681e7John McCall  static bool classof(const DependentTemplateSpecializationType *T) {
315633500955d731c73717af52088b7fc0e7a85681e7John McCall    return true;
315733500955d731c73717af52088b7fc0e7a85681e7John McCall  }
315833500955d731c73717af52088b7fc0e7a85681e7John McCall};
315933500955d731c73717af52088b7fc0e7a85681e7John McCall
3160c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// ObjCObjectType - Represents a class type in Objective C.
3161c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// Every Objective C type is a combination of a base type and a
3162c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// list of protocols.
3163c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall///
3164c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// Given the following declarations:
3165c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall///   @class C;
3166c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall///   @protocol P;
3167c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall///
3168c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// 'C' is an ObjCInterfaceType C.  It is sugar for an ObjCObjectType
3169c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// with base C and no protocols.
3170c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall///
3171c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// 'C<P>' is an ObjCObjectType with base C and protocol list [P].
3172c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall///
3173e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// 'id' is a TypedefType which is sugar for an ObjCPointerType whose
3174e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// pointee is an ObjCObjectType with base BuiltinType::ObjCIdType
3175e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// and no protocols.
3176c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall///
3177e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// 'id<P>' is an ObjCPointerType whose pointee is an ObjCObjecType
3178e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// with base BuiltinType::ObjCIdType and protocol list [P].  Eventually
3179e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// this should get its own sugar class to better represent the source.
3180c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallclass ObjCObjectType : public Type {
3181b870b88df784c2940efce448ebfaf54dece14666John McCall  // ObjCObjectType.NumProtocols - the number of protocols stored
3182b870b88df784c2940efce448ebfaf54dece14666John McCall  // after the ObjCObjectPointerType node.
318371c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  //
318471c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  // These protocols are those written directly on the type.  If
318571c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  // protocol qualifiers ever become additive, the iterators will need
318671c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  // to get kindof complicated.
318771c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  //
318871c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  // In the canonical object type, these are sorted alphabetically
318971c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  // and uniqued.
3190c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff
3191c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  /// Either a BuiltinType or an InterfaceType or sugar for either.
3192c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  QualType BaseType;
3193c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3194c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  ObjCProtocolDecl * const *getProtocolStorage() const {
3195c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return const_cast<ObjCObjectType*>(this)->getProtocolStorage();
3196c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  }
3197c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3198c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  ObjCProtocolDecl **getProtocolStorage();
3199c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3200c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallprotected:
3201c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  ObjCObjectType(QualType Canonical, QualType Base,
3202c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall                 ObjCProtocolDecl * const *Protocols, unsigned NumProtocols);
3203c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3204c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  enum Nonce_ObjCInterface { Nonce_ObjCInterface };
3205c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  ObjCObjectType(enum Nonce_ObjCInterface)
3206d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor        : Type(ObjCInterface, QualType(), false, false, false),
320771c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall      BaseType(QualType(this_(), 0)) {
3208b870b88df784c2940efce448ebfaf54dece14666John McCall    ObjCObjectTypeBits.NumProtocols = 0;
320971c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  }
3210c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff
32113536b443bc50d58a79f14fca9b6842541a434854Steve Naroffpublic:
3212e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// getBaseType - Gets the base type of this object type.  This is
3213e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// always (possibly sugar for) one of:
3214e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///  - the 'id' builtin type (as opposed to the 'id' type visible to the
3215e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///    user, which is a typedef for an ObjCPointerType)
3216e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///  - the 'Class' builtin type (same caveat)
3217e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///  - an ObjCObjectType (currently always an ObjCInterfaceType)
3218c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  QualType getBaseType() const { return BaseType; }
321971842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek
3220c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool isObjCId() const {
3221c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getBaseType()->isSpecificBuiltinType(BuiltinType::ObjCId);
3222c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  }
3223c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool isObjCClass() const {
3224c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getBaseType()->isSpecificBuiltinType(BuiltinType::ObjCClass);
3225c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  }
3226c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool isObjCUnqualifiedId() const { return qual_empty() && isObjCId(); }
3227c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool isObjCUnqualifiedClass() const { return qual_empty() && isObjCClass(); }
3228c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool isObjCUnqualifiedIdOrClass() const {
3229c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    if (!qual_empty()) return false;
3230c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    if (const BuiltinType *T = getBaseType()->getAs<BuiltinType>())
3231c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall      return T->getKind() == BuiltinType::ObjCId ||
3232c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall             T->getKind() == BuiltinType::ObjCClass;
3233c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return false;
3234c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  }
3235c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool isObjCQualifiedId() const { return !qual_empty() && isObjCId(); }
3236c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool isObjCQualifiedClass() const { return !qual_empty() && isObjCClass(); }
3237c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3238c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  /// Gets the interface declaration for this object type, if the base type
3239c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  /// really is an interface.
3240c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  ObjCInterfaceDecl *getInterface() const;
3241c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3242c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  typedef ObjCProtocolDecl * const *qual_iterator;
3243c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3244c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  qual_iterator qual_begin() const { return getProtocolStorage(); }
3245c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  qual_iterator qual_end() const { return qual_begin() + getNumProtocols(); }
3246c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3247c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool qual_empty() const { return getNumProtocols() == 0; }
32481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3249c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff  /// getNumProtocols - Return the number of qualifying protocols in this
3250c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff  /// interface type, or 0 if there are none.
3251b870b88df784c2940efce448ebfaf54dece14666John McCall  unsigned getNumProtocols() const { return ObjCObjectTypeBits.NumProtocols; }
325214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff
3253c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  /// \brief Fetch a protocol by index.
325473dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor  ObjCProtocolDecl *getProtocol(unsigned I) const {
325573dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor    assert(I < getNumProtocols() && "Out-of-range protocol access");
325673dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor    return qual_begin()[I];
325773dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor  }
325873dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor
3259bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
3260bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
3261bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
3262c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  static bool classof(const Type *T) {
3263c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return T->getTypeClass() == ObjCObject ||
3264c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall           T->getTypeClass() == ObjCInterface;
3265c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  }
3266c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  static bool classof(const ObjCObjectType *) { return true; }
3267c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall};
3268c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3269c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// ObjCObjectTypeImpl - A class providing a concrete implementation
3270c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// of ObjCObjectType, so as to not increase the footprint of
3271c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// ObjCInterfaceType.  Code outside of ASTContext and the core type
3272c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// system should not reference this type.
3273c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallclass ObjCObjectTypeImpl : public ObjCObjectType, public llvm::FoldingSetNode {
3274c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  friend class ASTContext;
3275c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3276c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  // If anyone adds fields here, ObjCObjectType::getProtocolStorage()
3277c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  // will need to be modified.
3278c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3279c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  ObjCObjectTypeImpl(QualType Canonical, QualType Base,
3280c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall                     ObjCProtocolDecl * const *Protocols,
3281c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall                     unsigned NumProtocols)
3282c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    : ObjCObjectType(Canonical, Base, Protocols, NumProtocols) {}
3283c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3284c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallpublic:
3285c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff  void Profile(llvm::FoldingSetNodeID &ID);
32861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static void Profile(llvm::FoldingSetNodeID &ID,
3287c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall                      QualType Base,
3288c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall                      ObjCProtocolDecl *const *protocols,
3289c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall                      unsigned NumProtocols);
3290c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall};
32911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3292c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallinline ObjCProtocolDecl **ObjCObjectType::getProtocolStorage() {
3293c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  return reinterpret_cast<ObjCProtocolDecl**>(
3294c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall            static_cast<ObjCObjectTypeImpl*>(this) + 1);
3295c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall}
3296c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3297c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// ObjCInterfaceType - Interfaces are the core concept in Objective-C for
3298c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// object oriented design.  They basically correspond to C++ classes.  There
3299c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// are two kinds of interface types, normal interfaces like "NSString" and
3300c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// qualified interfaces, which are qualified with a protocol list like
3301c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// "NSString<NSCopyable, NSAmazing>".
3302e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall///
3303e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// ObjCInterfaceType guarantees the following properties when considered
3304e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// as a subtype of its superclass, ObjCObjectType:
3305e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall///   - There are no protocol qualifiers.  To reinforce this, code which
3306e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall///     tries to invoke the protocol methods via an ObjCInterfaceType will
3307e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall///     fail to compile.
3308e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall///   - It is its own base type.  That is, if T is an ObjCInterfaceType*,
3309e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall///     T->getBaseType() == QualType(T, 0).
3310c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallclass ObjCInterfaceType : public ObjCObjectType {
3311c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  ObjCInterfaceDecl *Decl;
3312c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3313c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  ObjCInterfaceType(const ObjCInterfaceDecl *D)
3314c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    : ObjCObjectType(Nonce_ObjCInterface),
3315c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall      Decl(const_cast<ObjCInterfaceDecl*>(D)) {}
3316c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  friend class ASTContext;  // ASTContext creates these.
33171fb0caaa7bef765b85972274e3b434af2572c141John McCall
3318c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallpublic:
3319e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// getDecl - Get the declaration of this interface.
3320deacbdca554298ccdf636f19c6094a8825ec6b34Douglas Gregor  ObjCInterfaceDecl *getDecl() const { return Decl; }
3321c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3322c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool isSugared() const { return false; }
3323c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  QualType desugar() const { return QualType(this, 0); }
33240b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor
33251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
33261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == ObjCInterface;
33273536b443bc50d58a79f14fca9b6842541a434854Steve Naroff  }
3328a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const ObjCInterfaceType *) { return true; }
3329c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3330c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  // Nonsense to "hide" certain members of ObjCObjectType within this
3331c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  // class.  People asking for protocols on an ObjCInterfaceType are
3332c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  // not going to get what they want: ObjCInterfaceTypes are
3333c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  // guaranteed to have no protocols.
3334c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  enum {
3335c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    qual_iterator,
3336c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    qual_begin,
3337c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    qual_end,
3338c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    getNumProtocols,
3339c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    getProtocol
3340c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  };
33413536b443bc50d58a79f14fca9b6842541a434854Steve Naroff};
33423536b443bc50d58a79f14fca9b6842541a434854Steve Naroff
3343c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallinline ObjCInterfaceDecl *ObjCObjectType::getInterface() const {
3344c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  if (const ObjCInterfaceType *T =
3345c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall        getBaseType()->getAs<ObjCInterfaceType>())
3346c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return T->getDecl();
3347c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  return 0;
3348c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall}
3349c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3350e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// ObjCObjectPointerType - Used to represent a pointer to an
3351e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// Objective C object.  These are constructed from pointer
3352e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// declarators when the pointee type is an ObjCObjectType (or sugar
3353e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// for one).  In addition, the 'id' and 'Class' types are typedefs
3354e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// for these, and the protocol-qualified types 'id<P>' and 'Class<P>'
3355e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// are translated into these.
335614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff///
3357e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// Pointers to pointers to Objective C objects are still PointerTypes;
3358e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// only the first level of pointer gets it own type implementation.
335914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroffclass ObjCObjectPointerType : public Type, public llvm::FoldingSetNode {
3360e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  QualType PointeeType;
33611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3362c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  ObjCObjectPointerType(QualType Canonical, QualType Pointee)
3363d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    : Type(ObjCObjectPointer, Canonical, false, false, false),
3364c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall      PointeeType(Pointee) {}
336514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  friend class ASTContext;  // ASTContext creates these.
33661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
336714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroffpublic:
3368e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// getPointeeType - Gets the type pointed to by this ObjC pointer.
3369e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// The result will always be an ObjCObjectType or sugar thereof.
337014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  QualType getPointeeType() const { return PointeeType; }
337114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff
3372e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// getObjCObjectType - Gets the type pointed to by this ObjC
3373e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// pointer.  This method always returns non-null.
3374e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///
3375e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// This method is equivalent to getPointeeType() except that
3376e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// it discards any typedefs (or other sugar) between this
3377e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// type and the "outermost" object type.  So for:
3378e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///   @class A; @protocol P; @protocol Q;
3379e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///   typedef A<P> AP;
3380e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///   typedef A A1;
3381e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///   typedef A1<P> A1P;
3382e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///   typedef A1P<Q> A1PQ;
3383e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// For 'A*', getObjectType() will return 'A'.
3384e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// For 'A<P>*', getObjectType() will return 'A<P>'.
3385e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// For 'AP*', getObjectType() will return 'A<P>'.
3386e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// For 'A1*', getObjectType() will return 'A'.
3387e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// For 'A1<P>*', getObjectType() will return 'A1<P>'.
3388e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// For 'A1P*', getObjectType() will return 'A1<P>'.
3389e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// For 'A1PQ*', getObjectType() will return 'A1<Q>', because
3390e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///   adding protocols to a protocol-qualified base discards the
3391e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///   old qualifiers (for now).  But if it didn't, getObjectType()
3392e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///   would return 'A1P<Q>' (and we'd have to make iterating over
3393e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///   qualifiers more complicated).
3394c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  const ObjCObjectType *getObjectType() const {
3395c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return PointeeType->getAs<ObjCObjectType>();
3396c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  }
3397c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
3398e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// getInterfaceType - If this pointer points to an Objective C
3399e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// @interface type, gets the type for that interface.  Any protocol
3400e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// qualifiers on the interface are ignored.
3401e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///
3402e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// \return null if the base type for this pointer is 'id' or 'Class'
34031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  const ObjCInterfaceType *getInterfaceType() const {
3404c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getObjectType()->getBaseType()->getAs<ObjCInterfaceType>();
340514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  }
3406e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall
3407e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// getInterfaceDecl - If this pointer points to an Objective @interface
3408e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// type, gets the declaration for that interface.
3409e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///
3410e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// \return null if the base type for this pointer is 'id' or 'Class'
341114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  ObjCInterfaceDecl *getInterfaceDecl() const {
3412e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall    return getObjectType()->getInterface();
341314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  }
3414e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall
3415e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// isObjCIdType - True if this is equivalent to the 'id' type, i.e. if
3416e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// its object type is the primitive 'id' type with no protocols.
341714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  bool isObjCIdType() const {
3418c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getObjectType()->isObjCUnqualifiedId();
341914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  }
3420e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall
3421e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// isObjCClassType - True if this is equivalent to the 'Class' type,
3422e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// i.e. if its object tive is the primitive 'Class' type with no protocols.
342314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  bool isObjCClassType() const {
3424c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getObjectType()->isObjCUnqualifiedClass();
3425de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff  }
34268d2c0a9814e56c2b22e22d1045181c735aef62fdFariborz Jahanian
3427e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// isObjCQualifiedIdType - True if this is equivalent to 'id<P>' for some
3428e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// non-empty set of protocols.
34291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  bool isObjCQualifiedIdType() const {
3430c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getObjectType()->isObjCQualifiedId();
3431de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff  }
3432e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall
3433e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// isObjCQualifiedClassType - True if this is equivalent to 'Class<P>' for
3434e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// some non-empty set of protocols.
3435470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroff  bool isObjCQualifiedClassType() const {
3436c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getObjectType()->isObjCQualifiedClass();
343714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  }
3438e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall
3439e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// An iterator over the qualifiers on the object type.  Provided
3440e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// for convenience.  This will always iterate over the full set of
3441e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// protocols on a type, not just those provided directly.
3442c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  typedef ObjCObjectType::qual_iterator qual_iterator;
344314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff
344471842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek  qual_iterator qual_begin() const {
3445c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getObjectType()->qual_begin();
344671842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek  }
3447c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  qual_iterator qual_end() const {
3448c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getObjectType()->qual_end();
344971842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek  }
3450c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool qual_empty() const { return getObjectType()->qual_empty(); }
345114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff
3452e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// getNumProtocols - Return the number of qualifying protocols on
3453e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// the object type.
3454c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  unsigned getNumProtocols() const {
3455c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getObjectType()->getNumProtocols();
3456c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  }
345714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff
3458e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// \brief Retrieve a qualifying protocol by index on the object
3459e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// type.
346073dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor  ObjCProtocolDecl *getProtocol(unsigned I) const {
3461c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getObjectType()->getProtocol(I);
346273dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor  }
346373dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor
3464bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
3465bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
3466bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
3467e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  void Profile(llvm::FoldingSetNodeID &ID) {
3468e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall    Profile(ID, getPointeeType());
3469e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  }
3470c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  static void Profile(llvm::FoldingSetNodeID &ID, QualType T) {
3471c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    ID.AddPointer(T.getAsOpaquePtr());
3472c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  }
34731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
34741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == ObjCObjectPointer;
347514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  }
347614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  static bool classof(const ObjCObjectPointerType *) { return true; }
347714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff};
34781bb8a45f7386a23871598d05141a07af03067925Argyrios Kyrtzidis
34790953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// A qualifier set is used to build a set of qualifiers.
34800953e767ff7817f97b3ab20896b229891eeff45bJohn McCallclass QualifierCollector : public Qualifiers {
34810953e767ff7817f97b3ab20896b229891eeff45bJohn McCallpublic:
348249f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  QualifierCollector(Qualifiers Qs = Qualifiers()) : Qualifiers(Qs) {}
34830953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
34840953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// Collect any qualifiers on the given type and return an
34850953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// unqualified type.
34860953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  const Type *strip(QualType QT) {
3487a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor    addFastQualifiers(QT.getLocalFastQualifiers());
3488a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor    if (QT.hasLocalNonFastQualifiers()) {
34890953e767ff7817f97b3ab20896b229891eeff45bJohn McCall      const ExtQuals *EQ = QT.getExtQualsUnsafe();
34900953e767ff7817f97b3ab20896b229891eeff45bJohn McCall      addQualifiers(EQ->getQualifiers());
34910953e767ff7817f97b3ab20896b229891eeff45bJohn McCall      return EQ->getBaseType();
34920953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    }
34930953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return QT.getTypePtrUnsafe();
34940953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
34950953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
34960953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// Apply the collected qualifiers to the given type.
349749f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  QualType apply(ASTContext &Context, QualType QT) const;
34980953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
34990953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// Apply the collected qualifiers to the given type.
350049f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  QualType apply(ASTContext &Context, const Type* T) const;
35010953e767ff7817f97b3ab20896b229891eeff45bJohn McCall};
35020953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
35030953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3504611c1fff195d32df97706e0920c92468b2509900Chris Lattner// Inline function definitions.
35055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3506467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCallinline bool QualType::isCanonical() const {
3507467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall  const Type *T = getTypePtr();
3508a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  if (hasLocalQualifiers())
3509467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall    return T->isCanonicalUnqualified() && !isa<ArrayType>(T);
3510467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall  return T->isCanonicalUnqualified();
3511467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall}
3512467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall
351354e14c4db764c0636160d26c5bbf491637c83a76John McCallinline bool QualType::isCanonicalAsParam() const {
3514a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  if (hasLocalQualifiers()) return false;
3515745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian
351654e14c4db764c0636160d26c5bbf491637c83a76John McCall  const Type *T = getTypePtr();
3517745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian  if ((*this)->isPointerType()) {
3518745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian    QualType BaseType = (*this)->getAs<PointerType>()->getPointeeType();
3519745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian    if (isa<VariableArrayType>(BaseType)) {
3520745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian      ArrayType *AT = dyn_cast<ArrayType>(BaseType);
3521745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian      VariableArrayType *VAT = cast<VariableArrayType>(AT);
3522745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian      if (VAT->getSizeExpr())
3523745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian        T = BaseType.getTypePtr();
3524745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian    }
3525745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian  }
352654e14c4db764c0636160d26c5bbf491637c83a76John McCall  return T->isCanonicalUnqualified() &&
352754e14c4db764c0636160d26c5bbf491637c83a76John McCall           !isa<FunctionType>(T) && !isa<ArrayType>(T);
352854e14c4db764c0636160d26c5bbf491637c83a76John McCall}
352954e14c4db764c0636160d26c5bbf491637c83a76John McCall
3530fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregorinline bool QualType::isConstQualified() const {
3531fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  return isLocalConstQualified() ||
3532fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor              getTypePtr()->getCanonicalTypeInternal().isLocalConstQualified();
3533fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor}
3534fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor
3535fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregorinline bool QualType::isRestrictQualified() const {
3536fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  return isLocalRestrictQualified() ||
3537fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor            getTypePtr()->getCanonicalTypeInternal().isLocalRestrictQualified();
3538fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor}
3539fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor
3540fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor
3541fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregorinline bool QualType::isVolatileQualified() const {
3542fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  return isLocalVolatileQualified() ||
3543fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  getTypePtr()->getCanonicalTypeInternal().isLocalVolatileQualified();
3544fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor}
3545fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor
3546fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregorinline bool QualType::hasQualifiers() const {
3547fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  return hasLocalQualifiers() ||
3548fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor                  getTypePtr()->getCanonicalTypeInternal().hasLocalQualifiers();
3549fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor}
3550fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor
3551fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregorinline Qualifiers QualType::getQualifiers() const {
3552fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  Qualifiers Quals = getLocalQualifiers();
3553fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  Quals.addQualifiers(
3554fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor                 getTypePtr()->getCanonicalTypeInternal().getLocalQualifiers());
3555fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  return Quals;
3556fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor}
3557fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor
3558fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregorinline unsigned QualType::getCVRQualifiers() const {
3559fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  return getLocalCVRQualifiers() |
3560fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor              getTypePtr()->getCanonicalTypeInternal().getLocalCVRQualifiers();
3561fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor}
3562e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth
3563e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth/// getCVRQualifiersThroughArrayTypes - If there are CVR qualifiers for this
3564e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth/// type, returns them. Otherwise, if this is an array type, recurses
3565e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth/// on the element type until some qualifiers have been found or a non-array
3566e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth/// type reached.
3567e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruthinline unsigned QualType::getCVRQualifiersThroughArrayTypes() const {
3568e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth  if (unsigned Quals = getCVRQualifiers())
3569e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth    return Quals;
3570e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth  QualType CT = getTypePtr()->getCanonicalTypeInternal();
3571e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth  if (const ArrayType *AT = dyn_cast<ArrayType>(CT))
3572e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth    return AT->getElementType().getCVRQualifiersThroughArrayTypes();
3573e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth  return 0;
3574e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth}
3575e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth
357649f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCallinline void QualType::removeLocalConst() {
357749f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  removeLocalFastQualifiers(Qualifiers::Const);
35780953e767ff7817f97b3ab20896b229891eeff45bJohn McCall}
35790953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
358049f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCallinline void QualType::removeLocalRestrict() {
358149f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  removeLocalFastQualifiers(Qualifiers::Restrict);
35820953e767ff7817f97b3ab20896b229891eeff45bJohn McCall}
35830953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
358449f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCallinline void QualType::removeLocalVolatile() {
358549f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  removeLocalFastQualifiers(Qualifiers::Volatile);
35860953e767ff7817f97b3ab20896b229891eeff45bJohn McCall}
35870953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
358849f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCallinline void QualType::removeLocalCVRQualifiers(unsigned Mask) {
35896b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall  assert(!(Mask & ~Qualifiers::CVRMask) && "mask has non-CVR bits");
3590c3c0af36bac3d71f61dd758585ab307892545de4Douglas Gregor  assert((int)Qualifiers::CVRMask == (int)Qualifiers::FastMask);
35910953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
35920953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Fast path: we don't need to touch the slow qualifiers.
359349f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  removeLocalFastQualifiers(Mask);
3594ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb}
3595ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb
3596ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb/// getAddressSpace - Return the address space of this type.
3597ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lambinline unsigned QualType::getAddressSpace() const {
3598a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  if (hasLocalNonFastQualifiers()) {
35990953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    const ExtQuals *EQ = getExtQualsUnsafe();
36000953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    if (EQ->hasAddressSpace())
36010953e767ff7817f97b3ab20896b229891eeff45bJohn McCall      return EQ->getAddressSpace();
36020953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
36030953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
36044243a94b43ef6207938f3023dfcfb804dd545363Chris Lattner  QualType CT = getTypePtr()->getCanonicalTypeInternal();
3605a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  if (CT.hasLocalNonFastQualifiers()) {
36060953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    const ExtQuals *EQ = CT.getExtQualsUnsafe();
36070953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    if (EQ->hasAddressSpace())
36080953e767ff7817f97b3ab20896b229891eeff45bJohn McCall      return EQ->getAddressSpace();
36090953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
36100953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
36114243a94b43ef6207938f3023dfcfb804dd545363Chris Lattner  if (const ArrayType *AT = dyn_cast<ArrayType>(CT))
3612c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner    return AT->getElementType().getAddressSpace();
36134243a94b43ef6207938f3023dfcfb804dd545363Chris Lattner  if (const RecordType *RT = dyn_cast<RecordType>(CT))
36148e7dafec4b70303dfaff95151cd06bfc5532720cNate Begeman    return RT->getAddressSpace();
3615ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb  return 0;
3616ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb}
3617611c1fff195d32df97706e0920c92468b2509900Chris Lattner
3618d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian/// getObjCGCAttr - Return the gc attribute of this type.
36190953e767ff7817f97b3ab20896b229891eeff45bJohn McCallinline Qualifiers::GC QualType::getObjCGCAttr() const {
3620a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  if (hasLocalNonFastQualifiers()) {
36210953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    const ExtQuals *EQ = getExtQualsUnsafe();
36220953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    if (EQ->hasObjCGCAttr())
36230953e767ff7817f97b3ab20896b229891eeff45bJohn McCall      return EQ->getObjCGCAttr();
36240953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
36250953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3626d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian  QualType CT = getTypePtr()->getCanonicalTypeInternal();
3627a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  if (CT.hasLocalNonFastQualifiers()) {
36280953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    const ExtQuals *EQ = CT.getExtQualsUnsafe();
36290953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    if (EQ->hasObjCGCAttr())
36300953e767ff7817f97b3ab20896b229891eeff45bJohn McCall      return EQ->getObjCGCAttr();
36310953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
36320953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3633d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian  if (const ArrayType *AT = dyn_cast<ArrayType>(CT))
3634d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian      return AT->getElementType().getObjCGCAttr();
3635183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  if (const ObjCObjectPointerType *PT = CT->getAs<ObjCObjectPointerType>())
36361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return PT->getPointeeType().getObjCGCAttr();
3637ac423ba85bb59cc7cc1d43081b20d7e8d40355ffFariborz Jahanian  // We most look at all pointer types, not just pointer to interface types.
3638ac423ba85bb59cc7cc1d43081b20d7e8d40355ffFariborz Jahanian  if (const PointerType *PT = CT->getAs<PointerType>())
36391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return PT->getPointeeType().getObjCGCAttr();
36400953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  return Qualifiers::GCNone;
3641d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian}
36422455636163fdd18581d7fdae816433f886d88213Mike Stump
3643264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindolainline FunctionType::ExtInfo getFunctionExtInfo(const Type &t) {
3644264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola  if (const PointerType *PT = t.getAs<PointerType>()) {
3645183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall    if (const FunctionType *FT = PT->getPointeeType()->getAs<FunctionType>())
3646264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola      return FT->getExtInfo();
3647264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola  } else if (const FunctionType *FT = t.getAs<FunctionType>())
3648264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    return FT->getExtInfo();
36492455636163fdd18581d7fdae816433f886d88213Mike Stump
3650264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola  return FunctionType::ExtInfo();
36512455636163fdd18581d7fdae816433f886d88213Mike Stump}
36521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3653264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindolainline FunctionType::ExtInfo getFunctionExtInfo(QualType t) {
3654264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola  return getFunctionExtInfo(*t);
3655ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor}
3656ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor
3657b87786f045d798b070980c108c922e1475d27b15Douglas Gregor/// \brief Determine whether this set of qualifiers is a superset of the given
3658b87786f045d798b070980c108c922e1475d27b15Douglas Gregor/// set of qualifiers.
3659b87786f045d798b070980c108c922e1475d27b15Douglas Gregorinline bool Qualifiers::isSupersetOf(Qualifiers Other) const {
3660b87786f045d798b070980c108c922e1475d27b15Douglas Gregor  return Mask != Other.Mask && (Mask | Other.Mask) == Mask;
3661b87786f045d798b070980c108c922e1475d27b15Douglas Gregor}
3662b87786f045d798b070980c108c922e1475d27b15Douglas Gregor
3663e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// isMoreQualifiedThan - Determine whether this type is more
3664e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// qualified than the Other type. For example, "const volatile int"
3665e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// is more qualified than "const int", "volatile int", and
3666e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// "int". However, it is not more qualified than "const volatile
3667e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// int".
3668e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregorinline bool QualType::isMoreQualifiedThan(QualType Other) const {
36690953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // FIXME: work on arbitrary qualifiers
3670e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth  unsigned MyQuals = this->getCVRQualifiersThroughArrayTypes();
3671e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth  unsigned OtherQuals = Other.getCVRQualifiersThroughArrayTypes();
3672ecca7536488e425417dcb005c39cc15ae1947aabChris Lattner  if (getAddressSpace() != Other.getAddressSpace())
3673ecca7536488e425417dcb005c39cc15ae1947aabChris Lattner    return false;
3674e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor  return MyQuals != OtherQuals && (MyQuals | OtherQuals) == MyQuals;
3675e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor}
3676e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor
3677e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// isAtLeastAsQualifiedAs - Determine whether this type is at last
3678e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// as qualified as the Other type. For example, "const volatile
3679e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// int" is at least as qualified as "const int", "volatile int",
3680e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// "int", and "const volatile int".
3681e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregorinline bool QualType::isAtLeastAsQualifiedAs(QualType Other) const {
36820953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // FIXME: work on arbitrary qualifiers
3683e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth  unsigned MyQuals = this->getCVRQualifiersThroughArrayTypes();
3684e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth  unsigned OtherQuals = Other.getCVRQualifiersThroughArrayTypes();
3685ecca7536488e425417dcb005c39cc15ae1947aabChris Lattner  if (getAddressSpace() != Other.getAddressSpace())
3686ecca7536488e425417dcb005c39cc15ae1947aabChris Lattner    return false;
3687e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor  return (MyQuals | OtherQuals) == MyQuals;
3688e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor}
3689e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor
3690e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// getNonReferenceType - If Type is a reference type (e.g., const
3691e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// int&), returns the type that the reference refers to ("const
3692e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// int"). Otherwise, returns the type itself. This routine is used
3693e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// throughout Sema to implement C++ 5p6:
3694e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor///
3695e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor///   If an expression initially has the type "reference to T" (8.3.2,
3696e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor///   8.5.3), the type is adjusted to "T" prior to any further
3697e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor///   analysis, the expression designates the object or function
3698e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor///   denoted by the reference, and the expression is an lvalue.
3699e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregorinline QualType QualType::getNonReferenceType() const {
37006217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek  if (const ReferenceType *RefType = (*this)->getAs<ReferenceType>())
3701e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor    return RefType->getPointeeType();
3702e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor  else
3703e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor    return *this;
3704e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor}
3705e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor
3706611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isFunctionType() const {
3707a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<FunctionType>(CanonicalType);
3708611c1fff195d32df97706e0920c92468b2509900Chris Lattner}
3709611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isPointerType() const {
3710a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<PointerType>(CanonicalType);
3711611c1fff195d32df97706e0920c92468b2509900Chris Lattner}
371258f9f2c884af6b72d036b746a016d8031d31cb7aSteve Naroffinline bool Type::isAnyPointerType() const {
371358f9f2c884af6b72d036b746a016d8031d31cb7aSteve Naroff  return isPointerType() || isObjCObjectPointerType();
371458f9f2c884af6b72d036b746a016d8031d31cb7aSteve Naroff}
37155618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroffinline bool Type::isBlockPointerType() const {
3716a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<BlockPointerType>(CanonicalType);
37175618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff}
3718bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattnerinline bool Type::isReferenceType() const {
3719a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<ReferenceType>(CanonicalType);
3720bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner}
37217c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlinline bool Type::isLValueReferenceType() const {
3722a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<LValueReferenceType>(CanonicalType);
37237c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl}
37247c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlinline bool Type::isRValueReferenceType() const {
3725a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<RValueReferenceType>(CanonicalType);
37267c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl}
3727498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenekinline bool Type::isFunctionPointerType() const {
37286217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek  if (const PointerType* T = getAs<PointerType>())
3729498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek    return T->getPointeeType()->isFunctionType();
3730498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek  else
3731498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek    return false;
3732498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek}
3733f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlinline bool Type::isMemberPointerType() const {
3734a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<MemberPointerType>(CanonicalType);
3735f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl}
3736f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlinline bool Type::isMemberFunctionPointerType() const {
37376217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek  if (const MemberPointerType* T = getAs<MemberPointerType>())
37380bab0cdab751248ca389a5592bcb70eac5d39260John McCall    return T->isMemberFunctionPointer();
3739f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  else
3740f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    return false;
3741f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl}
3742db68e28c05a67735211e688009890cf834c22e75Douglas Gregorinline bool Type::isMemberDataPointerType() const {
3743db68e28c05a67735211e688009890cf834c22e75Douglas Gregor  if (const MemberPointerType* T = getAs<MemberPointerType>())
37440bab0cdab751248ca389a5592bcb70eac5d39260John McCall    return T->isMemberDataPointer();
3745db68e28c05a67735211e688009890cf834c22e75Douglas Gregor  else
3746db68e28c05a67735211e688009890cf834c22e75Douglas Gregor    return false;
3747db68e28c05a67735211e688009890cf834c22e75Douglas Gregor}
3748611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isArrayType() const {
3749a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<ArrayType>(CanonicalType);
3750611c1fff195d32df97706e0920c92468b2509900Chris Lattner}
3751c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattnerinline bool Type::isConstantArrayType() const {
3752a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<ConstantArrayType>(CanonicalType);
3753c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner}
3754c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattnerinline bool Type::isIncompleteArrayType() const {
3755a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<IncompleteArrayType>(CanonicalType);
3756c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner}
3757c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattnerinline bool Type::isVariableArrayType() const {
3758a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<VariableArrayType>(CanonicalType);
3759c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner}
3760898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorinline bool Type::isDependentSizedArrayType() const {
3761a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<DependentSizedArrayType>(CanonicalType);
3762898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor}
37633ff83dd534ccc828203670ce3f5125a4eb4199f8John McCallinline bool Type::isBuiltinType() const {
37643ff83dd534ccc828203670ce3f5125a4eb4199f8John McCall  return isa<BuiltinType>(CanonicalType);
37653ff83dd534ccc828203670ce3f5125a4eb4199f8John McCall}
3766611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isRecordType() const {
3767a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<RecordType>(CanonicalType);
3768611c1fff195d32df97706e0920c92468b2509900Chris Lattner}
37693ff83dd534ccc828203670ce3f5125a4eb4199f8John McCallinline bool Type::isEnumeralType() const {
37703ff83dd534ccc828203670ce3f5125a4eb4199f8John McCall  return isa<EnumType>(CanonicalType);
37713ff83dd534ccc828203670ce3f5125a4eb4199f8John McCall}
3772f23d364084d1aabea688222780d6fc1dd8c7f78cChris Lattnerinline bool Type::isAnyComplexType() const {
3773a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<ComplexType>(CanonicalType);
3774f23d364084d1aabea688222780d6fc1dd8c7f78cChris Lattner}
3775611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isVectorType() const {
3776a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<VectorType>(CanonicalType);
3777611c1fff195d32df97706e0920c92468b2509900Chris Lattner}
3778213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begemaninline bool Type::isExtVectorType() const {
3779a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<ExtVectorType>(CanonicalType);
3780611c1fff195d32df97706e0920c92468b2509900Chris Lattner}
3781d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroffinline bool Type::isObjCObjectPointerType() const {
3782a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<ObjCObjectPointerType>(CanonicalType);
3783d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff}
3784c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallinline bool Type::isObjCObjectType() const {
3785c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  return isa<ObjCObjectType>(CanonicalType);
3786368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner}
3787569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregorinline bool Type::isObjCObjectOrInterfaceType() const {
3788569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor  return isa<ObjCInterfaceType>(CanonicalType) ||
3789569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor    isa<ObjCObjectType>(CanonicalType);
3790569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor}
3791569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor
3792a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekinline bool Type::isObjCQualifiedIdType() const {
3793183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>())
3794d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff    return OPT->isObjCQualifiedIdType();
3795d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff  return false;
3796d58fabf7ed279be18a5e82617f809c9deff9be67Fariborz Jahanian}
3797470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroffinline bool Type::isObjCQualifiedClassType() const {
3798183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>())
3799470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroff    return OPT->isObjCQualifiedClassType();
3800470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroff  return false;
3801470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroff}
380214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroffinline bool Type::isObjCIdType() const {
3803183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>())
380414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff    return OPT->isObjCIdType();
380514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  return false;
380614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff}
380714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroffinline bool Type::isObjCClassType() const {
3808183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>())
380914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff    return OPT->isObjCClassType();
381014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  return false;
381114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff}
381213dcd00615de5c4279d97bdf63cd5f0a14fd9dccFariborz Jahanianinline bool Type::isObjCSelType() const {
38138d2c0a9814e56c2b22e22d1045181c735aef62fdFariborz Jahanian  if (const PointerType *OPT = getAs<PointerType>())
38148d2c0a9814e56c2b22e22d1045181c735aef62fdFariborz Jahanian    return OPT->getPointeeType()->isSpecificBuiltinType(BuiltinType::ObjCSel);
381513dcd00615de5c4279d97bdf63cd5f0a14fd9dccFariborz Jahanian  return false;
381613dcd00615de5c4279d97bdf63cd5f0a14fd9dccFariborz Jahanian}
3817de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroffinline bool Type::isObjCBuiltinType() const {
381813dcd00615de5c4279d97bdf63cd5f0a14fd9dccFariborz Jahanian  return isObjCIdType() || isObjCClassType() || isObjCSelType();
3819de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff}
382072c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregorinline bool Type::isTemplateTypeParmType() const {
3821a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<TemplateTypeParmType>(CanonicalType);
382272c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor}
382372c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor
3824e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbarinline bool Type::isSpecificBuiltinType(unsigned K) const {
3825183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  if (const BuiltinType *BT = getAs<BuiltinType>())
3826e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar    if (BT->getKind() == (BuiltinType::Kind) K)
3827e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar      return true;
3828e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar  return false;
3829e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar}
3830e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar
38312a984cad5ac3fdceeff2bd99daa7b90979313475John McCallinline bool Type::isPlaceholderType() const {
38322a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  if (const BuiltinType *BT = getAs<BuiltinType>())
38332a984cad5ac3fdceeff2bd99daa7b90979313475John McCall    return BT->isPlaceholderType();
38342a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  return false;
38352a984cad5ac3fdceeff2bd99daa7b90979313475John McCall}
38362a984cad5ac3fdceeff2bd99daa7b90979313475John McCall
3837063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor/// \brief Determines whether this is a type for which one can define
3838063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor/// an overloaded operator.
3839063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregorinline bool Type::isOverloadableType() const {
3840063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  return isDependentType() || isRecordType() || isEnumeralType();
3841904eed3f6148758d39a2d3c88f3133274460d645Douglas Gregor}
3842904eed3f6148758d39a2d3c88f3133274460d645Douglas Gregor
38438958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbarinline bool Type::hasPointerRepresentation() const {
38448958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar  return (isPointerType() || isReferenceType() || isBlockPointerType() ||
3845c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall          isObjCObjectPointerType() || isNullPtrType());
38468958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar}
38478958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar
3848820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanianinline bool Type::hasObjCPointerRepresentation() const {
3849c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  return isObjCObjectPointerType();
3850820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian}
3851820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian
385222caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner/// Insertion operator for diagnostics.  This allows sending QualType's into a
385322caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner/// diagnostic with <<.
385422caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattnerinline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
385522caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner                                           QualType T) {
385622caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner  DB.AddTaggedVal(reinterpret_cast<intptr_t>(T.getAsOpaquePtr()),
385722caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner                  Diagnostic::ak_qualtype);
385822caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner  return DB;
385922caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner}
38601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
386147c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth/// Insertion operator for partial diagnostics.  This allows sending QualType's
386247c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth/// into a diagnostic with <<.
386347c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruthinline const PartialDiagnostic &operator<<(const PartialDiagnostic &PD,
386447c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth                                           QualType T) {
386547c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth  PD.AddTaggedVal(reinterpret_cast<intptr_t>(T.getAsOpaquePtr()),
386647c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth                  Diagnostic::ak_qualtype);
386747c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth  return PD;
386847c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth}
386947c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth
387089c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor// Helper class template that is used by Type::getAs to ensure that one does
387189c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor// not try to look through a qualified type to get to an array type.
387289c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregortemplate<typename T,
387389c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor         bool isArrayType = (llvm::is_same<T, ArrayType>::value ||
387489c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor                             llvm::is_base_of<ArrayType, T>::value)>
387589c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregorstruct ArrayType_cannot_be_used_with_getAs { };
387689c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor
387789c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregortemplate<typename T>
387889c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregorstruct ArrayType_cannot_be_used_with_getAs<T, true>;
387989c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor
38801a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek/// Member-template getAs<specific type>'.
38811a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenektemplate <typename T> const T *Type::getAs() const {
388289c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor  ArrayType_cannot_be_used_with_getAs<T> at;
388389c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor  (void)at;
388489c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor
38851a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek  // If this is directly a T type, return it.
38861a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek  if (const T *Ty = dyn_cast<T>(this))
38871a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek    return Ty;
38881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
38891a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek  // If the canonical form of this type isn't the right kind, reject it.
38900953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  if (!isa<T>(CanonicalType))
38911a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek    return 0;
38921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
38930953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // If this is a typedef for the type, strip the typedef off without
38941a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek  // losing all typedef information.
3895bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  return cast<T>(getUnqualifiedDesugaredType());
38961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump}
389722caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner
38985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}  // end namespace clang
38995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
39005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif
3901