Type.h revision 146060435c3efce95c95a092c7a1eb651cfb9ae0
15f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===--- Type.h - C Language Family Type Representation ---------*- C++ -*-===//
25f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
35f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//                     The LLVM Compiler Infrastructure
45f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
50bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// This file is distributed under the University of Illinois Open Source
60bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// License. See LICENSE.TXT for details.
75f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
85f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
95f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//  This file defines the Type interface and subclasses.
115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#ifndef LLVM_CLANG_AST_TYPE_H
155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#define LLVM_CLANG_AST_TYPE_H
165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1722caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner#include "clang/Basic/Diagnostic.h"
188b5b4099c61a136e9a1714c4d8a593febe942268Sebastian Redl#include "clang/Basic/ExceptionSpecificationType.h"
191734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor#include "clang/Basic/IdentifierTable.h"
200b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor#include "clang/Basic/Linkage.h"
2147c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth#include "clang/Basic/PartialDiagnostic.h"
221fb0caaa7bef765b85972274e3b434af2572c141John McCall#include "clang/Basic/Visibility.h"
23e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor#include "clang/AST/NestedNameSpecifier.h"
247532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor#include "clang/AST/TemplateName.h"
255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "llvm/Support/Casting.h"
2650d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor#include "llvm/Support/type_traits.h"
27fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff#include "llvm/ADT/APSInt.h"
285cf243a883872441d73ca49cea7e20de5802629bChris Lattner#include "llvm/ADT/FoldingSet.h"
29cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor#include "llvm/ADT/Optional.h"
305cf243a883872441d73ca49cea7e20de5802629bChris Lattner#include "llvm/ADT/PointerIntPair.h"
311734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor#include "llvm/ADT/PointerUnion.h"
327532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor
335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing llvm::isa;
345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing llvm::cast;
355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing llvm::cast_or_null;
365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing llvm::dyn_cast;
375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing llvm::dyn_cast_or_null;
386b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCallnamespace clang {
396b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall  enum {
40f7616b9067790757f4e12e834b216c53c8c04ebeDouglas Gregor    TypeAlignmentInBits = 4,
416b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall    TypeAlignment = 1 << TypeAlignmentInBits
426b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall  };
43aed1df80bf64228e1429c1edc408397f9174847cChris Lattner  class Type;
44aed1df80bf64228e1429c1edc408397f9174847cChris Lattner  class ExtQuals;
45aed1df80bf64228e1429c1edc408397f9174847cChris Lattner  class QualType;
466b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall}
475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
484e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattnernamespace llvm {
494e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner  template <typename T>
50daae940507f2e93c6fa12e8062fa958e34cc2d1cChris Lattner  class PointerLikeTypeTraits;
51bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner  template<>
52bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner  class PointerLikeTypeTraits< ::clang::Type*> {
53bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner  public:
54bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner    static inline void *getAsVoidPointer(::clang::Type *P) { return P; }
55bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner    static inline ::clang::Type *getFromVoidPointer(void *P) {
56bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner      return static_cast< ::clang::Type*>(P);
57bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner    }
586b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall    enum { NumLowBitsAvailable = clang::TypeAlignmentInBits };
59bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner  };
600953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  template<>
610953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  class PointerLikeTypeTraits< ::clang::ExtQuals*> {
620953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  public:
630953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    static inline void *getAsVoidPointer(::clang::ExtQuals *P) { return P; }
640953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    static inline ::clang::ExtQuals *getFromVoidPointer(void *P) {
650953e767ff7817f97b3ab20896b229891eeff45bJohn McCall      return static_cast< ::clang::ExtQuals*>(P);
660953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    }
676b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall    enum { NumLowBitsAvailable = clang::TypeAlignmentInBits };
680953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  };
69aed1df80bf64228e1429c1edc408397f9174847cChris Lattner
70aed1df80bf64228e1429c1edc408397f9174847cChris Lattner  template <>
71aed1df80bf64228e1429c1edc408397f9174847cChris Lattner  struct isPodLike<clang::QualType> { static const bool value = true; };
724e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner}
734e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner
745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang {
755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class ASTContext;
76162e1c1b487352434552147967c3dd296ebee2f7Richard Smith  class TypedefNameDecl;
7755f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  class TemplateDecl;
7872c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor  class TemplateTypeParmDecl;
79aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor  class NonTypeTemplateParmDecl;
807532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor  class TemplateTemplateParmDecl;
815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class TagDecl;
825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class RecordDecl;
8349aa7ff1245abd03e6e998e01302df31e4c6f8f6Argyrios Kyrtzidis  class CXXRecordDecl;
845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class EnumDecl;
8521d50e12c3c412d8457071dc419363b7a7e8b855Ted Kremenek  class FieldDecl;
86a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  class ObjCInterfaceDecl;
87a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  class ObjCProtocolDecl;
88a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  class ObjCMethodDecl;
89ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  class UnresolvedUsingTypenameDecl;
905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class Expr;
91b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek  class Stmt;
925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class SourceLocation;
9392866e2e90f6d93fb95e25a7ac4438e239d89ce6Ted Kremenek  class StmtIteratorBase;
9440808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  class TemplateArgument;
95833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  class TemplateArgumentLoc;
96d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  class TemplateArgumentListInfo;
97465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  class ElaboratedType;
983b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  class ExtQuals;
993b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  class ExtQualsTypeCommonBase;
1003b4ea54acf01f72f6eb74d96689dda86d950228fDaniel Dunbar  struct PrintingPolicy;
10172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor
102ead608af31b6c9abeae1ca6d0b75094dac4641c0John McCall  template <typename> class CanQual;
103ead608af31b6c9abeae1ca6d0b75094dac4641c0John McCall  typedef CanQual<Type> CanQualType;
104ead608af31b6c9abeae1ca6d0b75094dac4641c0John McCall
10572564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  // Provide forward declarations for all of the *Type classes
10672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#define TYPE(Class, Base) class Class##Type;
10772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#include "clang/AST/TypeNodes.def"
108f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl
1090953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// Qualifiers - The collection of all-type qualifiers we support.
1100953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// Clang supports five independent qualifiers:
1110953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// * C99: const, volatile, and restrict
1120953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// * Embedded C (TR18037): address spaces
1130953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// * Objective C: the GC attributes (none, weak, or strong)
1140953e767ff7817f97b3ab20896b229891eeff45bJohn McCallclass Qualifiers {
1155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
1160953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  enum TQ { // NOTE: These flags must be kept in sync with DeclSpec::TQ.
1175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Const    = 0x1,
1185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Restrict = 0x2,
1195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Volatile = 0x4,
1200953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    CVRMask = Const | Volatile | Restrict
1215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
1221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1230953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  enum GC {
124d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian    GCNone = 0,
125d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian    Weak,
126d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian    Strong
127d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian  };
128efadb7768e7c7418185f5a4010ecd8b21ca9731bJohn McCall
129f85e193739c953358c865005855253af4f68a497John McCall  enum ObjCLifetime {
130f85e193739c953358c865005855253af4f68a497John McCall    /// There is no lifetime qualification on this type.
131f85e193739c953358c865005855253af4f68a497John McCall    OCL_None,
132f85e193739c953358c865005855253af4f68a497John McCall
133f85e193739c953358c865005855253af4f68a497John McCall    /// This object can be modified without requiring retains or
134f85e193739c953358c865005855253af4f68a497John McCall    /// releases.
135f85e193739c953358c865005855253af4f68a497John McCall    OCL_ExplicitNone,
136f85e193739c953358c865005855253af4f68a497John McCall
137f85e193739c953358c865005855253af4f68a497John McCall    /// Assigning into this object requires the old value to be
138f85e193739c953358c865005855253af4f68a497John McCall    /// released and the new value to be retained.  The timing of the
139f85e193739c953358c865005855253af4f68a497John McCall    /// release of the old value is inexact: it may be moved to
140f85e193739c953358c865005855253af4f68a497John McCall    /// immediately after the last known point where the value is
141f85e193739c953358c865005855253af4f68a497John McCall    /// live.
142f85e193739c953358c865005855253af4f68a497John McCall    OCL_Strong,
143f85e193739c953358c865005855253af4f68a497John McCall
144f85e193739c953358c865005855253af4f68a497John McCall    /// Reading or writing from this object requires a barrier call.
145f85e193739c953358c865005855253af4f68a497John McCall    OCL_Weak,
146f85e193739c953358c865005855253af4f68a497John McCall
147f85e193739c953358c865005855253af4f68a497John McCall    /// Assigning into this object requires a lifetime extension.
148f85e193739c953358c865005855253af4f68a497John McCall    OCL_Autoreleasing
149f85e193739c953358c865005855253af4f68a497John McCall  };
150f85e193739c953358c865005855253af4f68a497John McCall
1510953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  enum {
1520953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    /// The maximum supported address space number.
1530953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    /// 24 bits should be enough for anyone.
1540953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    MaxAddressSpace = 0xffffffu,
1550953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
1560953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    /// The width of the "fast" qualifier mask.
157f7616b9067790757f4e12e834b216c53c8c04ebeDouglas Gregor    FastWidth = 3,
1580953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
1590953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    /// The fast qualifier mask.
1600953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    FastMask = (1 << FastWidth) - 1
1610953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  };
1620953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
1630953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  Qualifiers() : Mask(0) {}
1640953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
1650953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  static Qualifiers fromFastMask(unsigned Mask) {
1660953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Qualifiers Qs;
1670953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Qs.addFastQualifiers(Mask);
1680953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return Qs;
1690953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
1700953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
1710953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  static Qualifiers fromCVRMask(unsigned CVR) {
1720953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Qualifiers Qs;
1730953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Qs.addCVRQualifiers(CVR);
1740953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return Qs;
1750953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
1760953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
1770953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Deserialize qualifiers from an opaque representation.
1780953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  static Qualifiers fromOpaqueValue(unsigned opaque) {
1790953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Qualifiers Qs;
1800953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Qs.Mask = opaque;
1810953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return Qs;
1820953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
1830953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
1840953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Serialize these qualifiers into an opaque representation.
1850953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  unsigned getAsOpaqueValue() const {
1860953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return Mask;
1870953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
1880953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
1890953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool hasConst() const { return Mask & Const; }
1900953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void setConst(bool flag) {
1910953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask = (Mask & ~Const) | (flag ? Const : 0);
1920953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
1930953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void removeConst() { Mask &= ~Const; }
1940953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void addConst() { Mask |= Const; }
1950953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
1960953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool hasVolatile() const { return Mask & Volatile; }
1970953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void setVolatile(bool flag) {
1980953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask = (Mask & ~Volatile) | (flag ? Volatile : 0);
1990953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2000953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void removeVolatile() { Mask &= ~Volatile; }
2010953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void addVolatile() { Mask |= Volatile; }
2020953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
2030953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool hasRestrict() const { return Mask & Restrict; }
2040953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void setRestrict(bool flag) {
2050953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask = (Mask & ~Restrict) | (flag ? Restrict : 0);
2060953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2070953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void removeRestrict() { Mask &= ~Restrict; }
2080953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void addRestrict() { Mask |= Restrict; }
2090953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
2100953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool hasCVRQualifiers() const { return getCVRQualifiers(); }
2110953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  unsigned getCVRQualifiers() const { return Mask & CVRMask; }
2120953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void setCVRQualifiers(unsigned mask) {
2130953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(!(mask & ~CVRMask) && "bitmask contains non-CVR bits");
2140953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask = (Mask & ~CVRMask) | mask;
2150953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2160953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void removeCVRQualifiers(unsigned mask) {
2170953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(!(mask & ~CVRMask) && "bitmask contains non-CVR bits");
2180953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask &= ~mask;
2190953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2200953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void removeCVRQualifiers() {
2210953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    removeCVRQualifiers(CVRMask);
2220953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2230953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void addCVRQualifiers(unsigned mask) {
2240953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(!(mask & ~CVRMask) && "bitmask contains non-CVR bits");
2250953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask |= mask;
2260953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2270953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
2280953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool hasObjCGCAttr() const { return Mask & GCAttrMask; }
2290953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  GC getObjCGCAttr() const { return GC((Mask & GCAttrMask) >> GCAttrShift); }
2300953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void setObjCGCAttr(GC type) {
2310953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask = (Mask & ~GCAttrMask) | (type << GCAttrShift);
2320953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2330953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void removeObjCGCAttr() { setObjCGCAttr(GCNone); }
2340953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void addObjCGCAttr(GC type) {
2350953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(type);
2360953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    setObjCGCAttr(type);
2370953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2382234873111009eb8655d63362cedc422eb9fc517John McCall  Qualifiers withoutObjCGCAttr() const {
2392234873111009eb8655d63362cedc422eb9fc517John McCall    Qualifiers qs = *this;
2402234873111009eb8655d63362cedc422eb9fc517John McCall    qs.removeObjCGCAttr();
2412234873111009eb8655d63362cedc422eb9fc517John McCall    return qs;
2422234873111009eb8655d63362cedc422eb9fc517John McCall  }
243f85e193739c953358c865005855253af4f68a497John McCall  Qualifiers withoutObjCGLifetime() const {
244f85e193739c953358c865005855253af4f68a497John McCall    Qualifiers qs = *this;
245f85e193739c953358c865005855253af4f68a497John McCall    qs.removeObjCLifetime();
246f85e193739c953358c865005855253af4f68a497John McCall    return qs;
247f85e193739c953358c865005855253af4f68a497John McCall  }
2480953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
249f85e193739c953358c865005855253af4f68a497John McCall  bool hasObjCLifetime() const { return Mask & LifetimeMask; }
250f85e193739c953358c865005855253af4f68a497John McCall  ObjCLifetime getObjCLifetime() const {
251f85e193739c953358c865005855253af4f68a497John McCall    return ObjCLifetime((Mask & LifetimeMask) >> LifetimeShift);
252f85e193739c953358c865005855253af4f68a497John McCall  }
253f85e193739c953358c865005855253af4f68a497John McCall  void setObjCLifetime(ObjCLifetime type) {
254f85e193739c953358c865005855253af4f68a497John McCall    Mask = (Mask & ~LifetimeMask) | (type << LifetimeShift);
255f85e193739c953358c865005855253af4f68a497John McCall  }
256f85e193739c953358c865005855253af4f68a497John McCall  void removeObjCLifetime() { setObjCLifetime(OCL_None); }
257f85e193739c953358c865005855253af4f68a497John McCall  void addObjCLifetime(ObjCLifetime type) {
258f85e193739c953358c865005855253af4f68a497John McCall    assert(type);
259f85e193739c953358c865005855253af4f68a497John McCall    setObjCLifetime(type);
260f85e193739c953358c865005855253af4f68a497John McCall  }
261f85e193739c953358c865005855253af4f68a497John McCall
262f85e193739c953358c865005855253af4f68a497John McCall  /// True if the lifetime is neither None or ExplicitNone.
263f85e193739c953358c865005855253af4f68a497John McCall  bool hasNonTrivialObjCLifetime() const {
264f85e193739c953358c865005855253af4f68a497John McCall    ObjCLifetime lifetime = getObjCLifetime();
265f85e193739c953358c865005855253af4f68a497John McCall    return (lifetime > OCL_ExplicitNone);
266f85e193739c953358c865005855253af4f68a497John McCall  }
267f85e193739c953358c865005855253af4f68a497John McCall
268f85e193739c953358c865005855253af4f68a497John McCall  /// True if the lifetime is either strong or weak.
269f85e193739c953358c865005855253af4f68a497John McCall  bool hasStrongOrWeakObjCLifetime() const {
270f85e193739c953358c865005855253af4f68a497John McCall    ObjCLifetime lifetime = getObjCLifetime();
271f85e193739c953358c865005855253af4f68a497John McCall    return (lifetime == OCL_Strong || lifetime == OCL_Weak);
272f85e193739c953358c865005855253af4f68a497John McCall  }
273f85e193739c953358c865005855253af4f68a497John McCall
2740953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool hasAddressSpace() const { return Mask & AddressSpaceMask; }
2750953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  unsigned getAddressSpace() const { return Mask >> AddressSpaceShift; }
2760953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void setAddressSpace(unsigned space) {
2770953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(space <= MaxAddressSpace);
2780953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask = (Mask & ~AddressSpaceMask)
2790953e767ff7817f97b3ab20896b229891eeff45bJohn McCall         | (((uint32_t) space) << AddressSpaceShift);
2800953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2810953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void removeAddressSpace() { setAddressSpace(0); }
2820953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void addAddressSpace(unsigned space) {
2830953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(space);
2840953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    setAddressSpace(space);
2850953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2860953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
2870953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Fast qualifiers are those that can be allocated directly
2880953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // on a QualType object.
2890953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool hasFastQualifiers() const { return getFastQualifiers(); }
2900953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  unsigned getFastQualifiers() const { return Mask & FastMask; }
2910953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void setFastQualifiers(unsigned mask) {
2920953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(!(mask & ~FastMask) && "bitmask contains non-fast qualifier bits");
2930953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask = (Mask & ~FastMask) | mask;
2940953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2950953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void removeFastQualifiers(unsigned mask) {
2960953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(!(mask & ~FastMask) && "bitmask contains non-fast qualifier bits");
2970953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask &= ~mask;
2980953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2990953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void removeFastQualifiers() {
3000953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    removeFastQualifiers(FastMask);
3010953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
3020953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void addFastQualifiers(unsigned mask) {
3030953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(!(mask & ~FastMask) && "bitmask contains non-fast qualifier bits");
3040953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask |= mask;
3050953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
3060953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3070953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// hasNonFastQualifiers - Return true if the set contains any
3080953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// qualifiers which require an ExtQuals node to be allocated.
3090953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool hasNonFastQualifiers() const { return Mask & ~FastMask; }
3100953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  Qualifiers getNonFastQualifiers() const {
3110953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Qualifiers Quals = *this;
3120953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Quals.setFastQualifiers(0);
3130953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return Quals;
3140953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
3150953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3160953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// hasQualifiers - Return true if the set contains any qualifiers.
3170953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool hasQualifiers() const { return Mask; }
3180953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool empty() const { return !Mask; }
3190953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3200953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// \brief Add the qualifiers from the given set to this set.
3210953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void addQualifiers(Qualifiers Q) {
3220953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    // If the other set doesn't have any non-boolean qualifiers, just
3230953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    // bit-or it in.
3240953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    if (!(Q.Mask & ~CVRMask))
3250953e767ff7817f97b3ab20896b229891eeff45bJohn McCall      Mask |= Q.Mask;
3260953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    else {
3270953e767ff7817f97b3ab20896b229891eeff45bJohn McCall      Mask |= (Q.Mask & CVRMask);
3280953e767ff7817f97b3ab20896b229891eeff45bJohn McCall      if (Q.hasAddressSpace())
3290953e767ff7817f97b3ab20896b229891eeff45bJohn McCall        addAddressSpace(Q.getAddressSpace());
3300953e767ff7817f97b3ab20896b229891eeff45bJohn McCall      if (Q.hasObjCGCAttr())
3310953e767ff7817f97b3ab20896b229891eeff45bJohn McCall        addObjCGCAttr(Q.getObjCGCAttr());
332f85e193739c953358c865005855253af4f68a497John McCall      if (Q.hasObjCLifetime())
333f85e193739c953358c865005855253af4f68a497John McCall        addObjCLifetime(Q.getObjCLifetime());
3340953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    }
3350953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
3360953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
33762c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// \brief Add the qualifiers from the given set to this set, given that
33862c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// they don't conflict.
33962c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  void addConsistentQualifiers(Qualifiers qs) {
34062c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall    assert(getAddressSpace() == qs.getAddressSpace() ||
34162c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall           !hasAddressSpace() || !qs.hasAddressSpace());
34262c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall    assert(getObjCGCAttr() == qs.getObjCGCAttr() ||
34362c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall           !hasObjCGCAttr() || !qs.hasObjCGCAttr());
344f85e193739c953358c865005855253af4f68a497John McCall    assert(getObjCLifetime() == qs.getObjCLifetime() ||
345f85e193739c953358c865005855253af4f68a497John McCall           !hasObjCLifetime() || !qs.hasObjCLifetime());
34662c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall    Mask |= qs.Mask;
34762c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  }
34862c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall
34962c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// \brief Determines if these qualifiers compatibly include another set.
35062c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// Generally this answers the question of whether an object with the other
35162c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// qualifiers can be safely used as an object with these qualifiers.
35262c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  bool compatiblyIncludes(Qualifiers other) const {
353377e1bd6853118c5b1718503569e5179c40f09b7Douglas Gregor    return
354377e1bd6853118c5b1718503569e5179c40f09b7Douglas Gregor      // Address spaces must match exactly.
355377e1bd6853118c5b1718503569e5179c40f09b7Douglas Gregor      getAddressSpace() == other.getAddressSpace() &&
356377e1bd6853118c5b1718503569e5179c40f09b7Douglas Gregor      // ObjC GC qualifiers can match, be added, or be removed, but can't be
357377e1bd6853118c5b1718503569e5179c40f09b7Douglas Gregor      // changed.
358377e1bd6853118c5b1718503569e5179c40f09b7Douglas Gregor      (getObjCGCAttr() == other.getObjCGCAttr() ||
359377e1bd6853118c5b1718503569e5179c40f09b7Douglas Gregor       !hasObjCGCAttr() || !other.hasObjCGCAttr()) &&
360f85e193739c953358c865005855253af4f68a497John McCall      // ObjC lifetime qualifiers must match exactly.
361f85e193739c953358c865005855253af4f68a497John McCall      getObjCLifetime() == other.getObjCLifetime() &&
362377e1bd6853118c5b1718503569e5179c40f09b7Douglas Gregor      // CVR qualifiers may subset.
363377e1bd6853118c5b1718503569e5179c40f09b7Douglas Gregor      (((Mask & CVRMask) | (other.Mask & CVRMask)) == (Mask & CVRMask));
36462c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  }
36562c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall
366f85e193739c953358c865005855253af4f68a497John McCall  /// \brief Determines if these qualifiers compatibly include another set of
367f85e193739c953358c865005855253af4f68a497John McCall  /// qualifiers from the narrow perspective of Objective-C ARC lifetime.
368f85e193739c953358c865005855253af4f68a497John McCall  ///
369f85e193739c953358c865005855253af4f68a497John McCall  /// One set of Objective-C lifetime qualifiers compatibly includes the other
370f85e193739c953358c865005855253af4f68a497John McCall  /// if the lifetime qualifiers match, or if both are non-__weak and the
371f85e193739c953358c865005855253af4f68a497John McCall  /// including set also contains the 'const' qualifier.
372f85e193739c953358c865005855253af4f68a497John McCall  bool compatiblyIncludesObjCLifetime(Qualifiers other) const {
373f85e193739c953358c865005855253af4f68a497John McCall    if (getObjCLifetime() == other.getObjCLifetime())
374f85e193739c953358c865005855253af4f68a497John McCall      return true;
375f85e193739c953358c865005855253af4f68a497John McCall
376f85e193739c953358c865005855253af4f68a497John McCall    if (getObjCLifetime() == OCL_Weak || other.getObjCLifetime() == OCL_Weak)
377f85e193739c953358c865005855253af4f68a497John McCall      return false;
378f85e193739c953358c865005855253af4f68a497John McCall
379f85e193739c953358c865005855253af4f68a497John McCall    return hasConst();
380f85e193739c953358c865005855253af4f68a497John McCall  }
381f85e193739c953358c865005855253af4f68a497John McCall
382f85e193739c953358c865005855253af4f68a497John McCall  bool isSupersetOf(Qualifiers Other) const;
383f85e193739c953358c865005855253af4f68a497John McCall
384769d0cc72b1831785596d0e76f327bdb887823beDouglas Gregor  /// \brief Determine whether this set of qualifiers is a strict superset of
385769d0cc72b1831785596d0e76f327bdb887823beDouglas Gregor  /// another set of qualifiers, not considering qualifier compatibility.
386769d0cc72b1831785596d0e76f327bdb887823beDouglas Gregor  bool isStrictSupersetOf(Qualifiers Other) const;
387769d0cc72b1831785596d0e76f327bdb887823beDouglas Gregor
3880953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool operator==(Qualifiers Other) const { return Mask == Other.Mask; }
3890953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool operator!=(Qualifiers Other) const { return Mask != Other.Mask; }
3900953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3910953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  operator bool() const { return hasQualifiers(); }
3920953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3930953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  Qualifiers &operator+=(Qualifiers R) {
3940953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    addQualifiers(R);
3950953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return *this;
3960953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
3970953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3980953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Union two qualifier sets.  If an enumerated qualifier appears
3990953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // in both sets, use the one from the right.
4000953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  friend Qualifiers operator+(Qualifiers L, Qualifiers R) {
4010953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    L += R;
4020953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return L;
4030953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
4043cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor
4053cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor  Qualifiers &operator-=(Qualifiers R) {
4063cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor    Mask = Mask & ~(R.Mask);
4073cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor    return *this;
4083cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor  }
4090953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
4103cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor  /// \brief Compute the difference between two qualifier sets.
4113cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor  friend Qualifiers operator-(Qualifiers L, Qualifiers R) {
4123cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor    L -= R;
4133cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor    return L;
4143cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor  }
4153cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor
4160953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  std::string getAsString() const;
4170953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  std::string getAsString(const PrintingPolicy &Policy) const {
4180953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    std::string Buffer;
4190953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    getAsStringInternal(Buffer, Policy);
4200953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return Buffer;
4210953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
4220953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void getAsStringInternal(std::string &S, const PrintingPolicy &Policy) const;
4230953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
4240953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void Profile(llvm::FoldingSetNodeID &ID) const {
4250953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    ID.AddInteger(Mask);
4260953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
4270953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
4280953e767ff7817f97b3ab20896b229891eeff45bJohn McCallprivate:
4290953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
430f85e193739c953358c865005855253af4f68a497John McCall  // bits:     |0 1 2|3 .. 4|5  ..  7|8   ...   31|
431f85e193739c953358c865005855253af4f68a497John McCall  //           |C R V|GCAttr|Lifetime|AddressSpace|
4320953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  uint32_t Mask;
4330953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
4340953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  static const uint32_t GCAttrMask = 0x18;
4350953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  static const uint32_t GCAttrShift = 3;
436f85e193739c953358c865005855253af4f68a497John McCall  static const uint32_t LifetimeMask = 0xE0;
437f85e193739c953358c865005855253af4f68a497John McCall  static const uint32_t LifetimeShift = 5;
438f85e193739c953358c865005855253af4f68a497John McCall  static const uint32_t AddressSpaceMask = ~(CVRMask|GCAttrMask|LifetimeMask);
439f85e193739c953358c865005855253af4f68a497John McCall  static const uint32_t AddressSpaceShift = 8;
4400953e767ff7817f97b3ab20896b229891eeff45bJohn McCall};
4410953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
442ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor/// CallingConv - Specifies the calling convention that a function uses.
443ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregorenum CallingConv {
444ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor  CC_Default,
445ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor  CC_C,           // __attribute__((cdecl))
446ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor  CC_X86StdCall,  // __attribute__((stdcall))
447f813a2c03fcb05381b3252010435f557eb6b3cdeDouglas Gregor  CC_X86FastCall, // __attribute__((fastcall))
44852fc314e1b5e1baee6305067cf831763d02bd243Dawn Perchik  CC_X86ThisCall, // __attribute__((thiscall))
449414d8967e1d760ea1e19a4aca96b13777a8cf8c5Anton Korobeynikov  CC_X86Pascal,   // __attribute__((pascal))
450414d8967e1d760ea1e19a4aca96b13777a8cf8c5Anton Korobeynikov  CC_AAPCS,       // __attribute__((pcs("aapcs")))
451414d8967e1d760ea1e19a4aca96b13777a8cf8c5Anton Korobeynikov  CC_AAPCS_VFP    // __attribute__((pcs("aapcs-vfp")))
452ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor};
453ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor
45449f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCalltypedef std::pair<const Type*, Qualifiers> SplitQualType;
4550953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
4560953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// QualType - For efficiency, we don't store CV-qualified types as nodes on
4570953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// their own: instead each reference to a type stores the qualifiers.  This
4580953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// greatly reduces the number of nodes we need to allocate for types (for
4590953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// example we only need one for 'int', 'const int', 'volatile int',
4600953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// 'const volatile int', etc).
4610953e767ff7817f97b3ab20896b229891eeff45bJohn McCall///
4620953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// As an added efficiency bonus, instead of making this a pair, we
4630953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// just store the two bits we care about in the low bits of the
4640953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// pointer.  To handle the packing/unpacking, we make QualType be a
4650953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// simple wrapper class that acts like a smart pointer.  A third bit
4660953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// indicates whether there are extended qualifiers present, in which
4670953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// case the pointer points to a special structure.
4680953e767ff7817f97b3ab20896b229891eeff45bJohn McCallclass QualType {
4690953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Thankfully, these are efficiently composable.
4700953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  llvm::PointerIntPair<llvm::PointerUnion<const Type*,const ExtQuals*>,
4710953e767ff7817f97b3ab20896b229891eeff45bJohn McCall                       Qualifiers::FastWidth> Value;
4720953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
4730953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  const ExtQuals *getExtQualsUnsafe() const {
4740953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return Value.getPointer().get<const ExtQuals*>();
4750953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
4760953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
4770953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  const Type *getTypePtrUnsafe() const {
4780953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return Value.getPointer().get<const Type*>();
4790953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
4800953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
4813b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  const ExtQualsTypeCommonBase *getCommonPtr() const {
4823b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    assert(!isNull() && "Cannot retrieve a NULL type pointer");
4833b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    uintptr_t CommonPtrVal
4843b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall      = reinterpret_cast<uintptr_t>(Value.getOpaqueValue());
4853b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    CommonPtrVal &= ~(uintptr_t)((1 << TypeAlignmentInBits) - 1);
4863b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    return reinterpret_cast<ExtQualsTypeCommonBase*>(CommonPtrVal);
4873b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  }
4883b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
4890953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  friend class QualifierCollector;
4900953e767ff7817f97b3ab20896b229891eeff45bJohn McCallpublic:
4915cf243a883872441d73ca49cea7e20de5802629bChris Lattner  QualType() {}
4921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4935cf243a883872441d73ca49cea7e20de5802629bChris Lattner  QualType(const Type *Ptr, unsigned Quals)
4940953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    : Value(Ptr, Quals) {}
4950953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  QualType(const ExtQuals *Ptr, unsigned Quals)
4960953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    : Value(Ptr, Quals) {}
4970953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
498a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  unsigned getLocalFastQualifiers() const { return Value.getInt(); }
499a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  void setLocalFastQualifiers(unsigned Quals) { Value.setInt(Quals); }
5005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
5010953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// Retrieves a pointer to the underlying (unqualified) type.
5020953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// This should really return a const Type, but it's not worth
5030953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// changing all the users right now.
5041ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor  ///
5051ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor  /// This function requires that the type not be NULL. If the type might be
5061ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor  /// NULL, use the (slightly less efficient) \c getTypePtrOrNull().
5073b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  const Type *getTypePtr() const;
5081ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor
5093b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  const Type *getTypePtrOrNull() const;
5101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
51149f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  /// Divides a QualType into its unqualified type and a set of local
51249f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  /// qualifiers.
5133b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  SplitQualType split() const;
51449f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall
5155cf243a883872441d73ca49cea7e20de5802629bChris Lattner  void *getAsOpaquePtr() const { return Value.getOpaqueValue(); }
516f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  static QualType getFromOpaquePtr(const void *Ptr) {
5175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    QualType T;
518f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall    T.Value.setFromOpaqueValue(const_cast<void*>(Ptr));
5195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T;
5205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
5211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
522f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const Type &operator*() const {
5235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return *getTypePtr();
5245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
5255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
526f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const Type *operator->() const {
5275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return getTypePtr();
5285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
5291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
530467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall  bool isCanonical() const;
53154e14c4db764c0636160d26c5bbf491637c83a76John McCall  bool isCanonicalAsParam() const;
532467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall
5335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isNull - Return true if this QualType doesn't point to a type yet.
5345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isNull() const {
5350953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return Value.getPointer().isNull();
5365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
5375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
538a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Determine whether this particular QualType instance has the
539a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// "const" qualifier set, without looking through typedefs that may have
540a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// added "const" at a different level.
541a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  bool isLocalConstQualified() const {
542a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor    return (getLocalFastQualifiers() & Qualifiers::Const);
5430953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
544a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor
545a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Determine whether this type is const-qualified.
546fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  bool isConstQualified() const;
547a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor
548a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Determine whether this particular QualType instance has the
549a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// "restrict" qualifier set, without looking through typedefs that may have
550a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// added "restrict" at a different level.
551a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  bool isLocalRestrictQualified() const {
552a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor    return (getLocalFastQualifiers() & Qualifiers::Restrict);
553a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  }
554a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor
555a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Determine whether this type is restrict-qualified.
556fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  bool isRestrictQualified() const;
557a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor
558a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Determine whether this particular QualType instance has the
559a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// "volatile" qualifier set, without looking through typedefs that may have
560a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// added "volatile" at a different level.
561a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  bool isLocalVolatileQualified() const {
562f7616b9067790757f4e12e834b216c53c8c04ebeDouglas Gregor    return (getLocalFastQualifiers() & Qualifiers::Volatile);
5635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
5640953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
565a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Determine whether this type is volatile-qualified.
566fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  bool isVolatileQualified() const;
567a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor
568a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Determine whether this particular QualType instance has any
569a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// qualifiers, without looking through any typedefs that might add
570a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// qualifiers at a different level.
571a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  bool hasLocalQualifiers() const {
572a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor    return getLocalFastQualifiers() || hasLocalNonFastQualifiers();
5730953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
5740953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
575a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Determine whether this type has any qualifiers.
576fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  bool hasQualifiers() const;
577a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor
578a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Determine whether this particular QualType instance has any
579a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// "non-fast" qualifiers, e.g., those that are stored in an ExtQualType
580a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// instance.
581a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  bool hasLocalNonFastQualifiers() const {
582a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor    return Value.getPointer().is<const ExtQuals*>();
5830953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
5840953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
585a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Retrieve the set of qualifiers local to this particular QualType
586a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// instance, not including any qualifiers acquired through typedefs or
587a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// other sugar.
5883b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  Qualifiers getLocalQualifiers() const;
5890953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
590a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Retrieve the set of qualifiers applied to this type.
591fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  Qualifiers getQualifiers() const;
592a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor
593a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Retrieve the set of CVR (const-volatile-restrict) qualifiers
594a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// local to this particular QualType instance, not including any qualifiers
595a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// acquired through typedefs or other sugar.
596a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  unsigned getLocalCVRQualifiers() const {
597f7616b9067790757f4e12e834b216c53c8c04ebeDouglas Gregor    return getLocalFastQualifiers();
5985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
599b381aac9bae6d608c72267dd0ed08ec6369e94e4Nuno Lopes
600a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Retrieve the set of CVR (const-volatile-restrict) qualifiers
601a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// applied to this type.
602fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  unsigned getCVRQualifiers() const;
603e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth
604bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isConstant(ASTContext& Ctx) const {
605bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall    return QualType::isConstant(*this, Ctx);
606bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  }
6071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
608f85e193739c953358c865005855253af4f68a497John McCall  /// \brief Determine whether this is a Plain Old Data (POD) type (C++ 3.9p10).
609f85e193739c953358c865005855253af4f68a497John McCall  bool isPODType(ASTContext &Context) const;
610f85e193739c953358c865005855253af4f68a497John McCall
611f85e193739c953358c865005855253af4f68a497John McCall  /// isCXX11PODType() - Return true if this is a POD type according to the
612f85e193739c953358c865005855253af4f68a497John McCall  /// more relaxed rules of the C++11 standard, regardless of the current
613f85e193739c953358c865005855253af4f68a497John McCall  /// compilation's language.
614f85e193739c953358c865005855253af4f68a497John McCall  /// (C++0x [basic.types]p9)
615f85e193739c953358c865005855253af4f68a497John McCall  bool isCXX11PODType(ASTContext &Context) const;
616f85e193739c953358c865005855253af4f68a497John McCall
617f85e193739c953358c865005855253af4f68a497John McCall  /// isTrivialType - Return true if this is a trivial type
618f85e193739c953358c865005855253af4f68a497John McCall  /// (C++0x [basic.types]p9)
619f85e193739c953358c865005855253af4f68a497John McCall  bool isTrivialType(ASTContext &Context) const;
620f85e193739c953358c865005855253af4f68a497John McCall
621f85e193739c953358c865005855253af4f68a497John McCall  /// isTriviallyCopyableType - Return true if this is a trivially
622f85e193739c953358c865005855253af4f68a497John McCall  /// copyable type (C++0x [basic.types]p9)
623f85e193739c953358c865005855253af4f68a497John McCall  bool isTriviallyCopyableType(ASTContext &Context) const;
624f85e193739c953358c865005855253af4f68a497John McCall
6250953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Don't promise in the API that anything besides 'const' can be
6260953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // easily added.
6270953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
6280953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// addConst - add the specified type qualifier to this QualType.
6290953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void addConst() {
6300953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    addFastQualifiers(Qualifiers::Const);
6310953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
6320953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  QualType withConst() const {
6330953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return withFastQualifiers(Qualifiers::Const);
6340953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
6350953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
636308742c87e2311c3f349092e5b823c3821e61b10Sean Hunt  /// addVolatile - add the specified type qualifier to this QualType.
637308742c87e2311c3f349092e5b823c3821e61b10Sean Hunt  void addVolatile() {
638308742c87e2311c3f349092e5b823c3821e61b10Sean Hunt    addFastQualifiers(Qualifiers::Volatile);
639308742c87e2311c3f349092e5b823c3821e61b10Sean Hunt  }
640308742c87e2311c3f349092e5b823c3821e61b10Sean Hunt  QualType withVolatile() const {
641308742c87e2311c3f349092e5b823c3821e61b10Sean Hunt    return withFastQualifiers(Qualifiers::Volatile);
642308742c87e2311c3f349092e5b823c3821e61b10Sean Hunt  }
643308742c87e2311c3f349092e5b823c3821e61b10Sean Hunt
644a07398ed98ea2b55ad7a505a3aab18aed93b149fJohn McCall  QualType withCVRQualifiers(unsigned CVR) const {
645a07398ed98ea2b55ad7a505a3aab18aed93b149fJohn McCall    return withFastQualifiers(CVR);
646a07398ed98ea2b55ad7a505a3aab18aed93b149fJohn McCall  }
647a07398ed98ea2b55ad7a505a3aab18aed93b149fJohn McCall
6480953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void addFastQualifiers(unsigned TQs) {
6490953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(!(TQs & ~Qualifiers::FastMask)
6500953e767ff7817f97b3ab20896b229891eeff45bJohn McCall           && "non-fast qualifier bits set in mask!");
6510953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Value.setInt(Value.getInt() | TQs);
6520953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
6530953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
65449f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  void removeLocalConst();
65549f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  void removeLocalVolatile();
65649f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  void removeLocalRestrict();
65749f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  void removeLocalCVRQualifiers(unsigned Mask);
6580953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
65949f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  void removeLocalFastQualifiers() { Value.setInt(0); }
66049f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  void removeLocalFastQualifiers(unsigned Mask) {
6610953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(!(Mask & ~Qualifiers::FastMask) && "mask has non-fast qualifiers");
6620953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Value.setInt(Value.getInt() & ~Mask);
6630953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
6645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
6650953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Creates a type with the given qualifiers in addition to any
6660953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // qualifiers already on this type.
6670953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  QualType withFastQualifiers(unsigned TQs) const {
6680953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    QualType T = *this;
6690953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    T.addFastQualifiers(TQs);
6700953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return T;
6710953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
6721c6a38bcea17801e9a4738753aee845381af2b6cSanjiv Gupta
6730953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Creates a type with exactly the given fast qualifiers, removing
6740953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // any existing fast qualifiers.
67549f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  QualType withExactLocalFastQualifiers(unsigned TQs) const {
67649f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall    return withoutLocalFastQualifiers().withFastQualifiers(TQs);
6775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
6780953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
6790953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Removes fast qualifiers, but leaves any extended qualifiers in place.
68049f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  QualType withoutLocalFastQualifiers() const {
6810953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    QualType T = *this;
68249f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall    T.removeLocalFastQualifiers();
6830953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return T;
684c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  }
685971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis
6863b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  QualType getCanonicalType() const;
6873b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
688a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Return this type with all of the instance-specific qualifiers
689a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// removed, but without removing any qualifiers that may have been applied
690a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// through typedefs.
691a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  QualType getLocalUnqualifiedType() const { return QualType(getTypePtr(), 0); }
6921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
69362c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// \brief Retrieve the unqualified variant of the given type,
69462c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// removing as little sugar as possible.
69562c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  ///
69662c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// This routine looks through various kinds of sugar to find the
69762c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// least-desugared type that is unqualified. For example, given:
69862c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  ///
69962c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// \code
70062c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// typedef int Integer;
70162c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// typedef const Integer CInteger;
70262c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// typedef CInteger DifferenceType;
70362c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// \endcode
70462c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  ///
70562c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// Executing \c getUnqualifiedType() on the type \c DifferenceType will
70662c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// desugar until we hit the type \c Integer, which has no qualifiers on it.
70762c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  ///
70862c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// The resulting type might still be qualified if it's an array
70962c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// type.  To strip qualifiers even from within an array type, use
71062c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// ASTContext::getUnqualifiedArrayType.
71162c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  inline QualType getUnqualifiedType() const;
71262c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall
71362c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// getSplitUnqualifiedType - Retrieve the unqualified variant of the
71462c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// given type, removing as little sugar as possible.
71562c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  ///
71662c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// Like getUnqualifiedType(), but also returns the set of
71762c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// qualifiers that were built up.
71862c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  ///
71962c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// The resulting type might still be qualified if it's an array
72062c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// type.  To strip qualifiers even from within an array type, use
72162c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// ASTContext::getUnqualifiedArrayType.
72262c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  inline SplitQualType getSplitUnqualifiedType() const;
723a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor
72461d0b6baf47cf411f6c0f6ddb4acffcfeec724f1Douglas Gregor  /// \brief Determine whether this type is more qualified than the other
72561d0b6baf47cf411f6c0f6ddb4acffcfeec724f1Douglas Gregor  /// given type, requiring exact equality for non-CVR qualifiers.
726e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor  bool isMoreQualifiedThan(QualType Other) const;
72761d0b6baf47cf411f6c0f6ddb4acffcfeec724f1Douglas Gregor
72861d0b6baf47cf411f6c0f6ddb4acffcfeec724f1Douglas Gregor  /// \brief Determine whether this type is at least as qualified as the other
72961d0b6baf47cf411f6c0f6ddb4acffcfeec724f1Douglas Gregor  /// given type, requiring exact equality for non-CVR qualifiers.
730e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor  bool isAtLeastAsQualifiedAs(QualType Other) const;
73161d0b6baf47cf411f6c0f6ddb4acffcfeec724f1Douglas Gregor
732e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor  QualType getNonReferenceType() const;
7331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7346398235d7890a81b785ea5af3b6e66d86bf184ccDouglas Gregor  /// \brief Determine the type of a (typically non-lvalue) expression with the
7356398235d7890a81b785ea5af3b6e66d86bf184ccDouglas Gregor  /// specified result type.
7365291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor  ///
7376398235d7890a81b785ea5af3b6e66d86bf184ccDouglas Gregor  /// This routine should be used for expressions for which the return type is
7386398235d7890a81b785ea5af3b6e66d86bf184ccDouglas Gregor  /// explicitly specified (e.g., in a cast or call) and isn't necessarily
7396398235d7890a81b785ea5af3b6e66d86bf184ccDouglas Gregor  /// an lvalue. It removes a top-level reference (since there are no
7405291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor  /// expressions of reference type) and deletes top-level cvr-qualifiers
7415291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor  /// from non-class types (in C++) or all types (in C).
7426398235d7890a81b785ea5af3b6e66d86bf184ccDouglas Gregor  QualType getNonLValueExprType(ASTContext &Context) const;
7435291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor
7442fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner  /// getDesugaredType - Return the specified type with any "sugar" removed from
7452fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner  /// the type.  This takes off typedefs, typeof's etc.  If the outer level of
7462fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner  /// the type is already concrete, it returns it unmodified.  This is similar
7472fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner  /// to getting the canonical type, but it doesn't remove *all* typedefs.  For
7482fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner  /// example, it returns "T*" as "T*", (not as "int*"), because the pointer is
7492fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner  /// concrete.
7500953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  ///
7510953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// Qualifiers are left in place.
7524ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  QualType getDesugaredType(const ASTContext &Context) const {
75349f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall    return getDesugaredType(*this, Context);
75449f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  }
75549f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall
75649f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  SplitQualType getSplitDesugaredType() const {
75749f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall    return getSplitDesugaredType(*this);
758bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  }
75998cd599ee8a9b259ed7388ee2921a20d97658864Douglas Gregor
760075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  /// IgnoreParens - Returns the specified type after dropping any
761075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  /// outer-level parentheses.
762075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  QualType IgnoreParens() const {
763723df245307a530da5433dfb43accf187dc3e243Abramo Bagnara    if (isa<ParenType>(*this))
764723df245307a530da5433dfb43accf187dc3e243Abramo Bagnara      return QualType::IgnoreParens(*this);
765723df245307a530da5433dfb43accf187dc3e243Abramo Bagnara    return *this;
766075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  }
767075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
7685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// operator==/!= - Indicate whether the specified types and qualifiers are
7695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// identical.
77050d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor  friend bool operator==(const QualType &LHS, const QualType &RHS) {
77150d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor    return LHS.Value == RHS.Value;
7725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
77350d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor  friend bool operator!=(const QualType &LHS, const QualType &RHS) {
77450d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor    return LHS.Value != RHS.Value;
7755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
77649f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  std::string getAsString() const {
77749f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall    return getAsString(split());
77849f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  }
77949f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  static std::string getAsString(SplitQualType split) {
78049f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall    return getAsString(split.first, split.second);
78149f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  }
78249f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  static std::string getAsString(const Type *ty, Qualifiers qs);
783d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor
784d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor  std::string getAsString(const PrintingPolicy &Policy) const {
7855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    std::string S;
786d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor    getAsStringInternal(S, Policy);
7875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return S;
7885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
789e4f2142d00fa5fdb580c4e2413da91882d955381Chris Lattner  void getAsStringInternal(std::string &Str,
79049f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall                           const PrintingPolicy &Policy) const {
79149f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall    return getAsStringInternal(split(), Str, Policy);
79249f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  }
79349f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  static void getAsStringInternal(SplitQualType split, std::string &out,
79449f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall                                  const PrintingPolicy &policy) {
79549f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall    return getAsStringInternal(split.first, split.second, out, policy);
79649f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  }
79749f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  static void getAsStringInternal(const Type *ty, Qualifiers qs,
79849f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall                                  std::string &out,
79949f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall                                  const PrintingPolicy &policy);
8001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
801c36d405a02fab41f6c45cb2bc750d64949742903Chris Lattner  void dump(const char *s) const;
802c36d405a02fab41f6c45cb2bc750d64949742903Chris Lattner  void dump() const;
8031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8043f2dcb1ca8bd2d5d3ccc5c80f4ab06f949d88a89Ted Kremenek  void Profile(llvm::FoldingSetNodeID &ID) const {
8053f2dcb1ca8bd2d5d3ccc5c80f4ab06f949d88a89Ted Kremenek    ID.AddPointer(getAsOpaquePtr());
8063f2dcb1ca8bd2d5d3ccc5c80f4ab06f949d88a89Ted Kremenek  }
8075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
808ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb  /// getAddressSpace - Return the address space of this type.
809ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb  inline unsigned getAddressSpace() const;
8101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
811f85e193739c953358c865005855253af4f68a497John McCall  /// getObjCGCAttr - Returns gc attribute of this type.
8120953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  inline Qualifiers::GC getObjCGCAttr() const;
813f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian
814f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian  /// isObjCGCWeak true when Type is objc's weak.
815f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian  bool isObjCGCWeak() const {
8160953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return getObjCGCAttr() == Qualifiers::Weak;
817f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian  }
818f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian
819f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian  /// isObjCGCStrong true when Type is objc's strong.
820f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian  bool isObjCGCStrong() const {
8210953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return getObjCGCAttr() == Qualifiers::Strong;
822f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian  }
8232455636163fdd18581d7fdae816433f886d88213Mike Stump
824f85e193739c953358c865005855253af4f68a497John McCall  /// getObjCLifetime - Returns lifetime attribute of this type.
825f85e193739c953358c865005855253af4f68a497John McCall  Qualifiers::ObjCLifetime getObjCLifetime() const {
826f85e193739c953358c865005855253af4f68a497John McCall    return getQualifiers().getObjCLifetime();
827f85e193739c953358c865005855253af4f68a497John McCall  }
828f85e193739c953358c865005855253af4f68a497John McCall
829f85e193739c953358c865005855253af4f68a497John McCall  bool hasNonTrivialObjCLifetime() const {
830f85e193739c953358c865005855253af4f68a497John McCall    return getQualifiers().hasNonTrivialObjCLifetime();
831f85e193739c953358c865005855253af4f68a497John McCall  }
832f85e193739c953358c865005855253af4f68a497John McCall
833f85e193739c953358c865005855253af4f68a497John McCall  bool hasStrongOrWeakObjCLifetime() const {
834f85e193739c953358c865005855253af4f68a497John McCall    return getQualifiers().hasStrongOrWeakObjCLifetime();
835f85e193739c953358c865005855253af4f68a497John McCall  }
836f85e193739c953358c865005855253af4f68a497John McCall
8370d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall  enum DestructionKind {
8380d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall    DK_none,
839f85e193739c953358c865005855253af4f68a497John McCall    DK_cxx_destructor,
840f85e193739c953358c865005855253af4f68a497John McCall    DK_objc_strong_lifetime,
841f85e193739c953358c865005855253af4f68a497John McCall    DK_objc_weak_lifetime
8420d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall  };
8430d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall
8440d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall  /// isDestructedType - nonzero if objects of this type require
8450d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall  /// non-trivial work to clean up after.  Non-zero because it's
8460d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall  /// conceivable that qualifiers (objc_gc(weak)?) could make
8470d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall  /// something require destruction.
8480d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall  DestructionKind isDestructedType() const {
8490d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall    return isDestructedTypeImpl(*this);
8500d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall  }
8510d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall
8522b1ad8b42bbbe00a1845e566f52f1941b8dbc725Douglas Gregor  /// \brief Determine whether expressions of the given type are forbidden
8532b1ad8b42bbbe00a1845e566f52f1941b8dbc725Douglas Gregor  /// from being lvalues in C.
8542b1ad8b42bbbe00a1845e566f52f1941b8dbc725Douglas Gregor  ///
8552b1ad8b42bbbe00a1845e566f52f1941b8dbc725Douglas Gregor  /// The expression types that are forbidden to be lvalues are:
8562b1ad8b42bbbe00a1845e566f52f1941b8dbc725Douglas Gregor  ///   - 'void', but not qualified void
8572b1ad8b42bbbe00a1845e566f52f1941b8dbc725Douglas Gregor  ///   - function types
8582b1ad8b42bbbe00a1845e566f52f1941b8dbc725Douglas Gregor  ///
8592b1ad8b42bbbe00a1845e566f52f1941b8dbc725Douglas Gregor  /// The exact rule here is C99 6.3.2.1:
8602b1ad8b42bbbe00a1845e566f52f1941b8dbc725Douglas Gregor  ///   An lvalue is an expression with an object type or an incomplete
8612b1ad8b42bbbe00a1845e566f52f1941b8dbc725Douglas Gregor  ///   type other than void.
8622b1ad8b42bbbe00a1845e566f52f1941b8dbc725Douglas Gregor  bool isCForbiddenLValueType() const;
8632b1ad8b42bbbe00a1845e566f52f1941b8dbc725Douglas Gregor
864f85e193739c953358c865005855253af4f68a497John McCall  /// \brief Determine whether this type has trivial copy-assignment semantics.
865f85e193739c953358c865005855253af4f68a497John McCall  bool hasTrivialCopyAssignment(ASTContext &Context) const;
866f85e193739c953358c865005855253af4f68a497John McCall
867bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCallprivate:
868bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  // These methods are implemented in a separate translation unit;
869bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  // "static"-ize them to avoid creating temporary QualTypes in the
870bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  // caller.
871bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  static bool isConstant(QualType T, ASTContext& Ctx);
8724ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  static QualType getDesugaredType(QualType T, const ASTContext &Context);
87349f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  static SplitQualType getSplitDesugaredType(QualType T);
87462c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  static SplitQualType getSplitUnqualifiedTypeImpl(QualType type);
875075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  static QualType IgnoreParens(QualType T);
8760d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall  static DestructionKind isDestructedTypeImpl(QualType type);
8775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
8785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
8795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end clang.
8805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
8815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace llvm {
8825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Implement simplify_type for QualType, so that we can dyn_cast from QualType
8835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// to a specific Type class.
8845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencertemplate<> struct simplify_type<const ::clang::QualType> {
885f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  typedef const ::clang::Type *SimpleType;
8865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static SimpleType getSimplifiedValue(const ::clang::QualType &Val) {
8874472fc641ea3069463798fb56a04043c28ea2910Douglas Gregor    return Val.getTypePtr();
8885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
8895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
8905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencertemplate<> struct simplify_type< ::clang::QualType>
8915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  : public simplify_type<const ::clang::QualType> {};
8921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8934e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner// Teach SmallPtrSet that QualType is "basically a pointer".
8944e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattnertemplate<>
895daae940507f2e93c6fa12e8062fa958e34cc2d1cChris Lattnerclass PointerLikeTypeTraits<clang::QualType> {
8964e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattnerpublic:
8974e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner  static inline void *getAsVoidPointer(clang::QualType P) {
8984e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner    return P.getAsOpaquePtr();
8994e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner  }
9004e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner  static inline clang::QualType getFromVoidPointer(void *P) {
9014e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner    return clang::QualType::getFromOpaquePtr(P);
9024e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner  }
9030953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Various qualifiers go in low bits.
9040eda3b31a672ea486fa92b9bc49a2c91be856b53Chris Lattner  enum { NumLowBitsAvailable = 0 };
9054e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner};
9061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
90773af669633e13c813f80cd15ecf3e6414778aee4Ted Kremenek} // end namespace llvm
9085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
9095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang {
9105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
9113b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// \brief Base class that is common to both the \c ExtQuals and \c Type
9123b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// classes, which allows \c QualType to access the common fields between the
9133b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// two.
9143b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall///
9153b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallclass ExtQualsTypeCommonBase {
9163b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  ExtQualsTypeCommonBase(const Type *baseType, QualType canon)
9173b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    : BaseType(baseType), CanonicalType(canon) {}
9183b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
9193b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  /// \brief The "base" type of an extended qualifiers type (\c ExtQuals) or
9203b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  /// a self-referential pointer (for \c Type).
9213b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  ///
9223b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  /// This pointer allows an efficient mapping from a QualType to its
9233b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  /// underlying type pointer.
9243b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  const Type *const BaseType;
9253b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
9263b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  /// \brief The canonical type of this type.  A QualType.
9273b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  QualType CanonicalType;
9283b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
9293b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  friend class QualType;
9303b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  friend class Type;
9313b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  friend class ExtQuals;
9323b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall};
9333b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
9343b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// ExtQuals - We can encode up to four bits in the low bits of a
9353b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// type pointer, but there are many more type qualifiers that we want
9363b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// to be able to apply to an arbitrary type.  Therefore we have this
9373b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// struct, intended to be heap-allocated and used by QualType to
9383b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// store qualifiers.
9393b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall///
9403b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// The current design tags the 'const', 'restrict', and 'volatile' qualifiers
9413b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// in three low bits on the QualType pointer; a fourth bit records whether
9423b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// the pointer is an ExtQuals node. The extended qualifiers (address spaces,
9433b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// Objective-C GC attributes) are much more rare.
9443b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallclass ExtQuals : public ExtQualsTypeCommonBase, public llvm::FoldingSetNode {
9453b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  // NOTE: changing the fast qualifiers should be straightforward as
9463b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  // long as you don't make 'const' non-fast.
9473b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  // 1. Qualifiers:
9483b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  //    a) Modify the bitmasks (Qualifiers::TQ and DeclSpec::TQ).
9493b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  //       Fast qualifiers must occupy the low-order bits.
9503b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  //    b) Update Qualifiers::FastWidth and FastMask.
9513b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  // 2. QualType:
9523b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  //    a) Update is{Volatile,Restrict}Qualified(), defined inline.
9533b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  //    b) Update remove{Volatile,Restrict}, defined near the end of
9543b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  //       this header.
9553b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  // 3. ASTContext:
9563b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  //    a) Update get{Volatile,Restrict}Type.
9573b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
9583b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  /// Quals - the immutable set of qualifiers applied by this
9593b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  /// node;  always contains extended qualifiers.
9603b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  Qualifiers Quals;
9613b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
9623b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  ExtQuals *this_() { return this; }
9633b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
9643b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallpublic:
9653b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  ExtQuals(const Type *baseType, QualType canon, Qualifiers quals)
9663b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    : ExtQualsTypeCommonBase(baseType,
9673b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall                             canon.isNull() ? QualType(this_(), 0) : canon),
9683b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall      Quals(quals)
9693b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  {
9703b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    assert(Quals.hasNonFastQualifiers()
9713b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall           && "ExtQuals created with no fast qualifiers");
9723b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    assert(!Quals.hasFastQualifiers()
9733b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall           && "ExtQuals created with fast qualifiers");
9743b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  }
9753b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
9763b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  Qualifiers getQualifiers() const { return Quals; }
9773b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
9783b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  bool hasObjCGCAttr() const { return Quals.hasObjCGCAttr(); }
9793b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  Qualifiers::GC getObjCGCAttr() const { return Quals.getObjCGCAttr(); }
9803b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
981f85e193739c953358c865005855253af4f68a497John McCall  bool hasObjCLifetime() const { return Quals.hasObjCLifetime(); }
982f85e193739c953358c865005855253af4f68a497John McCall  Qualifiers::ObjCLifetime getObjCLifetime() const {
983f85e193739c953358c865005855253af4f68a497John McCall    return Quals.getObjCLifetime();
984f85e193739c953358c865005855253af4f68a497John McCall  }
985f85e193739c953358c865005855253af4f68a497John McCall
9863b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  bool hasAddressSpace() const { return Quals.hasAddressSpace(); }
9873b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  unsigned getAddressSpace() const { return Quals.getAddressSpace(); }
9883b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
9893b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  const Type *getBaseType() const { return BaseType; }
9903b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
9913b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallpublic:
9923b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  void Profile(llvm::FoldingSetNodeID &ID) const {
9933b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    Profile(ID, getBaseType(), Quals);
9943b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  }
9953b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  static void Profile(llvm::FoldingSetNodeID &ID,
9963b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall                      const Type *BaseType,
9973b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall                      Qualifiers Quals) {
9983b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    assert(!Quals.hasFastQualifiers() && "fast qualifiers in ExtQuals hash!");
9993b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    ID.AddPointer(BaseType);
10003b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    Quals.Profile(ID);
10013b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  }
10023b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall};
10033b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
1004c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor/// \brief The kind of C++0x ref-qualifier associated with a function type,
1005c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor/// which determines whether a member function's "this" object can be an
1006c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor/// lvalue, rvalue, or neither.
1007c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregorenum RefQualifierKind {
1008c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor  /// \brief No ref-qualifier was provided.
1009c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor  RQ_None = 0,
1010c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor  /// \brief An lvalue ref-qualifier was provided (\c &).
1011c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor  RQ_LValue,
1012c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor  /// \brief An rvalue ref-qualifier was provided (\c &&).
1013c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor  RQ_RValue
1014c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor};
1015c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor
10165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Type - This is the base class of the type hierarchy.  A central concept
10175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// with types is that each type always has a canonical type.  A canonical type
10185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// is the type with any typedef names stripped out of it or the types it
10195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// references.  For example, consider:
10205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
10215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///  typedef int  foo;
10225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///  typedef foo* bar;
10235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///    'int *'    'foo *'    'bar'
10245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
10255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// There will be a Type object created for 'int'.  Since int is canonical, its
10265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// canonicaltype pointer points to itself.  There is also a Type for 'foo' (a
102772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// TypedefType).  Its CanonicalType pointer points to the 'int' Type.  Next
10285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// there is a PointerType that represents 'int*', which, like 'int', is
10295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// canonical.  Finally, there is a PointerType type for 'foo*' whose canonical
103072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// type is 'int*', and there is a TypedefType for 'bar', whose canonical type
10315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// is also 'int*'.
10325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
10335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Non-canonical types are useful for emitting diagnostics, without losing
10345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// information about typedefs being used.  Canonical types are useful for type
10355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// comparisons (they allow by-pointer equality tests) and useful for reasoning
10365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// about whether something has a particular form (e.g. is a function type),
10375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// because they implicitly, recursively, strip all typedefs out of a type.
10385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
10395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Types, once created, are immutable.
10405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
10411ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregorclass Type : public ExtQualsTypeCommonBase {
10425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
10435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  enum TypeClass {
104472564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#define TYPE(Class, Base) Class,
104527935ee59c30b0d8b610ab676aab8e65350af932John McCall#define LAST_TYPE(Class) TypeLast = Class,
104672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#define ABSTRACT_TYPE(Class, Base)
104772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#include "clang/AST/TypeNodes.def"
104872564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor    TagFirst = Record, TagLast = Enum
10495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
10501bb8a45f7386a23871598d05141a07af03067925Argyrios Kyrtzidis
10515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate:
1052c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  Type(const Type&);           // DO NOT IMPLEMENT.
1053c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  void operator=(const Type&); // DO NOT IMPLEMENT.
1054c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
1055b870b88df784c2940efce448ebfaf54dece14666John McCall  /// Bitfields required by the Type class.
1056b870b88df784c2940efce448ebfaf54dece14666John McCall  class TypeBitfields {
1057b870b88df784c2940efce448ebfaf54dece14666John McCall    friend class Type;
1058b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall    template <class T> friend class TypePropertyCache;
105927935ee59c30b0d8b610ab676aab8e65350af932John McCall
1060b870b88df784c2940efce448ebfaf54dece14666John McCall    /// TypeClass bitfield - Enum that specifies what subclass this belongs to.
1061b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned TC : 8;
1062b870b88df784c2940efce448ebfaf54dece14666John McCall
1063b870b88df784c2940efce448ebfaf54dece14666John McCall    /// Dependent - Whether this type is a dependent type (C++ [temp.dep.type]).
1064b870b88df784c2940efce448ebfaf54dece14666John McCall    /// Note that this should stay at the end of the ivars for Type so that
1065b870b88df784c2940efce448ebfaf54dece14666John McCall    /// subclasses can pack their bitfields into the same word.
1066bdb5b0e8ad8ed297ad01eb2ccd0d6d5ed6058033Francois Pichet    unsigned Dependent : 1;
106760e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
1068b870b88df784c2940efce448ebfaf54dece14666John McCall    /// \brief Whether this type is a variably-modified type (C99 6.7.5).
1069bdb5b0e8ad8ed297ad01eb2ccd0d6d5ed6058033Francois Pichet    unsigned VariablyModified : 1;
1070d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor
1071d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    /// \brief Whether this type contains an unexpanded parameter pack
1072d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    /// (for C++0x variadic templates).
1073d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    unsigned ContainsUnexpandedParameterPack : 1;
107435495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor
10751fb0caaa7bef765b85972274e3b434af2572c141John McCall    /// \brief Nonzero if the cache (i.e. the bitfields here starting
10761fb0caaa7bef765b85972274e3b434af2572c141John McCall    /// with 'Cache') is valid.  If so, then this is a
10771fb0caaa7bef765b85972274e3b434af2572c141John McCall    /// LangOptions::VisibilityMode+1.
10781fb0caaa7bef765b85972274e3b434af2572c141John McCall    mutable unsigned CacheValidAndVisibility : 2;
107960e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
1080b870b88df784c2940efce448ebfaf54dece14666John McCall    /// \brief Linkage of this type.
1081b870b88df784c2940efce448ebfaf54dece14666John McCall    mutable unsigned CachedLinkage : 2;
108207a353c2af3a3c557205466d4f4ed2513462ebfeSebastian Redl
1083b870b88df784c2940efce448ebfaf54dece14666John McCall    /// \brief Whether this type involves and local or unnamed types.
1084bdb5b0e8ad8ed297ad01eb2ccd0d6d5ed6058033Francois Pichet    mutable unsigned CachedLocalOrUnnamed : 1;
1085db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor
1086b870b88df784c2940efce448ebfaf54dece14666John McCall    /// \brief FromAST - Whether this type comes from an AST file.
1087bdb5b0e8ad8ed297ad01eb2ccd0d6d5ed6058033Francois Pichet    mutable unsigned FromAST : 1;
1088b870b88df784c2940efce448ebfaf54dece14666John McCall
10891fb0caaa7bef765b85972274e3b434af2572c141John McCall    bool isCacheValid() const {
10901fb0caaa7bef765b85972274e3b434af2572c141John McCall      return (CacheValidAndVisibility != 0);
10911fb0caaa7bef765b85972274e3b434af2572c141John McCall    }
10921fb0caaa7bef765b85972274e3b434af2572c141John McCall    Visibility getVisibility() const {
10931fb0caaa7bef765b85972274e3b434af2572c141John McCall      assert(isCacheValid() && "getting linkage from invalid cache");
10941fb0caaa7bef765b85972274e3b434af2572c141John McCall      return static_cast<Visibility>(CacheValidAndVisibility-1);
10951fb0caaa7bef765b85972274e3b434af2572c141John McCall    }
10961fb0caaa7bef765b85972274e3b434af2572c141John McCall    Linkage getLinkage() const {
10971fb0caaa7bef765b85972274e3b434af2572c141John McCall      assert(isCacheValid() && "getting linkage from invalid cache");
10981fb0caaa7bef765b85972274e3b434af2572c141John McCall      return static_cast<Linkage>(CachedLinkage);
10991fb0caaa7bef765b85972274e3b434af2572c141John McCall    }
11001fb0caaa7bef765b85972274e3b434af2572c141John McCall    bool hasLocalOrUnnamedType() const {
11011fb0caaa7bef765b85972274e3b434af2572c141John McCall      assert(isCacheValid() && "getting linkage from invalid cache");
11021fb0caaa7bef765b85972274e3b434af2572c141John McCall      return CachedLocalOrUnnamed;
11031fb0caaa7bef765b85972274e3b434af2572c141John McCall    }
1104b870b88df784c2940efce448ebfaf54dece14666John McCall  };
1105d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  enum { NumTypeBits = 17 };
1106b870b88df784c2940efce448ebfaf54dece14666John McCall
1107b870b88df784c2940efce448ebfaf54dece14666John McCallprotected:
1108b870b88df784c2940efce448ebfaf54dece14666John McCall  // These classes allow subclasses to somewhat cleanly pack bitfields
1109b870b88df784c2940efce448ebfaf54dece14666John McCall  // into Type.
1110b870b88df784c2940efce448ebfaf54dece14666John McCall
1111b870b88df784c2940efce448ebfaf54dece14666John McCall  class ArrayTypeBitfields {
1112b870b88df784c2940efce448ebfaf54dece14666John McCall    friend class ArrayType;
1113b870b88df784c2940efce448ebfaf54dece14666John McCall
1114b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned : NumTypeBits;
1115b870b88df784c2940efce448ebfaf54dece14666John McCall
1116b870b88df784c2940efce448ebfaf54dece14666John McCall    /// IndexTypeQuals - CVR qualifiers from declarations like
1117b870b88df784c2940efce448ebfaf54dece14666John McCall    /// 'int X[static restrict 4]'. For function parameters only.
1118b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned IndexTypeQuals : 3;
1119b870b88df784c2940efce448ebfaf54dece14666John McCall
1120b870b88df784c2940efce448ebfaf54dece14666John McCall    /// SizeModifier - storage class qualifiers from declarations like
1121b870b88df784c2940efce448ebfaf54dece14666John McCall    /// 'int X[static restrict 4]'. For function parameters only.
1122b870b88df784c2940efce448ebfaf54dece14666John McCall    /// Actually an ArrayType::ArraySizeModifier.
1123b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned SizeModifier : 3;
1124b870b88df784c2940efce448ebfaf54dece14666John McCall  };
1125b870b88df784c2940efce448ebfaf54dece14666John McCall
1126b870b88df784c2940efce448ebfaf54dece14666John McCall  class BuiltinTypeBitfields {
1127b870b88df784c2940efce448ebfaf54dece14666John McCall    friend class BuiltinType;
1128b870b88df784c2940efce448ebfaf54dece14666John McCall
1129b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned : NumTypeBits;
1130b870b88df784c2940efce448ebfaf54dece14666John McCall
1131b870b88df784c2940efce448ebfaf54dece14666John McCall    /// The kind (BuiltinType::Kind) of builtin type this is.
1132b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned Kind : 8;
1133b870b88df784c2940efce448ebfaf54dece14666John McCall  };
1134b870b88df784c2940efce448ebfaf54dece14666John McCall
1135b870b88df784c2940efce448ebfaf54dece14666John McCall  class FunctionTypeBitfields {
1136b870b88df784c2940efce448ebfaf54dece14666John McCall    friend class FunctionType;
1137b870b88df784c2940efce448ebfaf54dece14666John McCall
1138b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned : NumTypeBits;
1139b870b88df784c2940efce448ebfaf54dece14666John McCall
1140b870b88df784c2940efce448ebfaf54dece14666John McCall    /// Extra information which affects how the function is called, like
1141b870b88df784c2940efce448ebfaf54dece14666John McCall    /// regparm and the calling convention.
11427e47e1e7e6a2b83d903c97129f27e92f584c3dc2Douglas Gregor    unsigned ExtInfo : 8;
1143b870b88df784c2940efce448ebfaf54dece14666John McCall
1144e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall    /// Whether the function is variadic.  Only used by FunctionProtoType.
1145e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall    unsigned Variadic : 1;
1146b870b88df784c2940efce448ebfaf54dece14666John McCall
1147b870b88df784c2940efce448ebfaf54dece14666John McCall    /// TypeQuals - Used only by FunctionProtoType, put here to pack with the
1148b870b88df784c2940efce448ebfaf54dece14666John McCall    /// other bitfields.
1149b870b88df784c2940efce448ebfaf54dece14666John McCall    /// The qualifiers are part of FunctionProtoType because...
1150b870b88df784c2940efce448ebfaf54dece14666John McCall    ///
1151b870b88df784c2940efce448ebfaf54dece14666John McCall    /// C++ 8.3.5p4: The return type, the parameter type list and the
1152b870b88df784c2940efce448ebfaf54dece14666John McCall    /// cv-qualifier-seq, [...], are part of the function type.
1153b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned TypeQuals : 3;
1154c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor
1155c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor    /// \brief The ref-qualifier associated with a \c FunctionProtoType.
1156c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor    ///
1157c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor    /// This is a value of type \c RefQualifierKind.
1158c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor    unsigned RefQualifier : 2;
1159b870b88df784c2940efce448ebfaf54dece14666John McCall  };
1160b870b88df784c2940efce448ebfaf54dece14666John McCall
1161b870b88df784c2940efce448ebfaf54dece14666John McCall  class ObjCObjectTypeBitfields {
1162b870b88df784c2940efce448ebfaf54dece14666John McCall    friend class ObjCObjectType;
1163b870b88df784c2940efce448ebfaf54dece14666John McCall
1164b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned : NumTypeBits;
1165b870b88df784c2940efce448ebfaf54dece14666John McCall
1166b870b88df784c2940efce448ebfaf54dece14666John McCall    /// NumProtocols - The number of protocols stored directly on this
1167b870b88df784c2940efce448ebfaf54dece14666John McCall    /// object type.
1168b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned NumProtocols : 32 - NumTypeBits;
1169b870b88df784c2940efce448ebfaf54dece14666John McCall  };
1170b870b88df784c2940efce448ebfaf54dece14666John McCall
1171b870b88df784c2940efce448ebfaf54dece14666John McCall  class ReferenceTypeBitfields {
1172b870b88df784c2940efce448ebfaf54dece14666John McCall    friend class ReferenceType;
1173b870b88df784c2940efce448ebfaf54dece14666John McCall
1174b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned : NumTypeBits;
1175b870b88df784c2940efce448ebfaf54dece14666John McCall
1176b870b88df784c2940efce448ebfaf54dece14666John McCall    /// True if the type was originally spelled with an lvalue sigil.
1177b870b88df784c2940efce448ebfaf54dece14666John McCall    /// This is never true of rvalue references but can also be false
1178b870b88df784c2940efce448ebfaf54dece14666John McCall    /// on lvalue references because of C++0x [dcl.typedef]p9,
1179b870b88df784c2940efce448ebfaf54dece14666John McCall    /// as follows:
1180b870b88df784c2940efce448ebfaf54dece14666John McCall    ///
1181b870b88df784c2940efce448ebfaf54dece14666John McCall    ///   typedef int &ref;    // lvalue, spelled lvalue
1182b870b88df784c2940efce448ebfaf54dece14666John McCall    ///   typedef int &&rvref; // rvalue
1183b870b88df784c2940efce448ebfaf54dece14666John McCall    ///   ref &a;              // lvalue, inner ref, spelled lvalue
1184b870b88df784c2940efce448ebfaf54dece14666John McCall    ///   ref &&a;             // lvalue, inner ref
1185b870b88df784c2940efce448ebfaf54dece14666John McCall    ///   rvref &a;            // lvalue, inner ref, spelled lvalue
1186b870b88df784c2940efce448ebfaf54dece14666John McCall    ///   rvref &&a;           // rvalue, inner ref
1187bdb5b0e8ad8ed297ad01eb2ccd0d6d5ed6058033Francois Pichet    unsigned SpelledAsLValue : 1;
1188b870b88df784c2940efce448ebfaf54dece14666John McCall
1189b870b88df784c2940efce448ebfaf54dece14666John McCall    /// True if the inner type is a reference type.  This only happens
1190b870b88df784c2940efce448ebfaf54dece14666John McCall    /// in non-canonical forms.
1191bdb5b0e8ad8ed297ad01eb2ccd0d6d5ed6058033Francois Pichet    unsigned InnerRef : 1;
1192b870b88df784c2940efce448ebfaf54dece14666John McCall  };
1193b870b88df784c2940efce448ebfaf54dece14666John McCall
119477be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall  class TypeWithKeywordBitfields {
119577be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall    friend class TypeWithKeyword;
119677be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall
119777be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall    unsigned : NumTypeBits;
119877be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall
119977be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall    /// An ElaboratedTypeKeyword.  8 bits for efficient access.
120077be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall    unsigned Keyword : 8;
120177be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall  };
120277be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall
1203b870b88df784c2940efce448ebfaf54dece14666John McCall  class VectorTypeBitfields {
1204b870b88df784c2940efce448ebfaf54dece14666John McCall    friend class VectorType;
120507a353c2af3a3c557205466d4f4ed2513462ebfeSebastian Redl
1206b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned : NumTypeBits;
120771c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall
1208e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson    /// VecKind - The kind of vector, either a generic vector type or some
1209e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson    /// target-specific vector type such as for AltiVec or Neon.
1210cc3b946c35c4372272034e6f0663089477a9a5bdBob Wilson    unsigned VecKind : 3;
1211b870b88df784c2940efce448ebfaf54dece14666John McCall
1212b870b88df784c2940efce448ebfaf54dece14666John McCall    /// NumElements - The number of elements in the vector.
1213cc3b946c35c4372272034e6f0663089477a9a5bdBob Wilson    unsigned NumElements : 29 - NumTypeBits;
1214b870b88df784c2940efce448ebfaf54dece14666John McCall  };
1215b870b88df784c2940efce448ebfaf54dece14666John McCall
12169d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  class AttributedTypeBitfields {
12179d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    friend class AttributedType;
12189d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
12199d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    unsigned : NumTypeBits;
12209d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
12219d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    /// AttrKind - an AttributedType::Kind
12229d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    unsigned AttrKind : 32 - NumTypeBits;
12239d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  };
12249d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
1225b870b88df784c2940efce448ebfaf54dece14666John McCall  union {
1226b870b88df784c2940efce448ebfaf54dece14666John McCall    TypeBitfields TypeBits;
1227b870b88df784c2940efce448ebfaf54dece14666John McCall    ArrayTypeBitfields ArrayTypeBits;
12289d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    AttributedTypeBitfields AttributedTypeBits;
1229b870b88df784c2940efce448ebfaf54dece14666John McCall    BuiltinTypeBitfields BuiltinTypeBits;
1230b870b88df784c2940efce448ebfaf54dece14666John McCall    FunctionTypeBitfields FunctionTypeBits;
1231b870b88df784c2940efce448ebfaf54dece14666John McCall    ObjCObjectTypeBitfields ObjCObjectTypeBits;
1232b870b88df784c2940efce448ebfaf54dece14666John McCall    ReferenceTypeBitfields ReferenceTypeBits;
123377be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall    TypeWithKeywordBitfields TypeWithKeywordBits;
1234b870b88df784c2940efce448ebfaf54dece14666John McCall    VectorTypeBitfields VectorTypeBits;
1235b870b88df784c2940efce448ebfaf54dece14666John McCall  };
1236b870b88df784c2940efce448ebfaf54dece14666John McCall
1237b870b88df784c2940efce448ebfaf54dece14666John McCallprivate:
12383c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief Set whether this type comes from an AST file.
12393c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  void setFromAST(bool V = true) const {
1240b870b88df784c2940efce448ebfaf54dece14666John McCall    TypeBits.FromAST = V;
124107a353c2af3a3c557205466d4f4ed2513462ebfeSebastian Redl  }
124207a353c2af3a3c557205466d4f4ed2513462ebfeSebastian Redl
1243b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall  template <class T> friend class TypePropertyCache;
12441fb0caaa7bef765b85972274e3b434af2572c141John McCall
12455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprotected:
1246124dd7b5777e29ecac006822bd4d4623f0dc4264Hartmut Kaiser  // silence VC++ warning C4355: 'this' : used in base member initializer list
1247124dd7b5777e29ecac006822bd4d4623f0dc4264Hartmut Kaiser  Type *this_() { return this; }
12483b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  Type(TypeClass tc, QualType canon, bool Dependent, bool VariablyModified,
1249d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor       bool ContainsUnexpandedParameterPack)
12503b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    : ExtQualsTypeCommonBase(this,
12513b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall                             canon.isNull() ? QualType(this_(), 0) : canon) {
1252b870b88df784c2940efce448ebfaf54dece14666John McCall    TypeBits.TC = tc;
1253b870b88df784c2940efce448ebfaf54dece14666John McCall    TypeBits.Dependent = Dependent;
1254b870b88df784c2940efce448ebfaf54dece14666John McCall    TypeBits.VariablyModified = VariablyModified;
1255d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    TypeBits.ContainsUnexpandedParameterPack = ContainsUnexpandedParameterPack;
12561fb0caaa7bef765b85972274e3b434af2572c141John McCall    TypeBits.CacheValidAndVisibility = 0;
1257b870b88df784c2940efce448ebfaf54dece14666John McCall    TypeBits.CachedLocalOrUnnamed = false;
1258b870b88df784c2940efce448ebfaf54dece14666John McCall    TypeBits.CachedLinkage = NoLinkage;
1259b870b88df784c2940efce448ebfaf54dece14666John McCall    TypeBits.FromAST = false;
1260b870b88df784c2940efce448ebfaf54dece14666John McCall  }
12615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;
12621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1263b870b88df784c2940efce448ebfaf54dece14666John McCall  void setDependent(bool D = true) { TypeBits.Dependent = D; }
1264b870b88df784c2940efce448ebfaf54dece14666John McCall  void setVariablyModified(bool VM = true) { TypeBits.VariablyModified = VM; }
1265d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  void setContainsUnexpandedParameterPack(bool PP = true) {
1266d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    TypeBits.ContainsUnexpandedParameterPack = PP;
1267d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  }
1268d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor
12698b9023ba35a86838789e2c9034a6128728c547aaChris Lattnerpublic:
1270b870b88df784c2940efce448ebfaf54dece14666John McCall  TypeClass getTypeClass() const { return static_cast<TypeClass>(TypeBits.TC); }
12711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12723c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief Whether this type comes from an AST file.
1273b870b88df784c2940efce448ebfaf54dece14666John McCall  bool isFromAST() const { return TypeBits.FromAST; }
127407a353c2af3a3c557205466d4f4ed2513462ebfeSebastian Redl
1275d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// \brief Whether this type is or contains an unexpanded parameter
1276d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// pack, used to support C++0x variadic templates.
1277d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  ///
1278d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// A type that contains a parameter pack shall be expanded by the
1279d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// ellipsis operator at some point. For example, the typedef in the
1280d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// following example contains an unexpanded parameter pack 'T':
1281d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  ///
1282d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// \code
1283d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// template<typename ...T>
1284d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// struct X {
1285d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  ///   typedef T* pointer_types; // ill-formed; T is a parameter pack.
1286d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// };
1287d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// \endcode
1288d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  ///
1289d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// Note that this routine does not specify which
1290d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  bool containsUnexpandedParameterPack() const {
1291d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    return TypeBits.ContainsUnexpandedParameterPack;
1292d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  }
1293d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor
12943b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  /// Determines if this type would be canonical if it had no further
12953b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  /// qualification.
1296467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall  bool isCanonicalUnqualified() const {
12973b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    return CanonicalType == QualType(this, 0);
1298467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall  }
12995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
13001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// Types are partitioned into 3 broad categories (C99 6.2.5p1):
13015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// object types, function types, and incomplete types.
13021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
13035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isIncompleteType - Return true if this is an incomplete type.
13045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// A type that can describe objects, but which lacks information needed to
13055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// determine its size (e.g. void, or a fwd declared struct). Clients of this
13061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// routine will need to determine if the size is actually required.
13075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isIncompleteType() const;
1308d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner
1309d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner  /// isIncompleteOrObjectType - Return true if this is an incomplete or object
1310d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner  /// type, in other words, not a function type.
1311d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner  bool isIncompleteOrObjectType() const {
1312d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner    return !isFunctionType();
1313d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner  }
13142fdc5e8199e1e239620f2faae88997153703e16fDouglas Gregor
13152fdc5e8199e1e239620f2faae88997153703e16fDouglas Gregor  /// \brief Determine whether this type is an object type.
13162fdc5e8199e1e239620f2faae88997153703e16fDouglas Gregor  bool isObjectType() const {
13172fdc5e8199e1e239620f2faae88997153703e16fDouglas Gregor    // C++ [basic.types]p8:
13182fdc5e8199e1e239620f2faae88997153703e16fDouglas Gregor    //   An object type is a (possibly cv-qualified) type that is not a
13192fdc5e8199e1e239620f2faae88997153703e16fDouglas Gregor    //   function type, not a reference type, and not a void type.
13202fdc5e8199e1e239620f2faae88997153703e16fDouglas Gregor    return !isReferenceType() && !isFunctionType() && !isVoidType();
13212fdc5e8199e1e239620f2faae88997153703e16fDouglas Gregor  }
132264b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
1323ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl  /// isLiteralType - Return true if this is a literal type
1324ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl  /// (C++0x [basic.types]p10)
1325ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl  bool isLiteralType() const;
1326ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl
1327636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth  /// \brief Test if this type is a standard-layout type.
1328636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth  /// (C++0x [basic.type]p9)
1329636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth  bool isStandardLayoutType() const;
1330636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth
13315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// Helper methods to distinguish type categories. All type predicates
1332ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb  /// operate on the canonical type, ignoring typedefs and qualifiers.
1333e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar
13349b065ddabf572772991a4aadad5bf4921fac5069Tom Care  /// isBuiltinType - returns true if the type is a builtin type.
13359b065ddabf572772991a4aadad5bf4921fac5069Tom Care  bool isBuiltinType() const;
13369b065ddabf572772991a4aadad5bf4921fac5069Tom Care
1337e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar  /// isSpecificBuiltinType - Test for a particular builtin type.
1338e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar  bool isSpecificBuiltinType(unsigned K) const;
13391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
13402a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  /// isPlaceholderType - Test for a type which does not represent an
13412a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  /// actual type-system type but is instead used as a placeholder for
13422a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  /// various convenient purposes within Clang.  All such types are
13432a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  /// BuiltinTypes.
13442a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  bool isPlaceholderType() const;
13452a984cad5ac3fdceeff2bd99daa7b90979313475John McCall
1346864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall  /// isSpecificPlaceholderType - Test for a specific placeholder type.
1347864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall  bool isSpecificPlaceholderType(unsigned K) const;
1348864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall
134996d2c438f5c9ada8229f7f2ac049d2e9957bc954Steve Naroff  /// isIntegerType() does *not* include complex integers (a GCC extension).
135096d2c438f5c9ada8229f7f2ac049d2e9957bc954Steve Naroff  /// isComplexIntegerType() can be used to test for complex integers.
13515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isIntegerType() const;     // C99 6.2.5p17 (int, char, bool, enum)
135213b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff  bool isEnumeralType() const;
135313b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff  bool isBooleanType() const;
135413b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff  bool isCharType() const;
135577a52233f7c0f162672652051bfe78b65ad4f789Douglas Gregor  bool isWideCharType() const;
135620093b4bf698f292c664676987541d5103b65b15Douglas Gregor  bool isAnyCharacterType() const;
13579d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor  bool isIntegralType(ASTContext &Ctx) const;
135820093b4bf698f292c664676987541d5103b65b15Douglas Gregor
13592ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor  /// \brief Determine whether this type is an integral or enumeration type.
13602ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor  bool isIntegralOrEnumerationType() const;
13611274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor  /// \brief Determine whether this type is an integral or unscoped enumeration
13621274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor  /// type.
13631274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor  bool isIntegralOrUnscopedEnumerationType() const;
13642ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor
13655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// Floating point categories.
13665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isRealFloatingType() const; // C99 6.2.5p10 (float, double, long double)
136702f62a9fedbc370fba081303399410a3afdde29fSteve Naroff  /// isComplexType() does *not* include complex integers (a GCC extension).
136802f62a9fedbc370fba081303399410a3afdde29fSteve Naroff  /// isComplexIntegerType() can be used to test for complex integers.
13695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isComplexType() const;      // C99 6.2.5p11 (complex)
1370f23d364084d1aabea688222780d6fc1dd8c7f78cChris Lattner  bool isAnyComplexType() const;   // C99 6.2.5p11 (complex) + Complex Int.
13715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isFloatingType() const;     // C99 6.2.5p11 (real floating + complex)
13725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isRealType() const;         // C99 6.2.5p17 (real floating + integer)
13735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isArithmeticType() const;   // C99 6.2.5p18 (integer + floating)
1374c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  bool isVoidType() const;         // C99 6.2.5p19
1375c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  bool isDerivedType() const;      // C99 6.2.5p20
1376c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  bool isScalarType() const;       // C99 6.2.5p21 (arithmetic + pointers)
1377d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor  bool isAggregateType() const;
1378aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth  bool isFundamentalType() const;
1379aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth  bool isCompoundType() const;
13801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1381c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  // Type Predicates: Check to see if this type is structurally the specified
1382ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb  // type, ignoring typedefs and qualifiers.
1383c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  bool isFunctionType() const;
1384183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  bool isFunctionNoProtoType() const { return getAs<FunctionNoProtoType>(); }
1385183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  bool isFunctionProtoType() const { return getAs<FunctionProtoType>(); }
1386befee48ff2a1dab236c5700f00ecca1cfdcd5837Chris Lattner  bool isPointerType() const;
138758f9f2c884af6b72d036b746a016d8031d31cb7aSteve Naroff  bool isAnyPointerType() const;   // Any C pointer or ObjC object pointer
13885618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  bool isBlockPointerType() const;
13897154a77e7c1f23418342d3b72836ab504aa7821eSteve Naroff  bool isVoidPointerType() const;
1390a1d9fdea79ba7bbd71862b9f9f78f5f117331fc7Chris Lattner  bool isReferenceType() const;
13917c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  bool isLValueReferenceType() const;
13927c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  bool isRValueReferenceType() const;
1393bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner  bool isFunctionPointerType() const;
1394f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  bool isMemberPointerType() const;
1395f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  bool isMemberFunctionPointerType() const;
1396db68e28c05a67735211e688009890cf834c22e75Douglas Gregor  bool isMemberDataPointerType() const;
1397c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  bool isArrayType() const;
1398c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  bool isConstantArrayType() const;
1399c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  bool isIncompleteArrayType() const;
1400c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  bool isVariableArrayType() const;
1401898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  bool isDependentSizedArrayType() const;
1402c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  bool isRecordType() const;
14031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  bool isClassType() const;
14041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  bool isStructureType() const;
1405fb87b89fc9eb103e19fb8e4b925c23f0bd091b99Douglas Gregor  bool isStructureOrClassType() const;
14064cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroff  bool isUnionType() const;
1407368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner  bool isComplexIntegerType() const;            // GCC _Complex integer type.
1408368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner  bool isVectorType() const;                    // GCC vector type.
1409213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman  bool isExtVectorType() const;                 // Extended vector type.
1410f85e193739c953358c865005855253af4f68a497John McCall  bool isObjCObjectPointerType() const;         // pointer to ObjC object
1411f85e193739c953358c865005855253af4f68a497John McCall  bool isObjCRetainableType() const;            // ObjC object or block pointer
1412f85e193739c953358c865005855253af4f68a497John McCall  bool isObjCLifetimeType() const;              // (array of)* retainable type
1413f85e193739c953358c865005855253af4f68a497John McCall  bool isObjCIndirectLifetimeType() const;      // (pointer to)* lifetime type
1414f85e193739c953358c865005855253af4f68a497John McCall  bool isObjCNSObjectType() const;              // __attribute__((NSObject))
141514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  // FIXME: change this to 'raw' interface type, so we can used 'interface' type
141614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  // for the common case.
1417c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool isObjCObjectType() const;                // NSString or typeof(*(id)0)
1418368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner  bool isObjCQualifiedInterfaceType() const;    // NSString<foo>
1419368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner  bool isObjCQualifiedIdType() const;           // id<foo>
1420470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroff  bool isObjCQualifiedClassType() const;        // Class<foo>
1421569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor  bool isObjCObjectOrInterfaceType() const;
142214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  bool isObjCIdType() const;                    // id
142314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  bool isObjCClassType() const;                 // Class
142413dcd00615de5c4279d97bdf63cd5f0a14fd9dccFariborz Jahanian  bool isObjCSelType() const;                 // Class
1425de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff  bool isObjCBuiltinType() const;               // 'id' or 'Class'
1426f85e193739c953358c865005855253af4f68a497John McCall  bool isObjCARCBridgableType() const;
1427f85e193739c953358c865005855253af4f68a497John McCall  bool isCARCBridgableType() const;
142872c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor  bool isTemplateTypeParmType() const;          // C++ template type parameter
14296e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl  bool isNullPtrType() const;                   // C++0x nullptr_t
1430898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
1431f85e193739c953358c865005855253af4f68a497John McCall  /// Determines if this type, which must satisfy
1432f85e193739c953358c865005855253af4f68a497John McCall  /// isObjCLifetimeType(), is implicitly __unsafe_unretained rather
1433f85e193739c953358c865005855253af4f68a497John McCall  /// than implicitly __strong.
1434f85e193739c953358c865005855253af4f68a497John McCall  bool isObjCARCImplicitlyUnretainedType() const;
1435f85e193739c953358c865005855253af4f68a497John McCall
1436f85e193739c953358c865005855253af4f68a497John McCall  /// Return the implicit lifetime for this type, which must not be dependent.
1437f85e193739c953358c865005855253af4f68a497John McCall  Qualifiers::ObjCLifetime getObjCARCImplicitLifetime() const;
1438f85e193739c953358c865005855253af4f68a497John McCall
1439daa8e4e888758d55a7a759dd4a91b83921cef222John McCall  enum ScalarTypeKind {
1440daa8e4e888758d55a7a759dd4a91b83921cef222John McCall    STK_Pointer,
1441daa8e4e888758d55a7a759dd4a91b83921cef222John McCall    STK_MemberPointer,
1442daa8e4e888758d55a7a759dd4a91b83921cef222John McCall    STK_Bool,
1443daa8e4e888758d55a7a759dd4a91b83921cef222John McCall    STK_Integral,
1444daa8e4e888758d55a7a759dd4a91b83921cef222John McCall    STK_Floating,
1445daa8e4e888758d55a7a759dd4a91b83921cef222John McCall    STK_IntegralComplex,
1446daa8e4e888758d55a7a759dd4a91b83921cef222John McCall    STK_FloatingComplex
1447daa8e4e888758d55a7a759dd4a91b83921cef222John McCall  };
1448daa8e4e888758d55a7a759dd4a91b83921cef222John McCall  /// getScalarTypeKind - Given that this is a scalar type, classify it.
1449daa8e4e888758d55a7a759dd4a91b83921cef222John McCall  ScalarTypeKind getScalarTypeKind() const;
1450daa8e4e888758d55a7a759dd4a91b83921cef222John McCall
1451898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// isDependentType - Whether this type is a dependent type, meaning
14521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// that its definition somehow depends on a template parameter
1453898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// (C++ [temp.dep.type]).
1454b870b88df784c2940efce448ebfaf54dece14666John McCall  bool isDependentType() const { return TypeBits.Dependent; }
145535495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor
145635495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor  /// \brief Whether this type is a variably-modified type (C99 6.7.5).
1457b870b88df784c2940efce448ebfaf54dece14666John McCall  bool isVariablyModifiedType() const { return TypeBits.VariablyModified; }
14583b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
14593b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  /// \brief Whether this type involves a variable-length array type
14603b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  /// with a definite size.
14613b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  bool hasSizedVLAType() const;
146235495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor
1463db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor  /// \brief Whether this type is or contains a local or unnamed type.
1464db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor  bool hasUnnamedOrLocalType() const;
1465db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor
1466063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  bool isOverloadableType() const;
146772c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor
14684033642464e8ba0982f88f34cffad808d247b393Douglas Gregor  /// \brief Determine wither this type is a C++ elaborated-type-specifier.
14694033642464e8ba0982f88f34cffad808d247b393Douglas Gregor  bool isElaboratedTypeSpecifier() const;
1470bc8d7f9fd4346cfcc285868be32b74e019a40f01Chandler Carruth
1471bc8d7f9fd4346cfcc285868be32b74e019a40f01Chandler Carruth  bool canDecayToPointerType() const;
14722b1ad8b42bbbe00a1845e566f52f1941b8dbc725Douglas Gregor
14738958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar  /// hasPointerRepresentation - Whether this type is represented
14748958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar  /// natively as a pointer; this includes pointers, references, block
14758958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar  /// pointers, and Objective-C interface, qualified id, and qualified
14766e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl  /// interface types, as well as nullptr_t.
14778958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar  bool hasPointerRepresentation() const;
14788958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar
1479820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian  /// hasObjCPointerRepresentation - Whether this type can represent
1480820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian  /// an objective pointer type for the purpose of GC'ability
14811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  bool hasObjCPointerRepresentation() const;
1482820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian
1483f60946222721d9ba3c059563935c17b84703187aDouglas Gregor  /// \brief Determine whether this type has an integer representation
1484f60946222721d9ba3c059563935c17b84703187aDouglas Gregor  /// of some sort, e.g., it is an integer type or a vector.
1485f60946222721d9ba3c059563935c17b84703187aDouglas Gregor  bool hasIntegerRepresentation() const;
1486f60946222721d9ba3c059563935c17b84703187aDouglas Gregor
1487f60946222721d9ba3c059563935c17b84703187aDouglas Gregor  /// \brief Determine whether this type has an signed integer representation
1488f60946222721d9ba3c059563935c17b84703187aDouglas Gregor  /// of some sort, e.g., it is an signed integer type or a vector.
1489f60946222721d9ba3c059563935c17b84703187aDouglas Gregor  bool hasSignedIntegerRepresentation() const;
1490f60946222721d9ba3c059563935c17b84703187aDouglas Gregor
1491f60946222721d9ba3c059563935c17b84703187aDouglas Gregor  /// \brief Determine whether this type has an unsigned integer representation
1492f60946222721d9ba3c059563935c17b84703187aDouglas Gregor  /// of some sort, e.g., it is an unsigned integer type or a vector.
1493f60946222721d9ba3c059563935c17b84703187aDouglas Gregor  bool hasUnsignedIntegerRepresentation() const;
1494f60946222721d9ba3c059563935c17b84703187aDouglas Gregor
14958eee119bf4f1693dde17b8552c1f9f81bf2b681eDouglas Gregor  /// \brief Determine whether this type has a floating-point representation
14968eee119bf4f1693dde17b8552c1f9f81bf2b681eDouglas Gregor  /// of some sort, e.g., it is a floating-point type or a vector thereof.
14978eee119bf4f1693dde17b8552c1f9f81bf2b681eDouglas Gregor  bool hasFloatingRepresentation() const;
1498f60946222721d9ba3c059563935c17b84703187aDouglas Gregor
1499c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  // Type Checking Functions: Check to see if this type is structurally the
1500f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner  // specified type, ignoring typedefs and qualifiers, and return a pointer to
1501f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner  // the best type we can.
1502769c9cfc6e06bd9d8ffe7a4397b939f19b0e4dc3Ted Kremenek  const RecordType *getAsStructureType() const;
1503898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// NOTE: getAs*ArrayType are methods on ASTContext.
1504c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  const RecordType *getAsUnionType() const;
15054cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroff  const ComplexType *getAsComplexIntegerType() const; // GCC complex int type.
150614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  // The following is a convenience method that returns an ObjCObjectPointerType
150714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  // for object declared using an interface.
150814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  const ObjCObjectPointerType *getAsObjCInterfacePointerType() const;
150914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  const ObjCObjectPointerType *getAsObjCQualifiedIdType() const;
1510759abb4d9ec14ae32104a9677b60f0542b60d1d8Fariborz Jahanian  const ObjCObjectPointerType *getAsObjCQualifiedClassType() const;
1511c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  const ObjCObjectType *getAsObjCQualifiedInterfaceType() const;
1512a91d6a6619a91d0ca7102d8ab5678d855f04d850Fariborz Jahanian  const CXXRecordDecl *getCXXRecordDeclForPointerType() const;
15131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1514c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor  /// \brief Retrieves the CXXRecordDecl that this type refers to, either
1515c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor  /// because the type is a RecordType or because it is the injected-class-name
1516c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor  /// type of a class template or class template partial specialization.
1517c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor  CXXRecordDecl *getAsCXXRecordDecl() const;
151834b41d939a1328f484511c6002ba2456db879a29Richard Smith
151934b41d939a1328f484511c6002ba2456db879a29Richard Smith  /// \brief Get the AutoType whose type will be deduced for a variable with
152034b41d939a1328f484511c6002ba2456db879a29Richard Smith  /// an initializer of this type. This looks through declarators like pointer
152134b41d939a1328f484511c6002ba2456db879a29Richard Smith  /// types, but not through decltype or typedefs.
152234b41d939a1328f484511c6002ba2456db879a29Richard Smith  AutoType *getContainedAutoType() const;
1523c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor
1524d0370f59e79702ac908c81bf556519f91e9ca297John McCall  /// Member-template getAs<specific type>'.  Look through sugar for
1525d0370f59e79702ac908c81bf556519f91e9ca297John McCall  /// an instance of <specific type>.   This scheme will eventually
1526d0370f59e79702ac908c81bf556519f91e9ca297John McCall  /// replace the specific getAsXXXX methods above.
1527d0370f59e79702ac908c81bf556519f91e9ca297John McCall  ///
1528d0370f59e79702ac908c81bf556519f91e9ca297John McCall  /// There are some specializations of this member template listed
1529d0370f59e79702ac908c81bf556519f91e9ca297John McCall  /// immediately following this class.
15301a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek  template <typename T> const T *getAs() const;
15311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
15323b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  /// A variant of getAs<> for array types which silently discards
15333b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  /// qualifiers from the outermost type.
15343b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  const ArrayType *getAsArrayTypeUnsafe() const;
15353b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
1536d0370f59e79702ac908c81bf556519f91e9ca297John McCall  /// Member-template castAs<specific type>.  Look through sugar for
1537d0370f59e79702ac908c81bf556519f91e9ca297John McCall  /// the underlying instance of <specific type>.
1538d0370f59e79702ac908c81bf556519f91e9ca297John McCall  ///
1539d0370f59e79702ac908c81bf556519f91e9ca297John McCall  /// This method has the same relationship to getAs<T> as cast<T> has
1540d0370f59e79702ac908c81bf556519f91e9ca297John McCall  /// to dyn_cast<T>; which is to say, the underlying type *must*
1541d0370f59e79702ac908c81bf556519f91e9ca297John McCall  /// have the intended type, and this method will never return null.
1542d0370f59e79702ac908c81bf556519f91e9ca297John McCall  template <typename T> const T *castAs() const;
1543d0370f59e79702ac908c81bf556519f91e9ca297John McCall
1544d0370f59e79702ac908c81bf556519f91e9ca297John McCall  /// A variant of castAs<> for array type which silently discards
1545d0370f59e79702ac908c81bf556519f91e9ca297John McCall  /// qualifiers from the outermost type.
1546d0370f59e79702ac908c81bf556519f91e9ca297John McCall  const ArrayType *castAsArrayTypeUnsafe() const;
1547d0370f59e79702ac908c81bf556519f91e9ca297John McCall
1548d0370f59e79702ac908c81bf556519f91e9ca297John McCall  /// getBaseElementTypeUnsafe - Get the base element type of this
1549d0370f59e79702ac908c81bf556519f91e9ca297John McCall  /// type, potentially discarding type qualifiers.  This method
1550d0370f59e79702ac908c81bf556519f91e9ca297John McCall  /// should never be used when type qualifiers are meaningful.
1551d0370f59e79702ac908c81bf556519f91e9ca297John McCall  const Type *getBaseElementTypeUnsafe() const;
1552d0370f59e79702ac908c81bf556519f91e9ca297John McCall
1553c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  /// getArrayElementTypeNoTypeQual - If this is an array type, return the
1554c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  /// element type of the array, potentially with type qualifiers missing.
1555c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  /// This method should never be used when type qualifiers are meaningful.
1556c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  const Type *getArrayElementTypeNoTypeQual() const;
15571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1558f8910df57799256c1897a8610dc52685729ae90eSteve Naroff  /// getPointeeType - If this is a pointer, ObjC object pointer, or block
1559f8910df57799256c1897a8610dc52685729ae90eSteve Naroff  /// pointer, this returns the respective pointee.
156014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  QualType getPointeeType() const;
15611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1562bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// getUnqualifiedDesugaredType() - Return the specified type with
1563bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// any "sugar" removed from the type, removing any typedefs,
1564bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// typeofs, etc., as well as any qualifiers.
1565bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  const Type *getUnqualifiedDesugaredType() const;
15661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
15675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// More type predicates useful for type checking/promotion
15685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isPromotableIntegerType() const; // C99 6.3.1.1p2
15695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
15705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isSignedIntegerType - Return true if this is an integer type that is
1571d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner  /// signed, according to C99 6.2.5p4 [char, signed char, short, int, long..],
15725f3827cabd526d0dd5f291d46c310103cebe7a44Eli Friedman  /// or an enum decl which has a signed representation.
15735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isSignedIntegerType() const;
15745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
15755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isUnsignedIntegerType - Return true if this is an integer type that is
15765f3827cabd526d0dd5f291d46c310103cebe7a44Eli Friedman  /// unsigned, according to C99 6.2.5p6 [which returns true for _Bool],
15775f3827cabd526d0dd5f291d46c310103cebe7a44Eli Friedman  /// or an enum decl which has an unsigned representation.
15785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isUnsignedIntegerType() const;
1579d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner
1580575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor  /// Determines whether this is an integer type that is signed or an
1581575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor  /// enumeration types whose underlying type is a signed integer type.
1582575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor  bool isSignedIntegerOrEnumerationType() const;
1583575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor
1584575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor  /// Determines whether this is an integer type that is unsigned or an
1585575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor  /// enumeration types whose underlying type is a unsigned integer type.
1586575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor  bool isUnsignedIntegerOrEnumerationType() const;
1587575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor
15885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isConstantSizeType - Return true if this is not a variable sized type,
15899bfa73c5ab7bf4b0e749d04f29da6884e8d5bd9fChris Lattner  /// according to the rules of C99 6.7.5p3.  It is not legal to call this on
15909bfa73c5ab7bf4b0e749d04f29da6884e8d5bd9fChris Lattner  /// incomplete types.
15913c2b3170041f69a92904e3bab9b6d654eaf260acEli Friedman  bool isConstantSizeType() const;
1592c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner
159322b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman  /// isSpecifierType - Returns true if this type can be represented by some
159422b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman  /// set of type specifiers.
159522b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman  bool isSpecifierType() const;
159622b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman
15970b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor  /// \brief Determine the linkage of this type.
159860e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor  Linkage getLinkage() const;
15991fb0caaa7bef765b85972274e3b434af2572c141John McCall
16001fb0caaa7bef765b85972274e3b434af2572c141John McCall  /// \brief Determine the visibility of this type.
16011fb0caaa7bef765b85972274e3b434af2572c141John McCall  Visibility getVisibility() const;
16021fb0caaa7bef765b85972274e3b434af2572c141John McCall
16031fb0caaa7bef765b85972274e3b434af2572c141John McCall  /// \brief Determine the linkage and visibility of this type.
16041fb0caaa7bef765b85972274e3b434af2572c141John McCall  std::pair<Linkage,Visibility> getLinkageAndVisibility() const;
160560e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
160660e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor  /// \brief Note that the linkage is no longer known.
160760e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor  void ClearLinkageCache();
160860e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
160960e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor  const char *getTypeClassName() const;
16100b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor
1611ead608af31b6c9abeae1ca6d0b75094dac4641c0John McCall  QualType getCanonicalTypeInternal() const {
1612ead608af31b6c9abeae1ca6d0b75094dac4641c0John McCall    return CanonicalType;
1613ead608af31b6c9abeae1ca6d0b75094dac4641c0John McCall  }
1614ead608af31b6c9abeae1ca6d0b75094dac4641c0John McCall  CanQualType getCanonicalTypeUnqualified() const; // in CanonicalType.h
1615c36d405a02fab41f6c45cb2bc750d64949742903Chris Lattner  void dump() const;
1616f85e193739c953358c865005855253af4f68a497John McCall
16175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *) { return true; }
1618be191100e034b23a3e13053757a57b7f5068c24aArgyrios Kyrtzidis
1619c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl  friend class ASTReader;
1620a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian Redl  friend class ASTWriter;
16215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
16225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1623183700f494ec9b6701b6efe82bcb25f4c79ba561John McCalltemplate <> inline const TypedefType *Type::getAs() const {
1624183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  return dyn_cast<TypedefType>(this);
1625183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall}
1626183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall
1627183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall// We can do canonical leaf types faster, because we don't have to
1628183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall// worry about preserving child type decoration.
1629183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall#define TYPE(Class, Base)
1630183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall#define LEAF_TYPE(Class) \
1631183700f494ec9b6701b6efe82bcb25f4c79ba561John McCalltemplate <> inline const Class##Type *Type::getAs() const { \
16320953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  return dyn_cast<Class##Type>(CanonicalType); \
1633d0370f59e79702ac908c81bf556519f91e9ca297John McCall} \
1634d0370f59e79702ac908c81bf556519f91e9ca297John McCalltemplate <> inline const Class##Type *Type::castAs() const { \
1635d0370f59e79702ac908c81bf556519f91e9ca297John McCall  return cast<Class##Type>(CanonicalType); \
1636183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall}
1637183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall#include "clang/AST/TypeNodes.def"
1638183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall
1639183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall
16405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// BuiltinType - This class is used for builtin types like 'int'.  Builtin
16415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// types are always canonical and have a literal name field.
16425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass BuiltinType : public Type {
16435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
16445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  enum Kind {
16455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Void,
16461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
16475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Bool,     // This is bool and/or _Bool.
16485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Char_U,   // This is 'char' for targets where char is unsigned.
16495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    UChar,    // This is explicitly qualified unsigned char.
16503f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner    WChar_U,  // This is 'wchar_t' for C++, when unsigned.
1651f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith    Char16,   // This is 'char16_t' for C++.
1652f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith    Char32,   // This is 'char32_t' for C++.
16535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    UShort,
16545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    UInt,
16555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ULong,
16565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ULongLong,
16572df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner    UInt128,  // __uint128_t
16581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
16595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Char_S,   // This is 'char' for targets where char is signed.
16605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    SChar,    // This is explicitly qualified signed char.
16613f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner    WChar_S,  // This is 'wchar_t' for C++, when signed.
16625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Short,
16635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Int,
16645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Long,
16655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    LongLong,
16662df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner    Int128,   // __int128_t
16671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
16688e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor    Float, Double, LongDouble,
16698e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor
16706e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl    NullPtr,  // This is the type of C++0x 'nullptr'.
16716e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl
1672864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall    /// The primitive Objective C 'id' type.  The user-visible 'id'
1673864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall    /// type is a typedef of an ObjCObjectPointerType to an
1674864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall    /// ObjCObjectType with this as its base.  In fact, this only ever
1675864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall    /// shows up in an AST as the base type of an ObjCObjectType.
1676864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall    ObjCId,
1677864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall
1678864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall    /// The primitive Objective C 'Class' type.  The user-visible
1679864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall    /// 'Class' type is a typedef of an ObjCObjectPointerType to an
1680864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall    /// ObjCObjectType with this as its base.  In fact, this only ever
1681864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall    /// shows up in an AST as the base type of an ObjCObjectType.
1682864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall    ObjCClass,
1683864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall
1684864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall    /// The primitive Objective C 'SEL' type.  The user-visible 'SEL'
1685864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall    /// type is a typedef of a PointerType to this.
1686864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall    ObjCSel,
1687864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall
16882a984cad5ac3fdceeff2bd99daa7b90979313475John McCall    /// This represents the type of an expression whose type is
16892a984cad5ac3fdceeff2bd99daa7b90979313475John McCall    /// totally unknown, e.g. 'T::foo'.  It is permitted for this to
16902a984cad5ac3fdceeff2bd99daa7b90979313475John McCall    /// appear in situations where the structure of the type is
16912a984cad5ac3fdceeff2bd99daa7b90979313475John McCall    /// theoretically deducible.
16922a984cad5ac3fdceeff2bd99daa7b90979313475John McCall    Dependent,
16932a984cad5ac3fdceeff2bd99daa7b90979313475John McCall
1694864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall    /// The type of an unresolved overload set.  A placeholder type.
1695864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall    /// Expressions with this type have one of the following basic
1696864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall    /// forms, with parentheses generally permitted:
1697864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall    ///   foo          # possibly qualified, not if an implicit access
1698864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall    ///   foo          # possibly qualified, not if an implicit access
1699864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall    ///   &foo         # possibly qualified, not if an implicit access
1700864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall    ///   x->foo       # only if might be a static member function
1701864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall    ///   &x->foo      # only if might be a static member function
1702864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall    ///   &Class::foo  # when a pointer-to-member; sub-expr also has this type
1703864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall    /// OverloadExpr::find can be used to analyze the expression.
17041de4d4e8cb2e9c88809fea8092bc6e835a5473d2John McCall    Overload,
17051de4d4e8cb2e9c88809fea8092bc6e835a5473d2John McCall
1706864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall    /// The type of a bound C++ non-static member function.
1707864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall    /// A placeholder type.  Expressions with this type have one of the
1708864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall    /// following basic forms:
1709864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall    ///   foo          # if an implicit access
1710864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall    ///   x->foo       # if only contains non-static members
1711864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall    BoundMember,
1712864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall
1713864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall    /// __builtin_any_type.  A placeholder type.  Useful for clients
1714864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall    /// like debuggers that don't know what type to give something.
1715864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall    /// Only a small number of operations are valid on expressions of
1716864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall    /// unknown type, most notably explicit casts.
1717864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall    UnknownAny
17185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
171971c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall
17205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
17211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  BuiltinType(Kind K)
172235495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    : Type(Builtin, QualType(), /*Dependent=*/(K == Dependent),
1723d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor           /*VariablyModified=*/false,
1724d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor           /*Unexpanded paramter pack=*/false) {
1725b870b88df784c2940efce448ebfaf54dece14666John McCall    BuiltinTypeBits.Kind = K;
172671c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  }
17271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1728b870b88df784c2940efce448ebfaf54dece14666John McCall  Kind getKind() const { return static_cast<Kind>(BuiltinTypeBits.Kind); }
1729e4f2142d00fa5fdb580c4e2413da91882d955381Chris Lattner  const char *getName(const LangOptions &LO) const;
17301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1731bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1732bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1733bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
1734680523a91dd3351389667c8de17121ba7ae82673John McCall  bool isInteger() const {
173571c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    return getKind() >= Bool && getKind() <= Int128;
1736680523a91dd3351389667c8de17121ba7ae82673John McCall  }
1737680523a91dd3351389667c8de17121ba7ae82673John McCall
1738680523a91dd3351389667c8de17121ba7ae82673John McCall  bool isSignedInteger() const {
173971c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    return getKind() >= Char_S && getKind() <= Int128;
1740680523a91dd3351389667c8de17121ba7ae82673John McCall  }
1741680523a91dd3351389667c8de17121ba7ae82673John McCall
1742680523a91dd3351389667c8de17121ba7ae82673John McCall  bool isUnsignedInteger() const {
174371c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    return getKind() >= Bool && getKind() <= UInt128;
1744680523a91dd3351389667c8de17121ba7ae82673John McCall  }
1745680523a91dd3351389667c8de17121ba7ae82673John McCall
1746680523a91dd3351389667c8de17121ba7ae82673John McCall  bool isFloatingPoint() const {
174771c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    return getKind() >= Float && getKind() <= LongDouble;
1748680523a91dd3351389667c8de17121ba7ae82673John McCall  }
1749680523a91dd3351389667c8de17121ba7ae82673John McCall
1750864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall  /// Determines whether this type is a placeholder type, i.e. a type
1751864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall  /// which cannot appear in arbitrary positions in a fully-formed
1752864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall  /// expression.
17532a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  bool isPlaceholderType() const {
1754864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall    return getKind() >= Overload;
17552a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  }
17562a984cad5ac3fdceeff2bd99daa7b90979313475John McCall
17575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T) { return T->getTypeClass() == Builtin; }
17585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const BuiltinType *) { return true; }
17595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
17605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
17615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ComplexType - C99 6.2.5p11 - Complex values.  This supports the C99 complex
17625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// types (_Complex float etc) as well as the GCC integer complex extensions.
17635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
17645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ComplexType : public Type, public llvm::FoldingSetNode {
17655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType ElementType;
17665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ComplexType(QualType Element, QualType CanonicalPtr) :
176735495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    Type(Complex, CanonicalPtr, Element->isDependentType(),
1768d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor         Element->isVariablyModifiedType(),
1769d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor         Element->containsUnexpandedParameterPack()),
1770898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    ElementType(Element) {
17715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
17725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
177360e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
17745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
17755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType getElementType() const { return ElementType; }
17761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1777bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1778bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1779bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
17805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void Profile(llvm::FoldingSetNodeID &ID) {
17815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Profile(ID, getElementType());
17825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
17835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static void Profile(llvm::FoldingSetNodeID &ID, QualType Element) {
17845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ID.AddPointer(Element.getAsOpaquePtr());
17855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
17861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
17875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T) { return T->getTypeClass() == Complex; }
17885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const ComplexType *) { return true; }
17895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
17905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1791075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara/// ParenType - Sugar for parentheses used when specifying types.
1792075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara///
1793075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnaraclass ParenType : public Type, public llvm::FoldingSetNode {
1794075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  QualType Inner;
1795075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
1796075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  ParenType(QualType InnerType, QualType CanonType) :
1797075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara    Type(Paren, CanonType, InnerType->isDependentType(),
1798d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor         InnerType->isVariablyModifiedType(),
1799d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor         InnerType->containsUnexpandedParameterPack()),
1800075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara    Inner(InnerType) {
1801075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  }
1802075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  friend class ASTContext;  // ASTContext creates these.
1803075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
1804075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnarapublic:
1805075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
1806075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  QualType getInnerType() const { return Inner; }
1807075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
1808075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  bool isSugared() const { return true; }
1809075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  QualType desugar() const { return getInnerType(); }
1810075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
1811075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  void Profile(llvm::FoldingSetNodeID &ID) {
1812075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara    Profile(ID, getInnerType());
1813075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  }
1814075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  static void Profile(llvm::FoldingSetNodeID &ID, QualType Inner) {
1815075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara    Inner.Profile(ID);
1816075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  }
1817075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
1818075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  static bool classof(const Type *T) { return T->getTypeClass() == Paren; }
1819075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  static bool classof(const ParenType *) { return true; }
1820075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara};
1821075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
182268694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar/// PointerType - C99 6.7.5.1 - Pointer Declarators.
1823bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner///
182468694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbarclass PointerType : public Type, public llvm::FoldingSetNode {
1825bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner  QualType PointeeType;
18265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
18275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  PointerType(QualType Pointee, QualType CanonicalPtr) :
182835495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    Type(Pointer, CanonicalPtr, Pointee->isDependentType(),
1829d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor         Pointee->isVariablyModifiedType(),
1830d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor         Pointee->containsUnexpandedParameterPack()),
183135495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    PointeeType(Pointee) {
18325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
18335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
183460e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
18355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
18361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
183768694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar  QualType getPointeeType() const { return PointeeType; }
183868694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar
1839bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1840bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1841bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
18425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void Profile(llvm::FoldingSetNodeID &ID) {
18435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Profile(ID, getPointeeType());
18445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
18455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) {
18465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ID.AddPointer(Pointee.getAsOpaquePtr());
18475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
18481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
18495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T) { return T->getTypeClass() == Pointer; }
18505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const PointerType *) { return true; }
18515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
18525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
18535618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff/// BlockPointerType - pointer to a block type.
18545618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff/// This type is to represent types syntactically represented as
18555618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff/// "void (^)(int)", etc. Pointee is required to always be a function type.
18565618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff///
18575618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroffclass BlockPointerType : public Type, public llvm::FoldingSetNode {
18585618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  QualType PointeeType;  // Block is some kind of pointer type
18595618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  BlockPointerType(QualType Pointee, QualType CanonicalCls) :
186035495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    Type(BlockPointer, CanonicalCls, Pointee->isDependentType(),
1861d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor         Pointee->isVariablyModifiedType(),
1862d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor         Pointee->containsUnexpandedParameterPack()),
1863898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    PointeeType(Pointee) {
18645618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  }
18655618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  friend class ASTContext;  // ASTContext creates these.
186660e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
18675618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroffpublic:
18681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
18695618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  // Get the pointee type. Pointee is required to always be a function type.
18705618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  QualType getPointeeType() const { return PointeeType; }
18715618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff
1872bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1873bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1874bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
18755618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  void Profile(llvm::FoldingSetNodeID &ID) {
18765618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff      Profile(ID, getPointeeType());
18775618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  }
18785618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) {
18795618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff      ID.AddPointer(Pointee.getAsOpaquePtr());
18805618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  }
18811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
18821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
18831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == BlockPointer;
18845618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  }
18855618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  static bool classof(const BlockPointerType *) { return true; }
18865618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff};
18875618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff
18887c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// ReferenceType - Base for LValueReferenceType and RValueReferenceType
18895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
189068694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbarclass ReferenceType : public Type, public llvm::FoldingSetNode {
189168694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar  QualType PointeeType;
189268694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar
18937c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlprotected:
189454e14c4db764c0636160d26c5bbf491637c83a76John McCall  ReferenceType(TypeClass tc, QualType Referencee, QualType CanonicalRef,
189554e14c4db764c0636160d26c5bbf491637c83a76John McCall                bool SpelledAsLValue) :
189635495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    Type(tc, CanonicalRef, Referencee->isDependentType(),
1897d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor         Referencee->isVariablyModifiedType(),
1898d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor         Referencee->containsUnexpandedParameterPack()),
1899d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    PointeeType(Referencee)
1900d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  {
1901b870b88df784c2940efce448ebfaf54dece14666John McCall    ReferenceTypeBits.SpelledAsLValue = SpelledAsLValue;
1902b870b88df784c2940efce448ebfaf54dece14666John McCall    ReferenceTypeBits.InnerRef = Referencee->isReferenceType();
19035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
190460e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
19055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
1906b870b88df784c2940efce448ebfaf54dece14666John McCall  bool isSpelledAsLValue() const { return ReferenceTypeBits.SpelledAsLValue; }
1907b870b88df784c2940efce448ebfaf54dece14666John McCall  bool isInnerRef() const { return ReferenceTypeBits.InnerRef; }
190873dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor
190954e14c4db764c0636160d26c5bbf491637c83a76John McCall  QualType getPointeeTypeAsWritten() const { return PointeeType; }
191054e14c4db764c0636160d26c5bbf491637c83a76John McCall  QualType getPointeeType() const {
191154e14c4db764c0636160d26c5bbf491637c83a76John McCall    // FIXME: this might strip inner qualifiers; okay?
191254e14c4db764c0636160d26c5bbf491637c83a76John McCall    const ReferenceType *T = this;
191371c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    while (T->isInnerRef())
1914d0370f59e79702ac908c81bf556519f91e9ca297John McCall      T = T->PointeeType->castAs<ReferenceType>();
191554e14c4db764c0636160d26c5bbf491637c83a76John McCall    return T->PointeeType;
191654e14c4db764c0636160d26c5bbf491637c83a76John McCall  }
191768694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar
19185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void Profile(llvm::FoldingSetNodeID &ID) {
191971c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    Profile(ID, PointeeType, isSpelledAsLValue());
19205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
192154e14c4db764c0636160d26c5bbf491637c83a76John McCall  static void Profile(llvm::FoldingSetNodeID &ID,
192254e14c4db764c0636160d26c5bbf491637c83a76John McCall                      QualType Referencee,
192354e14c4db764c0636160d26c5bbf491637c83a76John McCall                      bool SpelledAsLValue) {
19245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ID.AddPointer(Referencee.getAsOpaquePtr());
192554e14c4db764c0636160d26c5bbf491637c83a76John McCall    ID.AddBoolean(SpelledAsLValue);
19265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
19275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
19287c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  static bool classof(const Type *T) {
19297c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl    return T->getTypeClass() == LValueReference ||
19307c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl           T->getTypeClass() == RValueReference;
19317c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  }
19325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const ReferenceType *) { return true; }
19337c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl};
19347c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl
19357c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// LValueReferenceType - C++ [dcl.ref] - Lvalue reference
19367c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl///
19377c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlclass LValueReferenceType : public ReferenceType {
193854e14c4db764c0636160d26c5bbf491637c83a76John McCall  LValueReferenceType(QualType Referencee, QualType CanonicalRef,
193954e14c4db764c0636160d26c5bbf491637c83a76John McCall                      bool SpelledAsLValue) :
194054e14c4db764c0636160d26c5bbf491637c83a76John McCall    ReferenceType(LValueReference, Referencee, CanonicalRef, SpelledAsLValue)
194154e14c4db764c0636160d26c5bbf491637c83a76John McCall  {}
19427c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  friend class ASTContext; // ASTContext creates these
19437c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlpublic:
1944bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1945bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1946bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
19477c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  static bool classof(const Type *T) {
19487c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl    return T->getTypeClass() == LValueReference;
19497c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  }
19507c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  static bool classof(const LValueReferenceType *) { return true; }
19517c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl};
19527c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl
19537c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// RValueReferenceType - C++0x [dcl.ref] - Rvalue reference
19547c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl///
19557c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlclass RValueReferenceType : public ReferenceType {
19567c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  RValueReferenceType(QualType Referencee, QualType CanonicalRef) :
195754e14c4db764c0636160d26c5bbf491637c83a76John McCall    ReferenceType(RValueReference, Referencee, CanonicalRef, false) {
19587c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  }
19597c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  friend class ASTContext; // ASTContext creates these
19607c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlpublic:
1961bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1962bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1963bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
19647c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  static bool classof(const Type *T) {
19657c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl    return T->getTypeClass() == RValueReference;
19667c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  }
19677c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  static bool classof(const RValueReferenceType *) { return true; }
1968f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl};
1969f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl
1970f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl/// MemberPointerType - C++ 8.3.3 - Pointers to members
1971f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl///
1972f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlclass MemberPointerType : public Type, public llvm::FoldingSetNode {
1973f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  QualType PointeeType;
1974f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  /// The class of which the pointee is a member. Must ultimately be a
1975f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  /// RecordType, but could be a typedef or a template parameter too.
1976f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  const Type *Class;
1977f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl
1978f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  MemberPointerType(QualType Pointee, const Type *Cls, QualType CanonicalPtr) :
1979f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    Type(MemberPointer, CanonicalPtr,
198035495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor         Cls->isDependentType() || Pointee->isDependentType(),
1981d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor         Pointee->isVariablyModifiedType(),
1982d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor         (Cls->containsUnexpandedParameterPack() ||
1983d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor          Pointee->containsUnexpandedParameterPack())),
1984f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    PointeeType(Pointee), Class(Cls) {
1985f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  }
1986f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  friend class ASTContext; // ASTContext creates these.
198760e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
1988f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlpublic:
1989f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  QualType getPointeeType() const { return PointeeType; }
1990f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl
19910bab0cdab751248ca389a5592bcb70eac5d39260John McCall  /// Returns true if the member type (i.e. the pointee type) is a
19920bab0cdab751248ca389a5592bcb70eac5d39260John McCall  /// function type rather than a data-member type.
19930bab0cdab751248ca389a5592bcb70eac5d39260John McCall  bool isMemberFunctionPointer() const {
19940bab0cdab751248ca389a5592bcb70eac5d39260John McCall    return PointeeType->isFunctionProtoType();
19950bab0cdab751248ca389a5592bcb70eac5d39260John McCall  }
19960bab0cdab751248ca389a5592bcb70eac5d39260John McCall
19970bab0cdab751248ca389a5592bcb70eac5d39260John McCall  /// Returns true if the member type (i.e. the pointee type) is a
19980bab0cdab751248ca389a5592bcb70eac5d39260John McCall  /// data type rather than a function type.
19990bab0cdab751248ca389a5592bcb70eac5d39260John McCall  bool isMemberDataPointer() const {
20000bab0cdab751248ca389a5592bcb70eac5d39260John McCall    return !PointeeType->isFunctionProtoType();
20010bab0cdab751248ca389a5592bcb70eac5d39260John McCall  }
20020bab0cdab751248ca389a5592bcb70eac5d39260John McCall
2003f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  const Type *getClass() const { return Class; }
2004f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl
2005bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2006bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2007bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
2008f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  void Profile(llvm::FoldingSetNodeID &ID) {
2009f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    Profile(ID, getPointeeType(), getClass());
2010f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  }
2011f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee,
2012f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl                      const Type *Class) {
2013f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    ID.AddPointer(Pointee.getAsOpaquePtr());
2014f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    ID.AddPointer(Class);
2015f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  }
2016f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl
2017f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  static bool classof(const Type *T) {
2018f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    return T->getTypeClass() == MemberPointer;
2019f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  }
2020f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  static bool classof(const MemberPointerType *) { return true; }
20215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
20225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
20235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ArrayType - C99 6.7.5.2 - Array Declarators.
20245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
20252e7d352dbec06755105237afba183492d31d03cbTed Kremenekclass ArrayType : public Type, public llvm::FoldingSetNode {
20265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
20275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// ArraySizeModifier - Capture whether this is a normal array (e.g. int X[4])
2028898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// an array with a static size (e.g. int X[static 4]), or an array
2029898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// with a star size (e.g. int X[*]).
2030898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// 'static' is only allowed on function parameters.
20315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  enum ArraySizeModifier {
20325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Normal, Static, Star
20335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
20345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate:
2035fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  /// ElementType - The element type of the array.
2036fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  QualType ElementType;
20371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2038fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroffprotected:
2039898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  // C++ [temp.dep.type]p1:
2040898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  //   A type is dependent if it is...
2041898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  //     - an array type constructed from any dependent type or whose
2042898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  //       size is specified by a constant expression that is
2043898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  //       value-dependent,
2044c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff  ArrayType(TypeClass tc, QualType et, QualType can,
2045d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor            ArraySizeModifier sm, unsigned tq,
2046d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor            bool ContainsUnexpandedParameterPack)
204735495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    : Type(tc, can, et->isDependentType() || tc == DependentSizedArray,
2048d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor           (tc == VariableArray || et->isVariablyModifiedType()),
2049d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor           ContainsUnexpandedParameterPack),
205071c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall      ElementType(et) {
2051b870b88df784c2940efce448ebfaf54dece14666John McCall    ArrayTypeBits.IndexTypeQuals = tq;
2052b870b88df784c2940efce448ebfaf54dece14666John McCall    ArrayTypeBits.SizeModifier = sm;
205371c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  }
2054898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
2055fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  friend class ASTContext;  // ASTContext creates these.
205660e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
2057fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroffpublic:
2058fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  QualType getElementType() const { return ElementType; }
2059ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek  ArraySizeModifier getSizeModifier() const {
2060b870b88df784c2940efce448ebfaf54dece14666John McCall    return ArraySizeModifier(ArrayTypeBits.SizeModifier);
2061ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek  }
20620953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  Qualifiers getIndexTypeQualifiers() const {
206371c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    return Qualifiers::fromCVRMask(getIndexTypeCVRQualifiers());
206471c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  }
206571c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  unsigned getIndexTypeCVRQualifiers() const {
2066b870b88df784c2940efce448ebfaf54dece14666John McCall    return ArrayTypeBits.IndexTypeQuals;
20670953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
20681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2069fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  static bool classof(const Type *T) {
2070fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff    return T->getTypeClass() == ConstantArray ||
2071c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman           T->getTypeClass() == VariableArray ||
2072898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor           T->getTypeClass() == IncompleteArray ||
2073898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor           T->getTypeClass() == DependentSizedArray;
2074fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  }
2075fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  static bool classof(const ArrayType *) { return true; }
2076fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff};
2077fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff
20787e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// ConstantArrayType - This class represents the canonical version of
20797e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// C arrays with a specified constant size.  For example, the canonical
20807e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// type for 'int A[4 + 4*100]' is a ConstantArrayType where the element
20817e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// type is 'int' and the size is 404.
20822e7d352dbec06755105237afba183492d31d03cbTed Kremenekclass ConstantArrayType : public ArrayType {
2083fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  llvm::APInt Size; // Allows us to unique the type.
20841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
20850be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner  ConstantArrayType(QualType et, QualType can, const llvm::APInt &size,
2086c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff                    ArraySizeModifier sm, unsigned tq)
2087d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    : ArrayType(ConstantArray, et, can, sm, tq,
2088d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor                et->containsUnexpandedParameterPack()),
20897e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor      Size(size) {}
20907e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregorprotected:
20917e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  ConstantArrayType(TypeClass tc, QualType et, QualType can,
20927e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor                    const llvm::APInt &size, ArraySizeModifier sm, unsigned tq)
2093d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    : ArrayType(tc, et, can, sm, tq, et->containsUnexpandedParameterPack()),
2094d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor      Size(size) {}
2095fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  friend class ASTContext;  // ASTContext creates these.
2096fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroffpublic:
2097c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  const llvm::APInt &getSize() const { return Size; }
2098bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2099bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2100bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
21012767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor
21022767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor  /// \brief Determine the number of bits required to address a member of
21032767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor  // an array with the given element type and number of elements.
21042767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor  static unsigned getNumAddressingBits(ASTContext &Context,
21052767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor                                       QualType ElementType,
21062767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor                                       const llvm::APInt &NumElements);
21072767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor
21082767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor  /// \brief Determine the maximum number of active bits that an array's size
21092767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor  /// can require, which limits the maximum size of the array.
21102767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor  static unsigned getMaxSizeBits(ASTContext &Context);
21112767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor
2112fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  void Profile(llvm::FoldingSetNodeID &ID) {
21131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    Profile(ID, getElementType(), getSize(),
21140953e767ff7817f97b3ab20896b229891eeff45bJohn McCall            getSizeModifier(), getIndexTypeCVRQualifiers());
2115fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  }
2116fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  static void Profile(llvm::FoldingSetNodeID &ID, QualType ET,
21170be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner                      const llvm::APInt &ArraySize, ArraySizeModifier SizeMod,
21180be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner                      unsigned TypeQuals) {
2119fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff    ID.AddPointer(ET.getAsOpaquePtr());
2120fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff    ID.AddInteger(ArraySize.getZExtValue());
21210be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner    ID.AddInteger(SizeMod);
21220be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner    ID.AddInteger(TypeQuals);
2123fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  }
21247e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  static bool classof(const Type *T) {
212546a617a792bfab0d9b1e057371ea3b9540802226John McCall    return T->getTypeClass() == ConstantArray;
2126fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  }
2127fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  static bool classof(const ConstantArrayType *) { return true; }
2128fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff};
2129fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff
2130da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// IncompleteArrayType - This class represents C arrays with an unspecified
2131da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// size.  For example 'int A[]' has an IncompleteArrayType where the element
2132da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// type is 'int' and the size is unspecified.
2133c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedmanclass IncompleteArrayType : public ArrayType {
21347e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor
2135c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman  IncompleteArrayType(QualType et, QualType can,
21367e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor                      ArraySizeModifier sm, unsigned tq)
2137d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    : ArrayType(IncompleteArray, et, can, sm, tq,
2138d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor                et->containsUnexpandedParameterPack()) {}
2139c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman  friend class ASTContext;  // ASTContext creates these.
2140c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedmanpublic:
2141bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2142bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2143bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
21441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
21451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == IncompleteArray;
2146c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman  }
2147c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman  static bool classof(const IncompleteArrayType *) { return true; }
21481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2149c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman  friend class StmtIteratorBase;
21501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2151c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman  void Profile(llvm::FoldingSetNodeID &ID) {
21520953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Profile(ID, getElementType(), getSizeModifier(),
21530953e767ff7817f97b3ab20896b229891eeff45bJohn McCall            getIndexTypeCVRQualifiers());
2154c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman  }
21551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
21560be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner  static void Profile(llvm::FoldingSetNodeID &ID, QualType ET,
21570be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner                      ArraySizeModifier SizeMod, unsigned TypeQuals) {
2158c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman    ID.AddPointer(ET.getAsOpaquePtr());
21590be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner    ID.AddInteger(SizeMod);
21600be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner    ID.AddInteger(TypeQuals);
2161c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman  }
2162c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman};
2163c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman
2164da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// VariableArrayType - This class represents C arrays with a specified size
2165da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// which is not an integer-constant-expression.  For example, 'int s[x+foo()]'.
2166da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// Since the size expression is an arbitrary expression, we store it as such.
2167da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner///
2168da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// Note: VariableArrayType's aren't uniqued (since the expressions aren't) and
2169da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// should not be: two lexically equivalent variable array types could mean
2170da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// different things, for example, these variables do not have the same type
2171da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// dynamically:
2172da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner///
2173da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// void foo(int x) {
2174da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner///   int Y[x];
2175da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner///   ++x;
2176da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner///   int Z[x];
2177da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// }
2178da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner///
21792e7d352dbec06755105237afba183492d31d03cbTed Kremenekclass VariableArrayType : public ArrayType {
21801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// SizeExpr - An assignment expression. VLA's are only permitted within
21811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// a function block.
2182b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek  Stmt *SizeExpr;
21837e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  /// Brackets - The left and right array brackets.
21847e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  SourceRange Brackets;
21857e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor
2186c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff  VariableArrayType(QualType et, QualType can, Expr *e,
21877e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor                    ArraySizeModifier sm, unsigned tq,
21887e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor                    SourceRange brackets)
2189d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    : ArrayType(VariableArray, et, can, sm, tq,
2190d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor                et->containsUnexpandedParameterPack()),
21917e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor      SizeExpr((Stmt*) e), Brackets(brackets) {}
21925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
21934b05b1dee6cc65ae61d93dab7edff72710f24589Ted Kremenek
21945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
21951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Expr *getSizeExpr() const {
2196b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek    // We use C-style casts instead of cast<> here because we do not wish
2197b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek    // to have a dependency of Type.h on Stmt.h/Expr.h.
2198b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek    return (Expr*) SizeExpr;
2199b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek  }
22007e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  SourceRange getBracketsRange() const { return Brackets; }
22017e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  SourceLocation getLBracketLoc() const { return Brackets.getBegin(); }
22027e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  SourceLocation getRBracketLoc() const { return Brackets.getEnd(); }
22031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2204bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2205bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2206bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
22071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
22081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == VariableArray;
22095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
2210fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  static bool classof(const VariableArrayType *) { return true; }
22111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
221292866e2e90f6d93fb95e25a7ac4438e239d89ce6Ted Kremenek  friend class StmtIteratorBase;
22131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
22142bd24ba6d10f8c811c8e2a57c8397e07082ba497Ted Kremenek  void Profile(llvm::FoldingSetNodeID &ID) {
2215fc8f0e14ad142ed811e90fbd9a30e419e301c717Chris Lattner    assert(0 && "Cannot unique VariableArrayTypes.");
22162bd24ba6d10f8c811c8e2a57c8397e07082ba497Ted Kremenek  }
22175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
22185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2219898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// DependentSizedArrayType - This type represents an array type in
2220898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// C++ whose size is a value-dependent expression. For example:
2221cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor///
2222cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor/// \code
22231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// template<typename T, int Size>
2224898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// class array {
2225898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor///   T data[Size];
2226898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// };
2227cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor/// \endcode
2228cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor///
2229898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// For these types, we won't actually know what the array bound is
2230898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// until template instantiation occurs, at which point this will
2231898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// become either a ConstantArrayType or a VariableArrayType.
2232898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorclass DependentSizedArrayType : public ArrayType {
22334ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  const ASTContext &Context;
22341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2235cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor  /// \brief An assignment expression that will instantiate to the
2236898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// size of the array.
2237cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor  ///
2238cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor  /// The expression itself might be NULL, in which case the array
2239cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor  /// type will have its size deduced from an initializer.
2240898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  Stmt *SizeExpr;
2241cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor
22427e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  /// Brackets - The left and right array brackets.
22437e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  SourceRange Brackets;
22441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
22454ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  DependentSizedArrayType(const ASTContext &Context, QualType et, QualType can,
224604d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor                          Expr *e, ArraySizeModifier sm, unsigned tq,
2247d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor                          SourceRange brackets);
2248d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor
2249898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  friend class ASTContext;  // ASTContext creates these.
2250898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
2251898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorpublic:
22521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Expr *getSizeExpr() const {
2253898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    // We use C-style casts instead of cast<> here because we do not wish
2254898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    // to have a dependency of Type.h on Stmt.h/Expr.h.
2255898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    return (Expr*) SizeExpr;
2256898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  }
22577e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  SourceRange getBracketsRange() const { return Brackets; }
22587e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  SourceLocation getLBracketLoc() const { return Brackets.getBegin(); }
22597e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  SourceLocation getRBracketLoc() const { return Brackets.getEnd(); }
22601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2261bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2262bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2263bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
22641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
22651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == DependentSizedArray;
2266898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  }
2267898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  static bool classof(const DependentSizedArrayType *) { return true; }
22681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2269898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  friend class StmtIteratorBase;
22701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
22711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2272898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  void Profile(llvm::FoldingSetNodeID &ID) {
22731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    Profile(ID, Context, getElementType(),
22740953e767ff7817f97b3ab20896b229891eeff45bJohn McCall            getSizeModifier(), getIndexTypeCVRQualifiers(), getSizeExpr());
2275898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  }
22761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
22774ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
22781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                      QualType ET, ArraySizeModifier SizeMod,
227904d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor                      unsigned TypeQuals, Expr *E);
2280898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor};
2281898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
2282f6ddb737cb882ffbf0b75a9abd50b930cc2b9068Douglas Gregor/// DependentSizedExtVectorType - This type represent an extended vector type
22839cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// where either the type or size is dependent. For example:
22849cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// @code
22859cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// template<typename T, int Size>
22869cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// class vector {
22879cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor///   typedef T __attribute__((ext_vector_type(Size))) type;
22889cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// }
22899cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// @endcode
22902ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregorclass DependentSizedExtVectorType : public Type, public llvm::FoldingSetNode {
22914ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  const ASTContext &Context;
22929cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor  Expr *SizeExpr;
22939cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor  /// ElementType - The element type of the array.
22949cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor  QualType ElementType;
22959cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor  SourceLocation loc;
22961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
22974ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  DependentSizedExtVectorType(const ASTContext &Context, QualType ElementType,
2298d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor                              QualType can, Expr *SizeExpr, SourceLocation loc);
2299d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor
23009cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor  friend class ASTContext;
23019cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor
23029cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregorpublic:
23032ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor  Expr *getSizeExpr() const { return SizeExpr; }
23049cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor  QualType getElementType() const { return ElementType; }
23059cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor  SourceLocation getAttributeLoc() const { return loc; }
23069cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor
2307bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2308bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2309bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
23101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
23111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == DependentSizedExtVector;
23129cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor  }
23131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const DependentSizedExtVectorType *) { return true; }
23142ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor
23152ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor  void Profile(llvm::FoldingSetNodeID &ID) {
23162ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor    Profile(ID, Context, getElementType(), getSizeExpr());
23172ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor  }
23181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
23194ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
23202ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor                      QualType ElementType, Expr *SizeExpr);
23219cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor};
23221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
23239cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor
232473322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// VectorType - GCC generic vector type. This type is created using
23251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// __attribute__((vector_size(n)), where "n" specifies the vector size in
232682287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson/// bytes; or from an Altivec __vector or vector declaration.
232782287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson/// Since the constructor takes the number of vector elements, the
232873322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// client is responsible for converting the size into the number of elements.
23295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass VectorType : public Type, public llvm::FoldingSetNode {
2330788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattnerpublic:
2331e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson  enum VectorKind {
2332e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson    GenericVector,  // not a target-specific vector type
2333e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson    AltiVecVector,  // is AltiVec vector
2334e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson    AltiVecPixel,   // is AltiVec 'vector Pixel'
2335e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson    AltiVecBool,    // is AltiVec 'vector bool ...'
2336491328c90c00ecad6ad27fa0ab3cdf9195a4a820Bob Wilson    NeonVector,     // is ARM Neon vector
2337491328c90c00ecad6ad27fa0ab3cdf9195a4a820Bob Wilson    NeonPolyVector  // is ARM Neon polynomial vector
2338788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner  };
233973322924127c873c13101b705dd823f5539ffa5fSteve Naroffprotected:
23405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// ElementType - The element type of the vector.
23415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType ElementType;
23421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
234382287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson  VectorType(QualType vecType, unsigned nElements, QualType canonType,
2344d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor             VectorKind vecKind);
234535495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor
23461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  VectorType(TypeClass tc, QualType vecType, unsigned nElements,
2347d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor             QualType canonType, VectorKind vecKind);
2348d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor
23495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
235060e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
23515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
23521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
23535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType getElementType() const { return ElementType; }
2354b870b88df784c2940efce448ebfaf54dece14666John McCall  unsigned getNumElements() const { return VectorTypeBits.NumElements; }
23555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2356bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2357bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2358bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
2359e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson  VectorKind getVectorKind() const {
2360e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson    return VectorKind(VectorTypeBits.VecKind);
236171c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  }
2362788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner
23635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void Profile(llvm::FoldingSetNodeID &ID) {
236471c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    Profile(ID, getElementType(), getNumElements(),
2365e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson            getTypeClass(), getVectorKind());
23665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
23671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static void Profile(llvm::FoldingSetNodeID &ID, QualType ElementType,
236882287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson                      unsigned NumElements, TypeClass TypeClass,
2369e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson                      VectorKind VecKind) {
23705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ID.AddPointer(ElementType.getAsOpaquePtr());
23715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ID.AddInteger(NumElements);
237273322924127c873c13101b705dd823f5539ffa5fSteve Naroff    ID.AddInteger(TypeClass);
2373e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson    ID.AddInteger(VecKind);
237473322924127c873c13101b705dd823f5539ffa5fSteve Naroff  }
23750b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor
23761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
23771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == Vector || T->getTypeClass() == ExtVector;
23785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
23795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const VectorType *) { return true; }
23805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
23815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2382213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman/// ExtVectorType - Extended vector type. This type is created using
2383213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman/// __attribute__((ext_vector_type(n)), where "n" is the number of elements.
2384213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman/// Unlike vector_size, ext_vector_type is only allowed on typedef's. This
2385fcac0fff877a461bc5d5a57e6c6727a4c819d95aSteve Naroff/// class enables syntactic extensions, like Vector Components for accessing
2386fcac0fff877a461bc5d5a57e6c6727a4c819d95aSteve Naroff/// points, colors, and textures (modeled after OpenGL Shading Language).
2387213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begemanclass ExtVectorType : public VectorType {
2388213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman  ExtVectorType(QualType vecType, unsigned nElements, QualType canonType) :
2389e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson    VectorType(ExtVector, vecType, nElements, canonType, GenericVector) {}
239073322924127c873c13101b705dd823f5539ffa5fSteve Naroff  friend class ASTContext;  // ASTContext creates these.
239173322924127c873c13101b705dd823f5539ffa5fSteve Naroffpublic:
239288dca0464804b8b26ae605f89784c927e8493dddChris Lattner  static int getPointAccessorIdx(char c) {
239388dca0464804b8b26ae605f89784c927e8493dddChris Lattner    switch (c) {
239488dca0464804b8b26ae605f89784c927e8493dddChris Lattner    default: return -1;
239588dca0464804b8b26ae605f89784c927e8493dddChris Lattner    case 'x': return 0;
239688dca0464804b8b26ae605f89784c927e8493dddChris Lattner    case 'y': return 1;
239788dca0464804b8b26ae605f89784c927e8493dddChris Lattner    case 'z': return 2;
239888dca0464804b8b26ae605f89784c927e8493dddChris Lattner    case 'w': return 3;
239988dca0464804b8b26ae605f89784c927e8493dddChris Lattner    }
2400e1b31fedbc006e6e4071bbb4f74c6116b56cfa9fSteve Naroff  }
2401353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman  static int getNumericAccessorIdx(char c) {
240288dca0464804b8b26ae605f89784c927e8493dddChris Lattner    switch (c) {
2403353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      default: return -1;
2404353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '0': return 0;
2405353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '1': return 1;
2406353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '2': return 2;
2407353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '3': return 3;
2408353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '4': return 4;
2409353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '5': return 5;
2410353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '6': return 6;
2411353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '7': return 7;
2412353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '8': return 8;
2413353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '9': return 9;
2414131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman      case 'A':
2415353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case 'a': return 10;
2416131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman      case 'B':
2417353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case 'b': return 11;
2418131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman      case 'C':
2419353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case 'c': return 12;
2420131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman      case 'D':
2421353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case 'd': return 13;
2422131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman      case 'E':
2423353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case 'e': return 14;
2424131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman      case 'F':
2425353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case 'f': return 15;
242688dca0464804b8b26ae605f89784c927e8493dddChris Lattner    }
2427e1b31fedbc006e6e4071bbb4f74c6116b56cfa9fSteve Naroff  }
24281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2429b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner  static int getAccessorIdx(char c) {
2430b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner    if (int idx = getPointAccessorIdx(c)+1) return idx-1;
2431353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman    return getNumericAccessorIdx(c);
2432b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner  }
24331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
243488dca0464804b8b26ae605f89784c927e8493dddChris Lattner  bool isAccessorWithinNumElements(char c) const {
2435b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner    if (int idx = getAccessorIdx(c)+1)
243671c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall      return unsigned(idx-1) < getNumElements();
243788dca0464804b8b26ae605f89784c927e8493dddChris Lattner    return false;
2438e1b31fedbc006e6e4071bbb4f74c6116b56cfa9fSteve Naroff  }
2439bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2440bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2441bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
24421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
24431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == ExtVector;
244473322924127c873c13101b705dd823f5539ffa5fSteve Naroff  }
2445213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman  static bool classof(const ExtVectorType *) { return true; }
244673322924127c873c13101b705dd823f5539ffa5fSteve Naroff};
244773322924127c873c13101b705dd823f5539ffa5fSteve Naroff
24485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// FunctionType - C99 6.7.5.3 - Function Declarators.  This is the common base
244972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// class of FunctionNoProtoType and FunctionProtoType.
24505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
24515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass FunctionType : public Type {
24525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // The type returned by the function.
24535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType ResultType;
2454264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola
2455264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola public:
2456373920bd733b1d28fe7bf209945a62eb9248d948John McCall  /// ExtInfo - A class which abstracts out some details necessary for
2457373920bd733b1d28fe7bf209945a62eb9248d948John McCall  /// making a call.
2458373920bd733b1d28fe7bf209945a62eb9248d948John McCall  ///
2459373920bd733b1d28fe7bf209945a62eb9248d948John McCall  /// It is not actually used directly for storing this information in
2460373920bd733b1d28fe7bf209945a62eb9248d948John McCall  /// a FunctionType, although FunctionType does currently use the
2461373920bd733b1d28fe7bf209945a62eb9248d948John McCall  /// same bit-pattern.
2462373920bd733b1d28fe7bf209945a62eb9248d948John McCall  ///
2463075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  // If you add a field (say Foo), other than the obvious places (both,
2464075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  // constructors, compile failures), what you need to update is
2465075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  // * Operator==
2466425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola  // * getFoo
2467425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola  // * withFoo
2468425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola  // * functionType. Add Foo, getFoo.
2469425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola  // * ASTContext::getFooType
2470425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola  // * ASTContext::mergeFunctionTypes
2471425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola  // * FunctionNoProtoType::Profile
2472425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola  // * FunctionProtoType::Profile
2473425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola  // * TypePrinter::PrintFunctionProto
24743c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  // * AST read and write
2475425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola  // * Codegen
2476264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola  class ExtInfo {
24777e47e1e7e6a2b83d903c97129f27e92f584c3dc2Douglas Gregor    // Feel free to rearrange or add bits, but if you go over 8,
2478373920bd733b1d28fe7bf209945a62eb9248d948John McCall    // you'll need to adjust both the Bits field below and
2479373920bd733b1d28fe7bf209945a62eb9248d948John McCall    // Type::FunctionTypeBitfields.
2480373920bd733b1d28fe7bf209945a62eb9248d948John McCall
24817e47e1e7e6a2b83d903c97129f27e92f584c3dc2Douglas Gregor    //   |  CC  |noreturn|produces|regparm|
24827e47e1e7e6a2b83d903c97129f27e92f584c3dc2Douglas Gregor    //   |0 .. 2|   3    |    4   | 5 .. 7|
24837e47e1e7e6a2b83d903c97129f27e92f584c3dc2Douglas Gregor    //
24847e47e1e7e6a2b83d903c97129f27e92f584c3dc2Douglas Gregor    // regparm is either 0 (no regparm attribute) or the regparm value+1.
2485b870b88df784c2940efce448ebfaf54dece14666John McCall    enum { CallConvMask = 0x7 };
2486b870b88df784c2940efce448ebfaf54dece14666John McCall    enum { NoReturnMask = 0x8 };
2487f85e193739c953358c865005855253af4f68a497John McCall    enum { ProducesResultMask = 0x10 };
2488f85e193739c953358c865005855253af4f68a497John McCall    enum { RegParmMask = ~(CallConvMask | NoReturnMask | ProducesResultMask),
24897e47e1e7e6a2b83d903c97129f27e92f584c3dc2Douglas Gregor           RegParmOffset = 5 }; // Assumed to be the last field
2490b870b88df784c2940efce448ebfaf54dece14666John McCall
2491f85e193739c953358c865005855253af4f68a497John McCall    uint16_t Bits;
249271c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall
2493f85e193739c953358c865005855253af4f68a497John McCall    ExtInfo(unsigned Bits) : Bits(static_cast<uint16_t>(Bits)) {}
249471c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall
249571c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    friend class FunctionType;
249671c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall
2497264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola   public:
2498264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    // Constructor with no defaults. Use this when you know that you
24993c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl    // have all the elements (when reading an AST file for example).
2500f85e193739c953358c865005855253af4f68a497John McCall    ExtInfo(bool noReturn, bool hasRegParm, unsigned regParm, CallingConv cc,
2501f85e193739c953358c865005855253af4f68a497John McCall            bool producesResult) {
25027e47e1e7e6a2b83d903c97129f27e92f584c3dc2Douglas Gregor      assert((!hasRegParm || regParm < 7) && "Invalid regparm value");
2503b870b88df784c2940efce448ebfaf54dece14666John McCall      Bits = ((unsigned) cc) |
2504b870b88df784c2940efce448ebfaf54dece14666John McCall             (noReturn ? NoReturnMask : 0) |
2505f85e193739c953358c865005855253af4f68a497John McCall             (producesResult ? ProducesResultMask : 0) |
25067e47e1e7e6a2b83d903c97129f27e92f584c3dc2Douglas Gregor             (hasRegParm ? ((regParm + 1) << RegParmOffset) : 0);
250771c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    }
2508264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola
2509264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    // Constructor with all defaults. Use when for example creating a
2510264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    // function know to use defaults.
251171c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    ExtInfo() : Bits(0) {}
2512264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola
2513b870b88df784c2940efce448ebfaf54dece14666John McCall    bool getNoReturn() const { return Bits & NoReturnMask; }
2514f85e193739c953358c865005855253af4f68a497John McCall    bool getProducesResult() const { return Bits & ProducesResultMask; }
25157e47e1e7e6a2b83d903c97129f27e92f584c3dc2Douglas Gregor    bool getHasRegParm() const { return (Bits >> RegParmOffset) != 0; }
25167e47e1e7e6a2b83d903c97129f27e92f584c3dc2Douglas Gregor    unsigned getRegParm() const {
25177e47e1e7e6a2b83d903c97129f27e92f584c3dc2Douglas Gregor      unsigned RegParm = Bits >> RegParmOffset;
25187e47e1e7e6a2b83d903c97129f27e92f584c3dc2Douglas Gregor      if (RegParm > 0)
25197e47e1e7e6a2b83d903c97129f27e92f584c3dc2Douglas Gregor        --RegParm;
25207e47e1e7e6a2b83d903c97129f27e92f584c3dc2Douglas Gregor      return RegParm;
25217e47e1e7e6a2b83d903c97129f27e92f584c3dc2Douglas Gregor    }
2522b870b88df784c2940efce448ebfaf54dece14666John McCall    CallingConv getCC() const { return CallingConv(Bits & CallConvMask); }
2523264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola
252471c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    bool operator==(ExtInfo Other) const {
252571c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall      return Bits == Other.Bits;
2526264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    }
252771c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    bool operator!=(ExtInfo Other) const {
252871c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall      return Bits != Other.Bits;
2529264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    }
2530264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola
2531264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    // Note that we don't have setters. That is by design, use
2532264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    // the following with methods instead of mutating these objects.
2533264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola
2534264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    ExtInfo withNoReturn(bool noReturn) const {
253571c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall      if (noReturn)
253671c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall        return ExtInfo(Bits | NoReturnMask);
253771c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall      else
253871c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall        return ExtInfo(Bits & ~NoReturnMask);
2539425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola    }
2540425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola
2541f85e193739c953358c865005855253af4f68a497John McCall    ExtInfo withProducesResult(bool producesResult) const {
2542f85e193739c953358c865005855253af4f68a497John McCall      if (producesResult)
2543f85e193739c953358c865005855253af4f68a497John McCall        return ExtInfo(Bits | ProducesResultMask);
2544f85e193739c953358c865005855253af4f68a497John McCall      else
2545f85e193739c953358c865005855253af4f68a497John McCall        return ExtInfo(Bits & ~ProducesResultMask);
2546f85e193739c953358c865005855253af4f68a497John McCall    }
2547f85e193739c953358c865005855253af4f68a497John McCall
2548425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola    ExtInfo withRegParm(unsigned RegParm) const {
25497e47e1e7e6a2b83d903c97129f27e92f584c3dc2Douglas Gregor      assert(RegParm < 7 && "Invalid regparm value");
2550f85e193739c953358c865005855253af4f68a497John McCall      return ExtInfo((Bits & ~RegParmMask) |
25517e47e1e7e6a2b83d903c97129f27e92f584c3dc2Douglas Gregor                     ((RegParm + 1) << RegParmOffset));
2552264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    }
2553264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola
2554264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    ExtInfo withCallingConv(CallingConv cc) const {
2555b870b88df784c2940efce448ebfaf54dece14666John McCall      return ExtInfo((Bits & ~CallConvMask) | (unsigned) cc);
2556264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    }
2557264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola
2558e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall    void Profile(llvm::FoldingSetNodeID &ID) const {
255971c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall      ID.AddInteger(Bits);
256071c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    }
2561264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola  };
2562264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola
25635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprotected:
2564e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall  FunctionType(TypeClass tc, QualType res, bool variadic,
2565c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor               unsigned typeQuals, RefQualifierKind RefQualifier,
2566c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor               QualType Canonical, bool Dependent,
2567d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor               bool VariablyModified, bool ContainsUnexpandedParameterPack,
2568d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor               ExtInfo Info)
2569d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    : Type(tc, Canonical, Dependent, VariablyModified,
2570d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor           ContainsUnexpandedParameterPack),
2571d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor      ResultType(res) {
2572b870b88df784c2940efce448ebfaf54dece14666John McCall    FunctionTypeBits.ExtInfo = Info.Bits;
2573e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall    FunctionTypeBits.Variadic = variadic;
2574b870b88df784c2940efce448ebfaf54dece14666John McCall    FunctionTypeBits.TypeQuals = typeQuals;
2575c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor    FunctionTypeBits.RefQualifier = static_cast<unsigned>(RefQualifier);
257671c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  }
2577e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall  bool isVariadic() const { return FunctionTypeBits.Variadic; }
2578b870b88df784c2940efce448ebfaf54dece14666John McCall  unsigned getTypeQuals() const { return FunctionTypeBits.TypeQuals; }
2579c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor
2580c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor  RefQualifierKind getRefQualifier() const {
2581c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor    return static_cast<RefQualifierKind>(FunctionTypeBits.RefQualifier);
2582c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor  }
2583c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor
25845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
25851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
25865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType getResultType() const { return ResultType; }
2587a49218e17bcbb1acde0245773173e2c0c42f4f19Eli Friedman
2588a49218e17bcbb1acde0245773173e2c0c42f4f19Eli Friedman  bool getHasRegParm() const { return getExtInfo().getHasRegParm(); }
2589b870b88df784c2940efce448ebfaf54dece14666John McCall  unsigned getRegParmType() const { return getExtInfo().getRegParm(); }
2590b870b88df784c2940efce448ebfaf54dece14666John McCall  bool getNoReturnAttr() const { return getExtInfo().getNoReturn(); }
2591b870b88df784c2940efce448ebfaf54dece14666John McCall  CallingConv getCallConv() const { return getExtInfo().getCC(); }
2592b870b88df784c2940efce448ebfaf54dece14666John McCall  ExtInfo getExtInfo() const { return ExtInfo(FunctionTypeBits.ExtInfo); }
25935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
25945291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor  /// \brief Determine the type of an expression that calls a function of
25955291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor  /// this type.
25965291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor  QualType getCallResultType(ASTContext &Context) const {
25976398235d7890a81b785ea5af3b6e66d86bf184ccDouglas Gregor    return getResultType().getNonLValueExprType(Context);
25985291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor  }
25995291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor
260004a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall  static llvm::StringRef getNameForCallConv(CallingConv CC);
260104a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall
26025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T) {
26035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T->getTypeClass() == FunctionNoProto ||
26045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer           T->getTypeClass() == FunctionProto;
26055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
26065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const FunctionType *) { return true; }
26075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
26085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
260972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// FunctionNoProtoType - Represents a K&R-style 'int foo()' function, which has
26105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// no information available about its arguments.
261172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregorclass FunctionNoProtoType : public FunctionType, public llvm::FoldingSetNode {
261271c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  FunctionNoProtoType(QualType Result, QualType Canonical, ExtInfo Info)
2613c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor    : FunctionType(FunctionNoProto, Result, false, 0, RQ_None, Canonical,
261435495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor                   /*Dependent=*/false, Result->isVariablyModifiedType(),
2615d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor                   /*ContainsUnexpandedParameterPack=*/false, Info) {}
2616d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor
26175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
261860e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
26195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
26205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // No additional state past what FunctionType provides.
26211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2622bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2623bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2624bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
26255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void Profile(llvm::FoldingSetNodeID &ID) {
2626264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    Profile(ID, getResultType(), getExtInfo());
26275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
26282455636163fdd18581d7fdae816433f886d88213Mike Stump  static void Profile(llvm::FoldingSetNodeID &ID, QualType ResultType,
262971c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall                      ExtInfo Info) {
263071c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    Info.Profile(ID);
26315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ID.AddPointer(ResultType.getAsOpaquePtr());
26325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
26331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
26345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T) {
26355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T->getTypeClass() == FunctionNoProto;
26365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
263772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  static bool classof(const FunctionNoProtoType *) { return true; }
26385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
26395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
264072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// FunctionProtoType - Represents a prototype with argument type info, e.g.
26415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 'int foo(int)' or 'int foo(void)'.  'void' is represented as having no
2642465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl/// arguments, not as having a single void argument. Such a type can have an
2643465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl/// exception specification, but this specification is not part of the canonical
2644465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl/// type.
264572564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregorclass FunctionProtoType : public FunctionType, public llvm::FoldingSetNode {
2646e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCallpublic:
2647e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall  /// ExtProtoInfo - Extra information about a function prototype.
2648e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall  struct ExtProtoInfo {
2649e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall    ExtProtoInfo() :
26508b5b4099c61a136e9a1714c4d8a593febe942268Sebastian Redl      Variadic(false), ExceptionSpecType(EST_None), TypeQuals(0),
2651f85e193739c953358c865005855253af4f68a497John McCall      RefQualifier(RQ_None), NumExceptions(0), Exceptions(0), NoexceptExpr(0),
2652f85e193739c953358c865005855253af4f68a497John McCall      ConsumedArguments(0) {}
2653e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall
2654e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall    FunctionType::ExtInfo ExtInfo;
2655e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall    bool Variadic;
26568b5b4099c61a136e9a1714c4d8a593febe942268Sebastian Redl    ExceptionSpecificationType ExceptionSpecType;
2657e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall    unsigned char TypeQuals;
2658c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor    RefQualifierKind RefQualifier;
2659e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall    unsigned NumExceptions;
2660e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall    const QualType *Exceptions;
26618b5b4099c61a136e9a1714c4d8a593febe942268Sebastian Redl    Expr *NoexceptExpr;
2662f85e193739c953358c865005855253af4f68a497John McCall    const bool *ConsumedArguments;
2663e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall  };
2664e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall
2665e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCallprivate:
2666d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// \brief Determine whether there are any argument types that
2667d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// contain an unexpanded parameter pack.
2668d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  static bool containsAnyUnexpandedParameterPack(const QualType *ArgArray,
2669d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor                                                 unsigned numArgs) {
2670d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    for (unsigned Idx = 0; Idx < numArgs; ++Idx)
2671d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor      if (ArgArray[Idx]->containsUnexpandedParameterPack())
2672d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor        return true;
2673d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor
2674d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    return false;
2675d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  }
2676d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor
2677e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall  FunctionProtoType(QualType result, const QualType *args, unsigned numArgs,
26788026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redl                    QualType canonical, const ExtProtoInfo &epi);
2679465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
26805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// NumArgs - The number of arguments this function has, not counting '...'.
2681f85e193739c953358c865005855253af4f68a497John McCall  unsigned NumArgs : 19;
2682465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
2683465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  /// NumExceptions - The number of types in the exception spec, if any.
268460618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  unsigned NumExceptions : 9;
2685465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
268660618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  /// ExceptionSpecType - The type of exception specification this function has.
268760618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  unsigned ExceptionSpecType : 3;
2688465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
2689f85e193739c953358c865005855253af4f68a497John McCall  /// HasAnyConsumedArgs - Whether this function has any consumed arguments.
2690f85e193739c953358c865005855253af4f68a497John McCall  unsigned HasAnyConsumedArgs : 1;
2691f85e193739c953358c865005855253af4f68a497John McCall
2692942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner  /// ArgInfo - There is an variable size array after the class in memory that
2693942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner  /// holds the argument types.
2694465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
2695465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  /// Exceptions - There is another variable size array after ArgInfo that
2696465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  /// holds the exception types.
2697465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
269860618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  /// NoexceptExpr - Instead of Exceptions, there may be a single Expr* pointing
269960618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  /// to the expression in the noexcept() specifier.
270060618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl
2701f85e193739c953358c865005855253af4f68a497John McCall  /// ConsumedArgs - A variable size array, following Exceptions
2702f85e193739c953358c865005855253af4f68a497John McCall  /// and of length NumArgs, holding flags indicating which arguments
2703f85e193739c953358c865005855253af4f68a497John McCall  /// are consumed.  This only appears if HasAnyConsumedArgs is true.
2704f85e193739c953358c865005855253af4f68a497John McCall
27055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
27064b05b1dee6cc65ae61d93dab7edff72710f24589Ted Kremenek
2707f85e193739c953358c865005855253af4f68a497John McCall  const bool *getConsumedArgsBuffer() const {
2708f85e193739c953358c865005855253af4f68a497John McCall    assert(hasAnyConsumedArgs());
2709f85e193739c953358c865005855253af4f68a497John McCall
2710f85e193739c953358c865005855253af4f68a497John McCall    // Find the end of the exceptions.
2711f85e193739c953358c865005855253af4f68a497John McCall    Expr * const *eh_end = reinterpret_cast<Expr * const *>(arg_type_end());
2712f85e193739c953358c865005855253af4f68a497John McCall    if (getExceptionSpecType() != EST_ComputedNoexcept)
2713f85e193739c953358c865005855253af4f68a497John McCall      eh_end += NumExceptions;
2714f85e193739c953358c865005855253af4f68a497John McCall    else
2715f85e193739c953358c865005855253af4f68a497John McCall      eh_end += 1; // NoexceptExpr
2716f85e193739c953358c865005855253af4f68a497John McCall
2717f85e193739c953358c865005855253af4f68a497John McCall    return reinterpret_cast<const bool*>(eh_end);
2718f85e193739c953358c865005855253af4f68a497John McCall  }
2719f85e193739c953358c865005855253af4f68a497John McCall
27205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
27215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned getNumArgs() const { return NumArgs; }
27225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType getArgType(unsigned i) const {
27235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    assert(i < NumArgs && "Invalid argument number!");
2724942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner    return arg_type_begin()[i];
27255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
2726465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
2727e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall  ExtProtoInfo getExtProtoInfo() const {
2728e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall    ExtProtoInfo EPI;
2729e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall    EPI.ExtInfo = getExtInfo();
2730e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall    EPI.Variadic = isVariadic();
273160618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    EPI.ExceptionSpecType = getExceptionSpecType();
2732e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall    EPI.TypeQuals = static_cast<unsigned char>(getTypeQuals());
2733c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor    EPI.RefQualifier = getRefQualifier();
273460618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    if (EPI.ExceptionSpecType == EST_Dynamic) {
273560618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl      EPI.NumExceptions = NumExceptions;
273660618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl      EPI.Exceptions = exception_begin();
273760618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    } else if (EPI.ExceptionSpecType == EST_ComputedNoexcept) {
273860618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl      EPI.NoexceptExpr = getNoexceptExpr();
273960618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    }
2740f85e193739c953358c865005855253af4f68a497John McCall    if (hasAnyConsumedArgs())
2741f85e193739c953358c865005855253af4f68a497John McCall      EPI.ConsumedArguments = getConsumedArgsBuffer();
2742e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall    return EPI;
2743e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall  }
2744e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall
274560618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  /// \brief Get the kind of exception specification on this function.
274660618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  ExceptionSpecificationType getExceptionSpecType() const {
274760618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    return static_cast<ExceptionSpecificationType>(ExceptionSpecType);
274860618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  }
274960618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  /// \brief Return whether this function has any kind of exception spec.
275060618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  bool hasExceptionSpec() const {
275160618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    return getExceptionSpecType() != EST_None;
275260618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  }
275360618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  /// \brief Return whether this function has a dynamic (throw) exception spec.
275460618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  bool hasDynamicExceptionSpec() const {
275560618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    return isDynamicExceptionSpec(getExceptionSpecType());
275660618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  }
2757fc8f0e14ad142ed811e90fbd9a30e419e301c717Chris Lattner  /// \brief Return whether this function has a noexcept exception spec.
275860618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  bool hasNoexceptExceptionSpec() const {
275960618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    return isNoexceptExceptionSpec(getExceptionSpecType());
276060618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  }
276160618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  /// \brief Result type of getNoexceptSpec().
276260618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  enum NoexceptResult {
276360618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    NR_NoNoexcept,  ///< There is no noexcept specifier.
276460618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    NR_BadNoexcept, ///< The noexcept specifier has a bad expression.
276560618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    NR_Dependent,   ///< The noexcept specifier is dependent.
276660618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    NR_Throw,       ///< The noexcept specifier evaluates to false.
276760618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    NR_Nothrow      ///< The noexcept specifier evaluates to true.
276860618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  };
276960618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  /// \brief Get the meaning of the noexcept spec on this function, if any.
27708026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redl  NoexceptResult getNoexceptSpec(ASTContext &Ctx) const;
2771465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  unsigned getNumExceptions() const { return NumExceptions; }
2772465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  QualType getExceptionType(unsigned i) const {
2773465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl    assert(i < NumExceptions && "Invalid exception number!");
2774465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl    return exception_begin()[i];
2775465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  }
277660618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  Expr *getNoexceptExpr() const {
277760618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    if (getExceptionSpecType() != EST_ComputedNoexcept)
277860618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl      return 0;
277960618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    // NoexceptExpr sits where the arguments end.
278060618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    return *reinterpret_cast<Expr *const *>(arg_type_end());
2781d3fd6bad1249d3f34d71b73e2333fab0db51cce4Anders Carlsson  }
27828026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redl  bool isNothrow(ASTContext &Ctx) const {
278360618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    ExceptionSpecificationType EST = getExceptionSpecType();
27847a614d8380297fcd2bc23986241905d97222948cRichard Smith    assert(EST != EST_Delayed);
278560618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    if (EST == EST_DynamicNone || EST == EST_BasicNoexcept)
278660618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl      return true;
278760618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    if (EST != EST_ComputedNoexcept)
278860618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl      return false;
27898026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redl    return getNoexceptSpec(Ctx) == NR_Nothrow;
2790c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall  }
2791c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall
2792e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall  using FunctionType::isVariadic;
279360618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl
2794f5c65ffbd7374b6c8d9f1e361041578640cab320Douglas Gregor  /// \brief Determines whether this function prototype contains a
2795f5c65ffbd7374b6c8d9f1e361041578640cab320Douglas Gregor  /// parameter pack at the end.
2796f5c65ffbd7374b6c8d9f1e361041578640cab320Douglas Gregor  ///
2797f5c65ffbd7374b6c8d9f1e361041578640cab320Douglas Gregor  /// A function template whose last parameter is a parameter pack can be
2798f5c65ffbd7374b6c8d9f1e361041578640cab320Douglas Gregor  /// called with an arbitrary number of arguments, much like a variadic
2799f5c65ffbd7374b6c8d9f1e361041578640cab320Douglas Gregor  /// function. However,
2800f5c65ffbd7374b6c8d9f1e361041578640cab320Douglas Gregor  bool isTemplateVariadic() const;
2801f5c65ffbd7374b6c8d9f1e361041578640cab320Douglas Gregor
2802971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis  unsigned getTypeQuals() const { return FunctionType::getTypeQuals(); }
28031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2804c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor
2805c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor  /// \brief Retrieve the ref-qualifier associated with this function type.
2806c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor  RefQualifierKind getRefQualifier() const {
2807c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor    return FunctionType::getRefQualifier();
2808c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor  }
2809c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor
28105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  typedef const QualType *arg_type_iterator;
2811942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner  arg_type_iterator arg_type_begin() const {
2812942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner    return reinterpret_cast<const QualType *>(this+1);
2813942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner  }
2814942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner  arg_type_iterator arg_type_end() const { return arg_type_begin()+NumArgs; }
2815465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
2816465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  typedef const QualType *exception_iterator;
2817465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  exception_iterator exception_begin() const {
2818465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl    // exceptions begin where arguments end
2819465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl    return arg_type_end();
2820465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  }
2821465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  exception_iterator exception_end() const {
282260618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    if (getExceptionSpecType() != EST_Dynamic)
282360618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl      return exception_begin();
2824465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl    return exception_begin() + NumExceptions;
2825465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  }
2826465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
2827f85e193739c953358c865005855253af4f68a497John McCall  bool hasAnyConsumedArgs() const {
2828f85e193739c953358c865005855253af4f68a497John McCall    return HasAnyConsumedArgs;
2829f85e193739c953358c865005855253af4f68a497John McCall  }
2830f85e193739c953358c865005855253af4f68a497John McCall  bool isArgConsumed(unsigned I) const {
2831f85e193739c953358c865005855253af4f68a497John McCall    assert(I < getNumArgs() && "argument index out of range!");
2832f85e193739c953358c865005855253af4f68a497John McCall    if (hasAnyConsumedArgs())
2833f85e193739c953358c865005855253af4f68a497John McCall      return getConsumedArgsBuffer()[I];
2834f85e193739c953358c865005855253af4f68a497John McCall    return false;
2835f85e193739c953358c865005855253af4f68a497John McCall  }
2836f85e193739c953358c865005855253af4f68a497John McCall
2837bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2838bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2839bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
28405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T) {
28415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T->getTypeClass() == FunctionProto;
28425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
284372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  static bool classof(const FunctionProtoType *) { return true; }
2844465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
28458026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redl  void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Ctx);
28465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static void Profile(llvm::FoldingSetNodeID &ID, QualType Result,
2847942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner                      arg_type_iterator ArgTys, unsigned NumArgs,
28488026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redl                      const ExtProtoInfo &EPI, const ASTContext &Context);
28495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
28505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
28515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2852ed97649e9574b9d854fa4d6109c9333ae0993554John McCall/// \brief Represents the dependent type named by a dependently-scoped
2853ed97649e9574b9d854fa4d6109c9333ae0993554John McCall/// typename using declaration, e.g.
2854ed97649e9574b9d854fa4d6109c9333ae0993554John McCall///   using typename Base<T>::foo;
2855ed97649e9574b9d854fa4d6109c9333ae0993554John McCall/// Template instantiation turns these into the underlying type.
2856ed97649e9574b9d854fa4d6109c9333ae0993554John McCallclass UnresolvedUsingType : public Type {
2857ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  UnresolvedUsingTypenameDecl *Decl;
2858ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
285919c8576b7328f4dc2d07682f5da552875c1912efJohn McCall  UnresolvedUsingType(const UnresolvedUsingTypenameDecl *D)
2860d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    : Type(UnresolvedUsing, QualType(), true, false,
2861d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor           /*ContainsUnexpandedParameterPack=*/false),
286219c8576b7328f4dc2d07682f5da552875c1912efJohn McCall      Decl(const_cast<UnresolvedUsingTypenameDecl*>(D)) {}
2863ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  friend class ASTContext; // ASTContext creates these.
2864ed97649e9574b9d854fa4d6109c9333ae0993554John McCallpublic:
2865ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
2866ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  UnresolvedUsingTypenameDecl *getDecl() const { return Decl; }
2867ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
2868ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  bool isSugared() const { return false; }
2869ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  QualType desugar() const { return QualType(this, 0); }
2870ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
2871ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  static bool classof(const Type *T) {
2872ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    return T->getTypeClass() == UnresolvedUsing;
2873ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  }
2874ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  static bool classof(const UnresolvedUsingType *) { return true; }
2875ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
2876ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  void Profile(llvm::FoldingSetNodeID &ID) {
2877ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    return Profile(ID, Decl);
2878ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  }
2879ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  static void Profile(llvm::FoldingSetNodeID &ID,
2880ed97649e9574b9d854fa4d6109c9333ae0993554John McCall                      UnresolvedUsingTypenameDecl *D) {
2881ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    ID.AddPointer(D);
2882ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  }
2883ed97649e9574b9d854fa4d6109c9333ae0993554John McCall};
2884ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
2885ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
28865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass TypedefType : public Type {
2887162e1c1b487352434552147967c3dd296ebee2f7Richard Smith  TypedefNameDecl *Decl;
2888c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanianprotected:
2889162e1c1b487352434552147967c3dd296ebee2f7Richard Smith  TypedefType(TypeClass tc, const TypedefNameDecl *D, QualType can)
2890d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    : Type(tc, can, can->isDependentType(), can->isVariablyModifiedType(),
2891d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor           /*ContainsUnexpandedParameterPack=*/false),
2892162e1c1b487352434552147967c3dd296ebee2f7Richard Smith      Decl(const_cast<TypedefNameDecl*>(D)) {
28935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    assert(!isa<TypedefType>(can) && "Invalid canonical type");
28945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
28955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
28965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
28971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2898162e1c1b487352434552147967c3dd296ebee2f7Richard Smith  TypedefNameDecl *getDecl() const { return Decl; }
28991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2900bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return true; }
2901bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const;
2902bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
290372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  static bool classof(const Type *T) { return T->getTypeClass() == Typedef; }
29045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const TypedefType *) { return true; }
29055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
29065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
290772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// TypeOfExprType (GCC extension).
290872564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregorclass TypeOfExprType : public Type {
2909d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  Expr *TOExpr;
29101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2911b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregorprotected:
2912dd0257c77719a13d4acd513df40b04300cbfc871Douglas Gregor  TypeOfExprType(Expr *E, QualType can = QualType());
2913d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  friend class ASTContext;  // ASTContext creates these.
2914d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroffpublic:
2915d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  Expr *getUnderlyingExpr() const { return TOExpr; }
29161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2917bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// \brief Remove a single level of sugar.
2918bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const;
2919bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
2920bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// \brief Returns whether this type directly provides sugar.
2921bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return true; }
2922bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
292372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  static bool classof(const Type *T) { return T->getTypeClass() == TypeOfExpr; }
292472564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  static bool classof(const TypeOfExprType *) { return true; }
2925d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff};
2926d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff
2927c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// \brief Internal representation of canonical, dependent
29281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// typeof(expr) types.
2929c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor///
2930c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// This class is used internally by the ASTContext to manage
2931c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// canonical, dependent types, only. Clients will only see instances
2932c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// of this class via TypeOfExprType nodes.
29331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpclass DependentTypeOfExprType
2934b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor  : public TypeOfExprType, public llvm::FoldingSetNode {
29354ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  const ASTContext &Context;
29361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2937b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregorpublic:
29384ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  DependentTypeOfExprType(const ASTContext &Context, Expr *E)
2939b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor    : TypeOfExprType(E), Context(Context) { }
29401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2941bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2942bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2943bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
2944b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor  void Profile(llvm::FoldingSetNodeID &ID) {
2945b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor    Profile(ID, Context, getUnderlyingExpr());
2946b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor  }
29471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
29484ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
2949b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor                      Expr *E);
2950b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor};
29511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2952d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff/// TypeOfType (GCC extension).
2953d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroffclass TypeOfType : public Type {
2954d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  QualType TOType;
29551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  TypeOfType(QualType T, QualType can)
2956d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    : Type(TypeOf, can, T->isDependentType(), T->isVariablyModifiedType(),
2957d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor           T->containsUnexpandedParameterPack()),
295835495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor      TOType(T) {
2959d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff    assert(!isa<TypedefType>(can) && "Invalid canonical type");
2960d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  }
2961d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  friend class ASTContext;  // ASTContext creates these.
2962d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroffpublic:
2963d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  QualType getUnderlyingType() const { return TOType; }
29641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2965bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// \brief Remove a single level of sugar.
2966bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return getUnderlyingType(); }
2967bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
2968bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// \brief Returns whether this type directly provides sugar.
2969bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return true; }
2970bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
297172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  static bool classof(const Type *T) { return T->getTypeClass() == TypeOf; }
2972d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  static bool classof(const TypeOfType *) { return true; }
2973d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff};
29745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2975395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson/// DecltypeType (C++0x)
2976395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlssonclass DecltypeType : public Type {
2977395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson  Expr *E;
29781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2979563a03b1338d31c2462def43253a722bc885d384Anders Carlsson  // FIXME: We could get rid of UnderlyingType if we wanted to: We would have to
2980563a03b1338d31c2462def43253a722bc885d384Anders Carlsson  // Move getDesugaredType to ASTContext so that it can call getDecltypeForExpr
2981563a03b1338d31c2462def43253a722bc885d384Anders Carlsson  // from it.
2982563a03b1338d31c2462def43253a722bc885d384Anders Carlsson  QualType UnderlyingType;
29831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
29849d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregorprotected:
2985563a03b1338d31c2462def43253a722bc885d384Anders Carlsson  DecltypeType(Expr *E, QualType underlyingType, QualType can = QualType());
2986395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson  friend class ASTContext;  // ASTContext creates these.
2987395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlssonpublic:
2988395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson  Expr *getUnderlyingExpr() const { return E; }
2989563a03b1338d31c2462def43253a722bc885d384Anders Carlsson  QualType getUnderlyingType() const { return UnderlyingType; }
2990563a03b1338d31c2462def43253a722bc885d384Anders Carlsson
2991bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// \brief Remove a single level of sugar.
2992bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return getUnderlyingType(); }
2993bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
2994bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// \brief Returns whether this type directly provides sugar.
2995bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return !isDependentType(); }
2996bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
2997395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson  static bool classof(const Type *T) { return T->getTypeClass() == Decltype; }
2998395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson  static bool classof(const DecltypeType *) { return true; }
2999395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson};
30001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3001c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// \brief Internal representation of canonical, dependent
3002c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// decltype(expr) types.
3003c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor///
3004c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// This class is used internally by the ASTContext to manage
3005c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// canonical, dependent types, only. Clients will only see instances
3006c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// of this class via DecltypeType nodes.
30079d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregorclass DependentDecltypeType : public DecltypeType, public llvm::FoldingSetNode {
30084ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  const ASTContext &Context;
30091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
30109d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregorpublic:
30114ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  DependentDecltypeType(const ASTContext &Context, Expr *E);
30121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3013bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
3014bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
3015bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
30169d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor  void Profile(llvm::FoldingSetNodeID &ID) {
30179d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor    Profile(ID, Context, getUnderlyingExpr());
30189d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor  }
30191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
30204ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
30211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                      Expr *E);
30229d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor};
30231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3024ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt/// \brief A unary type transform, which is a type constructed from another
3025ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Huntclass UnaryTransformType : public Type {
3026ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Huntpublic:
3027ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  enum UTTKind {
3028ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt    EnumUnderlyingType
3029ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  };
3030ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt
3031ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Huntprivate:
3032ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  /// The untransformed type.
3033ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  QualType BaseType;
3034ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  /// The transformed type if not dependent, otherwise the same as BaseType.
3035ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  QualType UnderlyingType;
3036ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt
3037ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  UTTKind UKind;
3038ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Huntprotected:
3039ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  UnaryTransformType(QualType BaseTy, QualType UnderlyingTy, UTTKind UKind,
3040ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt                     QualType CanonicalTy);
3041ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  friend class ASTContext;
3042ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Huntpublic:
3043ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  bool isSugared() const { return !isDependentType(); }
3044ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  QualType desugar() const { return UnderlyingType; }
3045ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt
3046ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  QualType getUnderlyingType() const { return UnderlyingType; }
3047ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  QualType getBaseType() const { return BaseType; }
3048ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt
3049ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  UTTKind getUTTKind() const { return UKind; }
3050ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt
3051ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  static bool classof(const Type *T) {
3052ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt    return T->getTypeClass() == UnaryTransform;
3053ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  }
3054ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  static bool classof(const UnaryTransformType *) { return true; }
3055ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt};
3056ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt
30575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass TagType : public Type {
3058ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl  /// Stores the TagDecl associated with this type. The decl may point to any
3059ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl  /// TagDecl that declares the entity.
3060ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl  TagDecl * decl;
30612ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor
30622ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregorprotected:
306319c8576b7328f4dc2d07682f5da552875c1912efJohn McCall  TagType(TypeClass TC, const TagDecl *D, QualType can);
30642ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor
30651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic:
3066ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl  TagDecl *getDecl() const;
30671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
30680b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor  /// @brief Determines whether this type is in the process of being
30691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// defined.
3070ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl  bool isBeingDefined() const;
30710b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor
30721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
307372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor    return T->getTypeClass() >= TagFirst && T->getTypeClass() <= TagLast;
307472564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  }
30755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const TagType *) { return true; }
307672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  static bool classof(const RecordType *) { return true; }
307772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  static bool classof(const EnumType *) { return true; }
30785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
30795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
30805edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner/// RecordType - This is a helper class that allows the use of isa/cast/dyncast
30815edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner/// to detect TagType objects of structs/unions/classes.
30825edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattnerclass RecordType : public TagType {
308349aa7ff1245abd03e6e998e01302df31e4c6f8f6Argyrios Kyrtzidisprotected:
308419c8576b7328f4dc2d07682f5da552875c1912efJohn McCall  explicit RecordType(const RecordDecl *D)
308519c8576b7328f4dc2d07682f5da552875c1912efJohn McCall    : TagType(Record, reinterpret_cast<const TagDecl*>(D), QualType()) { }
308672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  explicit RecordType(TypeClass TC, RecordDecl *D)
308719c8576b7328f4dc2d07682f5da552875c1912efJohn McCall    : TagType(TC, reinterpret_cast<const TagDecl*>(D), QualType()) { }
30882ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor  friend class ASTContext;   // ASTContext creates these.
30895edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattnerpublic:
30901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
30915edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner  RecordDecl *getDecl() const {
30925edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner    return reinterpret_cast<RecordDecl*>(TagType::getDecl());
30935edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner  }
30941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
30951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  // FIXME: This predicate is a helper to QualType/Type. It needs to
30965edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner  // recursively check all fields for const-ness. If any field is declared
30971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  // const, it needs to return false.
30985edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner  bool hasConstFields() const { return false; }
30995edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner
3100bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
3101bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
3102bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
31032daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner  static bool classof(const TagType *T);
31042daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner  static bool classof(const Type *T) {
31052daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner    return isa<TagType>(T) && classof(cast<TagType>(T));
31062daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner  }
31075edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner  static bool classof(const RecordType *) { return true; }
31085edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner};
31095edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner
31105edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner/// EnumType - This is a helper class that allows the use of isa/cast/dyncast
31115edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner/// to detect TagType objects of enums.
31125edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattnerclass EnumType : public TagType {
311319c8576b7328f4dc2d07682f5da552875c1912efJohn McCall  explicit EnumType(const EnumDecl *D)
311419c8576b7328f4dc2d07682f5da552875c1912efJohn McCall    : TagType(Enum, reinterpret_cast<const TagDecl*>(D), QualType()) { }
31152ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor  friend class ASTContext;   // ASTContext creates these.
31165edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattnerpublic:
31171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
31185edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner  EnumDecl *getDecl() const {
31195edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner    return reinterpret_cast<EnumDecl*>(TagType::getDecl());
31205edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner  }
31211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3122bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
3123bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
3124bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
31252daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner  static bool classof(const TagType *T);
31262daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner  static bool classof(const Type *T) {
31272daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner    return isa<TagType>(T) && classof(cast<TagType>(T));
31282daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner  }
31295edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner  static bool classof(const EnumType *) { return true; }
31305edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner};
31315edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner
31329d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall/// AttributedType - An attributed type is a type to which a type
31339d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall/// attribute has been applied.  The "modified type" is the
31349d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall/// fully-sugared type to which the attributed type was applied;
31359d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall/// generally it is not canonically equivalent to the attributed type.
31369d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall/// The "equivalent type" is the minimally-desugared type which the
31379d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall/// type is canonically equivalent to.
31389d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall///
31399d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall/// For example, in the following attributed type:
31409d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall///     int32_t __attribute__((vector_size(16)))
31419d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall///   - the modified type is the TypedefType for int32_t
31429d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall///   - the equivalent type is VectorType(16, int32_t)
31439d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall///   - the canonical type is VectorType(16, int)
31449d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCallclass AttributedType : public Type, public llvm::FoldingSetNode {
31459d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCallpublic:
31469d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  // It is really silly to have yet another attribute-kind enum, but
31479d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  // clang::attr::Kind doesn't currently cover the pure type attrs.
31489d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  enum Kind {
31499d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    // Expression operand.
3150170464b7c0a2c0c86f2821f14a46f0d540cb5e94Francois Pichet    attr_address_space,
3151170464b7c0a2c0c86f2821f14a46f0d540cb5e94Francois Pichet    attr_regparm,
3152170464b7c0a2c0c86f2821f14a46f0d540cb5e94Francois Pichet    attr_vector_size,
3153170464b7c0a2c0c86f2821f14a46f0d540cb5e94Francois Pichet    attr_neon_vector_type,
3154170464b7c0a2c0c86f2821f14a46f0d540cb5e94Francois Pichet    attr_neon_polyvector_type,
31559d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
3156170464b7c0a2c0c86f2821f14a46f0d540cb5e94Francois Pichet    FirstExprOperandKind = attr_address_space,
3157170464b7c0a2c0c86f2821f14a46f0d540cb5e94Francois Pichet    LastExprOperandKind = attr_neon_polyvector_type,
31589d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
31599d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    // Enumerated operand (string or keyword).
3160170464b7c0a2c0c86f2821f14a46f0d540cb5e94Francois Pichet    attr_objc_gc,
3161b8b0313e84700b5c6d597b3be4de41c97b7550f1Argyrios Kyrtzidis    attr_objc_ownership,
3162414d8967e1d760ea1e19a4aca96b13777a8cf8c5Anton Korobeynikov    attr_pcs,
31639d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
3164170464b7c0a2c0c86f2821f14a46f0d540cb5e94Francois Pichet    FirstEnumOperandKind = attr_objc_gc,
3165414d8967e1d760ea1e19a4aca96b13777a8cf8c5Anton Korobeynikov    LastEnumOperandKind = attr_pcs,
31669d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
31679d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    // No operand.
31683cd47e7883dbfce73189b583850cea81e1d1d261Francois Pichet    attr_noreturn,
31693cd47e7883dbfce73189b583850cea81e1d1d261Francois Pichet    attr_cdecl,
31703cd47e7883dbfce73189b583850cea81e1d1d261Francois Pichet    attr_fastcall,
31713cd47e7883dbfce73189b583850cea81e1d1d261Francois Pichet    attr_stdcall,
31723cd47e7883dbfce73189b583850cea81e1d1d261Francois Pichet    attr_thiscall,
31733cd47e7883dbfce73189b583850cea81e1d1d261Francois Pichet    attr_pascal
31749d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  };
31759d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
31769d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCallprivate:
31779d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  QualType ModifiedType;
31789d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  QualType EquivalentType;
31799d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
31809d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  friend class ASTContext; // creates these
31819d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
31829d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  AttributedType(QualType canon, Kind attrKind,
31839d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall                 QualType modified, QualType equivalent)
31849d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    : Type(Attributed, canon, canon->isDependentType(),
31859d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall           canon->isVariablyModifiedType(),
31869d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall           canon->containsUnexpandedParameterPack()),
31879d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall      ModifiedType(modified), EquivalentType(equivalent) {
31889d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    AttributedTypeBits.AttrKind = attrKind;
31899d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  }
31909d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
31919d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCallpublic:
31929d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  Kind getAttrKind() const {
31939d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    return static_cast<Kind>(AttributedTypeBits.AttrKind);
31949d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  }
31959d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
31969d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  QualType getModifiedType() const { return ModifiedType; }
31979d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  QualType getEquivalentType() const { return EquivalentType; }
31989d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
31999d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  bool isSugared() const { return true; }
32009d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  QualType desugar() const { return getEquivalentType(); }
32019d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
32029d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  void Profile(llvm::FoldingSetNodeID &ID) {
32039d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    Profile(ID, getAttrKind(), ModifiedType, EquivalentType);
32049d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  }
32059d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
32069d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  static void Profile(llvm::FoldingSetNodeID &ID, Kind attrKind,
32079d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall                      QualType modified, QualType equivalent) {
32089d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    ID.AddInteger(attrKind);
32099d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    ID.AddPointer(modified.getAsOpaquePtr());
32109d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    ID.AddPointer(equivalent.getAsOpaquePtr());
32119d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  }
32129d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
32139d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  static bool classof(const Type *T) {
32149d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    return T->getTypeClass() == Attributed;
32159d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  }
32169d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  static bool classof(const AttributedType *T) { return true; }
32179d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall};
32189d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
3219fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregorclass TemplateTypeParmType : public Type, public llvm::FoldingSetNode {
32204fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth  // Helper data collector for canonical types.
32214fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth  struct CanonicalTTPTInfo {
32224fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth    unsigned Depth : 15;
32234fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth    unsigned ParameterPack : 1;
32244fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth    unsigned Index : 16;
32254fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth  };
32264fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth
32274fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth  union {
32284fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth    // Info for the canonical type.
32294fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth    CanonicalTTPTInfo CanTTPTInfo;
32304fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth    // Info for the non-canonical type.
32314fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth    TemplateTypeParmDecl *TTPDecl;
32324fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth  };
323372c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor
32344fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth  /// Build a non-canonical type.
32354fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth  TemplateTypeParmType(TemplateTypeParmDecl *TTPDecl, QualType Canon)
323635495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    : Type(TemplateTypeParm, Canon, /*Dependent=*/true,
32374fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth           /*VariablyModified=*/false,
32385d65e34b08b3e57a4da834195757d0d15baaffd0Chandler Carruth           Canon->containsUnexpandedParameterPack()),
32394fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth      TTPDecl(TTPDecl) { }
324072c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor
32414fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth  /// Build the canonical type.
32421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  TemplateTypeParmType(unsigned D, unsigned I, bool PP)
324335495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    : Type(TemplateTypeParm, QualType(this, 0), /*Dependent=*/true,
32444fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth           /*VariablyModified=*/false, PP) {
32454fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth    CanTTPTInfo.Depth = D;
32464fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth    CanTTPTInfo.Index = I;
32474fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth    CanTTPTInfo.ParameterPack = PP;
32484fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth  }
324972c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor
3250fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor  friend class ASTContext;  // ASTContext creates these
325172c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor
32524fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth  const CanonicalTTPTInfo& getCanTTPTInfo() const {
32534fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth    QualType Can = getCanonicalTypeInternal();
32545d65e34b08b3e57a4da834195757d0d15baaffd0Chandler Carruth    return Can->castAs<TemplateTypeParmType>()->CanTTPTInfo;
32554fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth  }
32564fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth
3257fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregorpublic:
32584fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth  unsigned getDepth() const { return getCanTTPTInfo().Depth; }
32594fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth  unsigned getIndex() const { return getCanTTPTInfo().Index; }
32604fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth  bool isParameterPack() const { return getCanTTPTInfo().ParameterPack; }
32614fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth
32624fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth  TemplateTypeParmDecl *getDecl() const {
32634fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth    return isCanonicalUnqualified() ? 0 : TTPDecl;
32644fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth  }
32654fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth
3266b7efff4bae117604f442bb6859c844f90b15f3ffChandler Carruth  IdentifierInfo *getIdentifier() const;
32671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3268bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
3269bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
3270bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
3271fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor  void Profile(llvm::FoldingSetNodeID &ID) {
32724fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth    Profile(ID, getDepth(), getIndex(), isParameterPack(), getDecl());
3273fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor  }
3274fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor
32751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static void Profile(llvm::FoldingSetNodeID &ID, unsigned Depth,
32761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                      unsigned Index, bool ParameterPack,
32774fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth                      TemplateTypeParmDecl *TTPDecl) {
3278fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor    ID.AddInteger(Depth);
3279fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor    ID.AddInteger(Index);
328076e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson    ID.AddBoolean(ParameterPack);
32814fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth    ID.AddPointer(TTPDecl);
3282fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor  }
3283fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor
32841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
32851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == TemplateTypeParm;
328672c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor  }
328772c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor  static bool classof(const TemplateTypeParmType *T) { return true; }
328872c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor};
3289fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor
329049a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// \brief Represents the result of substituting a type for a template
329149a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// type parameter.
329249a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall///
329349a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// Within an instantiated template, all template type parameters have
329449a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// been replaced with these.  They are used solely to record that a
329549a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// type was originally written as a template type parameter;
329649a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// therefore they are never canonical.
329749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCallclass SubstTemplateTypeParmType : public Type, public llvm::FoldingSetNode {
329849a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  // The original type parameter.
329949a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  const TemplateTypeParmType *Replaced;
330049a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall
330149a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  SubstTemplateTypeParmType(const TemplateTypeParmType *Param, QualType Canon)
330235495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    : Type(SubstTemplateTypeParm, Canon, Canon->isDependentType(),
3303d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor           Canon->isVariablyModifiedType(),
3304d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor           Canon->containsUnexpandedParameterPack()),
330549a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall      Replaced(Param) { }
330649a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall
330749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  friend class ASTContext;
330849a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall
330949a832bd499d6f61c23655f1fac99f0dd229756eJohn McCallpublic:
331049a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  /// Gets the template parameter that was substituted for.
331149a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  const TemplateTypeParmType *getReplacedParameter() const {
331249a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall    return Replaced;
331349a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  }
331449a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall
331549a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  /// Gets the type that was substituted for the template
331649a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  /// parameter.
331749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  QualType getReplacementType() const {
331849a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall    return getCanonicalTypeInternal();
331949a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  }
332049a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall
332149a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  bool isSugared() const { return true; }
332249a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  QualType desugar() const { return getReplacementType(); }
332349a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall
332449a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  void Profile(llvm::FoldingSetNodeID &ID) {
332549a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall    Profile(ID, getReplacedParameter(), getReplacementType());
332649a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  }
332749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  static void Profile(llvm::FoldingSetNodeID &ID,
332849a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall                      const TemplateTypeParmType *Replaced,
332949a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall                      QualType Replacement) {
333049a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall    ID.AddPointer(Replaced);
333149a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall    ID.AddPointer(Replacement.getAsOpaquePtr());
333249a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  }
333349a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall
333449a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  static bool classof(const Type *T) {
333549a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall    return T->getTypeClass() == SubstTemplateTypeParm;
333649a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  }
333749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  static bool classof(const SubstTemplateTypeParmType *T) { return true; }
333849a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall};
333949a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall
3340c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// \brief Represents the result of substituting a set of types for a template
3341c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// type parameter pack.
3342c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor///
3343c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// When a pack expansion in the source code contains multiple parameter packs
3344c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// and those parameter packs correspond to different levels of template
3345c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// parameter lists, this type node is used to represent a template type
3346c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// parameter pack from an outer level, which has already had its argument pack
3347c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// substituted but that still lives within a pack expansion that itself
3348c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// could not be instantiated. When actually performing a substitution into
3349c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// that pack expansion (e.g., when all template parameters have corresponding
3350c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// arguments), this type will be replaced with the \c SubstTemplateTypeParmType
3351c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// at the current pack substitution index.
3352c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregorclass SubstTemplateTypeParmPackType : public Type, public llvm::FoldingSetNode {
3353c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  /// \brief The original type parameter.
3354c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  const TemplateTypeParmType *Replaced;
3355c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor
3356c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  /// \brief A pointer to the set of template arguments that this
3357c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  /// parameter pack is instantiated with.
3358c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  const TemplateArgument *Arguments;
3359c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor
3360c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  /// \brief The number of template arguments in \c Arguments.
3361c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  unsigned NumArguments;
3362c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor
3363c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  SubstTemplateTypeParmPackType(const TemplateTypeParmType *Param,
3364c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor                                QualType Canon,
3365c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor                                const TemplateArgument &ArgPack);
3366c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor
3367c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  friend class ASTContext;
3368c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor
3369c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregorpublic:
3370b7efff4bae117604f442bb6859c844f90b15f3ffChandler Carruth  IdentifierInfo *getIdentifier() const { return Replaced->getIdentifier(); }
3371c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor
3372c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  /// Gets the template parameter that was substituted for.
3373c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  const TemplateTypeParmType *getReplacedParameter() const {
3374c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor    return Replaced;
3375c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  }
3376c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor
3377c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  bool isSugared() const { return false; }
3378c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  QualType desugar() const { return QualType(this, 0); }
3379c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor
3380c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  TemplateArgument getArgumentPack() const;
3381c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor
3382c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  void Profile(llvm::FoldingSetNodeID &ID);
3383c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  static void Profile(llvm::FoldingSetNodeID &ID,
3384c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor                      const TemplateTypeParmType *Replaced,
3385c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor                      const TemplateArgument &ArgPack);
3386c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor
3387c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  static bool classof(const Type *T) {
3388c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor    return T->getTypeClass() == SubstTemplateTypeParmPack;
3389c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  }
3390c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  static bool classof(const SubstTemplateTypeParmPackType *T) { return true; }
3391c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor};
3392c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor
339334b41d939a1328f484511c6002ba2456db879a29Richard Smith/// \brief Represents a C++0x auto type.
339434b41d939a1328f484511c6002ba2456db879a29Richard Smith///
339534b41d939a1328f484511c6002ba2456db879a29Richard Smith/// These types are usually a placeholder for a deduced type. However, within
339634b41d939a1328f484511c6002ba2456db879a29Richard Smith/// templates and before the initializer is attached, there is no deduced type
339734b41d939a1328f484511c6002ba2456db879a29Richard Smith/// and an auto type is type-dependent and canonical.
339834b41d939a1328f484511c6002ba2456db879a29Richard Smithclass AutoType : public Type, public llvm::FoldingSetNode {
339934b41d939a1328f484511c6002ba2456db879a29Richard Smith  AutoType(QualType DeducedType)
340034b41d939a1328f484511c6002ba2456db879a29Richard Smith    : Type(Auto, DeducedType.isNull() ? QualType(this, 0) : DeducedType,
340134b41d939a1328f484511c6002ba2456db879a29Richard Smith           /*Dependent=*/DeducedType.isNull(),
340234b41d939a1328f484511c6002ba2456db879a29Richard Smith           /*VariablyModified=*/false, /*ContainsParameterPack=*/false) {
340334b41d939a1328f484511c6002ba2456db879a29Richard Smith    assert((DeducedType.isNull() || !DeducedType->isDependentType()) &&
340434b41d939a1328f484511c6002ba2456db879a29Richard Smith           "deduced a dependent type for auto");
340534b41d939a1328f484511c6002ba2456db879a29Richard Smith  }
340634b41d939a1328f484511c6002ba2456db879a29Richard Smith
340734b41d939a1328f484511c6002ba2456db879a29Richard Smith  friend class ASTContext;  // ASTContext creates these
340834b41d939a1328f484511c6002ba2456db879a29Richard Smith
340934b41d939a1328f484511c6002ba2456db879a29Richard Smithpublic:
341034b41d939a1328f484511c6002ba2456db879a29Richard Smith  bool isSugared() const { return isDeduced(); }
341134b41d939a1328f484511c6002ba2456db879a29Richard Smith  QualType desugar() const { return getCanonicalTypeInternal(); }
341234b41d939a1328f484511c6002ba2456db879a29Richard Smith
341334b41d939a1328f484511c6002ba2456db879a29Richard Smith  QualType getDeducedType() const {
341434b41d939a1328f484511c6002ba2456db879a29Richard Smith    return isDeduced() ? getCanonicalTypeInternal() : QualType();
341534b41d939a1328f484511c6002ba2456db879a29Richard Smith  }
341634b41d939a1328f484511c6002ba2456db879a29Richard Smith  bool isDeduced() const {
341734b41d939a1328f484511c6002ba2456db879a29Richard Smith    return !isDependentType();
341834b41d939a1328f484511c6002ba2456db879a29Richard Smith  }
341934b41d939a1328f484511c6002ba2456db879a29Richard Smith
342034b41d939a1328f484511c6002ba2456db879a29Richard Smith  void Profile(llvm::FoldingSetNodeID &ID) {
342134b41d939a1328f484511c6002ba2456db879a29Richard Smith    Profile(ID, getDeducedType());
342234b41d939a1328f484511c6002ba2456db879a29Richard Smith  }
342334b41d939a1328f484511c6002ba2456db879a29Richard Smith
342434b41d939a1328f484511c6002ba2456db879a29Richard Smith  static void Profile(llvm::FoldingSetNodeID &ID,
342534b41d939a1328f484511c6002ba2456db879a29Richard Smith                      QualType Deduced) {
342634b41d939a1328f484511c6002ba2456db879a29Richard Smith    ID.AddPointer(Deduced.getAsOpaquePtr());
342734b41d939a1328f484511c6002ba2456db879a29Richard Smith  }
342834b41d939a1328f484511c6002ba2456db879a29Richard Smith
342934b41d939a1328f484511c6002ba2456db879a29Richard Smith  static bool classof(const Type *T) {
343034b41d939a1328f484511c6002ba2456db879a29Richard Smith    return T->getTypeClass() == Auto;
343134b41d939a1328f484511c6002ba2456db879a29Richard Smith  }
343234b41d939a1328f484511c6002ba2456db879a29Richard Smith  static bool classof(const AutoType *T) { return true; }
343334b41d939a1328f484511c6002ba2456db879a29Richard Smith};
343434b41d939a1328f484511c6002ba2456db879a29Richard Smith
34351901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall/// \brief Represents a type template specialization; the template
34361901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall/// must be a class template, a type alias template, or a template
34371901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall/// template parameter.  A template which cannot be resolved to one of
34381901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall/// these, e.g. because it is written with a dependent scope
34391901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall/// specifier, is instead represented as a
34401901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall/// @c DependentTemplateSpecializationType.
344155f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor///
34421901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall/// A non-dependent template specialization type is always "sugar",
34431901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall/// typically for a @c RecordType.  For example, a class template
34441901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall/// specialization type of @c vector<int> will refer to a tag type for
34451901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall/// the instantiation @c std::vector<int, std::allocator<int>>
34467532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor///
34471901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall/// Template specializations are dependent if either the template or
34481901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall/// any of the template arguments are dependent, in which case the
34491901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall/// type may also be canonical.
34503e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith///
34511901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall/// Instances of this type are allocated with a trailing array of
34521901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall/// TemplateArguments, followed by a QualType representing the
34531901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall/// non-canonical aliased type when the template is a type alias
34541901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall/// template.
34551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpclass TemplateSpecializationType
345655f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  : public Type, public llvm::FoldingSetNode {
34571901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall  /// \brief The name of the template being specialized.  This is
34581901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall  /// either a TemplateName::Template (in which case it is a
34591901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall  /// ClassTemplateDecl*, a TemplateTemplateParmDecl*, or a
3460146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall  /// TypeAliasTemplateDecl*), a
3461146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall  /// TemplateName::SubstTemplateTemplateParmPack, or a
3462146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall  /// TemplateName::SubstTemplateTemplateParm (in which case the
3463146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall  /// replacement must, recursively, be one of these).
34647532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor  TemplateName Template;
346555f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
346640808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  /// \brief - The number of template arguments named in this class
346740808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  /// template specialization.
346855f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  unsigned NumArgs;
346955f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
3470ef99001908e799c388f1363b1e607dad5f5b57d3John McCall  TemplateSpecializationType(TemplateName T,
34717532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor                             const TemplateArgument *Args,
34723e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith                             unsigned NumArgs, QualType Canon,
34733e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith                             QualType Aliased);
347455f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
347555f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  friend class ASTContext;  // ASTContext creates these
347655f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
347755f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregorpublic:
347840808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  /// \brief Determine whether any of the given template arguments are
347940808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  /// dependent.
348040808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  static bool anyDependentTemplateArguments(const TemplateArgument *Args,
34811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                            unsigned NumArgs);
348240808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor
3483833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  static bool anyDependentTemplateArguments(const TemplateArgumentLoc *Args,
3484833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                            unsigned NumArgs);
3485833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
3486d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  static bool anyDependentTemplateArguments(const TemplateArgumentListInfo &);
3487d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall
3488df667e71b1daadeacb230cf94fc717843f1a138aDouglas Gregor  /// \brief Print a template argument list, including the '<' and '>'
3489df667e71b1daadeacb230cf94fc717843f1a138aDouglas Gregor  /// enclosing the template arguments.
3490df667e71b1daadeacb230cf94fc717843f1a138aDouglas Gregor  static std::string PrintTemplateArgumentList(const TemplateArgument *Args,
3491d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor                                               unsigned NumArgs,
3492dace95b13e2ceb0c3ec8de6babd926dc5114e1e5Douglas Gregor                                               const PrintingPolicy &Policy,
3493dace95b13e2ceb0c3ec8de6babd926dc5114e1e5Douglas Gregor                                               bool SkipBrackets = false);
3494df667e71b1daadeacb230cf94fc717843f1a138aDouglas Gregor
3495833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  static std::string PrintTemplateArgumentList(const TemplateArgumentLoc *Args,
3496833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                               unsigned NumArgs,
3497833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                               const PrintingPolicy &Policy);
3498833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
3499d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  static std::string PrintTemplateArgumentList(const TemplateArgumentListInfo &,
3500d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall                                               const PrintingPolicy &Policy);
3501d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall
350231f17ecbef57b5679c017c375db330546b7b5145John McCall  /// True if this template specialization type matches a current
350331f17ecbef57b5679c017c375db330546b7b5145John McCall  /// instantiation in the context in which it is found.
350431f17ecbef57b5679c017c375db330546b7b5145John McCall  bool isCurrentInstantiation() const {
350571d74bc0d6e522ce7c21a599db8e19d3883b518fJohn McCall    return isa<InjectedClassNameType>(getCanonicalTypeInternal());
350631f17ecbef57b5679c017c375db330546b7b5145John McCall  }
350731f17ecbef57b5679c017c375db330546b7b5145John McCall
35083e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  /// True if this template specialization type is for a type alias
35093e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  /// template.
35103e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  bool isTypeAlias() const;
35113e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  /// Get the aliased type, if this is a specialization of a type alias
35123e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  /// template.
35133e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  QualType getAliasedType() const {
35143e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith    assert(isTypeAlias() && "not a type alias template specialization");
35153e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith    return *reinterpret_cast<const QualType*>(end());
35163e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  }
35173e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith
351840808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  typedef const TemplateArgument * iterator;
351940808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor
352040808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  iterator begin() const { return getArgs(); }
352133500955d731c73717af52088b7fc0e7a85681e7John McCall  iterator end() const; // defined inline in TemplateBase.h
352240808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor
35237532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor  /// \brief Retrieve the name of the template that we are specializing.
35247532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor  TemplateName getTemplateName() const { return Template; }
352555f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
352640808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  /// \brief Retrieve the template arguments.
35271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  const TemplateArgument *getArgs() const {
352840808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor    return reinterpret_cast<const TemplateArgument *>(this + 1);
352940808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  }
353040808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor
353140808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  /// \brief Retrieve the number of template arguments.
353255f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  unsigned getNumArgs() const { return NumArgs; }
353355f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
353455f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  /// \brief Retrieve a specific template argument as a type.
353555f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  /// \precondition @c isArgType(Arg)
353633500955d731c73717af52088b7fc0e7a85681e7John McCall  const TemplateArgument &getArg(unsigned Idx) const; // in TemplateBase.h
353755f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
353831f17ecbef57b5679c017c375db330546b7b5145John McCall  bool isSugared() const {
35393e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith    return !isDependentType() || isCurrentInstantiation() || isTypeAlias();
354031f17ecbef57b5679c017c375db330546b7b5145John McCall  }
3541bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return getCanonicalTypeInternal(); }
3542bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
35434ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Ctx) {
354471d74bc0d6e522ce7c21a599db8e19d3883b518fJohn McCall    Profile(ID, Template, getArgs(), NumArgs, Ctx);
35453e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith    if (isTypeAlias())
35463e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith      getAliasedType().Profile(ID);
354755f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  }
354855f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
35497532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor  static void Profile(llvm::FoldingSetNodeID &ID, TemplateName T,
355031f17ecbef57b5679c017c375db330546b7b5145John McCall                      const TemplateArgument *Args,
355131f17ecbef57b5679c017c375db330546b7b5145John McCall                      unsigned NumArgs,
35524ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad                      const ASTContext &Context);
355355f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
35541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
35551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == TemplateSpecialization;
355655f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  }
35577532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor  static bool classof(const TemplateSpecializationType *T) { return true; }
355855f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor};
355955f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
356031f17ecbef57b5679c017c375db330546b7b5145John McCall/// \brief The injected class name of a C++ class template or class
356131f17ecbef57b5679c017c375db330546b7b5145John McCall/// template partial specialization.  Used to record that a type was
356231f17ecbef57b5679c017c375db330546b7b5145John McCall/// spelled with a bare identifier rather than as a template-id; the
356331f17ecbef57b5679c017c375db330546b7b5145John McCall/// equivalent for non-templated classes is just RecordType.
35643cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall///
356531f17ecbef57b5679c017c375db330546b7b5145John McCall/// Injected class name types are always dependent.  Template
356631f17ecbef57b5679c017c375db330546b7b5145John McCall/// instantiation turns these into RecordTypes.
35673cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall///
356831f17ecbef57b5679c017c375db330546b7b5145John McCall/// Injected class name types are always canonical.  This works
356931f17ecbef57b5679c017c375db330546b7b5145John McCall/// because it is impossible to compare an injected class name type
357031f17ecbef57b5679c017c375db330546b7b5145John McCall/// with the corresponding non-injected template type, for the same
357131f17ecbef57b5679c017c375db330546b7b5145John McCall/// reason that it is impossible to directly compare template
357231f17ecbef57b5679c017c375db330546b7b5145John McCall/// parameters from different dependent contexts: injected class name
357331f17ecbef57b5679c017c375db330546b7b5145John McCall/// types can only occur within the scope of a particular templated
357431f17ecbef57b5679c017c375db330546b7b5145John McCall/// declaration, and within that scope every template specialization
357531f17ecbef57b5679c017c375db330546b7b5145John McCall/// will canonicalize to the injected class name (when appropriate
357631f17ecbef57b5679c017c375db330546b7b5145John McCall/// according to the rules of the language).
35773cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCallclass InjectedClassNameType : public Type {
35783cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  CXXRecordDecl *Decl;
35793cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall
358031f17ecbef57b5679c017c375db330546b7b5145John McCall  /// The template specialization which this type represents.
358131f17ecbef57b5679c017c375db330546b7b5145John McCall  /// For example, in
358231f17ecbef57b5679c017c375db330546b7b5145John McCall  ///   template <class T> class A { ... };
358331f17ecbef57b5679c017c375db330546b7b5145John McCall  /// this is A<T>, whereas in
358431f17ecbef57b5679c017c375db330546b7b5145John McCall  ///   template <class X, class Y> class A<B<X,Y> > { ... };
358531f17ecbef57b5679c017c375db330546b7b5145John McCall  /// this is A<B<X,Y> >.
358631f17ecbef57b5679c017c375db330546b7b5145John McCall  ///
358731f17ecbef57b5679c017c375db330546b7b5145John McCall  /// It is always unqualified, always a template specialization type,
358831f17ecbef57b5679c017c375db330546b7b5145John McCall  /// and always dependent.
358931f17ecbef57b5679c017c375db330546b7b5145John McCall  QualType InjectedType;
35903cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall
35913cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  friend class ASTContext; // ASTContext creates these.
3592c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl  friend class ASTReader; // FIXME: ASTContext::getInjectedClassNameType is not
3593c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl                          // currently suitable for AST reading, too much
359443921b53b582145f0d1b7c48223bd4d9f0a9d1beArgyrios Kyrtzidis                          // interdependencies.
359531f17ecbef57b5679c017c375db330546b7b5145John McCall  InjectedClassNameType(CXXRecordDecl *D, QualType TST)
359635495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    : Type(InjectedClassName, QualType(), /*Dependent=*/true,
3597d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor           /*VariablyModified=*/false,
3598d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor           /*ContainsUnexpandedParameterPack=*/false),
359931f17ecbef57b5679c017c375db330546b7b5145John McCall      Decl(D), InjectedType(TST) {
36003cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall    assert(isa<TemplateSpecializationType>(TST));
36013cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall    assert(!TST.hasQualifiers());
360231f17ecbef57b5679c017c375db330546b7b5145John McCall    assert(TST->isDependentType());
36033cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  }
36043cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall
36053cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCallpublic:
360631f17ecbef57b5679c017c375db330546b7b5145John McCall  QualType getInjectedSpecializationType() const { return InjectedType; }
360731f17ecbef57b5679c017c375db330546b7b5145John McCall  const TemplateSpecializationType *getInjectedTST() const {
360831f17ecbef57b5679c017c375db330546b7b5145John McCall    return cast<TemplateSpecializationType>(InjectedType.getTypePtr());
36093cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  }
36103cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall
3611ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl  CXXRecordDecl *getDecl() const;
36123cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall
361331f17ecbef57b5679c017c375db330546b7b5145John McCall  bool isSugared() const { return false; }
361431f17ecbef57b5679c017c375db330546b7b5145John McCall  QualType desugar() const { return QualType(this, 0); }
36153cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall
36163cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  static bool classof(const Type *T) {
36173cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall    return T->getTypeClass() == InjectedClassName;
36183cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  }
36193cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  static bool classof(const InjectedClassNameType *T) { return true; }
36203cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall};
36213cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall
3622465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// \brief The kind of a tag type.
3623465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnaraenum TagTypeKind {
3624465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// \brief The "struct" keyword.
3625465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  TTK_Struct,
3626465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// \brief The "union" keyword.
3627465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  TTK_Union,
3628465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// \brief The "class" keyword.
3629465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  TTK_Class,
3630465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// \brief The "enum" keyword.
3631465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  TTK_Enum
3632465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara};
3633465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
36344a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// \brief The elaboration keyword that precedes a qualified type name or
36354a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// introduces an elaborated-type-specifier.
36364a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregorenum ElaboratedTypeKeyword {
36374a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor  /// \brief The "struct" keyword introduces the elaborated-type-specifier.
36384a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor  ETK_Struct,
36394a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor  /// \brief The "union" keyword introduces the elaborated-type-specifier.
36404a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor  ETK_Union,
3641465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// \brief The "class" keyword introduces the elaborated-type-specifier.
3642465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  ETK_Class,
36434a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor  /// \brief The "enum" keyword introduces the elaborated-type-specifier.
3644465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  ETK_Enum,
3645465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// \brief The "typename" keyword precedes the qualified type name, e.g.,
3646465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// \c typename T::type.
3647465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  ETK_Typename,
3648465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// \brief No keyword precedes the qualified type name.
3649465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  ETK_None
36504a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor};
3651465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
3652465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// A helper class for Type nodes having an ElaboratedTypeKeyword.
3653465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// The keyword in stored in the free bits of the base class.
3654465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// Also provides a few static helpers for converting and printing
3655465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// elaborated type keyword and tag type kind enumerations.
3656465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnaraclass TypeWithKeyword : public Type {
3657465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnaraprotected:
3658465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  TypeWithKeyword(ElaboratedTypeKeyword Keyword, TypeClass tc,
3659d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor                  QualType Canonical, bool Dependent, bool VariablyModified,
3660d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor                  bool ContainsUnexpandedParameterPack)
3661d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  : Type(tc, Canonical, Dependent, VariablyModified,
3662d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor         ContainsUnexpandedParameterPack) {
366377be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall    TypeWithKeywordBits.Keyword = Keyword;
366477be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall  }
3665465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
3666465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnarapublic:
3667465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  ElaboratedTypeKeyword getKeyword() const {
366877be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall    return static_cast<ElaboratedTypeKeyword>(TypeWithKeywordBits.Keyword);
3669465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  }
3670465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
3671465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// getKeywordForTypeSpec - Converts a type specifier (DeclSpec::TST)
3672465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// into an elaborated type keyword.
3673465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  static ElaboratedTypeKeyword getKeywordForTypeSpec(unsigned TypeSpec);
3674465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
3675465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// getTagTypeKindForTypeSpec - Converts a type specifier (DeclSpec::TST)
3676465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// into a tag type kind.  It is an error to provide a type specifier
3677465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// which *isn't* a tag kind here.
3678465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  static TagTypeKind getTagTypeKindForTypeSpec(unsigned TypeSpec);
3679465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
3680465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// getKeywordForTagDeclKind - Converts a TagTypeKind into an
3681465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// elaborated type keyword.
3682465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  static ElaboratedTypeKeyword getKeywordForTagTypeKind(TagTypeKind Tag);
3683465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
3684465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// getTagTypeKindForKeyword - Converts an elaborated type keyword into
3685465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  // a TagTypeKind. It is an error to provide an elaborated type keyword
3686465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// which *isn't* a tag kind here.
3687465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  static TagTypeKind getTagTypeKindForKeyword(ElaboratedTypeKeyword Keyword);
3688465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
3689465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  static bool KeywordIsTagTypeKind(ElaboratedTypeKeyword Keyword);
3690465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
3691465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  static const char *getKeywordName(ElaboratedTypeKeyword Keyword);
3692465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
3693465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  static const char *getTagTypeKindName(TagTypeKind Kind) {
3694465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    return getKeywordName(getKeywordForTagTypeKind(Kind));
3695465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  }
3696465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
3697465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  class CannotCastToThisType {};
3698465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  static CannotCastToThisType classof(const Type *);
3699465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara};
3700465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
3701465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// \brief Represents a type that was referred to using an elaborated type
3702465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// keyword, e.g., struct S, or via a qualified name, e.g., N::M::type,
3703465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// or both.
3704e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor///
3705e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor/// This type is used to keep track of a type name as written in the
3706465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// source code, including tag keywords and any nested-name-specifiers.
3707465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// The type itself is always "sugar", used to express what was written
3708465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// in the source code but containing no additional semantic information.
3709465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnaraclass ElaboratedType : public TypeWithKeyword, public llvm::FoldingSetNode {
3710465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
3711ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor  /// \brief The nested name specifier containing the qualifier.
3712ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor  NestedNameSpecifier *NNS;
3713e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor
3714e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor  /// \brief The type that this qualified name refers to.
3715e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor  QualType NamedType;
3716e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor
3717465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  ElaboratedType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS,
3718465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara                 QualType NamedType, QualType CanonType)
3719465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    : TypeWithKeyword(Keyword, Elaborated, CanonType,
372035495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor                      NamedType->isDependentType(),
3721d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor                      NamedType->isVariablyModifiedType(),
3722d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor                      NamedType->containsUnexpandedParameterPack()),
3723465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara      NNS(NNS), NamedType(NamedType) {
3724465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    assert(!(Keyword == ETK_None && NNS == 0) &&
3725465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara           "ElaboratedType cannot have elaborated type keyword "
3726465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara           "and name qualifier both null.");
3727465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  }
3728e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor
3729e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor  friend class ASTContext;  // ASTContext creates these
3730e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor
3731e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregorpublic:
373233500955d731c73717af52088b7fc0e7a85681e7John McCall  ~ElaboratedType();
3733465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
3734ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor  /// \brief Retrieve the qualification on this type.
3735ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor  NestedNameSpecifier *getQualifier() const { return NNS; }
3736e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor
3737e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor  /// \brief Retrieve the type named by the qualified-id.
3738e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor  QualType getNamedType() const { return NamedType; }
3739e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor
3740bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// \brief Remove a single level of sugar.
3741bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return getNamedType(); }
3742bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
3743bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// \brief Returns whether this type directly provides sugar.
3744bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return true; }
3745bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
3746e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor  void Profile(llvm::FoldingSetNodeID &ID) {
3747465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    Profile(ID, getKeyword(), NNS, NamedType);
3748e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor  }
3749e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor
3750465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  static void Profile(llvm::FoldingSetNodeID &ID, ElaboratedTypeKeyword Keyword,
3751465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara                      NestedNameSpecifier *NNS, QualType NamedType) {
3752465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    ID.AddInteger(Keyword);
3753ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor    ID.AddPointer(NNS);
3754ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor    NamedType.Profile(ID);
3755ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor  }
3756e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor
37571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
3758465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    return T->getTypeClass() == Elaborated;
3759e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor  }
3760465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  static bool classof(const ElaboratedType *T) { return true; }
3761e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor};
3762e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor
37634a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// \brief Represents a qualified type name for which the type name is
37644a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// dependent.
3765d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor///
37664a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// DependentNameType represents a class of dependent types that involve a
37674a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// dependent nested-name-specifier (e.g., "T::") followed by a (dependent)
37684a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// name of a type. The DependentNameType may start with a "typename" (for a
37694a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// typename-specifier), "class", "struct", "union", or "enum" (for a
37704a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// dependent elaborated-type-specifier), or nothing (in contexts where we
37714a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// know that we must be referring to a type, e.g., in a base class specifier).
3772465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnaraclass DependentNameType : public TypeWithKeyword, public llvm::FoldingSetNode {
3773465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
3774d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  /// \brief The nested name specifier containing the qualifier.
3775d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  NestedNameSpecifier *NNS;
3776d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor
3777d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  /// \brief The type that this typename specifier refers to.
377833500955d731c73717af52088b7fc0e7a85681e7John McCall  const IdentifierInfo *Name;
3779d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor
37804a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor  DependentNameType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS,
37814a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor                    const IdentifierInfo *Name, QualType CanonType)
378235495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    : TypeWithKeyword(Keyword, DependentName, CanonType, /*Dependent=*/true,
3783d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor                      /*VariablyModified=*/false,
3784d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor                      NNS->containsUnexpandedParameterPack()),
3785465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara      NNS(NNS), Name(Name) {
37861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    assert(NNS->isDependent() &&
37874714c12a1ab759156b78be8f109ea4c12213af57Douglas Gregor           "DependentNameType requires a dependent nested-name-specifier");
3788d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  }
3789d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor
3790d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  friend class ASTContext;  // ASTContext creates these
3791d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor
3792d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregorpublic:
3793d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  /// \brief Retrieve the qualification on this type.
3794d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  NestedNameSpecifier *getQualifier() const { return NNS; }
3795d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor
37961734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor  /// \brief Retrieve the type named by the typename specifier as an
37971734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor  /// identifier.
37981734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor  ///
37991734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor  /// This routine will return a non-NULL identifier pointer when the
38001734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor  /// form of the original typename was terminated by an identifier,
38011734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor  /// e.g., "typename T::type".
38021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  const IdentifierInfo *getIdentifier() const {
380333500955d731c73717af52088b7fc0e7a85681e7John McCall    return Name;
38041734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor  }
3805d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor
3806bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
3807bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
3808bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
3809d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  void Profile(llvm::FoldingSetNodeID &ID) {
3810465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    Profile(ID, getKeyword(), NNS, Name);
3811d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  }
3812d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor
38134a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor  static void Profile(llvm::FoldingSetNodeID &ID, ElaboratedTypeKeyword Keyword,
381433500955d731c73717af52088b7fc0e7a85681e7John McCall                      NestedNameSpecifier *NNS, const IdentifierInfo *Name) {
38154a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor    ID.AddInteger(Keyword);
3816d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor    ID.AddPointer(NNS);
381733500955d731c73717af52088b7fc0e7a85681e7John McCall    ID.AddPointer(Name);
3818d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  }
3819d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor
38201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
38214714c12a1ab759156b78be8f109ea4c12213af57Douglas Gregor    return T->getTypeClass() == DependentName;
3822d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  }
38234714c12a1ab759156b78be8f109ea4c12213af57Douglas Gregor  static bool classof(const DependentNameType *T) { return true; }
3824d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor};
3825d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor
382633500955d731c73717af52088b7fc0e7a85681e7John McCall/// DependentTemplateSpecializationType - Represents a template
382733500955d731c73717af52088b7fc0e7a85681e7John McCall/// specialization type whose template cannot be resolved, e.g.
382833500955d731c73717af52088b7fc0e7a85681e7John McCall///   A<T>::template B<T>
382933500955d731c73717af52088b7fc0e7a85681e7John McCallclass DependentTemplateSpecializationType :
383033500955d731c73717af52088b7fc0e7a85681e7John McCall  public TypeWithKeyword, public llvm::FoldingSetNode {
383133500955d731c73717af52088b7fc0e7a85681e7John McCall
383233500955d731c73717af52088b7fc0e7a85681e7John McCall  /// \brief The nested name specifier containing the qualifier.
383333500955d731c73717af52088b7fc0e7a85681e7John McCall  NestedNameSpecifier *NNS;
383433500955d731c73717af52088b7fc0e7a85681e7John McCall
383533500955d731c73717af52088b7fc0e7a85681e7John McCall  /// \brief The identifier of the template.
383633500955d731c73717af52088b7fc0e7a85681e7John McCall  const IdentifierInfo *Name;
383733500955d731c73717af52088b7fc0e7a85681e7John McCall
383833500955d731c73717af52088b7fc0e7a85681e7John McCall  /// \brief - The number of template arguments named in this class
383933500955d731c73717af52088b7fc0e7a85681e7John McCall  /// template specialization.
384033500955d731c73717af52088b7fc0e7a85681e7John McCall  unsigned NumArgs;
384133500955d731c73717af52088b7fc0e7a85681e7John McCall
384233500955d731c73717af52088b7fc0e7a85681e7John McCall  const TemplateArgument *getArgBuffer() const {
384333500955d731c73717af52088b7fc0e7a85681e7John McCall    return reinterpret_cast<const TemplateArgument*>(this+1);
384433500955d731c73717af52088b7fc0e7a85681e7John McCall  }
384533500955d731c73717af52088b7fc0e7a85681e7John McCall  TemplateArgument *getArgBuffer() {
384633500955d731c73717af52088b7fc0e7a85681e7John McCall    return reinterpret_cast<TemplateArgument*>(this+1);
384733500955d731c73717af52088b7fc0e7a85681e7John McCall  }
384833500955d731c73717af52088b7fc0e7a85681e7John McCall
3849ef99001908e799c388f1363b1e607dad5f5b57d3John McCall  DependentTemplateSpecializationType(ElaboratedTypeKeyword Keyword,
385033500955d731c73717af52088b7fc0e7a85681e7John McCall                                      NestedNameSpecifier *NNS,
385133500955d731c73717af52088b7fc0e7a85681e7John McCall                                      const IdentifierInfo *Name,
385233500955d731c73717af52088b7fc0e7a85681e7John McCall                                      unsigned NumArgs,
385333500955d731c73717af52088b7fc0e7a85681e7John McCall                                      const TemplateArgument *Args,
385433500955d731c73717af52088b7fc0e7a85681e7John McCall                                      QualType Canon);
385533500955d731c73717af52088b7fc0e7a85681e7John McCall
385633500955d731c73717af52088b7fc0e7a85681e7John McCall  friend class ASTContext;  // ASTContext creates these
385733500955d731c73717af52088b7fc0e7a85681e7John McCall
385833500955d731c73717af52088b7fc0e7a85681e7John McCallpublic:
385933500955d731c73717af52088b7fc0e7a85681e7John McCall  NestedNameSpecifier *getQualifier() const { return NNS; }
386033500955d731c73717af52088b7fc0e7a85681e7John McCall  const IdentifierInfo *getIdentifier() const { return Name; }
386133500955d731c73717af52088b7fc0e7a85681e7John McCall
386233500955d731c73717af52088b7fc0e7a85681e7John McCall  /// \brief Retrieve the template arguments.
386333500955d731c73717af52088b7fc0e7a85681e7John McCall  const TemplateArgument *getArgs() const {
386433500955d731c73717af52088b7fc0e7a85681e7John McCall    return getArgBuffer();
386533500955d731c73717af52088b7fc0e7a85681e7John McCall  }
386633500955d731c73717af52088b7fc0e7a85681e7John McCall
386733500955d731c73717af52088b7fc0e7a85681e7John McCall  /// \brief Retrieve the number of template arguments.
386833500955d731c73717af52088b7fc0e7a85681e7John McCall  unsigned getNumArgs() const { return NumArgs; }
386933500955d731c73717af52088b7fc0e7a85681e7John McCall
387033500955d731c73717af52088b7fc0e7a85681e7John McCall  const TemplateArgument &getArg(unsigned Idx) const; // in TemplateBase.h
387133500955d731c73717af52088b7fc0e7a85681e7John McCall
387233500955d731c73717af52088b7fc0e7a85681e7John McCall  typedef const TemplateArgument * iterator;
387333500955d731c73717af52088b7fc0e7a85681e7John McCall  iterator begin() const { return getArgs(); }
387433500955d731c73717af52088b7fc0e7a85681e7John McCall  iterator end() const; // inline in TemplateBase.h
387533500955d731c73717af52088b7fc0e7a85681e7John McCall
387633500955d731c73717af52088b7fc0e7a85681e7John McCall  bool isSugared() const { return false; }
387733500955d731c73717af52088b7fc0e7a85681e7John McCall  QualType desugar() const { return QualType(this, 0); }
387833500955d731c73717af52088b7fc0e7a85681e7John McCall
38794ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context) {
388033500955d731c73717af52088b7fc0e7a85681e7John McCall    Profile(ID, Context, getKeyword(), NNS, Name, NumArgs, getArgs());
388133500955d731c73717af52088b7fc0e7a85681e7John McCall  }
388233500955d731c73717af52088b7fc0e7a85681e7John McCall
388333500955d731c73717af52088b7fc0e7a85681e7John McCall  static void Profile(llvm::FoldingSetNodeID &ID,
38844ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad                      const ASTContext &Context,
388533500955d731c73717af52088b7fc0e7a85681e7John McCall                      ElaboratedTypeKeyword Keyword,
388633500955d731c73717af52088b7fc0e7a85681e7John McCall                      NestedNameSpecifier *Qualifier,
388733500955d731c73717af52088b7fc0e7a85681e7John McCall                      const IdentifierInfo *Name,
388833500955d731c73717af52088b7fc0e7a85681e7John McCall                      unsigned NumArgs,
388933500955d731c73717af52088b7fc0e7a85681e7John McCall                      const TemplateArgument *Args);
389033500955d731c73717af52088b7fc0e7a85681e7John McCall
389133500955d731c73717af52088b7fc0e7a85681e7John McCall  static bool classof(const Type *T) {
389233500955d731c73717af52088b7fc0e7a85681e7John McCall    return T->getTypeClass() == DependentTemplateSpecialization;
389333500955d731c73717af52088b7fc0e7a85681e7John McCall  }
389433500955d731c73717af52088b7fc0e7a85681e7John McCall  static bool classof(const DependentTemplateSpecializationType *T) {
389533500955d731c73717af52088b7fc0e7a85681e7John McCall    return true;
389633500955d731c73717af52088b7fc0e7a85681e7John McCall  }
389733500955d731c73717af52088b7fc0e7a85681e7John McCall};
389833500955d731c73717af52088b7fc0e7a85681e7John McCall
38997536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// \brief Represents a pack expansion of types.
39007536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor///
39017536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// Pack expansions are part of C++0x variadic templates. A pack
39027536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// expansion contains a pattern, which itself contains one or more
39037536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// "unexpanded" parameter packs. When instantiated, a pack expansion
39047536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// produces a series of types, each instantiated from the pattern of
39057536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// the expansion, where the Ith instantiation of the pattern uses the
39067536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// Ith arguments bound to each of the unexpanded parameter packs. The
39077536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// pack expansion is considered to "expand" these unexpanded
39087536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// parameter packs.
39097536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor///
39107536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// \code
39117536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// template<typename ...Types> struct tuple;
39127536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor///
39137536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// template<typename ...Types>
39147536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// struct tuple_of_references {
39157536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor///   typedef tuple<Types&...> type;
39167536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// };
39177536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// \endcode
39187536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor///
39197536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// Here, the pack expansion \c Types&... is represented via a
39207536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// PackExpansionType whose pattern is Types&.
39217536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregorclass PackExpansionType : public Type, public llvm::FoldingSetNode {
39227536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  /// \brief The pattern of the pack expansion.
39237536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  QualType Pattern;
39247536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor
3925cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  /// \brief The number of expansions that this pack expansion will
3926cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  /// generate when substituted (+1), or indicates that
3927cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  ///
3928cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  /// This field will only have a non-zero value when some of the parameter
3929cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  /// packs that occur within the pattern have been substituted but others have
3930cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  /// not.
3931cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  unsigned NumExpansions;
3932cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor
3933cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  PackExpansionType(QualType Pattern, QualType Canon,
3934cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor                    llvm::Optional<unsigned> NumExpansions)
39357536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor    : Type(PackExpansion, Canon, /*Dependent=*/true,
39367536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor           /*VariableModified=*/Pattern->isVariablyModifiedType(),
39377536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor           /*ContainsUnexpandedParameterPack=*/false),
3938cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor      Pattern(Pattern),
3939cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor      NumExpansions(NumExpansions? *NumExpansions + 1: 0) { }
39407536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor
39417536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  friend class ASTContext;  // ASTContext creates these
3942cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor
39437536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregorpublic:
39447536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  /// \brief Retrieve the pattern of this pack expansion, which is the
39457536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  /// type that will be repeatedly instantiated when instantiating the
39467536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  /// pack expansion itself.
39477536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  QualType getPattern() const { return Pattern; }
39487536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor
3949cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  /// \brief Retrieve the number of expansions that this pack expansion will
3950cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  /// generate, if known.
3951cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  llvm::Optional<unsigned> getNumExpansions() const {
3952cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor    if (NumExpansions)
3953cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor      return NumExpansions - 1;
3954cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor
3955cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor    return llvm::Optional<unsigned>();
3956cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  }
3957cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor
39587536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  bool isSugared() const { return false; }
39597536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  QualType desugar() const { return QualType(this, 0); }
39607536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor
39617536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  void Profile(llvm::FoldingSetNodeID &ID) {
3962cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor    Profile(ID, getPattern(), getNumExpansions());
39637536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  }
39647536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor
3965cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  static void Profile(llvm::FoldingSetNodeID &ID, QualType Pattern,
3966cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor                      llvm::Optional<unsigned> NumExpansions) {
39677536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor    ID.AddPointer(Pattern.getAsOpaquePtr());
3968cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor    ID.AddBoolean(NumExpansions);
3969cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor    if (NumExpansions)
3970cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor      ID.AddInteger(*NumExpansions);
39717536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  }
39727536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor
39737536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  static bool classof(const Type *T) {
39747536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor    return T->getTypeClass() == PackExpansion;
39757536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  }
39767536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  static bool classof(const PackExpansionType *T) {
39777536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor    return true;
39787536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  }
39797536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor};
39807536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor
3981c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// ObjCObjectType - Represents a class type in Objective C.
3982c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// Every Objective C type is a combination of a base type and a
3983c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// list of protocols.
3984c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall///
3985c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// Given the following declarations:
3986c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall///   @class C;
3987c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall///   @protocol P;
3988c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall///
3989c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// 'C' is an ObjCInterfaceType C.  It is sugar for an ObjCObjectType
3990c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// with base C and no protocols.
3991c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall///
3992c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// 'C<P>' is an ObjCObjectType with base C and protocol list [P].
3993c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall///
3994e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// 'id' is a TypedefType which is sugar for an ObjCPointerType whose
3995e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// pointee is an ObjCObjectType with base BuiltinType::ObjCIdType
3996e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// and no protocols.
3997c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall///
3998e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// 'id<P>' is an ObjCPointerType whose pointee is an ObjCObjecType
3999e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// with base BuiltinType::ObjCIdType and protocol list [P].  Eventually
4000e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// this should get its own sugar class to better represent the source.
4001c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallclass ObjCObjectType : public Type {
4002b870b88df784c2940efce448ebfaf54dece14666John McCall  // ObjCObjectType.NumProtocols - the number of protocols stored
4003b870b88df784c2940efce448ebfaf54dece14666John McCall  // after the ObjCObjectPointerType node.
400471c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  //
400571c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  // These protocols are those written directly on the type.  If
400671c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  // protocol qualifiers ever become additive, the iterators will need
400771c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  // to get kindof complicated.
400871c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  //
400971c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  // In the canonical object type, these are sorted alphabetically
401071c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  // and uniqued.
4011c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff
4012c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  /// Either a BuiltinType or an InterfaceType or sugar for either.
4013c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  QualType BaseType;
4014c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
4015c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  ObjCProtocolDecl * const *getProtocolStorage() const {
4016c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return const_cast<ObjCObjectType*>(this)->getProtocolStorage();
4017c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  }
4018c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
4019c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  ObjCProtocolDecl **getProtocolStorage();
4020c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
4021c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallprotected:
4022c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  ObjCObjectType(QualType Canonical, QualType Base,
4023c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall                 ObjCProtocolDecl * const *Protocols, unsigned NumProtocols);
4024c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
4025c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  enum Nonce_ObjCInterface { Nonce_ObjCInterface };
4026c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  ObjCObjectType(enum Nonce_ObjCInterface)
4027d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor        : Type(ObjCInterface, QualType(), false, false, false),
402871c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall      BaseType(QualType(this_(), 0)) {
4029b870b88df784c2940efce448ebfaf54dece14666John McCall    ObjCObjectTypeBits.NumProtocols = 0;
403071c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  }
4031c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff
40323536b443bc50d58a79f14fca9b6842541a434854Steve Naroffpublic:
4033e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// getBaseType - Gets the base type of this object type.  This is
4034e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// always (possibly sugar for) one of:
4035e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///  - the 'id' builtin type (as opposed to the 'id' type visible to the
4036e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///    user, which is a typedef for an ObjCPointerType)
4037e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///  - the 'Class' builtin type (same caveat)
4038e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///  - an ObjCObjectType (currently always an ObjCInterfaceType)
4039c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  QualType getBaseType() const { return BaseType; }
404071842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek
4041c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool isObjCId() const {
4042c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getBaseType()->isSpecificBuiltinType(BuiltinType::ObjCId);
4043c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  }
4044c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool isObjCClass() const {
4045c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getBaseType()->isSpecificBuiltinType(BuiltinType::ObjCClass);
4046c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  }
4047c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool isObjCUnqualifiedId() const { return qual_empty() && isObjCId(); }
4048c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool isObjCUnqualifiedClass() const { return qual_empty() && isObjCClass(); }
4049c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool isObjCUnqualifiedIdOrClass() const {
4050c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    if (!qual_empty()) return false;
4051c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    if (const BuiltinType *T = getBaseType()->getAs<BuiltinType>())
4052c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall      return T->getKind() == BuiltinType::ObjCId ||
4053c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall             T->getKind() == BuiltinType::ObjCClass;
4054c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return false;
4055c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  }
4056c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool isObjCQualifiedId() const { return !qual_empty() && isObjCId(); }
4057c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool isObjCQualifiedClass() const { return !qual_empty() && isObjCClass(); }
4058c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
4059c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  /// Gets the interface declaration for this object type, if the base type
4060c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  /// really is an interface.
4061c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  ObjCInterfaceDecl *getInterface() const;
4062c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
4063c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  typedef ObjCProtocolDecl * const *qual_iterator;
4064c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
4065c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  qual_iterator qual_begin() const { return getProtocolStorage(); }
4066c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  qual_iterator qual_end() const { return qual_begin() + getNumProtocols(); }
4067c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
4068c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool qual_empty() const { return getNumProtocols() == 0; }
40691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4070c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff  /// getNumProtocols - Return the number of qualifying protocols in this
4071c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff  /// interface type, or 0 if there are none.
4072b870b88df784c2940efce448ebfaf54dece14666John McCall  unsigned getNumProtocols() const { return ObjCObjectTypeBits.NumProtocols; }
407314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff
4074c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  /// \brief Fetch a protocol by index.
407573dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor  ObjCProtocolDecl *getProtocol(unsigned I) const {
407673dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor    assert(I < getNumProtocols() && "Out-of-range protocol access");
407773dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor    return qual_begin()[I];
407873dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor  }
407973dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor
4080bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
4081bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
4082bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
4083c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  static bool classof(const Type *T) {
4084c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return T->getTypeClass() == ObjCObject ||
4085c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall           T->getTypeClass() == ObjCInterface;
4086c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  }
4087c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  static bool classof(const ObjCObjectType *) { return true; }
4088c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall};
4089c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
4090c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// ObjCObjectTypeImpl - A class providing a concrete implementation
4091c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// of ObjCObjectType, so as to not increase the footprint of
4092c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// ObjCInterfaceType.  Code outside of ASTContext and the core type
4093c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// system should not reference this type.
4094c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallclass ObjCObjectTypeImpl : public ObjCObjectType, public llvm::FoldingSetNode {
4095c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  friend class ASTContext;
4096c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
4097c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  // If anyone adds fields here, ObjCObjectType::getProtocolStorage()
4098c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  // will need to be modified.
4099c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
4100c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  ObjCObjectTypeImpl(QualType Canonical, QualType Base,
4101c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall                     ObjCProtocolDecl * const *Protocols,
4102c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall                     unsigned NumProtocols)
4103c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    : ObjCObjectType(Canonical, Base, Protocols, NumProtocols) {}
4104c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
4105c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallpublic:
4106c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff  void Profile(llvm::FoldingSetNodeID &ID);
41071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static void Profile(llvm::FoldingSetNodeID &ID,
4108c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall                      QualType Base,
4109c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall                      ObjCProtocolDecl *const *protocols,
4110c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall                      unsigned NumProtocols);
4111c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall};
41121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4113c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallinline ObjCProtocolDecl **ObjCObjectType::getProtocolStorage() {
4114c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  return reinterpret_cast<ObjCProtocolDecl**>(
4115c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall            static_cast<ObjCObjectTypeImpl*>(this) + 1);
4116c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall}
4117c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
4118c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// ObjCInterfaceType - Interfaces are the core concept in Objective-C for
4119c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// object oriented design.  They basically correspond to C++ classes.  There
4120c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// are two kinds of interface types, normal interfaces like "NSString" and
4121c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// qualified interfaces, which are qualified with a protocol list like
4122c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// "NSString<NSCopyable, NSAmazing>".
4123e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall///
4124e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// ObjCInterfaceType guarantees the following properties when considered
4125e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// as a subtype of its superclass, ObjCObjectType:
4126e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall///   - There are no protocol qualifiers.  To reinforce this, code which
4127e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall///     tries to invoke the protocol methods via an ObjCInterfaceType will
4128e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall///     fail to compile.
4129e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall///   - It is its own base type.  That is, if T is an ObjCInterfaceType*,
4130e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall///     T->getBaseType() == QualType(T, 0).
4131c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallclass ObjCInterfaceType : public ObjCObjectType {
4132c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  ObjCInterfaceDecl *Decl;
4133c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
4134c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  ObjCInterfaceType(const ObjCInterfaceDecl *D)
4135c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    : ObjCObjectType(Nonce_ObjCInterface),
4136c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall      Decl(const_cast<ObjCInterfaceDecl*>(D)) {}
4137c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  friend class ASTContext;  // ASTContext creates these.
41381fb0caaa7bef765b85972274e3b434af2572c141John McCall
4139c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallpublic:
4140e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// getDecl - Get the declaration of this interface.
4141deacbdca554298ccdf636f19c6094a8825ec6b34Douglas Gregor  ObjCInterfaceDecl *getDecl() const { return Decl; }
4142c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
4143c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool isSugared() const { return false; }
4144c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  QualType desugar() const { return QualType(this, 0); }
41450b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor
41461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
41471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == ObjCInterface;
41483536b443bc50d58a79f14fca9b6842541a434854Steve Naroff  }
4149a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const ObjCInterfaceType *) { return true; }
4150c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
4151c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  // Nonsense to "hide" certain members of ObjCObjectType within this
4152c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  // class.  People asking for protocols on an ObjCInterfaceType are
4153c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  // not going to get what they want: ObjCInterfaceTypes are
4154c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  // guaranteed to have no protocols.
4155c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  enum {
4156c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    qual_iterator,
4157c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    qual_begin,
4158c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    qual_end,
4159c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    getNumProtocols,
4160c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    getProtocol
4161c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  };
41623536b443bc50d58a79f14fca9b6842541a434854Steve Naroff};
41633536b443bc50d58a79f14fca9b6842541a434854Steve Naroff
4164c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallinline ObjCInterfaceDecl *ObjCObjectType::getInterface() const {
4165c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  if (const ObjCInterfaceType *T =
4166c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall        getBaseType()->getAs<ObjCInterfaceType>())
4167c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return T->getDecl();
4168c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  return 0;
4169c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall}
4170c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
4171e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// ObjCObjectPointerType - Used to represent a pointer to an
4172e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// Objective C object.  These are constructed from pointer
4173e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// declarators when the pointee type is an ObjCObjectType (or sugar
4174e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// for one).  In addition, the 'id' and 'Class' types are typedefs
4175e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// for these, and the protocol-qualified types 'id<P>' and 'Class<P>'
4176e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// are translated into these.
417714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff///
4178e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// Pointers to pointers to Objective C objects are still PointerTypes;
4179e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// only the first level of pointer gets it own type implementation.
418014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroffclass ObjCObjectPointerType : public Type, public llvm::FoldingSetNode {
4181e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  QualType PointeeType;
41821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4183c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  ObjCObjectPointerType(QualType Canonical, QualType Pointee)
4184d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    : Type(ObjCObjectPointer, Canonical, false, false, false),
4185c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall      PointeeType(Pointee) {}
418614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  friend class ASTContext;  // ASTContext creates these.
41871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
418814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroffpublic:
4189e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// getPointeeType - Gets the type pointed to by this ObjC pointer.
4190e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// The result will always be an ObjCObjectType or sugar thereof.
419114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  QualType getPointeeType() const { return PointeeType; }
419214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff
4193e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// getObjCObjectType - Gets the type pointed to by this ObjC
4194e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// pointer.  This method always returns non-null.
4195e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///
4196e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// This method is equivalent to getPointeeType() except that
4197e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// it discards any typedefs (or other sugar) between this
4198e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// type and the "outermost" object type.  So for:
4199e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///   @class A; @protocol P; @protocol Q;
4200e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///   typedef A<P> AP;
4201e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///   typedef A A1;
4202e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///   typedef A1<P> A1P;
4203e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///   typedef A1P<Q> A1PQ;
4204e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// For 'A*', getObjectType() will return 'A'.
4205e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// For 'A<P>*', getObjectType() will return 'A<P>'.
4206e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// For 'AP*', getObjectType() will return 'A<P>'.
4207e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// For 'A1*', getObjectType() will return 'A'.
4208e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// For 'A1<P>*', getObjectType() will return 'A1<P>'.
4209e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// For 'A1P*', getObjectType() will return 'A1<P>'.
4210e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// For 'A1PQ*', getObjectType() will return 'A1<Q>', because
4211e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///   adding protocols to a protocol-qualified base discards the
4212e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///   old qualifiers (for now).  But if it didn't, getObjectType()
4213e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///   would return 'A1P<Q>' (and we'd have to make iterating over
4214e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///   qualifiers more complicated).
4215c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  const ObjCObjectType *getObjectType() const {
4216d0370f59e79702ac908c81bf556519f91e9ca297John McCall    return PointeeType->castAs<ObjCObjectType>();
4217c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  }
4218c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
4219e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// getInterfaceType - If this pointer points to an Objective C
4220e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// @interface type, gets the type for that interface.  Any protocol
4221e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// qualifiers on the interface are ignored.
4222e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///
4223e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// \return null if the base type for this pointer is 'id' or 'Class'
42241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  const ObjCInterfaceType *getInterfaceType() const {
4225c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getObjectType()->getBaseType()->getAs<ObjCInterfaceType>();
422614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  }
4227e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall
4228e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// getInterfaceDecl - If this pointer points to an Objective @interface
4229e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// type, gets the declaration for that interface.
4230e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///
4231e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// \return null if the base type for this pointer is 'id' or 'Class'
423214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  ObjCInterfaceDecl *getInterfaceDecl() const {
4233e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall    return getObjectType()->getInterface();
423414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  }
4235e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall
4236e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// isObjCIdType - True if this is equivalent to the 'id' type, i.e. if
4237e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// its object type is the primitive 'id' type with no protocols.
423814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  bool isObjCIdType() const {
4239c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getObjectType()->isObjCUnqualifiedId();
424014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  }
4241e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall
4242e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// isObjCClassType - True if this is equivalent to the 'Class' type,
4243e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// i.e. if its object tive is the primitive 'Class' type with no protocols.
424414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  bool isObjCClassType() const {
4245c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getObjectType()->isObjCUnqualifiedClass();
4246de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff  }
42478d2c0a9814e56c2b22e22d1045181c735aef62fdFariborz Jahanian
4248e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// isObjCQualifiedIdType - True if this is equivalent to 'id<P>' for some
4249e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// non-empty set of protocols.
42501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  bool isObjCQualifiedIdType() const {
4251c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getObjectType()->isObjCQualifiedId();
4252de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff  }
4253e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall
4254e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// isObjCQualifiedClassType - True if this is equivalent to 'Class<P>' for
4255e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// some non-empty set of protocols.
4256470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroff  bool isObjCQualifiedClassType() const {
4257c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getObjectType()->isObjCQualifiedClass();
425814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  }
4259e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall
4260e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// An iterator over the qualifiers on the object type.  Provided
4261e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// for convenience.  This will always iterate over the full set of
4262e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// protocols on a type, not just those provided directly.
4263c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  typedef ObjCObjectType::qual_iterator qual_iterator;
426414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff
426571842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek  qual_iterator qual_begin() const {
4266c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getObjectType()->qual_begin();
426771842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek  }
4268c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  qual_iterator qual_end() const {
4269c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getObjectType()->qual_end();
427071842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek  }
4271c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool qual_empty() const { return getObjectType()->qual_empty(); }
427214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff
4273e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// getNumProtocols - Return the number of qualifying protocols on
4274e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// the object type.
4275c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  unsigned getNumProtocols() const {
4276c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getObjectType()->getNumProtocols();
4277c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  }
427814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff
4279e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// \brief Retrieve a qualifying protocol by index on the object
4280e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// type.
428173dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor  ObjCProtocolDecl *getProtocol(unsigned I) const {
4282c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getObjectType()->getProtocol(I);
428373dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor  }
428473dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor
4285bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
4286bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
4287bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
4288e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  void Profile(llvm::FoldingSetNodeID &ID) {
4289e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall    Profile(ID, getPointeeType());
4290e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  }
4291c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  static void Profile(llvm::FoldingSetNodeID &ID, QualType T) {
4292c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    ID.AddPointer(T.getAsOpaquePtr());
4293c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  }
42941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
42951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == ObjCObjectPointer;
429614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  }
429714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  static bool classof(const ObjCObjectPointerType *) { return true; }
429814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff};
42991bb8a45f7386a23871598d05141a07af03067925Argyrios Kyrtzidis
43000953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// A qualifier set is used to build a set of qualifiers.
43010953e767ff7817f97b3ab20896b229891eeff45bJohn McCallclass QualifierCollector : public Qualifiers {
43020953e767ff7817f97b3ab20896b229891eeff45bJohn McCallpublic:
430349f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  QualifierCollector(Qualifiers Qs = Qualifiers()) : Qualifiers(Qs) {}
43040953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
43050953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// Collect any qualifiers on the given type and return an
43063b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  /// unqualified type.  The qualifiers are assumed to be consistent
43073b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  /// with those already in the type.
43083b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  const Type *strip(QualType type) {
43093b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    addFastQualifiers(type.getLocalFastQualifiers());
43103b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    if (!type.hasLocalNonFastQualifiers())
43113b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall      return type.getTypePtrUnsafe();
43123b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
43133b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    const ExtQuals *extQuals = type.getExtQualsUnsafe();
43143b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    addConsistentQualifiers(extQuals->getQualifiers());
43153b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    return extQuals->getBaseType();
43160953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
43170953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
43180953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// Apply the collected qualifiers to the given type.
43194ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  QualType apply(const ASTContext &Context, QualType QT) const;
43200953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
43210953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// Apply the collected qualifiers to the given type.
43224ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  QualType apply(const ASTContext &Context, const Type* T) const;
43230953e767ff7817f97b3ab20896b229891eeff45bJohn McCall};
43240953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
43250953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
4326611c1fff195d32df97706e0920c92468b2509900Chris Lattner// Inline function definitions.
43275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
43283b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallinline const Type *QualType::getTypePtr() const {
43293b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  return getCommonPtr()->BaseType;
43303b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall}
43313b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
43323b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallinline const Type *QualType::getTypePtrOrNull() const {
43333b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  return (isNull() ? 0 : getCommonPtr()->BaseType);
43343b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall}
43353b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
43363b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallinline SplitQualType QualType::split() const {
43373b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  if (!hasLocalNonFastQualifiers())
43383b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    return SplitQualType(getTypePtrUnsafe(),
43393b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall                         Qualifiers::fromFastMask(getLocalFastQualifiers()));
43403b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
43413b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  const ExtQuals *eq = getExtQualsUnsafe();
43423b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  Qualifiers qs = eq->getQualifiers();
43433b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  qs.addFastQualifiers(getLocalFastQualifiers());
43443b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  return SplitQualType(eq->getBaseType(), qs);
43453b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall}
43463b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
43473b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallinline Qualifiers QualType::getLocalQualifiers() const {
43483b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  Qualifiers Quals;
43493b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  if (hasLocalNonFastQualifiers())
43503b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    Quals = getExtQualsUnsafe()->getQualifiers();
43513b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  Quals.addFastQualifiers(getLocalFastQualifiers());
43523b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  return Quals;
43533b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall}
43543b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
43553b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallinline Qualifiers QualType::getQualifiers() const {
43563b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  Qualifiers quals = getCommonPtr()->CanonicalType.getLocalQualifiers();
43573b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  quals.addFastQualifiers(getLocalFastQualifiers());
43583b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  return quals;
43593b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall}
43603b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
43613b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallinline unsigned QualType::getCVRQualifiers() const {
43623b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  unsigned cvr = getCommonPtr()->CanonicalType.getLocalCVRQualifiers();
43633b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  cvr |= getLocalCVRQualifiers();
43643b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  return cvr;
43653b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall}
43663b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
43673b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallinline QualType QualType::getCanonicalType() const {
43683b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  QualType canon = getCommonPtr()->CanonicalType;
43693b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  return canon.withFastQualifiers(getLocalFastQualifiers());
43703b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall}
43713b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
4372467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCallinline bool QualType::isCanonical() const {
43733b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  return getTypePtr()->isCanonicalUnqualified();
4374467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall}
4375467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall
437654e14c4db764c0636160d26c5bbf491637c83a76John McCallinline bool QualType::isCanonicalAsParam() const {
43773b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  if (!isCanonical()) return false;
4378a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  if (hasLocalQualifiers()) return false;
4379745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian
438054e14c4db764c0636160d26c5bbf491637c83a76John McCall  const Type *T = getTypePtr();
43813b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  if (T->isVariablyModifiedType() && T->hasSizedVLAType())
43823b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    return false;
43833b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
43843b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  return !isa<FunctionType>(T) && !isa<ArrayType>(T);
438554e14c4db764c0636160d26c5bbf491637c83a76John McCall}
438654e14c4db764c0636160d26c5bbf491637c83a76John McCall
4387fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregorinline bool QualType::isConstQualified() const {
4388fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  return isLocalConstQualified() ||
43893b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall         getCommonPtr()->CanonicalType.isLocalConstQualified();
4390fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor}
4391fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor
4392fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregorinline bool QualType::isRestrictQualified() const {
4393fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  return isLocalRestrictQualified() ||
43943b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall         getCommonPtr()->CanonicalType.isLocalRestrictQualified();
4395fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor}
4396fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor
4397fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor
4398fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregorinline bool QualType::isVolatileQualified() const {
4399fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  return isLocalVolatileQualified() ||
44003b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall         getCommonPtr()->CanonicalType.isLocalVolatileQualified();
4401fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor}
4402fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor
4403fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregorinline bool QualType::hasQualifiers() const {
4404fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  return hasLocalQualifiers() ||
44053b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall         getCommonPtr()->CanonicalType.hasLocalQualifiers();
4406fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor}
440762c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall
440862c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCallinline QualType QualType::getUnqualifiedType() const {
440962c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  if (!getTypePtr()->getCanonicalTypeInternal().hasLocalQualifiers())
441062c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall    return QualType(getTypePtr(), 0);
441162c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall
441262c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  return QualType(getSplitUnqualifiedTypeImpl(*this).first, 0);
441362c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall}
441462c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall
441562c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCallinline SplitQualType QualType::getSplitUnqualifiedType() const {
441662c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  if (!getTypePtr()->getCanonicalTypeInternal().hasLocalQualifiers())
441762c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall    return split();
441862c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall
441962c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  return getSplitUnqualifiedTypeImpl(*this);
4420fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor}
4421fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor
442249f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCallinline void QualType::removeLocalConst() {
442349f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  removeLocalFastQualifiers(Qualifiers::Const);
44240953e767ff7817f97b3ab20896b229891eeff45bJohn McCall}
44250953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
442649f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCallinline void QualType::removeLocalRestrict() {
442749f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  removeLocalFastQualifiers(Qualifiers::Restrict);
44280953e767ff7817f97b3ab20896b229891eeff45bJohn McCall}
44290953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
443049f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCallinline void QualType::removeLocalVolatile() {
443149f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  removeLocalFastQualifiers(Qualifiers::Volatile);
44320953e767ff7817f97b3ab20896b229891eeff45bJohn McCall}
44330953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
443449f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCallinline void QualType::removeLocalCVRQualifiers(unsigned Mask) {
44356b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall  assert(!(Mask & ~Qualifiers::CVRMask) && "mask has non-CVR bits");
4436c3c0af36bac3d71f61dd758585ab307892545de4Douglas Gregor  assert((int)Qualifiers::CVRMask == (int)Qualifiers::FastMask);
44370953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
44380953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Fast path: we don't need to touch the slow qualifiers.
443949f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  removeLocalFastQualifiers(Mask);
4440ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb}
4441ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb
4442ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb/// getAddressSpace - Return the address space of this type.
4443ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lambinline unsigned QualType::getAddressSpace() const {
44443b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  return getQualifiers().getAddressSpace();
4445ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb}
4446611c1fff195d32df97706e0920c92468b2509900Chris Lattner
4447d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian/// getObjCGCAttr - Return the gc attribute of this type.
44480953e767ff7817f97b3ab20896b229891eeff45bJohn McCallinline Qualifiers::GC QualType::getObjCGCAttr() const {
44493b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  return getQualifiers().getObjCGCAttr();
4450d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian}
44512455636163fdd18581d7fdae816433f886d88213Mike Stump
4452264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindolainline FunctionType::ExtInfo getFunctionExtInfo(const Type &t) {
4453264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola  if (const PointerType *PT = t.getAs<PointerType>()) {
4454183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall    if (const FunctionType *FT = PT->getPointeeType()->getAs<FunctionType>())
4455264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola      return FT->getExtInfo();
4456264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola  } else if (const FunctionType *FT = t.getAs<FunctionType>())
4457264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    return FT->getExtInfo();
44582455636163fdd18581d7fdae816433f886d88213Mike Stump
4459264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola  return FunctionType::ExtInfo();
44602455636163fdd18581d7fdae816433f886d88213Mike Stump}
44611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4462264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindolainline FunctionType::ExtInfo getFunctionExtInfo(QualType t) {
4463264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola  return getFunctionExtInfo(*t);
4464ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor}
4465ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor
4466e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// isMoreQualifiedThan - Determine whether this type is more
4467e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// qualified than the Other type. For example, "const volatile int"
4468e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// is more qualified than "const int", "volatile int", and
4469e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// "int". However, it is not more qualified than "const volatile
4470e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// int".
447162c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCallinline bool QualType::isMoreQualifiedThan(QualType other) const {
447262c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  Qualifiers myQuals = getQualifiers();
447362c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  Qualifiers otherQuals = other.getQualifiers();
447462c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  return (myQuals != otherQuals && myQuals.compatiblyIncludes(otherQuals));
4475e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor}
4476e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor
4477e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// isAtLeastAsQualifiedAs - Determine whether this type is at last
4478e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// as qualified as the Other type. For example, "const volatile
4479e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// int" is at least as qualified as "const int", "volatile int",
4480e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// "int", and "const volatile int".
448162c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCallinline bool QualType::isAtLeastAsQualifiedAs(QualType other) const {
448262c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  return getQualifiers().compatiblyIncludes(other.getQualifiers());
4483e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor}
4484e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor
4485e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// getNonReferenceType - If Type is a reference type (e.g., const
4486e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// int&), returns the type that the reference refers to ("const
4487e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// int"). Otherwise, returns the type itself. This routine is used
4488e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// throughout Sema to implement C++ 5p6:
4489e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor///
4490e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor///   If an expression initially has the type "reference to T" (8.3.2,
4491e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor///   8.5.3), the type is adjusted to "T" prior to any further
4492e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor///   analysis, the expression designates the object or function
4493e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor///   denoted by the reference, and the expression is an lvalue.
4494e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregorinline QualType QualType::getNonReferenceType() const {
44956217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek  if (const ReferenceType *RefType = (*this)->getAs<ReferenceType>())
4496e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor    return RefType->getPointeeType();
4497e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor  else
4498e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor    return *this;
4499e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor}
4500e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor
45012b1ad8b42bbbe00a1845e566f52f1941b8dbc725Douglas Gregorinline bool QualType::isCForbiddenLValueType() const {
45022b1ad8b42bbbe00a1845e566f52f1941b8dbc725Douglas Gregor  return ((getTypePtr()->isVoidType() && !hasQualifiers()) ||
45032b1ad8b42bbbe00a1845e566f52f1941b8dbc725Douglas Gregor          getTypePtr()->isFunctionType());
45042b1ad8b42bbbe00a1845e566f52f1941b8dbc725Douglas Gregor}
45052b1ad8b42bbbe00a1845e566f52f1941b8dbc725Douglas Gregor
4506aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth/// \brief Tests whether the type is categorized as a fundamental type.
4507aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth///
4508aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth/// \returns True for types specified in C++0x [basic.fundamental].
4509aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruthinline bool Type::isFundamentalType() const {
4510aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth  return isVoidType() ||
4511aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth         // FIXME: It's really annoying that we don't have an
4512aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth         // 'isArithmeticType()' which agrees with the standard definition.
4513aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth         (isArithmeticType() && !isEnumeralType());
4514aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth}
4515aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth
4516aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth/// \brief Tests whether the type is categorized as a compound type.
4517aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth///
4518aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth/// \returns True for types specified in C++0x [basic.compound].
4519aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruthinline bool Type::isCompoundType() const {
4520aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth  // C++0x [basic.compound]p1:
4521aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth  //   Compound types can be constructed in the following ways:
4522aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth  //    -- arrays of objects of a given type [...];
4523aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth  return isArrayType() ||
4524aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth  //    -- functions, which have parameters of given types [...];
4525aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth         isFunctionType() ||
4526aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth  //    -- pointers to void or objects or functions [...];
4527aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth         isPointerType() ||
4528aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth  //    -- references to objects or functions of a given type. [...]
4529aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth         isReferenceType() ||
4530aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth  //    -- classes containing a sequence of objects of various types, [...];
4531aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth         isRecordType() ||
4532aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth  //    -- unions, which ar classes capable of containing objects of different types at different times;
4533aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth         isUnionType() ||
4534aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth  //    -- enumerations, which comprise a set of named constant values. [...];
4535aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth         isEnumeralType() ||
4536aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth  //    -- pointers to non-static class members, [...].
4537aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth         isMemberPointerType();
4538aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth}
4539aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth
4540611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isFunctionType() const {
4541a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<FunctionType>(CanonicalType);
4542611c1fff195d32df97706e0920c92468b2509900Chris Lattner}
4543611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isPointerType() const {
4544a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<PointerType>(CanonicalType);
4545611c1fff195d32df97706e0920c92468b2509900Chris Lattner}
454658f9f2c884af6b72d036b746a016d8031d31cb7aSteve Naroffinline bool Type::isAnyPointerType() const {
454758f9f2c884af6b72d036b746a016d8031d31cb7aSteve Naroff  return isPointerType() || isObjCObjectPointerType();
454858f9f2c884af6b72d036b746a016d8031d31cb7aSteve Naroff}
45495618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroffinline bool Type::isBlockPointerType() const {
4550a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<BlockPointerType>(CanonicalType);
45515618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff}
4552bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattnerinline bool Type::isReferenceType() const {
4553a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<ReferenceType>(CanonicalType);
4554bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner}
45557c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlinline bool Type::isLValueReferenceType() const {
4556a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<LValueReferenceType>(CanonicalType);
45577c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl}
45587c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlinline bool Type::isRValueReferenceType() const {
4559a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<RValueReferenceType>(CanonicalType);
45607c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl}
4561498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenekinline bool Type::isFunctionPointerType() const {
4562d0370f59e79702ac908c81bf556519f91e9ca297John McCall  if (const PointerType *T = getAs<PointerType>())
4563498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek    return T->getPointeeType()->isFunctionType();
4564498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek  else
4565498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek    return false;
4566498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek}
4567f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlinline bool Type::isMemberPointerType() const {
4568a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<MemberPointerType>(CanonicalType);
4569f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl}
4570f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlinline bool Type::isMemberFunctionPointerType() const {
45716217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek  if (const MemberPointerType* T = getAs<MemberPointerType>())
45720bab0cdab751248ca389a5592bcb70eac5d39260John McCall    return T->isMemberFunctionPointer();
4573f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  else
4574f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    return false;
4575f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl}
4576db68e28c05a67735211e688009890cf834c22e75Douglas Gregorinline bool Type::isMemberDataPointerType() const {
4577db68e28c05a67735211e688009890cf834c22e75Douglas Gregor  if (const MemberPointerType* T = getAs<MemberPointerType>())
45780bab0cdab751248ca389a5592bcb70eac5d39260John McCall    return T->isMemberDataPointer();
4579db68e28c05a67735211e688009890cf834c22e75Douglas Gregor  else
4580db68e28c05a67735211e688009890cf834c22e75Douglas Gregor    return false;
4581db68e28c05a67735211e688009890cf834c22e75Douglas Gregor}
4582611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isArrayType() const {
4583a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<ArrayType>(CanonicalType);
4584611c1fff195d32df97706e0920c92468b2509900Chris Lattner}
4585c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattnerinline bool Type::isConstantArrayType() const {
4586a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<ConstantArrayType>(CanonicalType);
4587c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner}
4588c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattnerinline bool Type::isIncompleteArrayType() const {
4589a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<IncompleteArrayType>(CanonicalType);
4590c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner}
4591c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattnerinline bool Type::isVariableArrayType() const {
4592a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<VariableArrayType>(CanonicalType);
4593c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner}
4594898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorinline bool Type::isDependentSizedArrayType() const {
4595a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<DependentSizedArrayType>(CanonicalType);
4596898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor}
45973ff83dd534ccc828203670ce3f5125a4eb4199f8John McCallinline bool Type::isBuiltinType() const {
45983ff83dd534ccc828203670ce3f5125a4eb4199f8John McCall  return isa<BuiltinType>(CanonicalType);
45993ff83dd534ccc828203670ce3f5125a4eb4199f8John McCall}
4600611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isRecordType() const {
4601a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<RecordType>(CanonicalType);
4602611c1fff195d32df97706e0920c92468b2509900Chris Lattner}
46033ff83dd534ccc828203670ce3f5125a4eb4199f8John McCallinline bool Type::isEnumeralType() const {
46043ff83dd534ccc828203670ce3f5125a4eb4199f8John McCall  return isa<EnumType>(CanonicalType);
46053ff83dd534ccc828203670ce3f5125a4eb4199f8John McCall}
4606f23d364084d1aabea688222780d6fc1dd8c7f78cChris Lattnerinline bool Type::isAnyComplexType() const {
4607a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<ComplexType>(CanonicalType);
4608f23d364084d1aabea688222780d6fc1dd8c7f78cChris Lattner}
4609611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isVectorType() const {
4610a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<VectorType>(CanonicalType);
4611611c1fff195d32df97706e0920c92468b2509900Chris Lattner}
4612213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begemaninline bool Type::isExtVectorType() const {
4613a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<ExtVectorType>(CanonicalType);
4614611c1fff195d32df97706e0920c92468b2509900Chris Lattner}
4615d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroffinline bool Type::isObjCObjectPointerType() const {
4616a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<ObjCObjectPointerType>(CanonicalType);
4617d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff}
4618c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallinline bool Type::isObjCObjectType() const {
4619c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  return isa<ObjCObjectType>(CanonicalType);
4620368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner}
4621569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregorinline bool Type::isObjCObjectOrInterfaceType() const {
4622569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor  return isa<ObjCInterfaceType>(CanonicalType) ||
4623569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor    isa<ObjCObjectType>(CanonicalType);
4624569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor}
4625569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor
4626a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekinline bool Type::isObjCQualifiedIdType() const {
4627183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>())
4628d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff    return OPT->isObjCQualifiedIdType();
4629d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff  return false;
4630d58fabf7ed279be18a5e82617f809c9deff9be67Fariborz Jahanian}
4631470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroffinline bool Type::isObjCQualifiedClassType() const {
4632183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>())
4633470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroff    return OPT->isObjCQualifiedClassType();
4634470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroff  return false;
4635470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroff}
463614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroffinline bool Type::isObjCIdType() const {
4637183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>())
463814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff    return OPT->isObjCIdType();
463914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  return false;
464014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff}
464114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroffinline bool Type::isObjCClassType() const {
4642183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>())
464314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff    return OPT->isObjCClassType();
464414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  return false;
464514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff}
464613dcd00615de5c4279d97bdf63cd5f0a14fd9dccFariborz Jahanianinline bool Type::isObjCSelType() const {
46478d2c0a9814e56c2b22e22d1045181c735aef62fdFariborz Jahanian  if (const PointerType *OPT = getAs<PointerType>())
46488d2c0a9814e56c2b22e22d1045181c735aef62fdFariborz Jahanian    return OPT->getPointeeType()->isSpecificBuiltinType(BuiltinType::ObjCSel);
464913dcd00615de5c4279d97bdf63cd5f0a14fd9dccFariborz Jahanian  return false;
465013dcd00615de5c4279d97bdf63cd5f0a14fd9dccFariborz Jahanian}
4651de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroffinline bool Type::isObjCBuiltinType() const {
465213dcd00615de5c4279d97bdf63cd5f0a14fd9dccFariborz Jahanian  return isObjCIdType() || isObjCClassType() || isObjCSelType();
4653de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff}
465472c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregorinline bool Type::isTemplateTypeParmType() const {
4655a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<TemplateTypeParmType>(CanonicalType);
465672c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor}
465772c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor
4658e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbarinline bool Type::isSpecificBuiltinType(unsigned K) const {
4659183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  if (const BuiltinType *BT = getAs<BuiltinType>())
4660e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar    if (BT->getKind() == (BuiltinType::Kind) K)
4661e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar      return true;
4662e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar  return false;
4663e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar}
4664e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar
46652a984cad5ac3fdceeff2bd99daa7b90979313475John McCallinline bool Type::isPlaceholderType() const {
46662a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  if (const BuiltinType *BT = getAs<BuiltinType>())
46672a984cad5ac3fdceeff2bd99daa7b90979313475John McCall    return BT->isPlaceholderType();
46682a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  return false;
46692a984cad5ac3fdceeff2bd99daa7b90979313475John McCall}
46702a984cad5ac3fdceeff2bd99daa7b90979313475John McCall
4671864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCallinline bool Type::isSpecificPlaceholderType(unsigned K) const {
4672864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall  if (const BuiltinType *BT = dyn_cast<BuiltinType>(this))
4673864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall    return (BT->getKind() == (BuiltinType::Kind) K);
4674864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall  return false;
4675864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall}
4676864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall
4677063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor/// \brief Determines whether this is a type for which one can define
4678063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor/// an overloaded operator.
4679063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregorinline bool Type::isOverloadableType() const {
4680063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  return isDependentType() || isRecordType() || isEnumeralType();
4681904eed3f6148758d39a2d3c88f3133274460d645Douglas Gregor}
4682904eed3f6148758d39a2d3c88f3133274460d645Douglas Gregor
4683bc8d7f9fd4346cfcc285868be32b74e019a40f01Chandler Carruth/// \brief Determines whether this type can decay to a pointer type.
4684bc8d7f9fd4346cfcc285868be32b74e019a40f01Chandler Carruthinline bool Type::canDecayToPointerType() const {
4685bc8d7f9fd4346cfcc285868be32b74e019a40f01Chandler Carruth  return isFunctionType() || isArrayType();
4686bc8d7f9fd4346cfcc285868be32b74e019a40f01Chandler Carruth}
4687bc8d7f9fd4346cfcc285868be32b74e019a40f01Chandler Carruth
46888958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbarinline bool Type::hasPointerRepresentation() const {
46898958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar  return (isPointerType() || isReferenceType() || isBlockPointerType() ||
4690c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall          isObjCObjectPointerType() || isNullPtrType());
46918958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar}
46928958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar
4693820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanianinline bool Type::hasObjCPointerRepresentation() const {
4694c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  return isObjCObjectPointerType();
4695820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian}
4696820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian
4697d0370f59e79702ac908c81bf556519f91e9ca297John McCallinline const Type *Type::getBaseElementTypeUnsafe() const {
4698d0370f59e79702ac908c81bf556519f91e9ca297John McCall  const Type *type = this;
4699d0370f59e79702ac908c81bf556519f91e9ca297John McCall  while (const ArrayType *arrayType = type->getAsArrayTypeUnsafe())
4700d0370f59e79702ac908c81bf556519f91e9ca297John McCall    type = arrayType->getElementType().getTypePtr();
4701d0370f59e79702ac908c81bf556519f91e9ca297John McCall  return type;
4702d0370f59e79702ac908c81bf556519f91e9ca297John McCall}
4703d0370f59e79702ac908c81bf556519f91e9ca297John McCall
470422caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner/// Insertion operator for diagnostics.  This allows sending QualType's into a
470522caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner/// diagnostic with <<.
470622caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattnerinline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
470722caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner                                           QualType T) {
470822caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner  DB.AddTaggedVal(reinterpret_cast<intptr_t>(T.getAsOpaquePtr()),
470922caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner                  Diagnostic::ak_qualtype);
471022caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner  return DB;
471122caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner}
47121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
471347c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth/// Insertion operator for partial diagnostics.  This allows sending QualType's
471447c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth/// into a diagnostic with <<.
471547c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruthinline const PartialDiagnostic &operator<<(const PartialDiagnostic &PD,
471647c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth                                           QualType T) {
471747c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth  PD.AddTaggedVal(reinterpret_cast<intptr_t>(T.getAsOpaquePtr()),
471847c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth                  Diagnostic::ak_qualtype);
471947c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth  return PD;
472047c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth}
472147c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth
472289c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor// Helper class template that is used by Type::getAs to ensure that one does
472389c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor// not try to look through a qualified type to get to an array type.
472489c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregortemplate<typename T,
472589c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor         bool isArrayType = (llvm::is_same<T, ArrayType>::value ||
472689c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor                             llvm::is_base_of<ArrayType, T>::value)>
472789c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregorstruct ArrayType_cannot_be_used_with_getAs { };
472889c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor
472989c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregortemplate<typename T>
473089c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregorstruct ArrayType_cannot_be_used_with_getAs<T, true>;
473189c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor
47321a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek/// Member-template getAs<specific type>'.
47331a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenektemplate <typename T> const T *Type::getAs() const {
473489c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor  ArrayType_cannot_be_used_with_getAs<T> at;
473589c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor  (void)at;
473689c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor
47371a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek  // If this is directly a T type, return it.
47381a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek  if (const T *Ty = dyn_cast<T>(this))
47391a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek    return Ty;
47401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
47411a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek  // If the canonical form of this type isn't the right kind, reject it.
47420953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  if (!isa<T>(CanonicalType))
47431a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek    return 0;
47441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
47450953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // If this is a typedef for the type, strip the typedef off without
47461a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek  // losing all typedef information.
4747bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  return cast<T>(getUnqualifiedDesugaredType());
47481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump}
474922caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner
47503b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallinline const ArrayType *Type::getAsArrayTypeUnsafe() const {
47513b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  // If this is directly an array type, return it.
47523b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  if (const ArrayType *arr = dyn_cast<ArrayType>(this))
47533b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    return arr;
47543b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
47553b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  // If the canonical form of this type isn't the right kind, reject it.
47563b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  if (!isa<ArrayType>(CanonicalType))
47573b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    return 0;
47583b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
47593b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  // If this is a typedef for the type, strip the typedef off without
47603b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  // losing all typedef information.
47613b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  return cast<ArrayType>(getUnqualifiedDesugaredType());
47623b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall}
47633b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
4764d0370f59e79702ac908c81bf556519f91e9ca297John McCalltemplate <typename T> const T *Type::castAs() const {
4765d0370f59e79702ac908c81bf556519f91e9ca297John McCall  ArrayType_cannot_be_used_with_getAs<T> at;
4766d0370f59e79702ac908c81bf556519f91e9ca297John McCall  (void) at;
4767d0370f59e79702ac908c81bf556519f91e9ca297John McCall
4768d0370f59e79702ac908c81bf556519f91e9ca297John McCall  assert(isa<T>(CanonicalType));
4769d0370f59e79702ac908c81bf556519f91e9ca297John McCall  if (const T *ty = dyn_cast<T>(this)) return ty;
4770d0370f59e79702ac908c81bf556519f91e9ca297John McCall  return cast<T>(getUnqualifiedDesugaredType());
4771d0370f59e79702ac908c81bf556519f91e9ca297John McCall}
4772d0370f59e79702ac908c81bf556519f91e9ca297John McCall
4773d0370f59e79702ac908c81bf556519f91e9ca297John McCallinline const ArrayType *Type::castAsArrayTypeUnsafe() const {
4774d0370f59e79702ac908c81bf556519f91e9ca297John McCall  assert(isa<ArrayType>(CanonicalType));
4775d0370f59e79702ac908c81bf556519f91e9ca297John McCall  if (const ArrayType *arr = dyn_cast<ArrayType>(this)) return arr;
4776d0370f59e79702ac908c81bf556519f91e9ca297John McCall  return cast<ArrayType>(getUnqualifiedDesugaredType());
4777d0370f59e79702ac908c81bf556519f91e9ca297John McCall}
4778d0370f59e79702ac908c81bf556519f91e9ca297John McCall
47795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}  // end namespace clang
47805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
47815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif
4782