Type.h revision 82287d19ded35248c4ce6a425ce74116a13ce44e
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"
20e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor#include "clang/AST/NestedNameSpecifier.h"
217532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor#include "clang/AST/TemplateName.h"
225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "llvm/Support/Casting.h"
2350d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor#include "llvm/Support/type_traits.h"
24fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff#include "llvm/ADT/APSInt.h"
255cf243a883872441d73ca49cea7e20de5802629bChris Lattner#include "llvm/ADT/FoldingSet.h"
265cf243a883872441d73ca49cea7e20de5802629bChris Lattner#include "llvm/ADT/PointerIntPair.h"
271734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor#include "llvm/ADT/PointerUnion.h"
287532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor
295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing llvm::isa;
305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing llvm::cast;
315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing llvm::cast_or_null;
325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing llvm::dyn_cast;
335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing llvm::dyn_cast_or_null;
346b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCallnamespace clang {
356b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall  enum {
366b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall    TypeAlignmentInBits = 3,
376b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall    TypeAlignment = 1 << TypeAlignmentInBits
386b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall  };
39aed1df80bf64228e1429c1edc408397f9174847cChris Lattner  class Type;
40aed1df80bf64228e1429c1edc408397f9174847cChris Lattner  class ExtQuals;
41aed1df80bf64228e1429c1edc408397f9174847cChris Lattner  class QualType;
426b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall}
435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
444e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattnernamespace llvm {
454e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner  template <typename T>
46daae940507f2e93c6fa12e8062fa958e34cc2d1cChris Lattner  class PointerLikeTypeTraits;
47bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner  template<>
48bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner  class PointerLikeTypeTraits< ::clang::Type*> {
49bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner  public:
50bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner    static inline void *getAsVoidPointer(::clang::Type *P) { return P; }
51bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner    static inline ::clang::Type *getFromVoidPointer(void *P) {
52bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner      return static_cast< ::clang::Type*>(P);
53bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner    }
546b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall    enum { NumLowBitsAvailable = clang::TypeAlignmentInBits };
55bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner  };
560953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  template<>
570953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  class PointerLikeTypeTraits< ::clang::ExtQuals*> {
580953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  public:
590953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    static inline void *getAsVoidPointer(::clang::ExtQuals *P) { return P; }
600953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    static inline ::clang::ExtQuals *getFromVoidPointer(void *P) {
610953e767ff7817f97b3ab20896b229891eeff45bJohn McCall      return static_cast< ::clang::ExtQuals*>(P);
620953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    }
636b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall    enum { NumLowBitsAvailable = clang::TypeAlignmentInBits };
640953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  };
65aed1df80bf64228e1429c1edc408397f9174847cChris Lattner
66aed1df80bf64228e1429c1edc408397f9174847cChris Lattner  template <>
67aed1df80bf64228e1429c1edc408397f9174847cChris Lattner  struct isPodLike<clang::QualType> { static const bool value = true; };
684e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner}
694e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner
705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang {
715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class ASTContext;
725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class TypedefDecl;
7355f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  class TemplateDecl;
7472c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor  class TemplateTypeParmDecl;
75aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor  class NonTypeTemplateParmDecl;
767532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor  class TemplateTemplateParmDecl;
775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class TagDecl;
785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class RecordDecl;
7949aa7ff1245abd03e6e998e01302df31e4c6f8f6Argyrios Kyrtzidis  class CXXRecordDecl;
805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class EnumDecl;
8121d50e12c3c412d8457071dc419363b7a7e8b855Ted Kremenek  class FieldDecl;
82a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  class ObjCInterfaceDecl;
83a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  class ObjCProtocolDecl;
84a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  class ObjCMethodDecl;
85ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  class UnresolvedUsingTypenameDecl;
865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class Expr;
87b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek  class Stmt;
885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class SourceLocation;
8992866e2e90f6d93fb95e25a7ac4438e239d89ce6Ted Kremenek  class StmtIteratorBase;
9040808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  class TemplateArgument;
91833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  class TemplateArgumentLoc;
92d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  class TemplateArgumentListInfo;
93e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor  class QualifiedNameType;
943b4ea54acf01f72f6eb74d96689dda86d950228fDaniel Dunbar  struct PrintingPolicy;
9572564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor
9672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  // Provide forward declarations for all of the *Type classes
9772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#define TYPE(Class, Base) class Class##Type;
9872564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#include "clang/AST/TypeNodes.def"
99f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl
1000953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// Qualifiers - The collection of all-type qualifiers we support.
1010953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// Clang supports five independent qualifiers:
1020953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// * C99: const, volatile, and restrict
1030953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// * Embedded C (TR18037): address spaces
1040953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// * Objective C: the GC attributes (none, weak, or strong)
1050953e767ff7817f97b3ab20896b229891eeff45bJohn McCallclass Qualifiers {
1065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
1070953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  enum TQ { // NOTE: These flags must be kept in sync with DeclSpec::TQ.
1085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Const    = 0x1,
1095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Restrict = 0x2,
1105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Volatile = 0x4,
1110953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    CVRMask = Const | Volatile | Restrict
1125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
1131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1140953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  enum GC {
115d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian    GCNone = 0,
116d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian    Weak,
117d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian    Strong
118d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian  };
119efadb7768e7c7418185f5a4010ecd8b21ca9731bJohn McCall
1200953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  enum {
1210953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    /// The maximum supported address space number.
1220953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    /// 24 bits should be enough for anyone.
1230953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    MaxAddressSpace = 0xffffffu,
1240953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
1250953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    /// The width of the "fast" qualifier mask.
1260953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    FastWidth = 2,
1270953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
1280953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    /// The fast qualifier mask.
1290953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    FastMask = (1 << FastWidth) - 1
1300953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  };
1310953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
1320953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  Qualifiers() : Mask(0) {}
1330953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
1340953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  static Qualifiers fromFastMask(unsigned Mask) {
1350953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Qualifiers Qs;
1360953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Qs.addFastQualifiers(Mask);
1370953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return Qs;
1380953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
1390953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
1400953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  static Qualifiers fromCVRMask(unsigned CVR) {
1410953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Qualifiers Qs;
1420953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Qs.addCVRQualifiers(CVR);
1430953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return Qs;
1440953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
1450953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
1460953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Deserialize qualifiers from an opaque representation.
1470953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  static Qualifiers fromOpaqueValue(unsigned opaque) {
1480953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Qualifiers Qs;
1490953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Qs.Mask = opaque;
1500953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return Qs;
1510953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
1520953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
1530953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Serialize these qualifiers into an opaque representation.
1540953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  unsigned getAsOpaqueValue() const {
1550953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return Mask;
1560953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
1570953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
1580953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool hasConst() const { return Mask & Const; }
1590953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void setConst(bool flag) {
1600953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask = (Mask & ~Const) | (flag ? Const : 0);
1610953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
1620953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void removeConst() { Mask &= ~Const; }
1630953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void addConst() { Mask |= Const; }
1640953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
1650953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool hasVolatile() const { return Mask & Volatile; }
1660953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void setVolatile(bool flag) {
1670953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask = (Mask & ~Volatile) | (flag ? Volatile : 0);
1680953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
1690953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void removeVolatile() { Mask &= ~Volatile; }
1700953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void addVolatile() { Mask |= Volatile; }
1710953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
1720953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool hasRestrict() const { return Mask & Restrict; }
1730953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void setRestrict(bool flag) {
1740953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask = (Mask & ~Restrict) | (flag ? Restrict : 0);
1750953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
1760953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void removeRestrict() { Mask &= ~Restrict; }
1770953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void addRestrict() { Mask |= Restrict; }
1780953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
1790953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool hasCVRQualifiers() const { return getCVRQualifiers(); }
1800953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  unsigned getCVRQualifiers() const { return Mask & CVRMask; }
1810953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void setCVRQualifiers(unsigned mask) {
1820953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(!(mask & ~CVRMask) && "bitmask contains non-CVR bits");
1830953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask = (Mask & ~CVRMask) | mask;
1840953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
1850953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void removeCVRQualifiers(unsigned mask) {
1860953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(!(mask & ~CVRMask) && "bitmask contains non-CVR bits");
1870953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask &= ~mask;
1880953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
1890953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void removeCVRQualifiers() {
1900953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    removeCVRQualifiers(CVRMask);
1910953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
1920953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void addCVRQualifiers(unsigned mask) {
1930953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(!(mask & ~CVRMask) && "bitmask contains non-CVR bits");
1940953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask |= mask;
1950953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
1960953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
1970953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool hasObjCGCAttr() const { return Mask & GCAttrMask; }
1980953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  GC getObjCGCAttr() const { return GC((Mask & GCAttrMask) >> GCAttrShift); }
1990953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void setObjCGCAttr(GC type) {
2000953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask = (Mask & ~GCAttrMask) | (type << GCAttrShift);
2010953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2020953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void removeObjCGCAttr() { setObjCGCAttr(GCNone); }
2030953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void addObjCGCAttr(GC type) {
2040953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(type);
2050953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    setObjCGCAttr(type);
2060953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2070953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
2080953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool hasAddressSpace() const { return Mask & AddressSpaceMask; }
2090953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  unsigned getAddressSpace() const { return Mask >> AddressSpaceShift; }
2100953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void setAddressSpace(unsigned space) {
2110953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(space <= MaxAddressSpace);
2120953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask = (Mask & ~AddressSpaceMask)
2130953e767ff7817f97b3ab20896b229891eeff45bJohn McCall         | (((uint32_t) space) << AddressSpaceShift);
2140953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2150953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void removeAddressSpace() { setAddressSpace(0); }
2160953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void addAddressSpace(unsigned space) {
2170953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(space);
2180953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    setAddressSpace(space);
2190953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2200953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
2210953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Fast qualifiers are those that can be allocated directly
2220953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // on a QualType object.
2230953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool hasFastQualifiers() const { return getFastQualifiers(); }
2240953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  unsigned getFastQualifiers() const { return Mask & FastMask; }
2250953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void setFastQualifiers(unsigned mask) {
2260953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(!(mask & ~FastMask) && "bitmask contains non-fast qualifier bits");
2270953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask = (Mask & ~FastMask) | mask;
2280953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2290953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void removeFastQualifiers(unsigned mask) {
2300953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(!(mask & ~FastMask) && "bitmask contains non-fast qualifier bits");
2310953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask &= ~mask;
2320953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2330953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void removeFastQualifiers() {
2340953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    removeFastQualifiers(FastMask);
2350953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2360953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void addFastQualifiers(unsigned mask) {
2370953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(!(mask & ~FastMask) && "bitmask contains non-fast qualifier bits");
2380953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask |= mask;
2390953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2400953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
2410953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// hasNonFastQualifiers - Return true if the set contains any
2420953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// qualifiers which require an ExtQuals node to be allocated.
2430953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool hasNonFastQualifiers() const { return Mask & ~FastMask; }
2440953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  Qualifiers getNonFastQualifiers() const {
2450953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Qualifiers Quals = *this;
2460953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Quals.setFastQualifiers(0);
2470953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return Quals;
2480953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2490953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
2500953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// hasQualifiers - Return true if the set contains any qualifiers.
2510953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool hasQualifiers() const { return Mask; }
2520953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool empty() const { return !Mask; }
2530953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
2540953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// \brief Add the qualifiers from the given set to this set.
2550953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void addQualifiers(Qualifiers Q) {
2560953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    // If the other set doesn't have any non-boolean qualifiers, just
2570953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    // bit-or it in.
2580953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    if (!(Q.Mask & ~CVRMask))
2590953e767ff7817f97b3ab20896b229891eeff45bJohn McCall      Mask |= Q.Mask;
2600953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    else {
2610953e767ff7817f97b3ab20896b229891eeff45bJohn McCall      Mask |= (Q.Mask & CVRMask);
2620953e767ff7817f97b3ab20896b229891eeff45bJohn McCall      if (Q.hasAddressSpace())
2630953e767ff7817f97b3ab20896b229891eeff45bJohn McCall        addAddressSpace(Q.getAddressSpace());
2640953e767ff7817f97b3ab20896b229891eeff45bJohn McCall      if (Q.hasObjCGCAttr())
2650953e767ff7817f97b3ab20896b229891eeff45bJohn McCall        addObjCGCAttr(Q.getObjCGCAttr());
2660953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    }
2670953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2680953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
2690953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool operator==(Qualifiers Other) const { return Mask == Other.Mask; }
2700953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool operator!=(Qualifiers Other) const { return Mask != Other.Mask; }
2710953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
2720953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  operator bool() const { return hasQualifiers(); }
2730953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
2740953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  Qualifiers &operator+=(Qualifiers R) {
2750953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    addQualifiers(R);
2760953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return *this;
2770953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2780953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
2790953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Union two qualifier sets.  If an enumerated qualifier appears
2800953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // in both sets, use the one from the right.
2810953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  friend Qualifiers operator+(Qualifiers L, Qualifiers R) {
2820953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    L += R;
2830953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return L;
2840953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2850953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
2860953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  std::string getAsString() const;
2870953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  std::string getAsString(const PrintingPolicy &Policy) const {
2880953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    std::string Buffer;
2890953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    getAsStringInternal(Buffer, Policy);
2900953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return Buffer;
2910953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2920953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void getAsStringInternal(std::string &S, const PrintingPolicy &Policy) const;
2930953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
2940953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void Profile(llvm::FoldingSetNodeID &ID) const {
2950953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    ID.AddInteger(Mask);
2960953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2970953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
2980953e767ff7817f97b3ab20896b229891eeff45bJohn McCallprivate:
2990953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3000953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // bits:     |0 1 2|3 .. 4|5  ..  31|
3010953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  //           |C R V|GCAttr|AddrSpace|
3020953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  uint32_t Mask;
3030953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3040953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  static const uint32_t GCAttrMask = 0x18;
3050953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  static const uint32_t GCAttrShift = 3;
3060953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  static const uint32_t AddressSpaceMask = ~(CVRMask | GCAttrMask);
3070953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  static const uint32_t AddressSpaceShift = 5;
3080953e767ff7817f97b3ab20896b229891eeff45bJohn McCall};
3090953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3100953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3110953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// ExtQuals - We can encode up to three bits in the low bits of a
3120953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// type pointer, but there are many more type qualifiers that we want
3130953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// to be able to apply to an arbitrary type.  Therefore we have this
3140953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// struct, intended to be heap-allocated and used by QualType to
3150953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// store qualifiers.
3160953e767ff7817f97b3ab20896b229891eeff45bJohn McCall///
3170953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// The current design tags the 'const' and 'restrict' qualifiers in
3180953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// two low bits on the QualType pointer; a third bit records whether
3190953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// the pointer is an ExtQuals node.  'const' was chosen because it is
3200953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// orders of magnitude more common than the other two qualifiers, in
3210953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// both library and user code.  It's relatively rare to see
3220953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// 'restrict' in user code, but many standard C headers are saturated
3230953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// with 'restrict' declarations, so that representing them efficiently
3240953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// is a critical goal of this representation.
3250953e767ff7817f97b3ab20896b229891eeff45bJohn McCallclass ExtQuals : public llvm::FoldingSetNode {
3260953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // NOTE: changing the fast qualifiers should be straightforward as
3270953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // long as you don't make 'const' non-fast.
3280953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // 1. Qualifiers:
3290953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  //    a) Modify the bitmasks (Qualifiers::TQ and DeclSpec::TQ).
3300953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  //       Fast qualifiers must occupy the low-order bits.
3310953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  //    b) Update Qualifiers::FastWidth and FastMask.
3320953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // 2. QualType:
3330953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  //    a) Update is{Volatile,Restrict}Qualified(), defined inline.
3340953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  //    b) Update remove{Volatile,Restrict}, defined near the end of
3350953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  //       this header.
3360953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // 3. ASTContext:
3370953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  //    a) Update get{Volatile,Restrict}Type.
3380953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3390953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// Context - the context to which this set belongs.  We save this
3400953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// here so that QualifierCollector can use it to reapply extended
3410953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// qualifiers to an arbitrary type without requiring a context to
3420953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// be pushed through every single API dealing with qualifiers.
3430953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  ASTContext& Context;
3440953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3450953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// BaseType - the underlying type that this qualifies
3460953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  const Type *BaseType;
3470953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3480953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// Quals - the immutable set of qualifiers applied by this
3490953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// node;  always contains extended qualifiers.
3500953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  Qualifiers Quals;
3510953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3520953e767ff7817f97b3ab20896b229891eeff45bJohn McCallpublic:
3530953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  ExtQuals(ASTContext& Context, const Type *Base, Qualifiers Quals)
3540953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    : Context(Context), BaseType(Base), Quals(Quals)
3550953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  {
3560953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(Quals.hasNonFastQualifiers()
3570953e767ff7817f97b3ab20896b229891eeff45bJohn McCall           && "ExtQuals created with no fast qualifiers");
3580953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(!Quals.hasFastQualifiers()
3590953e767ff7817f97b3ab20896b229891eeff45bJohn McCall           && "ExtQuals created with fast qualifiers");
3600953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
3610953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3620953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  Qualifiers getQualifiers() const { return Quals; }
3630953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3640953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool hasVolatile() const { return Quals.hasVolatile(); }
3650953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3660953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool hasObjCGCAttr() const { return Quals.hasObjCGCAttr(); }
3670953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  Qualifiers::GC getObjCGCAttr() const { return Quals.getObjCGCAttr(); }
3680953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3690953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool hasAddressSpace() const { return Quals.hasAddressSpace(); }
3700953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  unsigned getAddressSpace() const { return Quals.getAddressSpace(); }
3710953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3720953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  const Type *getBaseType() const { return BaseType; }
3731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3740953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  ASTContext &getContext() const { return Context; }
3750953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3760953e767ff7817f97b3ab20896b229891eeff45bJohn McCallpublic:
3770953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void Profile(llvm::FoldingSetNodeID &ID) const {
3780953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Profile(ID, getBaseType(), Quals);
3790953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
3800953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  static void Profile(llvm::FoldingSetNodeID &ID,
3810953e767ff7817f97b3ab20896b229891eeff45bJohn McCall                      const Type *BaseType,
3820953e767ff7817f97b3ab20896b229891eeff45bJohn McCall                      Qualifiers Quals) {
3830953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(!Quals.hasFastQualifiers() && "fast qualifiers in ExtQuals hash!");
3840953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    ID.AddPointer(BaseType);
3850953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Quals.Profile(ID);
3860953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
3870953e767ff7817f97b3ab20896b229891eeff45bJohn McCall};
3880953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
389ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor/// CallingConv - Specifies the calling convention that a function uses.
390ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregorenum CallingConv {
391ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor  CC_Default,
392ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor  CC_C,           // __attribute__((cdecl))
393ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor  CC_X86StdCall,  // __attribute__((stdcall))
394ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor  CC_X86FastCall  // __attribute__((fastcall))
395ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor};
396ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor
3970953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3980953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// QualType - For efficiency, we don't store CV-qualified types as nodes on
3990953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// their own: instead each reference to a type stores the qualifiers.  This
4000953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// greatly reduces the number of nodes we need to allocate for types (for
4010953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// example we only need one for 'int', 'const int', 'volatile int',
4020953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// 'const volatile int', etc).
4030953e767ff7817f97b3ab20896b229891eeff45bJohn McCall///
4040953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// As an added efficiency bonus, instead of making this a pair, we
4050953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// just store the two bits we care about in the low bits of the
4060953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// pointer.  To handle the packing/unpacking, we make QualType be a
4070953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// simple wrapper class that acts like a smart pointer.  A third bit
4080953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// indicates whether there are extended qualifiers present, in which
4090953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// case the pointer points to a special structure.
4100953e767ff7817f97b3ab20896b229891eeff45bJohn McCallclass QualType {
4110953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Thankfully, these are efficiently composable.
4120953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  llvm::PointerIntPair<llvm::PointerUnion<const Type*,const ExtQuals*>,
4130953e767ff7817f97b3ab20896b229891eeff45bJohn McCall                       Qualifiers::FastWidth> Value;
4140953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
4150953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  const ExtQuals *getExtQualsUnsafe() const {
4160953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return Value.getPointer().get<const ExtQuals*>();
4170953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
4180953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
4190953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  const Type *getTypePtrUnsafe() const {
4200953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return Value.getPointer().get<const Type*>();
4210953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
4220953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
423fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  QualType getUnqualifiedTypeSlow() const;
424fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor
4250953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  friend class QualifierCollector;
4260953e767ff7817f97b3ab20896b229891eeff45bJohn McCallpublic:
4275cf243a883872441d73ca49cea7e20de5802629bChris Lattner  QualType() {}
4281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4295cf243a883872441d73ca49cea7e20de5802629bChris Lattner  QualType(const Type *Ptr, unsigned Quals)
4300953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    : Value(Ptr, Quals) {}
4310953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  QualType(const ExtQuals *Ptr, unsigned Quals)
4320953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    : Value(Ptr, Quals) {}
4330953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
434a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  unsigned getLocalFastQualifiers() const { return Value.getInt(); }
435a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  void setLocalFastQualifiers(unsigned Quals) { Value.setInt(Quals); }
4365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4370953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// Retrieves a pointer to the underlying (unqualified) type.
4380953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// This should really return a const Type, but it's not worth
4390953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// changing all the users right now.
4400953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  Type *getTypePtr() const {
441a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor    if (hasLocalNonFastQualifiers())
4420953e767ff7817f97b3ab20896b229891eeff45bJohn McCall      return const_cast<Type*>(getExtQualsUnsafe()->getBaseType());
4430953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return const_cast<Type*>(getTypePtrUnsafe());
4440953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
4451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4465cf243a883872441d73ca49cea7e20de5802629bChris Lattner  void *getAsOpaquePtr() const { return Value.getOpaqueValue(); }
4475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static QualType getFromOpaquePtr(void *Ptr) {
4485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    QualType T;
4495cf243a883872441d73ca49cea7e20de5802629bChris Lattner    T.Value.setFromOpaqueValue(Ptr);
4505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T;
4515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
4521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Type &operator*() const {
4545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return *getTypePtr();
4555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
4565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Type *operator->() const {
4585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return getTypePtr();
4595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
4601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
461467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall  bool isCanonical() const;
46254e14c4db764c0636160d26c5bbf491637c83a76John McCall  bool isCanonicalAsParam() const;
463467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall
4645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isNull - Return true if this QualType doesn't point to a type yet.
4655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isNull() const {
4660953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return Value.getPointer().isNull();
4675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
4685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
469a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Determine whether this particular QualType instance has the
470a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// "const" qualifier set, without looking through typedefs that may have
471a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// added "const" at a different level.
472a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  bool isLocalConstQualified() const {
473a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor    return (getLocalFastQualifiers() & Qualifiers::Const);
4740953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
475a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor
476a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Determine whether this type is const-qualified.
477fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  bool isConstQualified() const;
478a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor
479a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Determine whether this particular QualType instance has the
480a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// "restrict" qualifier set, without looking through typedefs that may have
481a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// added "restrict" at a different level.
482a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  bool isLocalRestrictQualified() const {
483a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor    return (getLocalFastQualifiers() & Qualifiers::Restrict);
484a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  }
485a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor
486a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Determine whether this type is restrict-qualified.
487fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  bool isRestrictQualified() const;
488a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor
489a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Determine whether this particular QualType instance has the
490a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// "volatile" qualifier set, without looking through typedefs that may have
491a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// added "volatile" at a different level.
492a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  bool isLocalVolatileQualified() const {
493a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor    return (hasLocalNonFastQualifiers() && getExtQualsUnsafe()->hasVolatile());
4945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
4950953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
496a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Determine whether this type is volatile-qualified.
497fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  bool isVolatileQualified() const;
498a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor
499a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Determine whether this particular QualType instance has any
500a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// qualifiers, without looking through any typedefs that might add
501a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// qualifiers at a different level.
502a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  bool hasLocalQualifiers() const {
503a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor    return getLocalFastQualifiers() || hasLocalNonFastQualifiers();
5040953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
5050953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
506a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Determine whether this type has any qualifiers.
507fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  bool hasQualifiers() const;
508a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor
509a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Determine whether this particular QualType instance has any
510a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// "non-fast" qualifiers, e.g., those that are stored in an ExtQualType
511a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// instance.
512a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  bool hasLocalNonFastQualifiers() const {
513a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor    return Value.getPointer().is<const ExtQuals*>();
5140953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
5150953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
516a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Retrieve the set of qualifiers local to this particular QualType
517a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// instance, not including any qualifiers acquired through typedefs or
518a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// other sugar.
519a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  Qualifiers getLocalQualifiers() const {
5200953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Qualifiers Quals;
521a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor    if (hasLocalNonFastQualifiers())
5220953e767ff7817f97b3ab20896b229891eeff45bJohn McCall      Quals = getExtQualsUnsafe()->getQualifiers();
523a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor    Quals.addFastQualifiers(getLocalFastQualifiers());
5240953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return Quals;
5250953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
5260953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
527a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Retrieve the set of qualifiers applied to this type.
528fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  Qualifiers getQualifiers() const;
529a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor
530a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Retrieve the set of CVR (const-volatile-restrict) qualifiers
531a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// local to this particular QualType instance, not including any qualifiers
532a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// acquired through typedefs or other sugar.
533a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  unsigned getLocalCVRQualifiers() const {
534a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor    unsigned CVR = getLocalFastQualifiers();
535a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor    if (isLocalVolatileQualified())
536a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor      CVR |= Qualifiers::Volatile;
5370953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return CVR;
5385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
539b381aac9bae6d608c72267dd0ed08ec6369e94e4Nuno Lopes
540a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Retrieve the set of CVR (const-volatile-restrict) qualifiers
541a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// applied to this type.
542fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  unsigned getCVRQualifiers() const;
543e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth
544e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth  /// \brief Retrieve the set of CVR (const-volatile-restrict) qualifiers
545e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth  /// applied to this type, looking through any number of unqualified array
546e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth  /// types to their element types' qualifiers.
547e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth  unsigned getCVRQualifiersThroughArrayTypes() const;
548e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth
549bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isConstant(ASTContext& Ctx) const {
550bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall    return QualType::isConstant(*this, Ctx);
551bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  }
5521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5530953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Don't promise in the API that anything besides 'const' can be
5540953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // easily added.
5550953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
5560953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// addConst - add the specified type qualifier to this QualType.
5570953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void addConst() {
5580953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    addFastQualifiers(Qualifiers::Const);
5590953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
5600953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  QualType withConst() const {
5610953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return withFastQualifiers(Qualifiers::Const);
5620953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
5630953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
5640953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void addFastQualifiers(unsigned TQs) {
5650953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(!(TQs & ~Qualifiers::FastMask)
5660953e767ff7817f97b3ab20896b229891eeff45bJohn McCall           && "non-fast qualifier bits set in mask!");
5670953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Value.setInt(Value.getInt() | TQs);
5680953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
5690953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
570a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  // FIXME: The remove* functions are semantically broken, because they might
571a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  // not remove a qualifier stored on a typedef. Most of the with* functions
572a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  // have the same problem.
5730953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void removeConst();
5740953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void removeVolatile();
5750953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void removeRestrict();
5760953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void removeCVRQualifiers(unsigned Mask);
5770953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
5780953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void removeFastQualifiers() { Value.setInt(0); }
5790953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void removeFastQualifiers(unsigned Mask) {
5800953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(!(Mask & ~Qualifiers::FastMask) && "mask has non-fast qualifiers");
5810953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Value.setInt(Value.getInt() & ~Mask);
5820953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
5835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
5840953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Creates a type with the given qualifiers in addition to any
5850953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // qualifiers already on this type.
5860953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  QualType withFastQualifiers(unsigned TQs) const {
5870953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    QualType T = *this;
5880953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    T.addFastQualifiers(TQs);
5890953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return T;
5900953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
5911c6a38bcea17801e9a4738753aee845381af2b6cSanjiv Gupta
5920953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Creates a type with exactly the given fast qualifiers, removing
5930953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // any existing fast qualifiers.
5940953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  QualType withExactFastQualifiers(unsigned TQs) const {
5950953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return withoutFastQualifiers().withFastQualifiers(TQs);
5965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
5970953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
5980953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Removes fast qualifiers, but leaves any extended qualifiers in place.
5990953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  QualType withoutFastQualifiers() const {
6000953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    QualType T = *this;
6010953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    T.removeFastQualifiers();
6020953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return T;
603c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  }
604971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis
605a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Return this type with all of the instance-specific qualifiers
606a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// removed, but without removing any qualifiers that may have been applied
607a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// through typedefs.
608a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  QualType getLocalUnqualifiedType() const { return QualType(getTypePtr(), 0); }
6091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
610a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Return the unqualified form of the given type, which might be
611a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// desugared to eliminate qualifiers introduced via typedefs.
612fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  QualType getUnqualifiedType() const {
613fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor    QualType T = getLocalUnqualifiedType();
614fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor    if (!T.hasQualifiers())
615fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor      return T;
616fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor
617fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor    return getUnqualifiedTypeSlow();
618a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  }
619a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor
620e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor  bool isMoreQualifiedThan(QualType Other) const;
621e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor  bool isAtLeastAsQualifiedAs(QualType Other) const;
622e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor  QualType getNonReferenceType() const;
6231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6242fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner  /// getDesugaredType - Return the specified type with any "sugar" removed from
6252fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner  /// the type.  This takes off typedefs, typeof's etc.  If the outer level of
6262fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner  /// the type is already concrete, it returns it unmodified.  This is similar
6272fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner  /// to getting the canonical type, but it doesn't remove *all* typedefs.  For
6282fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner  /// example, it returns "T*" as "T*", (not as "int*"), because the pointer is
6292fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner  /// concrete.
6300953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  ///
6310953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// Qualifiers are left in place.
632bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType getDesugaredType() const {
633bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall    return QualType::getDesugaredType(*this);
634bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  }
63598cd599ee8a9b259ed7388ee2921a20d97658864Douglas Gregor
6365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// operator==/!= - Indicate whether the specified types and qualifiers are
6375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// identical.
63850d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor  friend bool operator==(const QualType &LHS, const QualType &RHS) {
63950d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor    return LHS.Value == RHS.Value;
6405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
64150d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor  friend bool operator!=(const QualType &LHS, const QualType &RHS) {
64250d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor    return LHS.Value != RHS.Value;
6435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
644d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor  std::string getAsString() const;
645d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor
646d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor  std::string getAsString(const PrintingPolicy &Policy) const {
6475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    std::string S;
648d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor    getAsStringInternal(S, Policy);
6495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return S;
6505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
651e4f2142d00fa5fdb580c4e2413da91882d955381Chris Lattner  void getAsStringInternal(std::string &Str,
652e4f2142d00fa5fdb580c4e2413da91882d955381Chris Lattner                           const PrintingPolicy &Policy) const;
6531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
654c36d405a02fab41f6c45cb2bc750d64949742903Chris Lattner  void dump(const char *s) const;
655c36d405a02fab41f6c45cb2bc750d64949742903Chris Lattner  void dump() const;
6561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6573f2dcb1ca8bd2d5d3ccc5c80f4ab06f949d88a89Ted Kremenek  void Profile(llvm::FoldingSetNodeID &ID) const {
6583f2dcb1ca8bd2d5d3ccc5c80f4ab06f949d88a89Ted Kremenek    ID.AddPointer(getAsOpaquePtr());
6593f2dcb1ca8bd2d5d3ccc5c80f4ab06f949d88a89Ted Kremenek  }
6605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
661ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb  /// getAddressSpace - Return the address space of this type.
662ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb  inline unsigned getAddressSpace() const;
6631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
664d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian  /// GCAttrTypesAttr - Returns gc attribute of this type.
6650953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  inline Qualifiers::GC getObjCGCAttr() const;
666f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian
667f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian  /// isObjCGCWeak true when Type is objc's weak.
668f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian  bool isObjCGCWeak() const {
6690953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return getObjCGCAttr() == Qualifiers::Weak;
670f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian  }
671f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian
672f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian  /// isObjCGCStrong true when Type is objc's strong.
673f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian  bool isObjCGCStrong() const {
6740953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return getObjCGCAttr() == Qualifiers::Strong;
675f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian  }
6762455636163fdd18581d7fdae816433f886d88213Mike Stump
677ae92140b542d5c1c096e39e74e59526184819b30Mike Stump  /// getNoReturnAttr - Returns true if the type has the noreturn attribute,
678ae92140b542d5c1c096e39e74e59526184819b30Mike Stump  /// false otherwise.
6792455636163fdd18581d7fdae816433f886d88213Mike Stump  bool getNoReturnAttr() const;
680bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
681ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor  /// getCallConv - Returns the calling convention of the type if the type
682ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor  /// is a function type, CC_Default otherwise.
683ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor  CallingConv getCallConv() const;
684ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor
685bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCallprivate:
686bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  // These methods are implemented in a separate translation unit;
687bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  // "static"-ize them to avoid creating temporary QualTypes in the
688bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  // caller.
689bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  static bool isConstant(QualType T, ASTContext& Ctx);
690bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  static QualType getDesugaredType(QualType T);
6915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
6925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
6935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end clang.
6945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
6955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace llvm {
6965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Implement simplify_type for QualType, so that we can dyn_cast from QualType
6975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// to a specific Type class.
6985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencertemplate<> struct simplify_type<const ::clang::QualType> {
6995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  typedef ::clang::Type* SimpleType;
7005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static SimpleType getSimplifiedValue(const ::clang::QualType &Val) {
7015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return Val.getTypePtr();
7025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
7035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
7045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencertemplate<> struct simplify_type< ::clang::QualType>
7055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  : public simplify_type<const ::clang::QualType> {};
7061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7074e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner// Teach SmallPtrSet that QualType is "basically a pointer".
7084e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattnertemplate<>
709daae940507f2e93c6fa12e8062fa958e34cc2d1cChris Lattnerclass PointerLikeTypeTraits<clang::QualType> {
7104e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattnerpublic:
7114e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner  static inline void *getAsVoidPointer(clang::QualType P) {
7124e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner    return P.getAsOpaquePtr();
7134e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner  }
7144e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner  static inline clang::QualType getFromVoidPointer(void *P) {
7154e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner    return clang::QualType::getFromOpaquePtr(P);
7164e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner  }
7170953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Various qualifiers go in low bits.
7180eda3b31a672ea486fa92b9bc49a2c91be856b53Chris Lattner  enum { NumLowBitsAvailable = 0 };
7194e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner};
7201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
72173af669633e13c813f80cd15ecf3e6414778aee4Ted Kremenek} // end namespace llvm
7225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang {
7245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Type - This is the base class of the type hierarchy.  A central concept
7265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// with types is that each type always has a canonical type.  A canonical type
7275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// is the type with any typedef names stripped out of it or the types it
7285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// references.  For example, consider:
7295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
7305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///  typedef int  foo;
7315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///  typedef foo* bar;
7325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///    'int *'    'foo *'    'bar'
7335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
7345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// There will be a Type object created for 'int'.  Since int is canonical, its
7355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// canonicaltype pointer points to itself.  There is also a Type for 'foo' (a
73672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// TypedefType).  Its CanonicalType pointer points to the 'int' Type.  Next
7375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// there is a PointerType that represents 'int*', which, like 'int', is
7385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// canonical.  Finally, there is a PointerType type for 'foo*' whose canonical
73972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// type is 'int*', and there is a TypedefType for 'bar', whose canonical type
7405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// is also 'int*'.
7415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
7425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Non-canonical types are useful for emitting diagnostics, without losing
7435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// information about typedefs being used.  Canonical types are useful for type
7445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// comparisons (they allow by-pointer equality tests) and useful for reasoning
7455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// about whether something has a particular form (e.g. is a function type),
7465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// because they implicitly, recursively, strip all typedefs out of a type.
7475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
7485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Types, once created, are immutable.
7495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
7505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass Type {
7515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
7525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  enum TypeClass {
75372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#define TYPE(Class, Base) Class,
75472564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#define ABSTRACT_TYPE(Class, Base)
75572564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#include "clang/AST/TypeNodes.def"
75672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor    TagFirst = Record, TagLast = Enum
7575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
7581bb8a45f7386a23871598d05141a07af03067925Argyrios Kyrtzidis
7591bb8a45f7386a23871598d05141a07af03067925Argyrios Kyrtzidisprotected:
7601bb8a45f7386a23871598d05141a07af03067925Argyrios Kyrtzidis  enum { TypeClassBitSize = 6 };
7611bb8a45f7386a23871598d05141a07af03067925Argyrios Kyrtzidis
7625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate:
7635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType CanonicalType;
7645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
765898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// Dependent - Whether this type is a dependent type (C++ [temp.dep.type]).
766898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  bool Dependent : 1;
767898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
7685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// TypeClass bitfield - Enum that specifies what subclass this belongs to.
7695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// Note that this should stay at the end of the ivars for Type so that
7705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// subclasses can pack their bitfields into the same word.
7711bb8a45f7386a23871598d05141a07af03067925Argyrios Kyrtzidis  unsigned TC : TypeClassBitSize;
772898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
77316ff705a594697f98b9473f9b7e7d378f331fe4bChris Lattner  Type(const Type&);           // DO NOT IMPLEMENT.
77416ff705a594697f98b9473f9b7e7d378f331fe4bChris Lattner  void operator=(const Type&); // DO NOT IMPLEMENT.
7755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprotected:
776124dd7b5777e29ecac006822bd4d4623f0dc4264Hartmut Kaiser  // silence VC++ warning C4355: 'this' : used in base member initializer list
777124dd7b5777e29ecac006822bd4d4623f0dc4264Hartmut Kaiser  Type *this_() { return this; }
778898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  Type(TypeClass tc, QualType Canonical, bool dependent)
779f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner    : CanonicalType(Canonical.isNull() ? QualType(this_(), 0) : Canonical),
780898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor      Dependent(dependent), TC(tc) {}
781898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  virtual ~Type() {}
7824b05b1dee6cc65ae61d93dab7edff72710f24589Ted Kremenek  virtual void Destroy(ASTContext& C);
7835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;
7841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7858b9023ba35a86838789e2c9034a6128728c547aaChris Lattnerpublic:
786a8ae51f79d35b7c1822ba4a086176b4a8c862862Hartmut Kaiser  TypeClass getTypeClass() const { return static_cast<TypeClass>(TC); }
7871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
788467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall  bool isCanonicalUnqualified() const {
789467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall    return CanonicalType.getTypePtr() == this;
790467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall  }
7915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// Types are partitioned into 3 broad categories (C99 6.2.5p1):
7935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// object types, function types, and incomplete types.
7941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
795bad0e656c3732e3539a9cd6525de721d7e47408bDouglas Gregor  /// \brief Determines whether the type describes an object in memory.
796bad0e656c3732e3539a9cd6525de721d7e47408bDouglas Gregor  ///
797bad0e656c3732e3539a9cd6525de721d7e47408bDouglas Gregor  /// Note that this definition of object type corresponds to the C++
798bad0e656c3732e3539a9cd6525de721d7e47408bDouglas Gregor  /// definition of object type, which includes incomplete types, as
799bad0e656c3732e3539a9cd6525de721d7e47408bDouglas Gregor  /// opposed to the C definition (which does not include incomplete
800bad0e656c3732e3539a9cd6525de721d7e47408bDouglas Gregor  /// types).
8015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isObjectType() const;
8025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
8035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isIncompleteType - Return true if this is an incomplete type.
8045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// A type that can describe objects, but which lacks information needed to
8055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// determine its size (e.g. void, or a fwd declared struct). Clients of this
8061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// routine will need to determine if the size is actually required.
8075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isIncompleteType() const;
808d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner
809d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner  /// isIncompleteOrObjectType - Return true if this is an incomplete or object
810d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner  /// type, in other words, not a function type.
811d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner  bool isIncompleteOrObjectType() const {
812d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner    return !isFunctionType();
813d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner  }
81464b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
81564b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  /// isPODType - Return true if this is a plain-old-data type (C++ 3.9p10).
81664b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl  bool isPODType() const;
81764b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
818ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl  /// isLiteralType - Return true if this is a literal type
819ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl  /// (C++0x [basic.types]p10)
820ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl  bool isLiteralType() const;
821ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl
822d7444aac1af1c2c1d5e5b7467ecf6006ee2d8abeSteve Naroff  /// isVariablyModifiedType (C99 6.7.5.2p2) - Return true for variable array
823d7444aac1af1c2c1d5e5b7467ecf6006ee2d8abeSteve Naroff  /// types that have a non-constant expression. This does not include "[]".
824d7444aac1af1c2c1d5e5b7467ecf6006ee2d8abeSteve Naroff  bool isVariablyModifiedType() const;
8251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// Helper methods to distinguish type categories. All type predicates
827ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb  /// operate on the canonical type, ignoring typedefs and qualifiers.
828e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar
829e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar  /// isSpecificBuiltinType - Test for a particular builtin type.
830e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar  bool isSpecificBuiltinType(unsigned K) const;
8311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
83296d2c438f5c9ada8229f7f2ac049d2e9957bc954Steve Naroff  /// isIntegerType() does *not* include complex integers (a GCC extension).
83396d2c438f5c9ada8229f7f2ac049d2e9957bc954Steve Naroff  /// isComplexIntegerType() can be used to test for complex integers.
8345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isIntegerType() const;     // C99 6.2.5p17 (int, char, bool, enum)
83513b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff  bool isEnumeralType() const;
83613b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff  bool isBooleanType() const;
83713b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff  bool isCharType() const;
83877a52233f7c0f162672652051bfe78b65ad4f789Douglas Gregor  bool isWideCharType() const;
83920093b4bf698f292c664676987541d5103b65b15Douglas Gregor  bool isAnyCharacterType() const;
84033e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian  bool isIntegralType() const;
84120093b4bf698f292c664676987541d5103b65b15Douglas Gregor
8425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// Floating point categories.
8435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isRealFloatingType() const; // C99 6.2.5p10 (float, double, long double)
84402f62a9fedbc370fba081303399410a3afdde29fSteve Naroff  /// isComplexType() does *not* include complex integers (a GCC extension).
84502f62a9fedbc370fba081303399410a3afdde29fSteve Naroff  /// isComplexIntegerType() can be used to test for complex integers.
8465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isComplexType() const;      // C99 6.2.5p11 (complex)
847f23d364084d1aabea688222780d6fc1dd8c7f78cChris Lattner  bool isAnyComplexType() const;   // C99 6.2.5p11 (complex) + Complex Int.
8485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isFloatingType() const;     // C99 6.2.5p11 (real floating + complex)
8495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isRealType() const;         // C99 6.2.5p17 (real floating + integer)
8505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isArithmeticType() const;   // C99 6.2.5p18 (integer + floating)
851c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  bool isVoidType() const;         // C99 6.2.5p19
852c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  bool isDerivedType() const;      // C99 6.2.5p20
853c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  bool isScalarType() const;       // C99 6.2.5p21 (arithmetic + pointers)
854d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor  bool isAggregateType() const;
8551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
856c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  // Type Predicates: Check to see if this type is structurally the specified
857ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb  // type, ignoring typedefs and qualifiers.
858c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  bool isFunctionType() const;
859183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  bool isFunctionNoProtoType() const { return getAs<FunctionNoProtoType>(); }
860183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  bool isFunctionProtoType() const { return getAs<FunctionProtoType>(); }
861befee48ff2a1dab236c5700f00ecca1cfdcd5837Chris Lattner  bool isPointerType() const;
86258f9f2c884af6b72d036b746a016d8031d31cb7aSteve Naroff  bool isAnyPointerType() const;   // Any C pointer or ObjC object pointer
8635618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  bool isBlockPointerType() const;
8647154a77e7c1f23418342d3b72836ab504aa7821eSteve Naroff  bool isVoidPointerType() const;
865a1d9fdea79ba7bbd71862b9f9f78f5f117331fc7Chris Lattner  bool isReferenceType() const;
8667c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  bool isLValueReferenceType() const;
8677c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  bool isRValueReferenceType() const;
868bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner  bool isFunctionPointerType() const;
869f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  bool isMemberPointerType() const;
870f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  bool isMemberFunctionPointerType() const;
871c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  bool isArrayType() const;
872c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  bool isConstantArrayType() const;
873c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  bool isIncompleteArrayType() const;
874c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  bool isVariableArrayType() const;
875898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  bool isDependentSizedArrayType() const;
876c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  bool isRecordType() const;
8771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  bool isClassType() const;
8781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  bool isStructureType() const;
8794cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroff  bool isUnionType() const;
880368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner  bool isComplexIntegerType() const;            // GCC _Complex integer type.
881368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner  bool isVectorType() const;                    // GCC vector type.
882213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman  bool isExtVectorType() const;                 // Extended vector type.
883d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff  bool isObjCObjectPointerType() const;         // Pointer to *any* ObjC object.
88414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  // FIXME: change this to 'raw' interface type, so we can used 'interface' type
88514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  // for the common case.
886368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner  bool isObjCInterfaceType() const;             // NSString or NSString<foo>
887368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner  bool isObjCQualifiedInterfaceType() const;    // NSString<foo>
888368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner  bool isObjCQualifiedIdType() const;           // id<foo>
889470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroff  bool isObjCQualifiedClassType() const;        // Class<foo>
89014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  bool isObjCIdType() const;                    // id
89114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  bool isObjCClassType() const;                 // Class
89213dcd00615de5c4279d97bdf63cd5f0a14fd9dccFariborz Jahanian  bool isObjCSelType() const;                 // Class
893de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff  bool isObjCBuiltinType() const;               // 'id' or 'Class'
89472c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor  bool isTemplateTypeParmType() const;          // C++ template type parameter
8956e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl  bool isNullPtrType() const;                   // C++0x nullptr_t
896898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
897898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// isDependentType - Whether this type is a dependent type, meaning
8981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// that its definition somehow depends on a template parameter
899898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// (C++ [temp.dep.type]).
900898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  bool isDependentType() const { return Dependent; }
901063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  bool isOverloadableType() const;
90272c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor
9038958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar  /// hasPointerRepresentation - Whether this type is represented
9048958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar  /// natively as a pointer; this includes pointers, references, block
9058958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar  /// pointers, and Objective-C interface, qualified id, and qualified
9066e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl  /// interface types, as well as nullptr_t.
9078958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar  bool hasPointerRepresentation() const;
9088958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar
909820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian  /// hasObjCPointerRepresentation - Whether this type can represent
910820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian  /// an objective pointer type for the purpose of GC'ability
9111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  bool hasObjCPointerRepresentation() const;
912820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian
913c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  // Type Checking Functions: Check to see if this type is structurally the
914f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner  // specified type, ignoring typedefs and qualifiers, and return a pointer to
915f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner  // the best type we can.
916769c9cfc6e06bd9d8ffe7a4397b939f19b0e4dc3Ted Kremenek  const RecordType *getAsStructureType() const;
917898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// NOTE: getAs*ArrayType are methods on ASTContext.
918c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  const RecordType *getAsUnionType() const;
9194cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroff  const ComplexType *getAsComplexIntegerType() const; // GCC complex int type.
92014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  // The following is a convenience method that returns an ObjCObjectPointerType
92114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  // for object declared using an interface.
92214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  const ObjCObjectPointerType *getAsObjCInterfacePointerType() const;
92314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  const ObjCObjectPointerType *getAsObjCQualifiedIdType() const;
924c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff  const ObjCInterfaceType *getAsObjCQualifiedInterfaceType() const;
925a91d6a6619a91d0ca7102d8ab5678d855f04d850Fariborz Jahanian  const CXXRecordDecl *getCXXRecordDeclForPointerType() const;
9261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
9271a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek  // Member-template getAs<specific type>'.  This scheme will eventually
9281a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek  // replace the specific getAsXXXX methods above.
929183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  //
930183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  // There are some specializations of this member template listed
931183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  // immediately following this class.
9321a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek  template <typename T> const T *getAs() const;
9331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
9342b1cc8be4dda4cd122485be0168b3c43d7dff15fChris Lattner  /// getAsPointerToObjCInterfaceType - If this is a pointer to an ObjC
9352b1cc8be4dda4cd122485be0168b3c43d7dff15fChris Lattner  /// interface, return the interface type, otherwise return null.
9362b1cc8be4dda4cd122485be0168b3c43d7dff15fChris Lattner  const ObjCInterfaceType *getAsPointerToObjCInterfaceType() const;
9372b1cc8be4dda4cd122485be0168b3c43d7dff15fChris Lattner
938c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  /// getArrayElementTypeNoTypeQual - If this is an array type, return the
939c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  /// element type of the array, potentially with type qualifiers missing.
940c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  /// This method should never be used when type qualifiers are meaningful.
941c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  const Type *getArrayElementTypeNoTypeQual() const;
9421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
943f8910df57799256c1897a8610dc52685729ae90eSteve Naroff  /// getPointeeType - If this is a pointer, ObjC object pointer, or block
944f8910df57799256c1897a8610dc52685729ae90eSteve Naroff  /// pointer, this returns the respective pointee.
94514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  QualType getPointeeType() const;
9461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
947bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// getUnqualifiedDesugaredType() - Return the specified type with
948bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// any "sugar" removed from the type, removing any typedefs,
949bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// typeofs, etc., as well as any qualifiers.
950bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  const Type *getUnqualifiedDesugaredType() const;
9511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
9525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// More type predicates useful for type checking/promotion
9535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isPromotableIntegerType() const; // C99 6.3.1.1p2
9545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
9555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isSignedIntegerType - Return true if this is an integer type that is
956d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner  /// signed, according to C99 6.2.5p4 [char, signed char, short, int, long..],
957d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner  /// an enum decl which has a signed representation, or a vector of signed
958d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner  /// integer element type.
9595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isSignedIntegerType() const;
9605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
9615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isUnsignedIntegerType - Return true if this is an integer type that is
962d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner  /// unsigned, according to C99 6.2.5p6 [which returns true for _Bool], an enum
963d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner  /// decl which has an unsigned representation, or a vector of unsigned integer
964d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner  /// element type.
9655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isUnsignedIntegerType() const;
966d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner
9675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isConstantSizeType - Return true if this is not a variable sized type,
9689bfa73c5ab7bf4b0e749d04f29da6884e8d5bd9fChris Lattner  /// according to the rules of C99 6.7.5p3.  It is not legal to call this on
9699bfa73c5ab7bf4b0e749d04f29da6884e8d5bd9fChris Lattner  /// incomplete types.
9703c2b3170041f69a92904e3bab9b6d654eaf260acEli Friedman  bool isConstantSizeType() const;
971c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner
97222b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman  /// isSpecifierType - Returns true if this type can be represented by some
97322b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman  /// set of type specifiers.
97422b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman  bool isSpecifierType() const;
97522b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman
976cd01f17358dc8ef19338c0e2321138dd0a6160d9Argyrios Kyrtzidis  const char *getTypeClassName() const;
977cd01f17358dc8ef19338c0e2321138dd0a6160d9Argyrios Kyrtzidis
9780b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor  /// \brief Determine the linkage of this type.
9790b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor  virtual Linkage getLinkage() const;
9800b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor
9815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType getCanonicalTypeInternal() const { return CanonicalType; }
982c36d405a02fab41f6c45cb2bc750d64949742903Chris Lattner  void dump() const;
9835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *) { return true; }
9845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
9855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
986183700f494ec9b6701b6efe82bcb25f4c79ba561John McCalltemplate <> inline const TypedefType *Type::getAs() const {
987183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  return dyn_cast<TypedefType>(this);
988183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall}
989183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall
990183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall// We can do canonical leaf types faster, because we don't have to
991183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall// worry about preserving child type decoration.
992183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall#define TYPE(Class, Base)
993183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall#define LEAF_TYPE(Class) \
994183700f494ec9b6701b6efe82bcb25f4c79ba561John McCalltemplate <> inline const Class##Type *Type::getAs() const { \
9950953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  return dyn_cast<Class##Type>(CanonicalType); \
996183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall}
997183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall#include "clang/AST/TypeNodes.def"
998183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall
999183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall
10005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// BuiltinType - This class is used for builtin types like 'int'.  Builtin
10015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// types are always canonical and have a literal name field.
10025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass BuiltinType : public Type {
10035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
10045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  enum Kind {
10055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Void,
10061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
10075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Bool,     // This is bool and/or _Bool.
10085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Char_U,   // This is 'char' for targets where char is unsigned.
10095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    UChar,    // This is explicitly qualified unsigned char.
1010f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith    Char16,   // This is 'char16_t' for C++.
1011f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith    Char32,   // This is 'char32_t' for C++.
10125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    UShort,
10135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    UInt,
10145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ULong,
10155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ULongLong,
10162df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner    UInt128,  // __uint128_t
10171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
10185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Char_S,   // This is 'char' for targets where char is signed.
10195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    SChar,    // This is explicitly qualified signed char.
10202ff9b4c7c8fed9233a0b8de2e9507368c451aab6Argyrios Kyrtzidis    WChar,    // This is 'wchar_t' for C++.
10215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Short,
10225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Int,
10235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Long,
10245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    LongLong,
10252df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner    Int128,   // __int128_t
10261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
10278e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor    Float, Double, LongDouble,
10288e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor
10296e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl    NullPtr,  // This is the type of C++0x 'nullptr'.
10306e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl
1031898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    Overload,  // This represents the type of an overloaded function declaration.
1032e89d15944dd3be750a09805ad21222d2fa9321faAnders Carlsson    Dependent, // This represents the type of a type-dependent expression.
10331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1034de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff    UndeducedAuto, // In C++0x, this represents the type of an auto variable
1035e89d15944dd3be750a09805ad21222d2fa9321faAnders Carlsson                   // that has not been deduced yet.
1036de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff    ObjCId,    // This represents the ObjC 'id' type.
103713dcd00615de5c4279d97bdf63cd5f0a14fd9dccFariborz Jahanian    ObjCClass, // This represents the ObjC 'Class' type.
103813dcd00615de5c4279d97bdf63cd5f0a14fd9dccFariborz Jahanian    ObjCSel    // This represents the ObjC 'SEL' type.
10395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
10405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate:
10415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Kind TypeKind;
10425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
10431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  BuiltinType(Kind K)
10441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    : Type(Builtin, QualType(), /*Dependent=*/(K == Dependent)),
1045898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor      TypeKind(K) {}
10461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
10475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Kind getKind() const { return TypeKind; }
1048e4f2142d00fa5fdb580c4e2413da91882d955381Chris Lattner  const char *getName(const LangOptions &LO) const;
10491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1050bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1051bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1052bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
1053680523a91dd3351389667c8de17121ba7ae82673John McCall  bool isInteger() const {
1054680523a91dd3351389667c8de17121ba7ae82673John McCall    return TypeKind >= Bool && TypeKind <= Int128;
1055680523a91dd3351389667c8de17121ba7ae82673John McCall  }
1056680523a91dd3351389667c8de17121ba7ae82673John McCall
1057680523a91dd3351389667c8de17121ba7ae82673John McCall  bool isSignedInteger() const {
1058680523a91dd3351389667c8de17121ba7ae82673John McCall    return TypeKind >= Char_S && TypeKind <= Int128;
1059680523a91dd3351389667c8de17121ba7ae82673John McCall  }
1060680523a91dd3351389667c8de17121ba7ae82673John McCall
1061680523a91dd3351389667c8de17121ba7ae82673John McCall  bool isUnsignedInteger() const {
1062680523a91dd3351389667c8de17121ba7ae82673John McCall    return TypeKind >= Bool && TypeKind <= UInt128;
1063680523a91dd3351389667c8de17121ba7ae82673John McCall  }
1064680523a91dd3351389667c8de17121ba7ae82673John McCall
1065680523a91dd3351389667c8de17121ba7ae82673John McCall  bool isFloatingPoint() const {
1066680523a91dd3351389667c8de17121ba7ae82673John McCall    return TypeKind >= Float && TypeKind <= LongDouble;
1067680523a91dd3351389667c8de17121ba7ae82673John McCall  }
1068680523a91dd3351389667c8de17121ba7ae82673John McCall
10690b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor  virtual Linkage getLinkage() const;
10700b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor
10715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T) { return T->getTypeClass() == Builtin; }
10725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const BuiltinType *) { return true; }
10735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
10745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
10755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ComplexType - C99 6.2.5p11 - Complex values.  This supports the C99 complex
10765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// types (_Complex float etc) as well as the GCC integer complex extensions.
10775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
10785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ComplexType : public Type, public llvm::FoldingSetNode {
10795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType ElementType;
10805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ComplexType(QualType Element, QualType CanonicalPtr) :
10811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    Type(Complex, CanonicalPtr, Element->isDependentType()),
1082898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    ElementType(Element) {
10835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
10845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
10855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
10865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType getElementType() const { return ElementType; }
10871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1088bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1089bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1090bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
10915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void Profile(llvm::FoldingSetNodeID &ID) {
10925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Profile(ID, getElementType());
10935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
10945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static void Profile(llvm::FoldingSetNodeID &ID, QualType Element) {
10955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ID.AddPointer(Element.getAsOpaquePtr());
10965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
10971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
10980b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor  virtual Linkage getLinkage() const;
10990b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor
11005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T) { return T->getTypeClass() == Complex; }
11015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const ComplexType *) { return true; }
11025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
11035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
110468694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar/// PointerType - C99 6.7.5.1 - Pointer Declarators.
1105bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner///
110668694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbarclass PointerType : public Type, public llvm::FoldingSetNode {
1107bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner  QualType PointeeType;
11085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
11095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  PointerType(QualType Pointee, QualType CanonicalPtr) :
111068694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar    Type(Pointer, CanonicalPtr, Pointee->isDependentType()), PointeeType(Pointee) {
11115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
11125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
11135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
11141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
111568694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar  QualType getPointeeType() const { return PointeeType; }
111668694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar
1117bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1118bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1119bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
11205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void Profile(llvm::FoldingSetNodeID &ID) {
11215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Profile(ID, getPointeeType());
11225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
11235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) {
11245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ID.AddPointer(Pointee.getAsOpaquePtr());
11255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
11261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
11270b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor  virtual Linkage getLinkage() const;
11280b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor
11295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T) { return T->getTypeClass() == Pointer; }
11305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const PointerType *) { return true; }
11315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
11325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
11335618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff/// BlockPointerType - pointer to a block type.
11345618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff/// This type is to represent types syntactically represented as
11355618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff/// "void (^)(int)", etc. Pointee is required to always be a function type.
11365618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff///
11375618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroffclass BlockPointerType : public Type, public llvm::FoldingSetNode {
11385618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  QualType PointeeType;  // Block is some kind of pointer type
11395618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  BlockPointerType(QualType Pointee, QualType CanonicalCls) :
11401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    Type(BlockPointer, CanonicalCls, Pointee->isDependentType()),
1141898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    PointeeType(Pointee) {
11425618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  }
11435618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  friend class ASTContext;  // ASTContext creates these.
11445618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroffpublic:
11451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
11465618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  // Get the pointee type. Pointee is required to always be a function type.
11475618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  QualType getPointeeType() const { return PointeeType; }
11485618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff
1149bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1150bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1151bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
11525618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  void Profile(llvm::FoldingSetNodeID &ID) {
11535618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff      Profile(ID, getPointeeType());
11545618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  }
11555618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) {
11565618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff      ID.AddPointer(Pointee.getAsOpaquePtr());
11575618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  }
11581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
11590b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor  virtual Linkage getLinkage() const;
11600b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor
11611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
11621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == BlockPointer;
11635618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  }
11645618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  static bool classof(const BlockPointerType *) { return true; }
11655618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff};
11665618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff
11677c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// ReferenceType - Base for LValueReferenceType and RValueReferenceType
11685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
116968694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbarclass ReferenceType : public Type, public llvm::FoldingSetNode {
117068694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar  QualType PointeeType;
117168694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar
117254e14c4db764c0636160d26c5bbf491637c83a76John McCall  /// True if the type was originally spelled with an lvalue sigil.
117354e14c4db764c0636160d26c5bbf491637c83a76John McCall  /// This is never true of rvalue references but can also be false
117454e14c4db764c0636160d26c5bbf491637c83a76John McCall  /// on lvalue references because of C++0x [dcl.typedef]p9,
117554e14c4db764c0636160d26c5bbf491637c83a76John McCall  /// as follows:
117654e14c4db764c0636160d26c5bbf491637c83a76John McCall  ///
117754e14c4db764c0636160d26c5bbf491637c83a76John McCall  ///   typedef int &ref;    // lvalue, spelled lvalue
117854e14c4db764c0636160d26c5bbf491637c83a76John McCall  ///   typedef int &&rvref; // rvalue
117954e14c4db764c0636160d26c5bbf491637c83a76John McCall  ///   ref &a;              // lvalue, inner ref, spelled lvalue
118054e14c4db764c0636160d26c5bbf491637c83a76John McCall  ///   ref &&a;             // lvalue, inner ref
118154e14c4db764c0636160d26c5bbf491637c83a76John McCall  ///   rvref &a;            // lvalue, inner ref, spelled lvalue
118254e14c4db764c0636160d26c5bbf491637c83a76John McCall  ///   rvref &&a;           // rvalue, inner ref
118354e14c4db764c0636160d26c5bbf491637c83a76John McCall  bool SpelledAsLValue;
118454e14c4db764c0636160d26c5bbf491637c83a76John McCall
118554e14c4db764c0636160d26c5bbf491637c83a76John McCall  /// True if the inner type is a reference type.  This only happens
118654e14c4db764c0636160d26c5bbf491637c83a76John McCall  /// in non-canonical forms.
118754e14c4db764c0636160d26c5bbf491637c83a76John McCall  bool InnerRef;
118854e14c4db764c0636160d26c5bbf491637c83a76John McCall
11897c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlprotected:
119054e14c4db764c0636160d26c5bbf491637c83a76John McCall  ReferenceType(TypeClass tc, QualType Referencee, QualType CanonicalRef,
119154e14c4db764c0636160d26c5bbf491637c83a76John McCall                bool SpelledAsLValue) :
11927c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl    Type(tc, CanonicalRef, Referencee->isDependentType()),
119354e14c4db764c0636160d26c5bbf491637c83a76John McCall    PointeeType(Referencee), SpelledAsLValue(SpelledAsLValue),
119454e14c4db764c0636160d26c5bbf491637c83a76John McCall    InnerRef(Referencee->isReferenceType()) {
11955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
11965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
119754e14c4db764c0636160d26c5bbf491637c83a76John McCall  bool isSpelledAsLValue() const { return SpelledAsLValue; }
119854e14c4db764c0636160d26c5bbf491637c83a76John McCall
119954e14c4db764c0636160d26c5bbf491637c83a76John McCall  QualType getPointeeTypeAsWritten() const { return PointeeType; }
120054e14c4db764c0636160d26c5bbf491637c83a76John McCall  QualType getPointeeType() const {
120154e14c4db764c0636160d26c5bbf491637c83a76John McCall    // FIXME: this might strip inner qualifiers; okay?
120254e14c4db764c0636160d26c5bbf491637c83a76John McCall    const ReferenceType *T = this;
120354e14c4db764c0636160d26c5bbf491637c83a76John McCall    while (T->InnerRef)
120454e14c4db764c0636160d26c5bbf491637c83a76John McCall      T = T->PointeeType->getAs<ReferenceType>();
120554e14c4db764c0636160d26c5bbf491637c83a76John McCall    return T->PointeeType;
120654e14c4db764c0636160d26c5bbf491637c83a76John McCall  }
120768694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar
12085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void Profile(llvm::FoldingSetNodeID &ID) {
120954e14c4db764c0636160d26c5bbf491637c83a76John McCall    Profile(ID, PointeeType, SpelledAsLValue);
12105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
121154e14c4db764c0636160d26c5bbf491637c83a76John McCall  static void Profile(llvm::FoldingSetNodeID &ID,
121254e14c4db764c0636160d26c5bbf491637c83a76John McCall                      QualType Referencee,
121354e14c4db764c0636160d26c5bbf491637c83a76John McCall                      bool SpelledAsLValue) {
12145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ID.AddPointer(Referencee.getAsOpaquePtr());
121554e14c4db764c0636160d26c5bbf491637c83a76John McCall    ID.AddBoolean(SpelledAsLValue);
12165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
12175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
12180b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor  virtual Linkage getLinkage() const;
12190b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor
12207c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  static bool classof(const Type *T) {
12217c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl    return T->getTypeClass() == LValueReference ||
12227c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl           T->getTypeClass() == RValueReference;
12237c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  }
12245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const ReferenceType *) { return true; }
12257c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl};
12267c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl
12277c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// LValueReferenceType - C++ [dcl.ref] - Lvalue reference
12287c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl///
12297c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlclass LValueReferenceType : public ReferenceType {
123054e14c4db764c0636160d26c5bbf491637c83a76John McCall  LValueReferenceType(QualType Referencee, QualType CanonicalRef,
123154e14c4db764c0636160d26c5bbf491637c83a76John McCall                      bool SpelledAsLValue) :
123254e14c4db764c0636160d26c5bbf491637c83a76John McCall    ReferenceType(LValueReference, Referencee, CanonicalRef, SpelledAsLValue)
123354e14c4db764c0636160d26c5bbf491637c83a76John McCall  {}
12347c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  friend class ASTContext; // ASTContext creates these
12357c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlpublic:
1236bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1237bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1238bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
12397c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  static bool classof(const Type *T) {
12407c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl    return T->getTypeClass() == LValueReference;
12417c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  }
12427c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  static bool classof(const LValueReferenceType *) { return true; }
12437c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl};
12447c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl
12457c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// RValueReferenceType - C++0x [dcl.ref] - Rvalue reference
12467c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl///
12477c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlclass RValueReferenceType : public ReferenceType {
12487c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  RValueReferenceType(QualType Referencee, QualType CanonicalRef) :
124954e14c4db764c0636160d26c5bbf491637c83a76John McCall    ReferenceType(RValueReference, Referencee, CanonicalRef, false) {
12507c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  }
12517c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  friend class ASTContext; // ASTContext creates these
12527c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlpublic:
1253bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1254bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1255bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
12567c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  static bool classof(const Type *T) {
12577c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl    return T->getTypeClass() == RValueReference;
12587c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  }
12597c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  static bool classof(const RValueReferenceType *) { return true; }
1260f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl};
1261f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl
1262f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl/// MemberPointerType - C++ 8.3.3 - Pointers to members
1263f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl///
1264f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlclass MemberPointerType : public Type, public llvm::FoldingSetNode {
1265f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  QualType PointeeType;
1266f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  /// The class of which the pointee is a member. Must ultimately be a
1267f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  /// RecordType, but could be a typedef or a template parameter too.
1268f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  const Type *Class;
1269f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl
1270f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  MemberPointerType(QualType Pointee, const Type *Cls, QualType CanonicalPtr) :
1271f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    Type(MemberPointer, CanonicalPtr,
1272f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl         Cls->isDependentType() || Pointee->isDependentType()),
1273f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    PointeeType(Pointee), Class(Cls) {
1274f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  }
1275f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  friend class ASTContext; // ASTContext creates these.
1276f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlpublic:
1277f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl
1278f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  QualType getPointeeType() const { return PointeeType; }
1279f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl
1280f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  const Type *getClass() const { return Class; }
1281f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl
1282bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1283bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1284bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
1285f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  void Profile(llvm::FoldingSetNodeID &ID) {
1286f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    Profile(ID, getPointeeType(), getClass());
1287f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  }
1288f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee,
1289f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl                      const Type *Class) {
1290f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    ID.AddPointer(Pointee.getAsOpaquePtr());
1291f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    ID.AddPointer(Class);
1292f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  }
1293f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl
12940b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor  virtual Linkage getLinkage() const;
12950b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor
1296f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  static bool classof(const Type *T) {
1297f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    return T->getTypeClass() == MemberPointer;
1298f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  }
1299f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  static bool classof(const MemberPointerType *) { return true; }
13005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
13015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
13025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ArrayType - C99 6.7.5.2 - Array Declarators.
13035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
13042e7d352dbec06755105237afba183492d31d03cbTed Kremenekclass ArrayType : public Type, public llvm::FoldingSetNode {
13055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
13065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// ArraySizeModifier - Capture whether this is a normal array (e.g. int X[4])
1307898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// an array with a static size (e.g. int X[static 4]), or an array
1308898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// with a star size (e.g. int X[*]).
1309898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// 'static' is only allowed on function parameters.
13105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  enum ArraySizeModifier {
13115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Normal, Static, Star
13125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
13135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate:
1314fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  /// ElementType - The element type of the array.
1315fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  QualType ElementType;
13161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1317ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek  // NOTE: VC++ treats enums as signed, avoid using the ArraySizeModifier enum
1318c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff  /// NOTE: These fields are packed into the bitfields space in the Type class.
1319ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek  unsigned SizeModifier : 2;
13201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1321c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff  /// IndexTypeQuals - Capture qualifiers in declarations like:
1322c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff  /// 'int X[static restrict 4]'. For function parameters only.
1323c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff  unsigned IndexTypeQuals : 3;
13241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1325fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroffprotected:
1326898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  // C++ [temp.dep.type]p1:
1327898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  //   A type is dependent if it is...
1328898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  //     - an array type constructed from any dependent type or whose
1329898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  //       size is specified by a constant expression that is
1330898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  //       value-dependent,
1331c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff  ArrayType(TypeClass tc, QualType et, QualType can,
1332c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff            ArraySizeModifier sm, unsigned tq)
1333898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    : Type(tc, can, et->isDependentType() || tc == DependentSizedArray),
1334898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor      ElementType(et), SizeModifier(sm), IndexTypeQuals(tq) {}
1335898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
1336fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  friend class ASTContext;  // ASTContext creates these.
1337fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroffpublic:
1338fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  QualType getElementType() const { return ElementType; }
1339ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek  ArraySizeModifier getSizeModifier() const {
1340ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek    return ArraySizeModifier(SizeModifier);
1341ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek  }
13420953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  Qualifiers getIndexTypeQualifiers() const {
13430953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return Qualifiers::fromCVRMask(IndexTypeQuals);
13440953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
13450953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  unsigned getIndexTypeCVRQualifiers() const { return IndexTypeQuals; }
13461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
13470b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor  virtual Linkage getLinkage() const;
13480b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor
1349fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  static bool classof(const Type *T) {
1350fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff    return T->getTypeClass() == ConstantArray ||
1351c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman           T->getTypeClass() == VariableArray ||
1352898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor           T->getTypeClass() == IncompleteArray ||
1353898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor           T->getTypeClass() == DependentSizedArray;
1354fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  }
1355fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  static bool classof(const ArrayType *) { return true; }
1356fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff};
1357fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff
13587e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// ConstantArrayType - This class represents the canonical version of
13597e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// C arrays with a specified constant size.  For example, the canonical
13607e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// type for 'int A[4 + 4*100]' is a ConstantArrayType where the element
13617e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// type is 'int' and the size is 404.
13622e7d352dbec06755105237afba183492d31d03cbTed Kremenekclass ConstantArrayType : public ArrayType {
1363fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  llvm::APInt Size; // Allows us to unique the type.
13641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
13650be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner  ConstantArrayType(QualType et, QualType can, const llvm::APInt &size,
1366c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff                    ArraySizeModifier sm, unsigned tq)
13677e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor    : ArrayType(ConstantArray, et, can, sm, tq),
13687e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor      Size(size) {}
13697e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregorprotected:
13707e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  ConstantArrayType(TypeClass tc, QualType et, QualType can,
13717e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor                    const llvm::APInt &size, ArraySizeModifier sm, unsigned tq)
13727e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor    : ArrayType(tc, et, can, sm, tq), Size(size) {}
1373fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  friend class ASTContext;  // ASTContext creates these.
1374fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroffpublic:
1375c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  const llvm::APInt &getSize() const { return Size; }
1376bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1377bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1378bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
1379fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  void Profile(llvm::FoldingSetNodeID &ID) {
13801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    Profile(ID, getElementType(), getSize(),
13810953e767ff7817f97b3ab20896b229891eeff45bJohn McCall            getSizeModifier(), getIndexTypeCVRQualifiers());
1382fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  }
1383fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  static void Profile(llvm::FoldingSetNodeID &ID, QualType ET,
13840be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner                      const llvm::APInt &ArraySize, ArraySizeModifier SizeMod,
13850be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner                      unsigned TypeQuals) {
1386fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff    ID.AddPointer(ET.getAsOpaquePtr());
1387fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff    ID.AddInteger(ArraySize.getZExtValue());
13880be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner    ID.AddInteger(SizeMod);
13890be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner    ID.AddInteger(TypeQuals);
1390fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  }
13917e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  static bool classof(const Type *T) {
139246a617a792bfab0d9b1e057371ea3b9540802226John McCall    return T->getTypeClass() == ConstantArray;
1393fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  }
1394fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  static bool classof(const ConstantArrayType *) { return true; }
1395fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff};
1396fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff
1397da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// IncompleteArrayType - This class represents C arrays with an unspecified
1398da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// size.  For example 'int A[]' has an IncompleteArrayType where the element
1399da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// type is 'int' and the size is unspecified.
1400c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedmanclass IncompleteArrayType : public ArrayType {
14017e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor
1402c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman  IncompleteArrayType(QualType et, QualType can,
14037e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor                      ArraySizeModifier sm, unsigned tq)
1404c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman    : ArrayType(IncompleteArray, et, can, sm, tq) {}
1405c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman  friend class ASTContext;  // ASTContext creates these.
1406c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedmanpublic:
1407bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1408bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1409bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
14101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
14111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == IncompleteArray;
1412c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman  }
1413c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman  static bool classof(const IncompleteArrayType *) { return true; }
14141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1415c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman  friend class StmtIteratorBase;
14161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1417c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman  void Profile(llvm::FoldingSetNodeID &ID) {
14180953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Profile(ID, getElementType(), getSizeModifier(),
14190953e767ff7817f97b3ab20896b229891eeff45bJohn McCall            getIndexTypeCVRQualifiers());
1420c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman  }
14211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
14220be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner  static void Profile(llvm::FoldingSetNodeID &ID, QualType ET,
14230be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner                      ArraySizeModifier SizeMod, unsigned TypeQuals) {
1424c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman    ID.AddPointer(ET.getAsOpaquePtr());
14250be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner    ID.AddInteger(SizeMod);
14260be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner    ID.AddInteger(TypeQuals);
1427c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman  }
1428c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman};
1429c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman
1430da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// VariableArrayType - This class represents C arrays with a specified size
1431da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// which is not an integer-constant-expression.  For example, 'int s[x+foo()]'.
1432da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// Since the size expression is an arbitrary expression, we store it as such.
1433da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner///
1434da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// Note: VariableArrayType's aren't uniqued (since the expressions aren't) and
1435da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// should not be: two lexically equivalent variable array types could mean
1436da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// different things, for example, these variables do not have the same type
1437da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// dynamically:
1438da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner///
1439da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// void foo(int x) {
1440da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner///   int Y[x];
1441da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner///   ++x;
1442da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner///   int Z[x];
1443da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// }
1444da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner///
14452e7d352dbec06755105237afba183492d31d03cbTed Kremenekclass VariableArrayType : public ArrayType {
14461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// SizeExpr - An assignment expression. VLA's are only permitted within
14471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// a function block.
1448b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek  Stmt *SizeExpr;
14497e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  /// Brackets - The left and right array brackets.
14507e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  SourceRange Brackets;
14517e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor
1452c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff  VariableArrayType(QualType et, QualType can, Expr *e,
14537e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor                    ArraySizeModifier sm, unsigned tq,
14547e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor                    SourceRange brackets)
14557e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor    : ArrayType(VariableArray, et, can, sm, tq),
14567e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor      SizeExpr((Stmt*) e), Brackets(brackets) {}
14575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
14584b05b1dee6cc65ae61d93dab7edff72710f24589Ted Kremenek  virtual void Destroy(ASTContext& C);
14594b05b1dee6cc65ae61d93dab7edff72710f24589Ted Kremenek
14605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
14611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Expr *getSizeExpr() const {
1462b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek    // We use C-style casts instead of cast<> here because we do not wish
1463b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek    // to have a dependency of Type.h on Stmt.h/Expr.h.
1464b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek    return (Expr*) SizeExpr;
1465b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek  }
14667e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  SourceRange getBracketsRange() const { return Brackets; }
14677e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  SourceLocation getLBracketLoc() const { return Brackets.getBegin(); }
14687e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  SourceLocation getRBracketLoc() const { return Brackets.getEnd(); }
14691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1470bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1471bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1472bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
14731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
14741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == VariableArray;
14755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
1476fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  static bool classof(const VariableArrayType *) { return true; }
14771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
147892866e2e90f6d93fb95e25a7ac4438e239d89ce6Ted Kremenek  friend class StmtIteratorBase;
14791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
14802bd24ba6d10f8c811c8e2a57c8397e07082ba497Ted Kremenek  void Profile(llvm::FoldingSetNodeID &ID) {
1481bc5e150b6d94cf131f7d01bc715571b741c5b408Chris Lattner    assert(0 && "Cannnot unique VariableArrayTypes.");
14822bd24ba6d10f8c811c8e2a57c8397e07082ba497Ted Kremenek  }
14835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
14845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1485898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// DependentSizedArrayType - This type represents an array type in
1486898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// C++ whose size is a value-dependent expression. For example:
1487cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor///
1488cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor/// \code
14891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// template<typename T, int Size>
1490898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// class array {
1491898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor///   T data[Size];
1492898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// };
1493cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor/// \endcode
1494cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor///
1495898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// For these types, we won't actually know what the array bound is
1496898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// until template instantiation occurs, at which point this will
1497898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// become either a ConstantArrayType or a VariableArrayType.
1498898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorclass DependentSizedArrayType : public ArrayType {
149904d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor  ASTContext &Context;
15001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1501cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor  /// \brief An assignment expression that will instantiate to the
1502898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// size of the array.
1503cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor  ///
1504cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor  /// The expression itself might be NULL, in which case the array
1505cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor  /// type will have its size deduced from an initializer.
1506898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  Stmt *SizeExpr;
1507cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor
15087e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  /// Brackets - The left and right array brackets.
15097e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  SourceRange Brackets;
15101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
15111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  DependentSizedArrayType(ASTContext &Context, QualType et, QualType can,
151204d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor                          Expr *e, ArraySizeModifier sm, unsigned tq,
15137e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor                          SourceRange brackets)
15147e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor    : ArrayType(DependentSizedArray, et, can, sm, tq),
151504d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor      Context(Context), SizeExpr((Stmt*) e), Brackets(brackets) {}
1516898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  friend class ASTContext;  // ASTContext creates these.
1517898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  virtual void Destroy(ASTContext& C);
1518898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
1519898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorpublic:
15201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Expr *getSizeExpr() const {
1521898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    // We use C-style casts instead of cast<> here because we do not wish
1522898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    // to have a dependency of Type.h on Stmt.h/Expr.h.
1523898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    return (Expr*) SizeExpr;
1524898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  }
15257e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  SourceRange getBracketsRange() const { return Brackets; }
15267e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  SourceLocation getLBracketLoc() const { return Brackets.getBegin(); }
15277e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  SourceLocation getRBracketLoc() const { return Brackets.getEnd(); }
15281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1529bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1530bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1531bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
15321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
15331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == DependentSizedArray;
1534898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  }
1535898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  static bool classof(const DependentSizedArrayType *) { return true; }
15361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1537898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  friend class StmtIteratorBase;
15381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
15391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1540898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  void Profile(llvm::FoldingSetNodeID &ID) {
15411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    Profile(ID, Context, getElementType(),
15420953e767ff7817f97b3ab20896b229891eeff45bJohn McCall            getSizeModifier(), getIndexTypeCVRQualifiers(), getSizeExpr());
1543898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  }
15441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
15451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static void Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context,
15461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                      QualType ET, ArraySizeModifier SizeMod,
154704d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor                      unsigned TypeQuals, Expr *E);
1548898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor};
1549898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
1550f6ddb737cb882ffbf0b75a9abd50b930cc2b9068Douglas Gregor/// DependentSizedExtVectorType - This type represent an extended vector type
15519cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// where either the type or size is dependent. For example:
15529cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// @code
15539cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// template<typename T, int Size>
15549cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// class vector {
15559cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor///   typedef T __attribute__((ext_vector_type(Size))) type;
15569cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// }
15579cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// @endcode
15582ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregorclass DependentSizedExtVectorType : public Type, public llvm::FoldingSetNode {
15592ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor  ASTContext &Context;
15609cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor  Expr *SizeExpr;
15619cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor  /// ElementType - The element type of the array.
15629cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor  QualType ElementType;
15639cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor  SourceLocation loc;
15641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
15651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  DependentSizedExtVectorType(ASTContext &Context, QualType ElementType,
15662ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor                              QualType can, Expr *SizeExpr, SourceLocation loc)
15671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    : Type (DependentSizedExtVector, can, true),
15681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      Context(Context), SizeExpr(SizeExpr), ElementType(ElementType),
15692ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor      loc(loc) {}
15709cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor  friend class ASTContext;
15719cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor  virtual void Destroy(ASTContext& C);
15729cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor
15739cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregorpublic:
15742ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor  Expr *getSizeExpr() const { return SizeExpr; }
15759cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor  QualType getElementType() const { return ElementType; }
15769cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor  SourceLocation getAttributeLoc() const { return loc; }
15779cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor
1578bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1579bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1580bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
15811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
15821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == DependentSizedExtVector;
15839cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor  }
15841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const DependentSizedExtVectorType *) { return true; }
15852ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor
15862ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor  void Profile(llvm::FoldingSetNodeID &ID) {
15872ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor    Profile(ID, Context, getElementType(), getSizeExpr());
15882ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor  }
15891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
15902ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor  static void Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context,
15912ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor                      QualType ElementType, Expr *SizeExpr);
15929cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor};
15931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
15949cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor
159573322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// VectorType - GCC generic vector type. This type is created using
15961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// __attribute__((vector_size(n)), where "n" specifies the vector size in
159782287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson/// bytes; or from an Altivec __vector or vector declaration.
159882287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson/// Since the constructor takes the number of vector elements, the
159973322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// client is responsible for converting the size into the number of elements.
16005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass VectorType : public Type, public llvm::FoldingSetNode {
160173322924127c873c13101b705dd823f5539ffa5fSteve Naroffprotected:
16025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// ElementType - The element type of the vector.
16035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType ElementType;
16041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
16055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// NumElements - The number of elements in the vector.
16065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned NumElements;
16071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
160882287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson  /// AltiVec - True if this is for an Altivec vector.
160982287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson  bool AltiVec;
161082287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson
161182287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson  /// Pixel - True if this is for an Altivec vector pixel.
161282287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson  bool Pixel;
161382287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson
161482287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson  VectorType(QualType vecType, unsigned nElements, QualType canonType,
161582287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson      bool isAltiVec, bool isPixel) :
16161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    Type(Vector, canonType, vecType->isDependentType()),
161782287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson    ElementType(vecType), NumElements(nElements),
161882287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson    AltiVec(isAltiVec), Pixel(isPixel) {}
16191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  VectorType(TypeClass tc, QualType vecType, unsigned nElements,
162082287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson             QualType canonType, bool isAltiVec, bool isPixel)
16211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    : Type(tc, canonType, vecType->isDependentType()), ElementType(vecType),
162282287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson      NumElements(nElements), AltiVec(isAltiVec), Pixel(isPixel) {}
16235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
16245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
16251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
16265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType getElementType() const { return ElementType; }
16271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  unsigned getNumElements() const { return NumElements; }
16285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1629bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1630bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1631bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
163282287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson  bool isAltiVec() const { return AltiVec; }
163382287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson
163482287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson  bool isPixel() const { return Pixel; }
163582287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson
16365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void Profile(llvm::FoldingSetNodeID &ID) {
163782287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson    Profile(ID, getElementType(), getNumElements(), getTypeClass(),
163882287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson      AltiVec, Pixel);
16395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
16401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static void Profile(llvm::FoldingSetNodeID &ID, QualType ElementType,
164182287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson                      unsigned NumElements, TypeClass TypeClass,
164282287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson                      bool isAltiVec, bool isPixel) {
16435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ID.AddPointer(ElementType.getAsOpaquePtr());
16445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ID.AddInteger(NumElements);
164573322924127c873c13101b705dd823f5539ffa5fSteve Naroff    ID.AddInteger(TypeClass);
164682287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson    ID.AddBoolean(isAltiVec);
164782287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson    ID.AddBoolean(isPixel);
164873322924127c873c13101b705dd823f5539ffa5fSteve Naroff  }
16490b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor
16500b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor  virtual Linkage getLinkage() const;
16510b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor
16521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
16531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == Vector || T->getTypeClass() == ExtVector;
16545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
16555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const VectorType *) { return true; }
16565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
16575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1658213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman/// ExtVectorType - Extended vector type. This type is created using
1659213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman/// __attribute__((ext_vector_type(n)), where "n" is the number of elements.
1660213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman/// Unlike vector_size, ext_vector_type is only allowed on typedef's. This
1661fcac0fff877a461bc5d5a57e6c6727a4c819d95aSteve Naroff/// class enables syntactic extensions, like Vector Components for accessing
1662fcac0fff877a461bc5d5a57e6c6727a4c819d95aSteve Naroff/// points, colors, and textures (modeled after OpenGL Shading Language).
1663213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begemanclass ExtVectorType : public VectorType {
1664213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman  ExtVectorType(QualType vecType, unsigned nElements, QualType canonType) :
166582287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson    VectorType(ExtVector, vecType, nElements, canonType, false, false) {}
166673322924127c873c13101b705dd823f5539ffa5fSteve Naroff  friend class ASTContext;  // ASTContext creates these.
166773322924127c873c13101b705dd823f5539ffa5fSteve Naroffpublic:
166888dca0464804b8b26ae605f89784c927e8493dddChris Lattner  static int getPointAccessorIdx(char c) {
166988dca0464804b8b26ae605f89784c927e8493dddChris Lattner    switch (c) {
167088dca0464804b8b26ae605f89784c927e8493dddChris Lattner    default: return -1;
167188dca0464804b8b26ae605f89784c927e8493dddChris Lattner    case 'x': return 0;
167288dca0464804b8b26ae605f89784c927e8493dddChris Lattner    case 'y': return 1;
167388dca0464804b8b26ae605f89784c927e8493dddChris Lattner    case 'z': return 2;
167488dca0464804b8b26ae605f89784c927e8493dddChris Lattner    case 'w': return 3;
167588dca0464804b8b26ae605f89784c927e8493dddChris Lattner    }
1676e1b31fedbc006e6e4071bbb4f74c6116b56cfa9fSteve Naroff  }
1677353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman  static int getNumericAccessorIdx(char c) {
167888dca0464804b8b26ae605f89784c927e8493dddChris Lattner    switch (c) {
1679353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      default: return -1;
1680353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '0': return 0;
1681353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '1': return 1;
1682353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '2': return 2;
1683353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '3': return 3;
1684353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '4': return 4;
1685353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '5': return 5;
1686353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '6': return 6;
1687353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '7': return 7;
1688353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '8': return 8;
1689353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '9': return 9;
1690131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman      case 'A':
1691353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case 'a': return 10;
1692131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman      case 'B':
1693353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case 'b': return 11;
1694131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman      case 'C':
1695353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case 'c': return 12;
1696131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman      case 'D':
1697353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case 'd': return 13;
1698131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman      case 'E':
1699353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case 'e': return 14;
1700131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman      case 'F':
1701353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case 'f': return 15;
170288dca0464804b8b26ae605f89784c927e8493dddChris Lattner    }
1703e1b31fedbc006e6e4071bbb4f74c6116b56cfa9fSteve Naroff  }
17041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1705b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner  static int getAccessorIdx(char c) {
1706b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner    if (int idx = getPointAccessorIdx(c)+1) return idx-1;
1707353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman    return getNumericAccessorIdx(c);
1708b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner  }
17091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
171088dca0464804b8b26ae605f89784c927e8493dddChris Lattner  bool isAccessorWithinNumElements(char c) const {
1711b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner    if (int idx = getAccessorIdx(c)+1)
171288dca0464804b8b26ae605f89784c927e8493dddChris Lattner      return unsigned(idx-1) < NumElements;
171388dca0464804b8b26ae605f89784c927e8493dddChris Lattner    return false;
1714e1b31fedbc006e6e4071bbb4f74c6116b56cfa9fSteve Naroff  }
1715bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1716bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1717bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
17181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
17191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == ExtVector;
172073322924127c873c13101b705dd823f5539ffa5fSteve Naroff  }
1721213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman  static bool classof(const ExtVectorType *) { return true; }
172273322924127c873c13101b705dd823f5539ffa5fSteve Naroff};
172373322924127c873c13101b705dd823f5539ffa5fSteve Naroff
17245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// FunctionType - C99 6.7.5.3 - Function Declarators.  This is the common base
172572564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// class of FunctionNoProtoType and FunctionProtoType.
17265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
17275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass FunctionType : public Type {
17285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// SubClassData - This field is owned by the subclass, put here to pack
17295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// tightly with the ivars in Type.
17305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool SubClassData : 1;
1731971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis
173272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  /// TypeQuals - Used only by FunctionProtoType, put here to pack with the
1733971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis  /// other bitfields.
173472564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  /// The qualifiers are part of FunctionProtoType because...
1735971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis  ///
1736971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis  /// C++ 8.3.5p4: The return type, the parameter type list and the
1737971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis  /// cv-qualifier-seq, [...], are part of the function type.
1738971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis  ///
1739971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis  unsigned TypeQuals : 3;
17402455636163fdd18581d7fdae816433f886d88213Mike Stump
17412455636163fdd18581d7fdae816433f886d88213Mike Stump  /// NoReturn - Indicates if the function type is attribute noreturn.
17422455636163fdd18581d7fdae816433f886d88213Mike Stump  unsigned NoReturn : 1;
17431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1744ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor  /// CallConv - The calling convention used by the function.
1745ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor  unsigned CallConv : 2;
1746ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor
17475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // The type returned by the function.
17485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType ResultType;
17495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprotected:
1750971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis  FunctionType(TypeClass tc, QualType res, bool SubclassInfo,
17512455636163fdd18581d7fdae816433f886d88213Mike Stump               unsigned typeQuals, QualType Canonical, bool Dependent,
1752ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor               bool noReturn = false, CallingConv callConv = CC_Default)
1753898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    : Type(tc, Canonical, Dependent),
17542455636163fdd18581d7fdae816433f886d88213Mike Stump      SubClassData(SubclassInfo), TypeQuals(typeQuals), NoReturn(noReturn),
1755ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor      CallConv(callConv), ResultType(res) {}
17565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool getSubClassData() const { return SubClassData; }
1757971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis  unsigned getTypeQuals() const { return TypeQuals; }
17585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
17591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
17605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType getResultType() const { return ResultType; }
17612455636163fdd18581d7fdae816433f886d88213Mike Stump  bool getNoReturnAttr() const { return NoReturn; }
1762ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor  CallingConv getCallConv() const { return (CallingConv)CallConv; }
17635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
17645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T) {
17655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T->getTypeClass() == FunctionNoProto ||
17665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer           T->getTypeClass() == FunctionProto;
17675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
17685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const FunctionType *) { return true; }
17695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
17705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
177172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// FunctionNoProtoType - Represents a K&R-style 'int foo()' function, which has
17725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// no information available about its arguments.
177372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregorclass FunctionNoProtoType : public FunctionType, public llvm::FoldingSetNode {
17742455636163fdd18581d7fdae816433f886d88213Mike Stump  FunctionNoProtoType(QualType Result, QualType Canonical,
1775ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor                      bool NoReturn = false, CallingConv CallConv = CC_Default)
17761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    : FunctionType(FunctionNoProto, Result, false, 0, Canonical,
1777ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor                   /*Dependent=*/false, NoReturn, CallConv) {}
17785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
17795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
17805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // No additional state past what FunctionType provides.
17811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1782bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1783bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1784bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
17855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void Profile(llvm::FoldingSetNodeID &ID) {
1786f82b4e85b1219295cad4b5851b035575bc293010John McCall    Profile(ID, getResultType(), getNoReturnAttr(), getCallConv());
17875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
17882455636163fdd18581d7fdae816433f886d88213Mike Stump  static void Profile(llvm::FoldingSetNodeID &ID, QualType ResultType,
1789f82b4e85b1219295cad4b5851b035575bc293010John McCall                      bool NoReturn, CallingConv CallConv) {
1790f82b4e85b1219295cad4b5851b035575bc293010John McCall    ID.AddInteger(CallConv);
17912455636163fdd18581d7fdae816433f886d88213Mike Stump    ID.AddInteger(NoReturn);
17925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ID.AddPointer(ResultType.getAsOpaquePtr());
17935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
17941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
17950b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor  virtual Linkage getLinkage() const;
17960b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor
17975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T) {
17985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T->getTypeClass() == FunctionNoProto;
17995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
180072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  static bool classof(const FunctionNoProtoType *) { return true; }
18015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
18025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
180372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// FunctionProtoType - Represents a prototype with argument type info, e.g.
18045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 'int foo(int)' or 'int foo(void)'.  'void' is represented as having no
1805465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl/// arguments, not as having a single void argument. Such a type can have an
1806465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl/// exception specification, but this specification is not part of the canonical
1807465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl/// type.
180872564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregorclass FunctionProtoType : public FunctionType, public llvm::FoldingSetNode {
1809898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// hasAnyDependentType - Determine whether there are any dependent
1810898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// types within the arguments passed in.
1811898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  static bool hasAnyDependentType(const QualType *ArgArray, unsigned numArgs) {
1812898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    for (unsigned Idx = 0; Idx < numArgs; ++Idx)
1813898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor      if (ArgArray[Idx]->isDependentType())
18144b4218f48fef71a179c5a8287dae281580faf52fNate Begeman    return true;
1815898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
1816898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    return false;
1817898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  }
1818898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
181972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  FunctionProtoType(QualType Result, const QualType *ArgArray, unsigned numArgs,
1820465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl                    bool isVariadic, unsigned typeQuals, bool hasExs,
1821465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl                    bool hasAnyExs, const QualType *ExArray,
1822ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor                    unsigned numExs, QualType Canonical, bool NoReturn,
1823ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor                    CallingConv CallConv)
1824898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    : FunctionType(FunctionProto, Result, isVariadic, typeQuals, Canonical,
18251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                   (Result->isDependentType() ||
1826ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor                    hasAnyDependentType(ArgArray, numArgs)), NoReturn,
1827ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor                   CallConv),
1828465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl      NumArgs(numArgs), NumExceptions(numExs), HasExceptionSpec(hasExs),
1829465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl      AnyExceptionSpec(hasAnyExs) {
1830942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner    // Fill in the trailing argument array.
1831465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl    QualType *ArgInfo = reinterpret_cast<QualType*>(this+1);
18325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    for (unsigned i = 0; i != numArgs; ++i)
18335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      ArgInfo[i] = ArgArray[i];
1834465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl    // Fill in the exception array.
1835465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl    QualType *Ex = ArgInfo + numArgs;
1836465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl    for (unsigned i = 0; i != numExs; ++i)
1837465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl      Ex[i] = ExArray[i];
18385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
1839465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
18405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// NumArgs - The number of arguments this function has, not counting '...'.
1841465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  unsigned NumArgs : 20;
1842465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
1843465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  /// NumExceptions - The number of types in the exception spec, if any.
1844465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  unsigned NumExceptions : 10;
1845465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
1846465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  /// HasExceptionSpec - Whether this function has an exception spec at all.
1847465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  bool HasExceptionSpec : 1;
1848465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
1849465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  /// AnyExceptionSpec - Whether this function has a throw(...) spec.
1850465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  bool AnyExceptionSpec : 1;
1851465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
1852942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner  /// ArgInfo - There is an variable size array after the class in memory that
1853942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner  /// holds the argument types.
1854465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
1855465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  /// Exceptions - There is another variable size array after ArgInfo that
1856465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  /// holds the exception types.
1857465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
18585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
18594b05b1dee6cc65ae61d93dab7edff72710f24589Ted Kremenek
18605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
18615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned getNumArgs() const { return NumArgs; }
18625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType getArgType(unsigned i) const {
18635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    assert(i < NumArgs && "Invalid argument number!");
1864942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner    return arg_type_begin()[i];
18655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
1866465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
1867465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  bool hasExceptionSpec() const { return HasExceptionSpec; }
1868465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  bool hasAnyExceptionSpec() const { return AnyExceptionSpec; }
1869465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  unsigned getNumExceptions() const { return NumExceptions; }
1870465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  QualType getExceptionType(unsigned i) const {
1871465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl    assert(i < NumExceptions && "Invalid exception number!");
1872465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl    return exception_begin()[i];
1873465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  }
18741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  bool hasEmptyExceptionSpec() const {
18751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return hasExceptionSpec() && !hasAnyExceptionSpec() &&
1876a12823f6c0ec9e0e644a9d0ee153e973f49c63fcAnders Carlsson      getNumExceptions() == 0;
1877d3fd6bad1249d3f34d71b73e2333fab0db51cce4Anders Carlsson  }
1878465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
18795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isVariadic() const { return getSubClassData(); }
1880971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis  unsigned getTypeQuals() const { return FunctionType::getTypeQuals(); }
18811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
18825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  typedef const QualType *arg_type_iterator;
1883942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner  arg_type_iterator arg_type_begin() const {
1884942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner    return reinterpret_cast<const QualType *>(this+1);
1885942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner  }
1886942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner  arg_type_iterator arg_type_end() const { return arg_type_begin()+NumArgs; }
1887465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
1888465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  typedef const QualType *exception_iterator;
1889465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  exception_iterator exception_begin() const {
1890465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl    // exceptions begin where arguments end
1891465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl    return arg_type_end();
1892465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  }
1893465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  exception_iterator exception_end() const {
1894465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl    return exception_begin() + NumExceptions;
1895465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  }
1896465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
1897bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1898bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1899bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
19000b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor  virtual Linkage getLinkage() const;
19010b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor
19025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T) {
19035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T->getTypeClass() == FunctionProto;
19045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
190572564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  static bool classof(const FunctionProtoType *) { return true; }
1906465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
19075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void Profile(llvm::FoldingSetNodeID &ID);
19085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static void Profile(llvm::FoldingSetNodeID &ID, QualType Result,
1909942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner                      arg_type_iterator ArgTys, unsigned NumArgs,
1910465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl                      bool isVariadic, unsigned TypeQuals,
1911465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl                      bool hasExceptionSpec, bool anyExceptionSpec,
19122455636163fdd18581d7fdae816433f886d88213Mike Stump                      unsigned NumExceptions, exception_iterator Exs,
1913f82b4e85b1219295cad4b5851b035575bc293010John McCall                      bool NoReturn, CallingConv CallConv);
19145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
19155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
19165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1917ed97649e9574b9d854fa4d6109c9333ae0993554John McCall/// \brief Represents the dependent type named by a dependently-scoped
1918ed97649e9574b9d854fa4d6109c9333ae0993554John McCall/// typename using declaration, e.g.
1919ed97649e9574b9d854fa4d6109c9333ae0993554John McCall///   using typename Base<T>::foo;
1920ed97649e9574b9d854fa4d6109c9333ae0993554John McCall/// Template instantiation turns these into the underlying type.
1921ed97649e9574b9d854fa4d6109c9333ae0993554John McCallclass UnresolvedUsingType : public Type {
1922ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  UnresolvedUsingTypenameDecl *Decl;
1923ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
1924ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  UnresolvedUsingType(UnresolvedUsingTypenameDecl *D)
1925ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    : Type(UnresolvedUsing, QualType(), true), Decl(D) {}
1926ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  friend class ASTContext; // ASTContext creates these.
1927ed97649e9574b9d854fa4d6109c9333ae0993554John McCallpublic:
1928ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
1929ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  UnresolvedUsingTypenameDecl *getDecl() const { return Decl; }
1930ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
1931ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  bool isSugared() const { return false; }
1932ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  QualType desugar() const { return QualType(this, 0); }
1933ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
1934ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  static bool classof(const Type *T) {
1935ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    return T->getTypeClass() == UnresolvedUsing;
1936ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  }
1937ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  static bool classof(const UnresolvedUsingType *) { return true; }
1938ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
1939ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  void Profile(llvm::FoldingSetNodeID &ID) {
1940ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    return Profile(ID, Decl);
1941ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  }
1942ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  static void Profile(llvm::FoldingSetNodeID &ID,
1943ed97649e9574b9d854fa4d6109c9333ae0993554John McCall                      UnresolvedUsingTypenameDecl *D) {
1944ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    ID.AddPointer(D);
1945ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  }
1946ed97649e9574b9d854fa4d6109c9333ae0993554John McCall};
1947ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
1948ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
19495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass TypedefType : public Type {
19505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  TypedefDecl *Decl;
1951c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanianprotected:
19521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  TypedefType(TypeClass tc, TypedefDecl *D, QualType can)
1953898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    : Type(tc, can, can->isDependentType()), Decl(D) {
19545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    assert(!isa<TypedefType>(can) && "Invalid canonical type");
19555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
19565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
19575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
19581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
19595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  TypedefDecl *getDecl() const { return Decl; }
19601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1961a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner  /// LookThroughTypedefs - Return the ultimate type this typedef corresponds to
1962fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor  /// potentially looking through *all* consecutive typedefs.  This returns the
1963a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner  /// sum of the type qualifiers, so if you have:
1964a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner  ///   typedef const int A;
1965a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner  ///   typedef volatile A B;
1966a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner  /// looking through the typedefs for B will give you "const volatile A".
1967a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner  QualType LookThroughTypedefs() const;
19681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1969bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return true; }
1970bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const;
1971bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
197272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  static bool classof(const Type *T) { return T->getTypeClass() == Typedef; }
19735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const TypedefType *) { return true; }
19745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
19755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
197672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// TypeOfExprType (GCC extension).
197772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregorclass TypeOfExprType : public Type {
1978d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  Expr *TOExpr;
19791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1980b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregorprotected:
1981dd0257c77719a13d4acd513df40b04300cbfc871Douglas Gregor  TypeOfExprType(Expr *E, QualType can = QualType());
1982d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  friend class ASTContext;  // ASTContext creates these.
1983d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroffpublic:
1984d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  Expr *getUnderlyingExpr() const { return TOExpr; }
19851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1986bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// \brief Remove a single level of sugar.
1987bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const;
1988bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
1989bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// \brief Returns whether this type directly provides sugar.
1990bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return true; }
1991bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
199272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  static bool classof(const Type *T) { return T->getTypeClass() == TypeOfExpr; }
199372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  static bool classof(const TypeOfExprType *) { return true; }
1994d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff};
1995d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff
19961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// Subclass of TypeOfExprType that is used for canonical, dependent
19971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// typeof(expr) types.
19981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpclass DependentTypeOfExprType
1999b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor  : public TypeOfExprType, public llvm::FoldingSetNode {
2000b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor  ASTContext &Context;
20011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2002b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregorpublic:
20031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  DependentTypeOfExprType(ASTContext &Context, Expr *E)
2004b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor    : TypeOfExprType(E), Context(Context) { }
20051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2006bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2007bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2008bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
2009b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor  void Profile(llvm::FoldingSetNodeID &ID) {
2010b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor    Profile(ID, Context, getUnderlyingExpr());
2011b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor  }
20121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2013b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor  static void Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context,
2014b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor                      Expr *E);
2015b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor};
20161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2017d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff/// TypeOfType (GCC extension).
2018d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroffclass TypeOfType : public Type {
2019d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  QualType TOType;
20201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  TypeOfType(QualType T, QualType can)
202172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor    : Type(TypeOf, can, T->isDependentType()), TOType(T) {
2022d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff    assert(!isa<TypedefType>(can) && "Invalid canonical type");
2023d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  }
2024d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  friend class ASTContext;  // ASTContext creates these.
2025d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroffpublic:
2026d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  QualType getUnderlyingType() const { return TOType; }
20271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2028bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// \brief Remove a single level of sugar.
2029bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return getUnderlyingType(); }
2030bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
2031bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// \brief Returns whether this type directly provides sugar.
2032bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return true; }
2033bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
203472564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  static bool classof(const Type *T) { return T->getTypeClass() == TypeOf; }
2035d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  static bool classof(const TypeOfType *) { return true; }
2036d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff};
20375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2038395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson/// DecltypeType (C++0x)
2039395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlssonclass DecltypeType : public Type {
2040395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson  Expr *E;
20411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2042563a03b1338d31c2462def43253a722bc885d384Anders Carlsson  // FIXME: We could get rid of UnderlyingType if we wanted to: We would have to
2043563a03b1338d31c2462def43253a722bc885d384Anders Carlsson  // Move getDesugaredType to ASTContext so that it can call getDecltypeForExpr
2044563a03b1338d31c2462def43253a722bc885d384Anders Carlsson  // from it.
2045563a03b1338d31c2462def43253a722bc885d384Anders Carlsson  QualType UnderlyingType;
20461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
20479d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregorprotected:
2048563a03b1338d31c2462def43253a722bc885d384Anders Carlsson  DecltypeType(Expr *E, QualType underlyingType, QualType can = QualType());
2049395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson  friend class ASTContext;  // ASTContext creates these.
2050395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlssonpublic:
2051395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson  Expr *getUnderlyingExpr() const { return E; }
2052563a03b1338d31c2462def43253a722bc885d384Anders Carlsson  QualType getUnderlyingType() const { return UnderlyingType; }
2053563a03b1338d31c2462def43253a722bc885d384Anders Carlsson
2054bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// \brief Remove a single level of sugar.
2055bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return getUnderlyingType(); }
2056bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
2057bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// \brief Returns whether this type directly provides sugar.
2058bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return !isDependentType(); }
2059bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
2060395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson  static bool classof(const Type *T) { return T->getTypeClass() == Decltype; }
2061395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson  static bool classof(const DecltypeType *) { return true; }
2062395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson};
20631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
20641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// Subclass of DecltypeType that is used for canonical, dependent
20651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// C++0x decltype types.
20669d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregorclass DependentDecltypeType : public DecltypeType, public llvm::FoldingSetNode {
20679d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor  ASTContext &Context;
20681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
20699d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregorpublic:
20709d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor  DependentDecltypeType(ASTContext &Context, Expr *E);
20711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2072bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2073bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2074bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
20759d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor  void Profile(llvm::FoldingSetNodeID &ID) {
20769d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor    Profile(ID, Context, getUnderlyingExpr());
20779d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor  }
20781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
20799d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor  static void Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context,
20801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                      Expr *E);
20819d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor};
20821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
20835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass TagType : public Type {
20840b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor  /// Stores the TagDecl associated with this type. The decl will
20850b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor  /// point to the TagDecl that actually defines the entity (or is a
20860b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor  /// definition in progress), if there is such a definition. The
20870b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor  /// single-bit value will be non-zero when this tag is in the
20880b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor  /// process of being defined.
2089fc705b84347e6fb4746a1a7e26949f64c2f2f358Douglas Gregor  mutable llvm::PointerIntPair<TagDecl *, 1> decl;
20904b7c98378ae0c1a3635f0b7756848b4a9923f8bcTed Kremenek  friend class ASTContext;
20910b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor  friend class TagDecl;
20922ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor
20932ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregorprotected:
20947da97d0f31e1ec16998d3de2cfd2e88fe3736673Douglas Gregor  TagType(TypeClass TC, TagDecl *D, QualType can);
20952ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor
20961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic:
20970b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor  TagDecl *getDecl() const { return decl.getPointer(); }
20981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
20990b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor  /// @brief Determines whether this type is in the process of being
21001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// defined.
21010b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor  bool isBeingDefined() const { return decl.getInt(); }
21020953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void setBeingDefined(bool Def) const { decl.setInt(Def? 1 : 0); }
21030b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor
21040b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor  virtual Linkage getLinkage() const;
21050b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor
21061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
210772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor    return T->getTypeClass() >= TagFirst && T->getTypeClass() <= TagLast;
210872564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  }
21095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const TagType *) { return true; }
211072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  static bool classof(const RecordType *) { return true; }
211172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  static bool classof(const EnumType *) { return true; }
21125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
21135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
21145edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner/// RecordType - This is a helper class that allows the use of isa/cast/dyncast
21155edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner/// to detect TagType objects of structs/unions/classes.
21165edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattnerclass RecordType : public TagType {
211749aa7ff1245abd03e6e998e01302df31e4c6f8f6Argyrios Kyrtzidisprotected:
2118509447e7cb9c24a9f2bd149fe95030050b088622Argyrios Kyrtzidis  explicit RecordType(RecordDecl *D)
211972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor    : TagType(Record, reinterpret_cast<TagDecl*>(D), QualType()) { }
212072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  explicit RecordType(TypeClass TC, RecordDecl *D)
212172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor    : TagType(TC, reinterpret_cast<TagDecl*>(D), QualType()) { }
21222ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor  friend class ASTContext;   // ASTContext creates these.
21235edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattnerpublic:
21241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
21255edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner  RecordDecl *getDecl() const {
21265edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner    return reinterpret_cast<RecordDecl*>(TagType::getDecl());
21275edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner  }
21281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
21291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  // FIXME: This predicate is a helper to QualType/Type. It needs to
21305edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner  // recursively check all fields for const-ness. If any field is declared
21311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  // const, it needs to return false.
21325edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner  bool hasConstFields() const { return false; }
21335edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner
21345edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner  // FIXME: RecordType needs to check when it is created that all fields are in
21355edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner  // the same address space, and return that.
21365edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner  unsigned getAddressSpace() const { return 0; }
21371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2138bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2139bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2140bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
21412daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner  static bool classof(const TagType *T);
21422daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner  static bool classof(const Type *T) {
21432daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner    return isa<TagType>(T) && classof(cast<TagType>(T));
21442daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner  }
21455edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner  static bool classof(const RecordType *) { return true; }
21465edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner};
21475edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner
21485edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner/// EnumType - This is a helper class that allows the use of isa/cast/dyncast
21495edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner/// to detect TagType objects of enums.
21505edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattnerclass EnumType : public TagType {
2151509447e7cb9c24a9f2bd149fe95030050b088622Argyrios Kyrtzidis  explicit EnumType(EnumDecl *D)
215272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor    : TagType(Enum, reinterpret_cast<TagDecl*>(D), QualType()) { }
21532ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor  friend class ASTContext;   // ASTContext creates these.
21545edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattnerpublic:
21551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
21565edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner  EnumDecl *getDecl() const {
21575edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner    return reinterpret_cast<EnumDecl*>(TagType::getDecl());
21585edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner  }
21591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2160bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2161bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2162bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
21632daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner  static bool classof(const TagType *T);
21642daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner  static bool classof(const Type *T) {
21652daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner    return isa<TagType>(T) && classof(cast<TagType>(T));
21662daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner  }
21675edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner  static bool classof(const EnumType *) { return true; }
21685edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner};
21695edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner
21707da2431c23ef1ee8acb114e39692246e1801afc2John McCall/// ElaboratedType - A non-canonical type used to represents uses of
21717da2431c23ef1ee8acb114e39692246e1801afc2John McCall/// elaborated type specifiers in C++.  For example:
21727da2431c23ef1ee8acb114e39692246e1801afc2John McCall///
21737da2431c23ef1ee8acb114e39692246e1801afc2John McCall///   void foo(union MyUnion);
21747da2431c23ef1ee8acb114e39692246e1801afc2John McCall///            ^^^^^^^^^^^^^
21757da2431c23ef1ee8acb114e39692246e1801afc2John McCall///
21767da2431c23ef1ee8acb114e39692246e1801afc2John McCall/// At the moment, for efficiency we do not create elaborated types in
21777da2431c23ef1ee8acb114e39692246e1801afc2John McCall/// C, since outside of typedefs all references to structs would
21787da2431c23ef1ee8acb114e39692246e1801afc2John McCall/// necessarily be elaborated.
21797da2431c23ef1ee8acb114e39692246e1801afc2John McCallclass ElaboratedType : public Type, public llvm::FoldingSetNode {
21807da2431c23ef1ee8acb114e39692246e1801afc2John McCallpublic:
21817da2431c23ef1ee8acb114e39692246e1801afc2John McCall  enum TagKind {
21827da2431c23ef1ee8acb114e39692246e1801afc2John McCall    TK_struct,
21837da2431c23ef1ee8acb114e39692246e1801afc2John McCall    TK_union,
21847da2431c23ef1ee8acb114e39692246e1801afc2John McCall    TK_class,
21857da2431c23ef1ee8acb114e39692246e1801afc2John McCall    TK_enum
21867da2431c23ef1ee8acb114e39692246e1801afc2John McCall  };
21877da2431c23ef1ee8acb114e39692246e1801afc2John McCall
21887da2431c23ef1ee8acb114e39692246e1801afc2John McCallprivate:
21897da2431c23ef1ee8acb114e39692246e1801afc2John McCall  /// The tag that was used in this elaborated type specifier.
21907da2431c23ef1ee8acb114e39692246e1801afc2John McCall  TagKind Tag;
21917da2431c23ef1ee8acb114e39692246e1801afc2John McCall
21927da2431c23ef1ee8acb114e39692246e1801afc2John McCall  /// The underlying type.
21937da2431c23ef1ee8acb114e39692246e1801afc2John McCall  QualType UnderlyingType;
21947da2431c23ef1ee8acb114e39692246e1801afc2John McCall
21957da2431c23ef1ee8acb114e39692246e1801afc2John McCall  explicit ElaboratedType(QualType Ty, TagKind Tag, QualType Canon)
21967da2431c23ef1ee8acb114e39692246e1801afc2John McCall    : Type(Elaborated, Canon, Canon->isDependentType()),
21977da2431c23ef1ee8acb114e39692246e1801afc2John McCall      Tag(Tag), UnderlyingType(Ty) { }
21987da2431c23ef1ee8acb114e39692246e1801afc2John McCall  friend class ASTContext;   // ASTContext creates these.
21997da2431c23ef1ee8acb114e39692246e1801afc2John McCall
22007da2431c23ef1ee8acb114e39692246e1801afc2John McCallpublic:
22017da2431c23ef1ee8acb114e39692246e1801afc2John McCall  TagKind getTagKind() const { return Tag; }
22027da2431c23ef1ee8acb114e39692246e1801afc2John McCall  QualType getUnderlyingType() const { return UnderlyingType; }
22037da2431c23ef1ee8acb114e39692246e1801afc2John McCall
2204bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// \brief Remove a single level of sugar.
2205bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return getUnderlyingType(); }
2206bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
2207bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// \brief Returns whether this type directly provides sugar.
2208bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return true; }
2209bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
22107da2431c23ef1ee8acb114e39692246e1801afc2John McCall  static const char *getNameForTagKind(TagKind Kind) {
22117da2431c23ef1ee8acb114e39692246e1801afc2John McCall    switch (Kind) {
22127da2431c23ef1ee8acb114e39692246e1801afc2John McCall    default: assert(0 && "Unknown TagKind!");
22137da2431c23ef1ee8acb114e39692246e1801afc2John McCall    case TK_struct: return "struct";
22147da2431c23ef1ee8acb114e39692246e1801afc2John McCall    case TK_union:  return "union";
22157da2431c23ef1ee8acb114e39692246e1801afc2John McCall    case TK_class:  return "class";
22167da2431c23ef1ee8acb114e39692246e1801afc2John McCall    case TK_enum:   return "enum";
22177da2431c23ef1ee8acb114e39692246e1801afc2John McCall    }
22187da2431c23ef1ee8acb114e39692246e1801afc2John McCall  }
22197da2431c23ef1ee8acb114e39692246e1801afc2John McCall
22207da2431c23ef1ee8acb114e39692246e1801afc2John McCall  void Profile(llvm::FoldingSetNodeID &ID) {
22217da2431c23ef1ee8acb114e39692246e1801afc2John McCall    Profile(ID, getUnderlyingType(), getTagKind());
22227da2431c23ef1ee8acb114e39692246e1801afc2John McCall  }
22237da2431c23ef1ee8acb114e39692246e1801afc2John McCall  static void Profile(llvm::FoldingSetNodeID &ID, QualType T, TagKind Tag) {
22247da2431c23ef1ee8acb114e39692246e1801afc2John McCall    ID.AddPointer(T.getAsOpaquePtr());
22257da2431c23ef1ee8acb114e39692246e1801afc2John McCall    ID.AddInteger(Tag);
22267da2431c23ef1ee8acb114e39692246e1801afc2John McCall  }
22277da2431c23ef1ee8acb114e39692246e1801afc2John McCall
22287da2431c23ef1ee8acb114e39692246e1801afc2John McCall  static bool classof(const ElaboratedType*) { return true; }
22297da2431c23ef1ee8acb114e39692246e1801afc2John McCall  static bool classof(const Type *T) { return T->getTypeClass() == Elaborated; }
22307da2431c23ef1ee8acb114e39692246e1801afc2John McCall};
22317da2431c23ef1ee8acb114e39692246e1801afc2John McCall
2232fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregorclass TemplateTypeParmType : public Type, public llvm::FoldingSetNode {
223376e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson  unsigned Depth : 15;
2234fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor  unsigned Index : 16;
223576e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson  unsigned ParameterPack : 1;
2236fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor  IdentifierInfo *Name;
223772c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor
22381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  TemplateTypeParmType(unsigned D, unsigned I, bool PP, IdentifierInfo *N,
22391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                       QualType Canon)
2240fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor    : Type(TemplateTypeParm, Canon, /*Dependent=*/true),
224176e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson      Depth(D), Index(I), ParameterPack(PP), Name(N) { }
224272c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor
22431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  TemplateTypeParmType(unsigned D, unsigned I, bool PP)
2244fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor    : Type(TemplateTypeParm, QualType(this, 0), /*Dependent=*/true),
224576e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson      Depth(D), Index(I), ParameterPack(PP), Name(0) { }
224672c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor
2247fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor  friend class ASTContext;  // ASTContext creates these
224872c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor
2249fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregorpublic:
2250fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor  unsigned getDepth() const { return Depth; }
2251fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor  unsigned getIndex() const { return Index; }
225276e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson  bool isParameterPack() const { return ParameterPack; }
2253fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor  IdentifierInfo *getName() const { return Name; }
22541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2255bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2256bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2257bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
2258fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor  void Profile(llvm::FoldingSetNodeID &ID) {
225976e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson    Profile(ID, Depth, Index, ParameterPack, Name);
2260fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor  }
2261fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor
22621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static void Profile(llvm::FoldingSetNodeID &ID, unsigned Depth,
22631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                      unsigned Index, bool ParameterPack,
226476e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson                      IdentifierInfo *Name) {
2265fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor    ID.AddInteger(Depth);
2266fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor    ID.AddInteger(Index);
226776e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson    ID.AddBoolean(ParameterPack);
2268fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor    ID.AddPointer(Name);
2269fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor  }
2270fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor
22711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
22721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == TemplateTypeParm;
227372c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor  }
227472c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor  static bool classof(const TemplateTypeParmType *T) { return true; }
227572c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor};
2276fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor
227749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// \brief Represents the result of substituting a type for a template
227849a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// type parameter.
227949a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall///
228049a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// Within an instantiated template, all template type parameters have
228149a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// been replaced with these.  They are used solely to record that a
228249a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// type was originally written as a template type parameter;
228349a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// therefore they are never canonical.
228449a832bd499d6f61c23655f1fac99f0dd229756eJohn McCallclass SubstTemplateTypeParmType : public Type, public llvm::FoldingSetNode {
228549a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  // The original type parameter.
228649a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  const TemplateTypeParmType *Replaced;
228749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall
228849a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  SubstTemplateTypeParmType(const TemplateTypeParmType *Param, QualType Canon)
228949a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall    : Type(SubstTemplateTypeParm, Canon, Canon->isDependentType()),
229049a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall      Replaced(Param) { }
229149a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall
229249a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  friend class ASTContext;
229349a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall
229449a832bd499d6f61c23655f1fac99f0dd229756eJohn McCallpublic:
229549a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  IdentifierInfo *getName() const { return Replaced->getName(); }
229649a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall
229749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  /// Gets the template parameter that was substituted for.
229849a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  const TemplateTypeParmType *getReplacedParameter() const {
229949a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall    return Replaced;
230049a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  }
230149a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall
230249a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  /// Gets the type that was substituted for the template
230349a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  /// parameter.
230449a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  QualType getReplacementType() const {
230549a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall    return getCanonicalTypeInternal();
230649a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  }
230749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall
230849a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  bool isSugared() const { return true; }
230949a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  QualType desugar() const { return getReplacementType(); }
231049a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall
231149a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  void Profile(llvm::FoldingSetNodeID &ID) {
231249a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall    Profile(ID, getReplacedParameter(), getReplacementType());
231349a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  }
231449a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  static void Profile(llvm::FoldingSetNodeID &ID,
231549a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall                      const TemplateTypeParmType *Replaced,
231649a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall                      QualType Replacement) {
231749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall    ID.AddPointer(Replaced);
231849a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall    ID.AddPointer(Replacement.getAsOpaquePtr());
231949a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  }
232049a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall
232149a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  static bool classof(const Type *T) {
232249a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall    return T->getTypeClass() == SubstTemplateTypeParm;
232349a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  }
232449a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  static bool classof(const SubstTemplateTypeParmType *T) { return true; }
232549a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall};
232649a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall
23277532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// \brief Represents the type of a template specialization as written
23287532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// in the source code.
232955f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor///
23307532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// Template specialization types represent the syntactic form of a
23317532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// template-id that refers to a type, e.g., @c vector<int>. Some
23327532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// template specialization types are syntactic sugar, whose canonical
23337532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// type will point to some other type node that represents the
23347532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// instantiation or class template specialization. For example, a
233555f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor/// class template specialization type of @c vector<int> will refer to
23361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// a tag type for the instantiation
233755f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor/// @c std::vector<int, std::allocator<int>>.
23387532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor///
23397532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// Other template specialization types, for which the template name
23407532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// is dependent, may be canonical types. These types are always
23417532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// dependent.
23421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpclass TemplateSpecializationType
234355f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  : public Type, public llvm::FoldingSetNode {
234455f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
2345828e226ab7ed08b3eb766549e9d3306432137460Douglas Gregor  // FIXME: Currently needed for profiling expressions; can we avoid this?
2346828e226ab7ed08b3eb766549e9d3306432137460Douglas Gregor  ASTContext &Context;
23471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2348828e226ab7ed08b3eb766549e9d3306432137460Douglas Gregor    /// \brief The name of the template being specialized.
23497532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor  TemplateName Template;
235055f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
235140808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  /// \brief - The number of template arguments named in this class
235240808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  /// template specialization.
235355f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  unsigned NumArgs;
235455f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
2355828e226ab7ed08b3eb766549e9d3306432137460Douglas Gregor  TemplateSpecializationType(ASTContext &Context,
2356828e226ab7ed08b3eb766549e9d3306432137460Douglas Gregor                             TemplateName T,
23577532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor                             const TemplateArgument *Args,
23587532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor                             unsigned NumArgs, QualType Canon);
235955f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
23605908e9f25bc9a334c99c095e0b1e6a515445be2dDouglas Gregor  virtual void Destroy(ASTContext& C);
23615908e9f25bc9a334c99c095e0b1e6a515445be2dDouglas Gregor
236255f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  friend class ASTContext;  // ASTContext creates these
236355f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
236455f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregorpublic:
236540808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  /// \brief Determine whether any of the given template arguments are
236640808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  /// dependent.
236740808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  static bool anyDependentTemplateArguments(const TemplateArgument *Args,
23681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                            unsigned NumArgs);
236940808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor
2370833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  static bool anyDependentTemplateArguments(const TemplateArgumentLoc *Args,
2371833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                            unsigned NumArgs);
2372833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
2373d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  static bool anyDependentTemplateArguments(const TemplateArgumentListInfo &);
2374d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall
2375df667e71b1daadeacb230cf94fc717843f1a138aDouglas Gregor  /// \brief Print a template argument list, including the '<' and '>'
2376df667e71b1daadeacb230cf94fc717843f1a138aDouglas Gregor  /// enclosing the template arguments.
2377df667e71b1daadeacb230cf94fc717843f1a138aDouglas Gregor  static std::string PrintTemplateArgumentList(const TemplateArgument *Args,
2378d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor                                               unsigned NumArgs,
2379d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor                                               const PrintingPolicy &Policy);
2380df667e71b1daadeacb230cf94fc717843f1a138aDouglas Gregor
2381833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  static std::string PrintTemplateArgumentList(const TemplateArgumentLoc *Args,
2382833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                               unsigned NumArgs,
2383833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                               const PrintingPolicy &Policy);
2384833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
2385d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  static std::string PrintTemplateArgumentList(const TemplateArgumentListInfo &,
2386d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall                                               const PrintingPolicy &Policy);
2387d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall
238840808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  typedef const TemplateArgument * iterator;
238940808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor
239040808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  iterator begin() const { return getArgs(); }
239140808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  iterator end() const;
239240808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor
23937532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor  /// \brief Retrieve the name of the template that we are specializing.
23947532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor  TemplateName getTemplateName() const { return Template; }
239555f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
239640808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  /// \brief Retrieve the template arguments.
23971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  const TemplateArgument *getArgs() const {
239840808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor    return reinterpret_cast<const TemplateArgument *>(this + 1);
239940808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  }
240040808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor
240140808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  /// \brief Retrieve the number of template arguments.
240255f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  unsigned getNumArgs() const { return NumArgs; }
240355f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
240455f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  /// \brief Retrieve a specific template argument as a type.
240555f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  /// \precondition @c isArgType(Arg)
240640808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  const TemplateArgument &getArg(unsigned Idx) const;
240755f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
2408bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return !isDependentType(); }
2409bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return getCanonicalTypeInternal(); }
2410bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
241155f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  void Profile(llvm::FoldingSetNodeID &ID) {
2412828e226ab7ed08b3eb766549e9d3306432137460Douglas Gregor    Profile(ID, Template, getArgs(), NumArgs, Context);
241355f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  }
241455f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
24157532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor  static void Profile(llvm::FoldingSetNodeID &ID, TemplateName T,
2416828e226ab7ed08b3eb766549e9d3306432137460Douglas Gregor                      const TemplateArgument *Args, unsigned NumArgs,
2417828e226ab7ed08b3eb766549e9d3306432137460Douglas Gregor                      ASTContext &Context);
241855f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
24191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
24201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == TemplateSpecialization;
242155f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  }
24227532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor  static bool classof(const TemplateSpecializationType *T) { return true; }
242355f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor};
242455f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
2425e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor/// \brief Represents a type that was referred to via a qualified
2426e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor/// name, e.g., N::M::type.
2427e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor///
2428e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor/// This type is used to keep track of a type name as written in the
2429119057adf21237d53dcd490cec9700dca2465e3eDouglas Gregor/// source code, including any nested-name-specifiers. The type itself
2430119057adf21237d53dcd490cec9700dca2465e3eDouglas Gregor/// is always "sugar", used to express what was written in the source
2431119057adf21237d53dcd490cec9700dca2465e3eDouglas Gregor/// code but containing no additional semantic information.
2432e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregorclass QualifiedNameType : public Type, public llvm::FoldingSetNode {
2433ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor  /// \brief The nested name specifier containing the qualifier.
2434ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor  NestedNameSpecifier *NNS;
2435e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor
2436e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor  /// \brief The type that this qualified name refers to.
2437e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor  QualType NamedType;
2438e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor
2439ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor  QualifiedNameType(NestedNameSpecifier *NNS, QualType NamedType,
2440ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor                    QualType CanonType)
2441ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor    : Type(QualifiedName, CanonType, NamedType->isDependentType()),
2442ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor      NNS(NNS), NamedType(NamedType) { }
2443e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor
2444e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor  friend class ASTContext;  // ASTContext creates these
2445e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor
2446e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregorpublic:
2447ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor  /// \brief Retrieve the qualification on this type.
2448ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor  NestedNameSpecifier *getQualifier() const { return NNS; }
2449e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor
2450e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor  /// \brief Retrieve the type named by the qualified-id.
2451e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor  QualType getNamedType() const { return NamedType; }
2452e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor
2453bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// \brief Remove a single level of sugar.
2454bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return getNamedType(); }
2455bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
2456bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// \brief Returns whether this type directly provides sugar.
2457bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return true; }
2458bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
2459e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor  void Profile(llvm::FoldingSetNodeID &ID) {
2460ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor    Profile(ID, NNS, NamedType);
2461e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor  }
2462e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor
2463ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor  static void Profile(llvm::FoldingSetNodeID &ID, NestedNameSpecifier *NNS,
2464ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor                      QualType NamedType) {
2465ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor    ID.AddPointer(NNS);
2466ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor    NamedType.Profile(ID);
2467ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor  }
2468e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor
24691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
24701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == QualifiedName;
2471e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor  }
2472e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor  static bool classof(const QualifiedNameType *T) { return true; }
2473e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor};
2474e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor
2475d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// \brief Represents a 'typename' specifier that names a type within
2476d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// a dependent type, e.g., "typename T::type".
2477d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor///
2478d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// TypenameType has a very similar structure to QualifiedNameType,
2479d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// which also involves a nested-name-specifier following by a type,
2480d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// and (FIXME!) both can even be prefixed by the 'typename'
2481d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// keyword. However, the two types serve very different roles:
2482d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// QualifiedNameType is a non-semantic type that serves only as sugar
2483d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// to show how a particular type was written in the source
2484d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// code. TypenameType, on the other hand, only occurs when the
2485d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// nested-name-specifier is dependent, such that we cannot resolve
2486d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// the actual type until after instantiation.
2487d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregorclass TypenameType : public Type, public llvm::FoldingSetNode {
2488d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  /// \brief The nested name specifier containing the qualifier.
2489d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  NestedNameSpecifier *NNS;
2490d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor
24911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  typedef llvm::PointerUnion<const IdentifierInfo *,
24921734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor                             const TemplateSpecializationType *> NameType;
24931734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor
2494d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  /// \brief The type that this typename specifier refers to.
24951734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor  NameType Name;
2496d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor
2497d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  TypenameType(NestedNameSpecifier *NNS, const IdentifierInfo *Name,
2498d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor               QualType CanonType)
24991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    : Type(Typename, CanonType, true), NNS(NNS), Name(Name) {
25001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    assert(NNS->isDependent() &&
2501d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor           "TypenameType requires a dependent nested-name-specifier");
2502d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  }
2503d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor
25041734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor  TypenameType(NestedNameSpecifier *NNS, const TemplateSpecializationType *Ty,
25051734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor               QualType CanonType)
25061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    : Type(Typename, CanonType, true), NNS(NNS), Name(Ty) {
25071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    assert(NNS->isDependent() &&
25081734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor           "TypenameType requires a dependent nested-name-specifier");
25091734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor  }
25101734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor
2511d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  friend class ASTContext;  // ASTContext creates these
2512d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor
2513d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregorpublic:
2514d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  /// \brief Retrieve the qualification on this type.
2515d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  NestedNameSpecifier *getQualifier() const { return NNS; }
2516d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor
25171734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor  /// \brief Retrieve the type named by the typename specifier as an
25181734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor  /// identifier.
25191734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor  ///
25201734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor  /// This routine will return a non-NULL identifier pointer when the
25211734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor  /// form of the original typename was terminated by an identifier,
25221734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor  /// e.g., "typename T::type".
25231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  const IdentifierInfo *getIdentifier() const {
25241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return Name.dyn_cast<const IdentifierInfo *>();
25251734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor  }
25261734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor
25271734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor  /// \brief Retrieve the type named by the typename specifier as a
25281734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor  /// type specialization.
25291734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor  const TemplateSpecializationType *getTemplateId() const {
25301734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor    return Name.dyn_cast<const TemplateSpecializationType *>();
25311734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor  }
2532d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor
2533bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2534bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2535bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
2536d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  void Profile(llvm::FoldingSetNodeID &ID) {
2537d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor    Profile(ID, NNS, Name);
2538d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  }
2539d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor
2540d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  static void Profile(llvm::FoldingSetNodeID &ID, NestedNameSpecifier *NNS,
25411734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor                      NameType Name) {
2542d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor    ID.AddPointer(NNS);
25431734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor    ID.AddPointer(Name.getOpaqueValue());
2544d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  }
2545d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor
25461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
25471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == Typename;
2548d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  }
2549d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  static bool classof(const TypenameType *T) { return true; }
2550d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor};
2551d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor
2552fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner/// ObjCInterfaceType - Interfaces are the core concept in Objective-C for
2553fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner/// object oriented design.  They basically correspond to C++ classes.  There
2554fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner/// are two kinds of interface types, normal interfaces like "NSString" and
2555fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner/// qualified interfaces, which are qualified with a protocol list like
2556c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff/// "NSString<NSCopyable, NSAmazing>".
2557c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroffclass ObjCInterfaceType : public Type, public llvm::FoldingSetNode {
2558a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCInterfaceDecl *Decl;
2559c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff
2560c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff  // List of protocols for this protocol conforming object type
2561c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff  // List is sorted on protocol name. No protocol is enterred more than once.
256271842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek  ObjCProtocolDecl **Protocols;
256371842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek  unsigned NumProtocols;
2564c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff
256571842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek  ObjCInterfaceType(ASTContext &Ctx, QualType Canonical, ObjCInterfaceDecl *D,
256671842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek                    ObjCProtocolDecl **Protos, unsigned NumP);
25673536b443bc50d58a79f14fca9b6842541a434854Steve Naroff  friend class ASTContext;  // ASTContext creates these.
25683536b443bc50d58a79f14fca9b6842541a434854Steve Naroffpublic:
256971842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek  void Destroy(ASTContext& C);
257071842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek
2571a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCInterfaceDecl *getDecl() const { return Decl; }
25721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2573c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff  /// getNumProtocols - Return the number of qualifying protocols in this
2574c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff  /// interface type, or 0 if there are none.
257571842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek  unsigned getNumProtocols() const { return NumProtocols; }
257614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff
2577fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner  /// qual_iterator and friends: this provides access to the (potentially empty)
2578c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff  /// list of protocols qualifying this interface.
257971842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek  typedef ObjCProtocolDecl*  const * qual_iterator;
258071842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek  qual_iterator qual_begin() const {
258171842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek    return Protocols;
258271842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek  }
258371842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek  qual_iterator qual_end() const   {
258471842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek    return Protocols ? Protocols + NumProtocols : 0;
258571842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek  }
258671842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek  bool qual_empty() const { return NumProtocols == 0; }
25871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2588bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2589bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2590bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
2591c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff  void Profile(llvm::FoldingSetNodeID &ID);
25921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static void Profile(llvm::FoldingSetNodeID &ID,
2593c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff                      const ObjCInterfaceDecl *Decl,
2594c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff                      ObjCProtocolDecl **protocols, unsigned NumProtocols);
25951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
25960b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor  virtual Linkage getLinkage() const;
25970b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor
25981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
25991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == ObjCInterface;
26003536b443bc50d58a79f14fca9b6842541a434854Steve Naroff  }
2601a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const ObjCInterfaceType *) { return true; }
26023536b443bc50d58a79f14fca9b6842541a434854Steve Naroff};
26033536b443bc50d58a79f14fca9b6842541a434854Steve Naroff
260414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff/// ObjCObjectPointerType - Used to represent 'id', 'Interface *', 'id <p>',
260514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff/// and 'Interface <p> *'.
260614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff///
260714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff/// Duplicate protocols are removed and protocol list is canonicalized to be in
260814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff/// alphabetical order.
260914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroffclass ObjCObjectPointerType : public Type, public llvm::FoldingSetNode {
2610f6265efe7e35fb0fba315da6391368aeee1e57c9Steve Naroff  QualType PointeeType; // A builtin or interface type.
26111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
261214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  // List of protocols for this protocol conforming object type
261314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  // List is sorted on protocol name. No protocol is entered more than once.
261471842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek  ObjCProtocolDecl **Protocols;
261571842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek  unsigned NumProtocols;
261614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff
261771842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek  ObjCObjectPointerType(ASTContext &Ctx, QualType Canonical, QualType T,
261871842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek                        ObjCProtocolDecl **Protos, unsigned NumP);
261914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  friend class ASTContext;  // ASTContext creates these.
26201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
262114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroffpublic:
262271842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek  void Destroy(ASTContext& C);
262371842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek
26248f16756441450ed9fb39316e47d107fc2a1ef35bSteve Naroff  // Get the pointee type. Pointee will either be:
26258f16756441450ed9fb39316e47d107fc2a1ef35bSteve Naroff  // - a built-in type (for 'id' and 'Class').
26268f16756441450ed9fb39316e47d107fc2a1ef35bSteve Naroff  // - an interface type (for user-defined types).
26278f16756441450ed9fb39316e47d107fc2a1ef35bSteve Naroff  // - a TypedefType whose canonical type is an interface (as in 'T' below).
26288f16756441450ed9fb39316e47d107fc2a1ef35bSteve Naroff  //   For example: typedef NSObject T; T *var;
262914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  QualType getPointeeType() const { return PointeeType; }
263014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff
26311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  const ObjCInterfaceType *getInterfaceType() const {
2632183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall    return PointeeType->getAs<ObjCInterfaceType>();
263314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  }
2634de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff  /// getInterfaceDecl - returns an interface decl for user-defined types.
263514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  ObjCInterfaceDecl *getInterfaceDecl() const {
2636de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff    return getInterfaceType() ? getInterfaceType()->getDecl() : 0;
263714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  }
2638de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff  /// isObjCIdType - true for "id".
263914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  bool isObjCIdType() const {
26401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return getPointeeType()->isSpecificBuiltinType(BuiltinType::ObjCId) &&
264171842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek           !NumProtocols;
264214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  }
2643de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff  /// isObjCClassType - true for "Class".
264414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  bool isObjCClassType() const {
26451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return getPointeeType()->isSpecificBuiltinType(BuiltinType::ObjCClass) &&
264671842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek           !NumProtocols;
2647de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff  }
26488d2c0a9814e56c2b22e22d1045181c735aef62fdFariborz Jahanian
2649de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff  /// isObjCQualifiedIdType - true for "id <p>".
26501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  bool isObjCQualifiedIdType() const {
26511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return getPointeeType()->isSpecificBuiltinType(BuiltinType::ObjCId) &&
265271842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek           NumProtocols;
2653de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff  }
2654de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff  /// isObjCQualifiedClassType - true for "Class <p>".
2655470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroff  bool isObjCQualifiedClassType() const {
26561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return getPointeeType()->isSpecificBuiltinType(BuiltinType::ObjCClass) &&
265771842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek           NumProtocols;
265814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  }
265914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  /// qual_iterator and friends: this provides access to the (potentially empty)
266014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  /// list of protocols qualifying this interface.
266171842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek  typedef ObjCProtocolDecl*  const * qual_iterator;
266214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff
266371842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek  qual_iterator qual_begin() const {
266471842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek    return Protocols;
266571842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek  }
266671842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek  qual_iterator qual_end() const   {
266771842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek    return Protocols ? Protocols + NumProtocols : NULL;
266871842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek  }
266971842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek  bool qual_empty() const { return NumProtocols == 0; }
267014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff
267114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  /// getNumProtocols - Return the number of qualifying protocols in this
267214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  /// interface type, or 0 if there are none.
267371842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek  unsigned getNumProtocols() const { return NumProtocols; }
267414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff
2675bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2676bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2677bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
26780b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor  virtual Linkage getLinkage() const;
26790b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor
268014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  void Profile(llvm::FoldingSetNodeID &ID);
268114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  static void Profile(llvm::FoldingSetNodeID &ID, QualType T,
268214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff                      ObjCProtocolDecl **protocols, unsigned NumProtocols);
26831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
26841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == ObjCObjectPointer;
268514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  }
268614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  static bool classof(const ObjCObjectPointerType *) { return true; }
268714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff};
26881bb8a45f7386a23871598d05141a07af03067925Argyrios Kyrtzidis
26890953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// A qualifier set is used to build a set of qualifiers.
26900953e767ff7817f97b3ab20896b229891eeff45bJohn McCallclass QualifierCollector : public Qualifiers {
26910953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  ASTContext *Context;
26920953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
26930953e767ff7817f97b3ab20896b229891eeff45bJohn McCallpublic:
26940953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  QualifierCollector(Qualifiers Qs = Qualifiers())
26950953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    : Qualifiers(Qs), Context(0) {}
26960953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  QualifierCollector(ASTContext &Context, Qualifiers Qs = Qualifiers())
26970953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    : Qualifiers(Qs), Context(&Context) {}
26980953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
26990953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void setContext(ASTContext &C) { Context = &C; }
27000953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
27010953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// Collect any qualifiers on the given type and return an
27020953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// unqualified type.
27030953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  const Type *strip(QualType QT) {
2704a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor    addFastQualifiers(QT.getLocalFastQualifiers());
2705a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor    if (QT.hasLocalNonFastQualifiers()) {
27060953e767ff7817f97b3ab20896b229891eeff45bJohn McCall      const ExtQuals *EQ = QT.getExtQualsUnsafe();
27070953e767ff7817f97b3ab20896b229891eeff45bJohn McCall      Context = &EQ->getContext();
27080953e767ff7817f97b3ab20896b229891eeff45bJohn McCall      addQualifiers(EQ->getQualifiers());
27090953e767ff7817f97b3ab20896b229891eeff45bJohn McCall      return EQ->getBaseType();
27100953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    }
27110953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return QT.getTypePtrUnsafe();
27120953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
27130953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
27140953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// Apply the collected qualifiers to the given type.
27150953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  QualType apply(QualType QT) const;
27160953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
27170953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// Apply the collected qualifiers to the given type.
27180953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  QualType apply(const Type* T) const;
27190953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
27200953e767ff7817f97b3ab20896b229891eeff45bJohn McCall};
27210953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
27220953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
2723611c1fff195d32df97706e0920c92468b2509900Chris Lattner// Inline function definitions.
27245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2725467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCallinline bool QualType::isCanonical() const {
2726467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall  const Type *T = getTypePtr();
2727a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  if (hasLocalQualifiers())
2728467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall    return T->isCanonicalUnqualified() && !isa<ArrayType>(T);
2729467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall  return T->isCanonicalUnqualified();
2730467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall}
2731467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall
273254e14c4db764c0636160d26c5bbf491637c83a76John McCallinline bool QualType::isCanonicalAsParam() const {
2733a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  if (hasLocalQualifiers()) return false;
273454e14c4db764c0636160d26c5bbf491637c83a76John McCall  const Type *T = getTypePtr();
273554e14c4db764c0636160d26c5bbf491637c83a76John McCall  return T->isCanonicalUnqualified() &&
273654e14c4db764c0636160d26c5bbf491637c83a76John McCall           !isa<FunctionType>(T) && !isa<ArrayType>(T);
273754e14c4db764c0636160d26c5bbf491637c83a76John McCall}
273854e14c4db764c0636160d26c5bbf491637c83a76John McCall
2739fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregorinline bool QualType::isConstQualified() const {
2740fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  return isLocalConstQualified() ||
2741fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor              getTypePtr()->getCanonicalTypeInternal().isLocalConstQualified();
2742fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor}
2743fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor
2744fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregorinline bool QualType::isRestrictQualified() const {
2745fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  return isLocalRestrictQualified() ||
2746fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor            getTypePtr()->getCanonicalTypeInternal().isLocalRestrictQualified();
2747fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor}
2748fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor
2749fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor
2750fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregorinline bool QualType::isVolatileQualified() const {
2751fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  return isLocalVolatileQualified() ||
2752fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  getTypePtr()->getCanonicalTypeInternal().isLocalVolatileQualified();
2753fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor}
2754fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor
2755fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregorinline bool QualType::hasQualifiers() const {
2756fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  return hasLocalQualifiers() ||
2757fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor                  getTypePtr()->getCanonicalTypeInternal().hasLocalQualifiers();
2758fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor}
2759fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor
2760fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregorinline Qualifiers QualType::getQualifiers() const {
2761fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  Qualifiers Quals = getLocalQualifiers();
2762fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  Quals.addQualifiers(
2763fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor                 getTypePtr()->getCanonicalTypeInternal().getLocalQualifiers());
2764fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  return Quals;
2765fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor}
2766fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor
2767fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregorinline unsigned QualType::getCVRQualifiers() const {
2768fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  return getLocalCVRQualifiers() |
2769fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor              getTypePtr()->getCanonicalTypeInternal().getLocalCVRQualifiers();
2770fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor}
2771e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth
2772e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth/// getCVRQualifiersThroughArrayTypes - If there are CVR qualifiers for this
2773e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth/// type, returns them. Otherwise, if this is an array type, recurses
2774e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth/// on the element type until some qualifiers have been found or a non-array
2775e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth/// type reached.
2776e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruthinline unsigned QualType::getCVRQualifiersThroughArrayTypes() const {
2777e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth  if (unsigned Quals = getCVRQualifiers())
2778e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth    return Quals;
2779e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth  QualType CT = getTypePtr()->getCanonicalTypeInternal();
2780e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth  if (const ArrayType *AT = dyn_cast<ArrayType>(CT))
2781e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth    return AT->getElementType().getCVRQualifiersThroughArrayTypes();
2782e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth  return 0;
2783e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth}
2784e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth
27850953e767ff7817f97b3ab20896b229891eeff45bJohn McCallinline void QualType::removeConst() {
27860953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  removeFastQualifiers(Qualifiers::Const);
27870953e767ff7817f97b3ab20896b229891eeff45bJohn McCall}
27880953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
27890953e767ff7817f97b3ab20896b229891eeff45bJohn McCallinline void QualType::removeRestrict() {
27900953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  removeFastQualifiers(Qualifiers::Restrict);
27910953e767ff7817f97b3ab20896b229891eeff45bJohn McCall}
27920953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
27930953e767ff7817f97b3ab20896b229891eeff45bJohn McCallinline void QualType::removeVolatile() {
27940953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  QualifierCollector Qc;
27950953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  const Type *Ty = Qc.strip(*this);
27960953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  if (Qc.hasVolatile()) {
27970953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Qc.removeVolatile();
27980953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    *this = Qc.apply(Ty);
27990953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
28000953e767ff7817f97b3ab20896b229891eeff45bJohn McCall}
28010953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
28020953e767ff7817f97b3ab20896b229891eeff45bJohn McCallinline void QualType::removeCVRQualifiers(unsigned Mask) {
28036b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall  assert(!(Mask & ~Qualifiers::CVRMask) && "mask has non-CVR bits");
28040953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
28050953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Fast path: we don't need to touch the slow qualifiers.
28060953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  if (!(Mask & ~Qualifiers::FastMask)) {
28070953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    removeFastQualifiers(Mask);
28080953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return;
28090953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
28100953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
28110953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  QualifierCollector Qc;
28120953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  const Type *Ty = Qc.strip(*this);
28130953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  Qc.removeCVRQualifiers(Mask);
28140953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  *this = Qc.apply(Ty);
2815ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb}
2816ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb
2817ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb/// getAddressSpace - Return the address space of this type.
2818ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lambinline unsigned QualType::getAddressSpace() const {
2819a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  if (hasLocalNonFastQualifiers()) {
28200953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    const ExtQuals *EQ = getExtQualsUnsafe();
28210953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    if (EQ->hasAddressSpace())
28220953e767ff7817f97b3ab20896b229891eeff45bJohn McCall      return EQ->getAddressSpace();
28230953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
28240953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
28254243a94b43ef6207938f3023dfcfb804dd545363Chris Lattner  QualType CT = getTypePtr()->getCanonicalTypeInternal();
2826a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  if (CT.hasLocalNonFastQualifiers()) {
28270953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    const ExtQuals *EQ = CT.getExtQualsUnsafe();
28280953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    if (EQ->hasAddressSpace())
28290953e767ff7817f97b3ab20896b229891eeff45bJohn McCall      return EQ->getAddressSpace();
28300953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
28310953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
28324243a94b43ef6207938f3023dfcfb804dd545363Chris Lattner  if (const ArrayType *AT = dyn_cast<ArrayType>(CT))
2833c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner    return AT->getElementType().getAddressSpace();
28344243a94b43ef6207938f3023dfcfb804dd545363Chris Lattner  if (const RecordType *RT = dyn_cast<RecordType>(CT))
28358e7dafec4b70303dfaff95151cd06bfc5532720cNate Begeman    return RT->getAddressSpace();
2836ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb  return 0;
2837ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb}
2838611c1fff195d32df97706e0920c92468b2509900Chris Lattner
2839d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian/// getObjCGCAttr - Return the gc attribute of this type.
28400953e767ff7817f97b3ab20896b229891eeff45bJohn McCallinline Qualifiers::GC QualType::getObjCGCAttr() const {
2841a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  if (hasLocalNonFastQualifiers()) {
28420953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    const ExtQuals *EQ = getExtQualsUnsafe();
28430953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    if (EQ->hasObjCGCAttr())
28440953e767ff7817f97b3ab20896b229891eeff45bJohn McCall      return EQ->getObjCGCAttr();
28450953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
28460953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
2847d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian  QualType CT = getTypePtr()->getCanonicalTypeInternal();
2848a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  if (CT.hasLocalNonFastQualifiers()) {
28490953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    const ExtQuals *EQ = CT.getExtQualsUnsafe();
28500953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    if (EQ->hasObjCGCAttr())
28510953e767ff7817f97b3ab20896b229891eeff45bJohn McCall      return EQ->getObjCGCAttr();
28520953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
28530953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
2854d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian  if (const ArrayType *AT = dyn_cast<ArrayType>(CT))
2855d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian      return AT->getElementType().getObjCGCAttr();
2856183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  if (const ObjCObjectPointerType *PT = CT->getAs<ObjCObjectPointerType>())
28571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return PT->getPointeeType().getObjCGCAttr();
2858ac423ba85bb59cc7cc1d43081b20d7e8d40355ffFariborz Jahanian  // We most look at all pointer types, not just pointer to interface types.
2859ac423ba85bb59cc7cc1d43081b20d7e8d40355ffFariborz Jahanian  if (const PointerType *PT = CT->getAs<PointerType>())
28601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return PT->getPointeeType().getObjCGCAttr();
28610953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  return Qualifiers::GCNone;
2862d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian}
28632455636163fdd18581d7fdae816433f886d88213Mike Stump
2864ae92140b542d5c1c096e39e74e59526184819b30Mike Stump  /// getNoReturnAttr - Returns true if the type has the noreturn attribute,
2865ae92140b542d5c1c096e39e74e59526184819b30Mike Stump  /// false otherwise.
28662455636163fdd18581d7fdae816433f886d88213Mike Stumpinline bool QualType::getNoReturnAttr() const {
28672455636163fdd18581d7fdae816433f886d88213Mike Stump  QualType CT = getTypePtr()->getCanonicalTypeInternal();
28686217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek  if (const PointerType *PT = getTypePtr()->getAs<PointerType>()) {
2869183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall    if (const FunctionType *FT = PT->getPointeeType()->getAs<FunctionType>())
28702455636163fdd18581d7fdae816433f886d88213Mike Stump      return FT->getNoReturnAttr();
2871183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  } else if (const FunctionType *FT = getTypePtr()->getAs<FunctionType>())
28722455636163fdd18581d7fdae816433f886d88213Mike Stump    return FT->getNoReturnAttr();
28732455636163fdd18581d7fdae816433f886d88213Mike Stump
28742455636163fdd18581d7fdae816433f886d88213Mike Stump  return false;
28752455636163fdd18581d7fdae816433f886d88213Mike Stump}
28761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2877ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor/// getCallConv - Returns the calling convention of the type if the type
2878ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor/// is a function type, CC_Default otherwise.
2879ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregorinline CallingConv QualType::getCallConv() const {
2880ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor  if (const PointerType *PT = getTypePtr()->getAs<PointerType>())
2881ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor    return PT->getPointeeType().getCallConv();
2882ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor  else if (const ReferenceType *RT = getTypePtr()->getAs<ReferenceType>())
2883ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor    return RT->getPointeeType().getCallConv();
2884ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor  else if (const MemberPointerType *MPT =
2885ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor           getTypePtr()->getAs<MemberPointerType>())
2886ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor    return MPT->getPointeeType().getCallConv();
2887ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor  else if (const BlockPointerType *BPT =
2888ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor           getTypePtr()->getAs<BlockPointerType>()) {
2889ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor    if (const FunctionType *FT = BPT->getPointeeType()->getAs<FunctionType>())
2890ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor      return FT->getCallConv();
2891ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor  } else if (const FunctionType *FT = getTypePtr()->getAs<FunctionType>())
2892ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor    return FT->getCallConv();
2893ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor
2894ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor  return CC_Default;
2895ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor}
2896ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor
2897e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// isMoreQualifiedThan - Determine whether this type is more
2898e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// qualified than the Other type. For example, "const volatile int"
2899e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// is more qualified than "const int", "volatile int", and
2900e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// "int". However, it is not more qualified than "const volatile
2901e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// int".
2902e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregorinline bool QualType::isMoreQualifiedThan(QualType Other) const {
29030953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // FIXME: work on arbitrary qualifiers
2904e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth  unsigned MyQuals = this->getCVRQualifiersThroughArrayTypes();
2905e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth  unsigned OtherQuals = Other.getCVRQualifiersThroughArrayTypes();
2906ecca7536488e425417dcb005c39cc15ae1947aabChris Lattner  if (getAddressSpace() != Other.getAddressSpace())
2907ecca7536488e425417dcb005c39cc15ae1947aabChris Lattner    return false;
2908e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor  return MyQuals != OtherQuals && (MyQuals | OtherQuals) == MyQuals;
2909e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor}
2910e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor
2911e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// isAtLeastAsQualifiedAs - Determine whether this type is at last
2912e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// as qualified as the Other type. For example, "const volatile
2913e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// int" is at least as qualified as "const int", "volatile int",
2914e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// "int", and "const volatile int".
2915e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregorinline bool QualType::isAtLeastAsQualifiedAs(QualType Other) const {
29160953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // FIXME: work on arbitrary qualifiers
2917e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth  unsigned MyQuals = this->getCVRQualifiersThroughArrayTypes();
2918e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth  unsigned OtherQuals = Other.getCVRQualifiersThroughArrayTypes();
2919ecca7536488e425417dcb005c39cc15ae1947aabChris Lattner  if (getAddressSpace() != Other.getAddressSpace())
2920ecca7536488e425417dcb005c39cc15ae1947aabChris Lattner    return false;
2921e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor  return (MyQuals | OtherQuals) == MyQuals;
2922e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor}
2923e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor
2924e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// getNonReferenceType - If Type is a reference type (e.g., const
2925e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// int&), returns the type that the reference refers to ("const
2926e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// int"). Otherwise, returns the type itself. This routine is used
2927e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// throughout Sema to implement C++ 5p6:
2928e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor///
2929e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor///   If an expression initially has the type "reference to T" (8.3.2,
2930e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor///   8.5.3), the type is adjusted to "T" prior to any further
2931e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor///   analysis, the expression designates the object or function
2932e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor///   denoted by the reference, and the expression is an lvalue.
2933e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregorinline QualType QualType::getNonReferenceType() const {
29346217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek  if (const ReferenceType *RefType = (*this)->getAs<ReferenceType>())
2935e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor    return RefType->getPointeeType();
2936e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor  else
2937e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor    return *this;
2938e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor}
2939e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor
29402b1cc8be4dda4cd122485be0168b3c43d7dff15fChris Lattnerinline const ObjCInterfaceType *Type::getAsPointerToObjCInterfaceType() const {
29416217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek  if (const PointerType *PT = getAs<PointerType>())
2942183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall    return PT->getPointeeType()->getAs<ObjCInterfaceType>();
29432b1cc8be4dda4cd122485be0168b3c43d7dff15fChris Lattner  return 0;
29442b1cc8be4dda4cd122485be0168b3c43d7dff15fChris Lattner}
29451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2946611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isFunctionType() const {
2947a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<FunctionType>(CanonicalType);
2948611c1fff195d32df97706e0920c92468b2509900Chris Lattner}
2949611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isPointerType() const {
2950a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<PointerType>(CanonicalType);
2951611c1fff195d32df97706e0920c92468b2509900Chris Lattner}
295258f9f2c884af6b72d036b746a016d8031d31cb7aSteve Naroffinline bool Type::isAnyPointerType() const {
295358f9f2c884af6b72d036b746a016d8031d31cb7aSteve Naroff  return isPointerType() || isObjCObjectPointerType();
295458f9f2c884af6b72d036b746a016d8031d31cb7aSteve Naroff}
29555618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroffinline bool Type::isBlockPointerType() const {
2956a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<BlockPointerType>(CanonicalType);
29575618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff}
2958bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattnerinline bool Type::isReferenceType() const {
2959a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<ReferenceType>(CanonicalType);
2960bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner}
29617c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlinline bool Type::isLValueReferenceType() const {
2962a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<LValueReferenceType>(CanonicalType);
29637c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl}
29647c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlinline bool Type::isRValueReferenceType() const {
2965a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<RValueReferenceType>(CanonicalType);
29667c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl}
2967498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenekinline bool Type::isFunctionPointerType() const {
29686217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek  if (const PointerType* T = getAs<PointerType>())
2969498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek    return T->getPointeeType()->isFunctionType();
2970498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek  else
2971498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek    return false;
2972498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek}
2973f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlinline bool Type::isMemberPointerType() const {
2974a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<MemberPointerType>(CanonicalType);
2975f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl}
2976f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlinline bool Type::isMemberFunctionPointerType() const {
29776217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek  if (const MemberPointerType* T = getAs<MemberPointerType>())
2978f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    return T->getPointeeType()->isFunctionType();
2979f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  else
2980f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    return false;
2981f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl}
2982611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isArrayType() const {
2983a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<ArrayType>(CanonicalType);
2984611c1fff195d32df97706e0920c92468b2509900Chris Lattner}
2985c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattnerinline bool Type::isConstantArrayType() const {
2986a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<ConstantArrayType>(CanonicalType);
2987c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner}
2988c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattnerinline bool Type::isIncompleteArrayType() const {
2989a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<IncompleteArrayType>(CanonicalType);
2990c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner}
2991c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattnerinline bool Type::isVariableArrayType() const {
2992a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<VariableArrayType>(CanonicalType);
2993c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner}
2994898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorinline bool Type::isDependentSizedArrayType() const {
2995a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<DependentSizedArrayType>(CanonicalType);
2996898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor}
2997611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isRecordType() const {
2998a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<RecordType>(CanonicalType);
2999611c1fff195d32df97706e0920c92468b2509900Chris Lattner}
3000f23d364084d1aabea688222780d6fc1dd8c7f78cChris Lattnerinline bool Type::isAnyComplexType() const {
3001a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<ComplexType>(CanonicalType);
3002f23d364084d1aabea688222780d6fc1dd8c7f78cChris Lattner}
3003611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isVectorType() const {
3004a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<VectorType>(CanonicalType);
3005611c1fff195d32df97706e0920c92468b2509900Chris Lattner}
3006213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begemaninline bool Type::isExtVectorType() const {
3007a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<ExtVectorType>(CanonicalType);
3008611c1fff195d32df97706e0920c92468b2509900Chris Lattner}
3009d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroffinline bool Type::isObjCObjectPointerType() const {
3010a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<ObjCObjectPointerType>(CanonicalType);
3011d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff}
3012a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekinline bool Type::isObjCInterfaceType() const {
3013a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<ObjCInterfaceType>(CanonicalType);
3014368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner}
3015a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekinline bool Type::isObjCQualifiedIdType() const {
3016183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>())
3017d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff    return OPT->isObjCQualifiedIdType();
3018d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff  return false;
3019d58fabf7ed279be18a5e82617f809c9deff9be67Fariborz Jahanian}
3020470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroffinline bool Type::isObjCQualifiedClassType() const {
3021183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>())
3022470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroff    return OPT->isObjCQualifiedClassType();
3023470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroff  return false;
3024470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroff}
302514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroffinline bool Type::isObjCIdType() const {
3026183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>())
302714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff    return OPT->isObjCIdType();
302814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  return false;
302914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff}
303014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroffinline bool Type::isObjCClassType() const {
3031183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>())
303214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff    return OPT->isObjCClassType();
303314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  return false;
303414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff}
303513dcd00615de5c4279d97bdf63cd5f0a14fd9dccFariborz Jahanianinline bool Type::isObjCSelType() const {
30368d2c0a9814e56c2b22e22d1045181c735aef62fdFariborz Jahanian  if (const PointerType *OPT = getAs<PointerType>())
30378d2c0a9814e56c2b22e22d1045181c735aef62fdFariborz Jahanian    return OPT->getPointeeType()->isSpecificBuiltinType(BuiltinType::ObjCSel);
303813dcd00615de5c4279d97bdf63cd5f0a14fd9dccFariborz Jahanian  return false;
303913dcd00615de5c4279d97bdf63cd5f0a14fd9dccFariborz Jahanian}
3040de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroffinline bool Type::isObjCBuiltinType() const {
304113dcd00615de5c4279d97bdf63cd5f0a14fd9dccFariborz Jahanian  return isObjCIdType() || isObjCClassType() || isObjCSelType();
3042de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff}
304372c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregorinline bool Type::isTemplateTypeParmType() const {
3044a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<TemplateTypeParmType>(CanonicalType);
304572c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor}
304672c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor
3047e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbarinline bool Type::isSpecificBuiltinType(unsigned K) const {
3048183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  if (const BuiltinType *BT = getAs<BuiltinType>())
3049e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar    if (BT->getKind() == (BuiltinType::Kind) K)
3050e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar      return true;
3051e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar  return false;
3052e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar}
3053e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar
3054063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor/// \brief Determines whether this is a type for which one can define
3055063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor/// an overloaded operator.
3056063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregorinline bool Type::isOverloadableType() const {
3057063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  return isDependentType() || isRecordType() || isEnumeralType();
3058904eed3f6148758d39a2d3c88f3133274460d645Douglas Gregor}
3059904eed3f6148758d39a2d3c88f3133274460d645Douglas Gregor
30608958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbarinline bool Type::hasPointerRepresentation() const {
30618958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar  return (isPointerType() || isReferenceType() || isBlockPointerType() ||
30621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump          isObjCInterfaceType() || isObjCObjectPointerType() ||
30636e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl          isObjCQualifiedInterfaceType() || isNullPtrType());
30648958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar}
30658958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar
3066820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanianinline bool Type::hasObjCPointerRepresentation() const {
30671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  return (isObjCInterfaceType() || isObjCObjectPointerType() ||
3068820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian          isObjCQualifiedInterfaceType());
3069820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian}
3070820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian
307122caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner/// Insertion operator for diagnostics.  This allows sending QualType's into a
307222caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner/// diagnostic with <<.
307322caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattnerinline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
307422caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner                                           QualType T) {
307522caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner  DB.AddTaggedVal(reinterpret_cast<intptr_t>(T.getAsOpaquePtr()),
307622caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner                  Diagnostic::ak_qualtype);
307722caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner  return DB;
307822caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner}
30791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
308089c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor// Helper class template that is used by Type::getAs to ensure that one does
308189c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor// not try to look through a qualified type to get to an array type.
308289c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregortemplate<typename T,
308389c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor         bool isArrayType = (llvm::is_same<T, ArrayType>::value ||
308489c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor                             llvm::is_base_of<ArrayType, T>::value)>
308589c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregorstruct ArrayType_cannot_be_used_with_getAs { };
308689c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor
308789c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregortemplate<typename T>
308889c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregorstruct ArrayType_cannot_be_used_with_getAs<T, true>;
308989c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor
30901a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek/// Member-template getAs<specific type>'.
30911a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenektemplate <typename T> const T *Type::getAs() const {
309289c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor  ArrayType_cannot_be_used_with_getAs<T> at;
309389c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor  (void)at;
309489c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor
30951a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek  // If this is directly a T type, return it.
30961a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek  if (const T *Ty = dyn_cast<T>(this))
30971a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek    return Ty;
30981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
30991a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek  // If the canonical form of this type isn't the right kind, reject it.
31000953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  if (!isa<T>(CanonicalType))
31011a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek    return 0;
31021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
31030953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // If this is a typedef for the type, strip the typedef off without
31041a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek  // losing all typedef information.
3105bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  return cast<T>(getUnqualifiedDesugaredType());
31061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump}
310722caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner
31085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}  // end namespace clang
31095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
31105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif
3111